Skip to content

Commit

Permalink
Merge pull request #32252 from lawnjelly/skin-fix
Browse files Browse the repository at this point in the history
Fix GLES2 skinning where VERTEX_TEXTURE not supported
  • Loading branch information
akien-mga committed Sep 22, 2019
2 parents 2e065d8 + f5365aa commit 6149ed0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions drivers/gles2/rasterizer_scene_gles2.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions drivers/gles2/rasterizer_storage_gles2.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions drivers/gles2/rasterizer_storage_gles2.h
Expand Up @@ -60,7 +60,9 @@ class RasterizerStorageGLES2 : public RasterizerStorage {

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;

Expand Down

0 comments on commit 6149ed0

Please sign in to comment.