Fix GLES2 skinning where VERTEX_TEXTURE not supported

Although the backup USE_SKELETON_SOFTWARE skinning path is currently used when float texture is not supported, the default skinning path still fails when float texture is supported but GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS is 0, i.e. the device cannot read from texture during vertex shader. This PR adds the logic to activate the SKELETON_SOFTWARE path if either of these cases occur, preventing crashes on devices which have this combination of features.
This commit is contained in:
lawnjelly 2019-09-20 09:45:51 +01:00
parent 2add51d082
commit f5365aa0e1
3 changed files with 13 additions and 6 deletions

View file

@ -1432,11 +1432,11 @@ void RasterizerSceneGLES2::_setup_geometry(RenderList::Element *p_element, Raste
}
}
bool clear_skeleton_buffer = !storage->config.float_texture_supported;
bool clear_skeleton_buffer = storage->config.use_skeleton_software;
if (p_skeleton) {
if (storage->config.float_texture_supported) {
if (!storage->config.use_skeleton_software) {
//use float texture workflow
glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1);
glBindTexture(GL_TEXTURE_2D, p_skeleton->tex_id);
@ -2452,7 +2452,7 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
if (skeleton) {
state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON, true);
state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON_SOFTWARE, !storage->config.float_texture_supported);
state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON_SOFTWARE, storage->config.use_skeleton_software);
} else {
state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON, false);
state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON_SOFTWARE, false);

View file

@ -2432,7 +2432,7 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS:
// from surface->data.
// if USE_SKELETON_SOFTWARE is active
if (!config.float_texture_supported) {
if (config.use_skeleton_software) {
// if this geometry is used specifically for skinning
if (p_format & (VS::ARRAY_FORMAT_BONES | VS::ARRAY_FORMAT_WEIGHTS))
surface->data = array;
@ -3514,7 +3514,7 @@ void RasterizerStorageGLES2::skeleton_allocate(RID p_skeleton, int p_bones, bool
skeleton->size = p_bones;
skeleton->use_2d = p_2d_skeleton;
if (config.float_texture_supported) {
if (!config.use_skeleton_software) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, skeleton->tex_id);
@ -3699,7 +3699,7 @@ void RasterizerStorageGLES2::_update_skeleton_transform_buffer(const PoolVector<
void RasterizerStorageGLES2::update_dirty_skeletons() {
if (!config.float_texture_supported)
if (config.use_skeleton_software)
return;
glActiveTexture(GL_TEXTURE0);
@ -5751,9 +5751,14 @@ void RasterizerStorageGLES2::initialize() {
frame.current_rt = NULL;
frame.clear_request = false;
glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &config.max_vertex_texture_image_units);
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &config.max_texture_image_units);
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &config.max_texture_size);
// the use skeleton software path should be used if either float texture is not supported,
// OR max_vertex_texture_image_units is zero
config.use_skeleton_software = (config.float_texture_supported == false) || (config.max_vertex_texture_image_units == 0);
shaders.copy.init();
shaders.cubemap_filter.init();
bool ggx_hq = GLOBAL_GET("rendering/quality/reflections/high_quality_ggx");

View file

@ -60,7 +60,9 @@ public:
bool shrink_textures_x2;
bool use_fast_texture_filter;
bool use_skeleton_software;
int max_vertex_texture_image_units;
int max_texture_image_units;
int max_texture_size;