@@ -844,6 +844,23 @@ struct PointsDrawCallback : public virtual osg::Drawable::DrawCallback
844844 const float scale_radius_combined = s.scale_radius * s.scale_element ;
845845 const float scale_proj_pass = opencover::cover->getScale () * static_cast <float >(vpHeight) * 0 .5f * projection_matrix.data_array [5 ];
846846
847+ const auto bindTexture2DToUnit = [](GLuint unit, GLuint texture) {
848+ #if defined(GL_VERSION_4_5)
849+ if (GLEW_VERSION_4_5 ) {
850+ glBindTextureUnit (unit, texture);
851+ return ;
852+ }
853+ #endif
854+ #if defined(GL_ARB_direct_state_access)
855+ if (GLEW_ARB_direct_state_access) {
856+ glBindTextureUnit (unit, texture);
857+ return ;
858+ }
859+ #endif
860+ glActiveTexture (GL_TEXTURE0 + unit);
861+ glBindTexture (GL_TEXTURE_2D , texture);
862+ };
863+
847864 // --- PASS 1: Depth pre-pass (depth-only, kreisförmiges discard im FS)
848865 glBindFramebuffer (GL_FRAMEBUFFER , target.fbo );
849866 glViewport (0 , 0 , vpWidth, vpHeight);
@@ -918,10 +935,7 @@ struct PointsDrawCallback : public virtual osg::Drawable::DrawCallback
918935 glViewport (0 , 0 , vpWidth, vpHeight);
919936
920937 // Tiefe aus Pass 1
921- glActiveTexture (GL_TEXTURE0 );
922- glBindTexture (GL_TEXTURE_2D , target.depth_texture );
923- if (_renderer->getSurfelPass2Shader ().depth_texture_loc >= 0 )
924- glUniform1i (_renderer->getSurfelPass2Shader ().depth_texture_loc , 0 );
938+ bindTexture2DToUnit (0 , target.depth_texture );
925939
926940 // Globale Uniforms für VS/GS/FS
927941 if (_renderer->getSurfelPass2Shader ().viewport_loc >= 0 ) glUniform2f (_renderer->getSurfelPass2Shader ().viewport_loc , viewport.x , viewport.y );
@@ -994,25 +1008,10 @@ struct PointsDrawCallback : public virtual osg::Drawable::DrawCallback
9941008 glUseProgram (_renderer->getSurfelPass3Shader ().program );
9951009
9961010 // G-Buffer
997- glActiveTexture (GL_TEXTURE0 );
998- glBindTexture (GL_TEXTURE_2D , target.texture_color );
999- if (_renderer->getSurfelPass3Shader ().in_color_texture_loc >= 0 )
1000- glUniform1i (_renderer->getSurfelPass3Shader ().in_color_texture_loc , 0 );
1001-
1002- glActiveTexture (GL_TEXTURE1 );
1003- glBindTexture (GL_TEXTURE_2D , target.texture_normal );
1004- if (_renderer->getSurfelPass3Shader ().in_normal_texture_loc >= 0 )
1005- glUniform1i (_renderer->getSurfelPass3Shader ().in_normal_texture_loc , 1 );
1006-
1007- glActiveTexture (GL_TEXTURE2 );
1008- glBindTexture (GL_TEXTURE_2D , target.texture_position );
1009- if (_renderer->getSurfelPass3Shader ().in_vs_position_texture_loc >= 0 )
1010- glUniform1i (_renderer->getSurfelPass3Shader ().in_vs_position_texture_loc , 2 );
1011-
1012- glActiveTexture (GL_TEXTURE3 );
1013- glBindTexture (GL_TEXTURE_2D , target.depth_texture );
1014- if (_renderer->getSurfelPass3Shader ().in_depth_texture_loc >= 0 )
1015- glUniform1i (_renderer->getSurfelPass3Shader ().in_depth_texture_loc , 3 );
1011+ bindTexture2DToUnit (0 , target.texture_color );
1012+ bindTexture2DToUnit (1 , target.texture_normal );
1013+ bindTexture2DToUnit (2 , target.texture_position );
1014+ bindTexture2DToUnit (3 , target.depth_texture );
10161015
10171016 // View-space lighting Setup
10181017 scm::math::mat4 viewMat = view_matrix;
0 commit comments