From 3a2048e44af94f213a66a1c6591a306ac41cc7ff Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 17 Nov 2020 21:01:56 +0100 Subject: [PATCH] glgsg: Fix skinning shader being unable to render unskinned models Panda was adding a column with weights (0, 0, 0, 0), but these weights don't add up to 1 so no useful identity matrix can be produced. Instead it's better to fall back to the OpenGL default, (0, 0, 0, 1). I'm also defaulting the transform_index values to (0, 1, 2, 3) to support non-indexed skinning (although that's pretty esoteric, given that that only supports 4 transforms...) --- panda/src/display/standardMunger.cxx | 5 +++-- panda/src/glstuff/glGraphicsStateGuardian_src.cxx | 11 +++++++++++ panda/src/glstuff/glGraphicsStateGuardian_src.h | 2 ++ panda/src/glstuff/glShaderContext_src.cxx | 4 ++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/panda/src/display/standardMunger.cxx b/panda/src/display/standardMunger.cxx index 2dba4aa6c0..10b66762a9 100644 --- a/panda/src/display/standardMunger.cxx +++ b/panda/src/display/standardMunger.cxx @@ -123,8 +123,9 @@ munge_data_impl(const GeomVertexData *data) { } GeomVertexAnimationSpec animation = new_data->get_format()->get_animation(); - if (_shader_skinning || (_auto_shader && hardware_animated_vertices && - !basic_shaders_only && animation.get_animation_type() == AT_panda)) { + if ((_shader_skinning && animation.get_animation_type() != AT_none) || + (_auto_shader && hardware_animated_vertices && + !basic_shaders_only && animation.get_animation_type() == AT_panda)) { animation.set_hardware(4, true); } else if (hardware_animated_vertices && diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 9083c31acc..dd3e2e25b4 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -1909,6 +1909,8 @@ reset() { get_extension_func("glUniform3uiv"); _glUniform4uiv = (PFNGLUNIFORM4UIVPROC) get_extension_func("glUniform4uiv"); + _glVertexAttribI4ui = (PFNGLVERTEXATTRIBI4UIPROC) + get_extension_func("glVertexAttribI4ui"); } else if (has_extension("GL_EXT_gpu_shader4")) { _glBindFragDataLocation = (PFNGLBINDFRAGDATALOCATIONPROC) @@ -1923,10 +1925,13 @@ reset() { get_extension_func("glUniform3uivEXT"); _glUniform4uiv = (PFNGLUNIFORM4UIVPROC) get_extension_func("glUniform4uivEXT"); + _glVertexAttribI4ui = (PFNGLVERTEXATTRIBI4UIPROC) + get_extension_func("glVertexAttribI4uiEXT"); } else { _glBindFragDataLocation = nullptr; _glVertexAttribIPointer = nullptr; + _glVertexAttribI4ui = nullptr; } if (is_at_least_gl_version(4, 1) || has_extension("GL_ARB_vertex_attrib_64bit")) { @@ -1955,8 +1960,11 @@ reset() { get_extension_func("glVertexAttribPointerARB"); _glBindFragDataLocation = nullptr; + _glVertexAttribI4ui = nullptr; _glVertexAttribIPointer = nullptr; _glVertexAttribLPointer = nullptr; + } else { + _glVertexAttribI4ui = nullptr; } #endif @@ -2003,8 +2011,11 @@ reset() { if (is_at_least_gles_version(3, 0)) { _glVertexAttribIPointer = (PFNGLVERTEXATTRIBIPOINTERPROC) get_extension_func("glVertexAttribIPointer"); + _glVertexAttribI4ui = (PFNGLVERTEXATTRIBI4UIPROC) + get_extension_func("glVertexAttribI4ui"); } else { _glVertexAttribIPointer = nullptr; + _glVertexAttribI4ui = nullptr; } if (has_extension("GL_EXT_blend_func_extended")) { diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.h b/panda/src/glstuff/glGraphicsStateGuardian_src.h index 1b5a1cdfb4..4fa16e067e 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.h +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.h @@ -186,6 +186,7 @@ typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei coun typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPROC) (GLuint program); typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat *v); typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); @@ -1010,6 +1011,7 @@ public: PFNGLVALIDATEPROGRAMPROC _glValidateProgram; PFNGLVERTEXATTRIB4FVPROC _glVertexAttrib4fv; PFNGLVERTEXATTRIB4DVPROC _glVertexAttrib4dv; + PFNGLVERTEXATTRIBI4UIPROC _glVertexAttribI4ui; PFNGLVERTEXATTRIBPOINTERPROC _glVertexAttribPointer; PFNGLVERTEXATTRIBIPOINTERPROC _glVertexAttribIPointer; PFNGLVERTEXATTRIBLPOINTERPROC _glVertexAttribLPointer; diff --git a/panda/src/glstuff/glShaderContext_src.cxx b/panda/src/glstuff/glShaderContext_src.cxx index 9dd82c1cdf..28429941c4 100644 --- a/panda/src/glstuff/glShaderContext_src.cxx +++ b/panda/src/glstuff/glShaderContext_src.cxx @@ -2529,6 +2529,10 @@ update_shader_vertex_arrays(ShaderContext *prev, bool force) { _glgsg->_glVertexAttrib4fv(p, _glgsg->_scene_graph_color.get_data()); #endif } + else if (name == InternalName::get_transform_index() && + _glgsg->_glVertexAttribI4ui != nullptr) { + _glgsg->_glVertexAttribI4ui(p, 0, 1, 2, 3); + } } }