diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 5f5f90abc1..74d9f208b3 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -2150,6 +2150,8 @@ reset() { get_extension_func("glGetProgramResourceName"); _glGetProgramResourceiv = (PFNGLGETPROGRAMRESOURCEIVPROC) get_extension_func("glGetProgramResourceiv"); + _glShaderStorageBlockBinding = (PFNGLSHADERSTORAGEBLOCKBINDINGPROC) + get_extension_func("glShaderStorageBlockBinding"); } else #endif { diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.h b/panda/src/glstuff/glGraphicsStateGuardian_src.h index b7aa02c08e..83f2721fa3 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.h +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.h @@ -1073,6 +1073,7 @@ public: PFNGLGETPROGRAMINTERFACEIVPROC _glGetProgramInterfaceiv; PFNGLGETPROGRAMRESOURCENAMEPROC _glGetProgramResourceName; PFNGLGETPROGRAMRESOURCEIVPROC _glGetProgramResourceiv; + PFNGLSHADERSTORAGEBLOCKBINDINGPROC _glShaderStorageBlockBinding; #endif // !OPENGLES GLenum _edge_clamp; diff --git a/panda/src/glstuff/glShaderContext_src.cxx b/panda/src/glstuff/glShaderContext_src.cxx index 33eb7256b2..38461838f6 100644 --- a/panda/src/glstuff/glShaderContext_src.cxx +++ b/panda/src/glstuff/glShaderContext_src.cxx @@ -339,6 +339,8 @@ CLP(ShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderContext block_maxlength = max(64, block_maxlength); char *block_name_cstr = (char *)alloca(block_maxlength); + BitArray bindings; + for (int i = 0; i < block_count; ++i) { block_name_cstr[0] = 0; _glgsg->_glGetProgramResourceName(_glsl_program, GL_SHADER_STORAGE_BLOCK, i, block_maxlength, nullptr, block_name_cstr); @@ -347,6 +349,20 @@ CLP(ShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderContext GLint values[2]; _glgsg->_glGetProgramResourceiv(_glsl_program, GL_SHADER_STORAGE_BLOCK, i, 2, props, 2, nullptr, values); + if (bindings.get_bit(values[0])) { + // Binding index already in use, assign a different one. + values[0] = bindings.get_lowest_off_bit(); + _glgsg->_glShaderStorageBlockBinding(_glsl_program, i, values[0]); + } + bindings.set_bit(values[0]); + + if (GLCAT.is_debug()) { + GLCAT.debug() + << "Active shader storage block " << block_name_cstr + << " with size " << values[1] << " is bound to binding " + << values[0] << "\n"; + } + StorageBlock block; block._name = InternalName::make(block_name_cstr); block._binding_index = values[0]; diff --git a/panda/src/pgui/pgTop.I b/panda/src/pgui/pgTop.I index 775e8cf827..24823b577b 100644 --- a/panda/src/pgui/pgTop.I +++ b/panda/src/pgui/pgTop.I @@ -74,6 +74,7 @@ get_start_sort() const { */ INLINE void PGTop:: add_region(MouseWatcherRegion *region) { - nassertv(_watcher_group != nullptr); - _watcher_group->add_region(region); + if (_watcher_group != nullptr) { + _watcher_group->add_region(region); + } }