@@ -1576,7 +1576,8 @@ void opengl_setup_scene_textures()
15761576
15771577 // create framebuffer
15781578 glGenFramebuffers (1 , &Scene_framebuffer);
1579- glBindFramebuffer (GL_FRAMEBUFFER, Scene_framebuffer);
1579+ GL_state.BindFrameBuffer (Scene_framebuffer);
1580+ opengl_set_object_label (GL_FRAMEBUFFER, Scene_framebuffer, " Scene framebuffer" );
15801581
15811582 // setup main render texture
15821583
@@ -1596,6 +1597,7 @@ void opengl_setup_scene_textures()
15961597 glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGBA16F, Scene_texture_width, Scene_texture_height, 0 , GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL );
15971598
15981599 glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, Scene_color_texture, 0 );
1600+ opengl_set_object_label (GL_TEXTURE, Scene_color_texture, " Scene color texture" );
15991601
16001602 // setup low dynamic range color texture
16011603 glGenTextures (1 , &Scene_ldr_texture);
@@ -1611,6 +1613,7 @@ void opengl_setup_scene_textures()
16111613 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
16121614
16131615 glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGBA8, Scene_texture_width, Scene_texture_height, 0 , GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL );
1616+ opengl_set_object_label (GL_TEXTURE, Scene_ldr_texture, " Scene LDR texture" );
16141617
16151618 // setup position render texture
16161619 glGenTextures (1 , &Scene_position_texture);
@@ -1626,6 +1629,7 @@ void opengl_setup_scene_textures()
16261629 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
16271630
16281631 glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGBA16F, Scene_texture_width, Scene_texture_height, 0 , GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL );
1632+ opengl_set_object_label (GL_TEXTURE, Scene_position_texture, " Scene Position texture" );
16291633
16301634 glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, Scene_position_texture, 0 );
16311635
@@ -1643,6 +1647,7 @@ void opengl_setup_scene_textures()
16431647 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
16441648
16451649 glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGBA16F, Scene_texture_width, Scene_texture_height, 0 , GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL );
1650+ opengl_set_object_label (GL_TEXTURE, Scene_normal_texture, " Scene Normal texture" );
16461651
16471652 glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, Scene_normal_texture, 0 );
16481653
@@ -1660,6 +1665,7 @@ void opengl_setup_scene_textures()
16601665 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
16611666
16621667 glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGBA8, Scene_texture_width, Scene_texture_height, 0 , GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL );
1668+ opengl_set_object_label (GL_TEXTURE, Scene_specular_texture, " Scene Specular texture" );
16631669
16641670 glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, Scene_specular_texture, 0 );
16651671
@@ -1678,6 +1684,7 @@ void opengl_setup_scene_textures()
16781684 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
16791685
16801686 glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGBA16F, Scene_texture_width, Scene_texture_height, 0 , GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL );
1687+ opengl_set_object_label (GL_TEXTURE, Scene_luminance_texture, " Scene Luminance texture" );
16811688
16821689 // setup effect texture
16831690
@@ -1694,6 +1701,7 @@ void opengl_setup_scene_textures()
16941701 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
16951702
16961703 glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGBA16F, Scene_texture_width, Scene_texture_height, 0 , GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL );
1704+ opengl_set_object_label (GL_TEXTURE, Scene_effect_texture, " Scene Effect texture" );
16971705
16981706 glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT4, GL_TEXTURE_2D, Scene_effect_texture, 0 );
16991707
@@ -1712,6 +1720,8 @@ void opengl_setup_scene_textures()
17121720 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
17131721
17141722 glTexImage2D (GL_TEXTURE_2D, 0 , GL_DEPTH_COMPONENT24, Scene_texture_width, Scene_texture_height, 0 , GL_DEPTH_COMPONENT, GL_FLOAT, NULL );
1723+ opengl_set_object_label (GL_TEXTURE, Cockpit_depth_texture, " Cockpit depth texture" );
1724+
17151725 glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, Cockpit_depth_texture, 0 );
17161726 gr_zbuffer_set (GR_ZBUFF_FULL);
17171727 glClear (GL_DEPTH_BUFFER_BIT);
@@ -1731,6 +1741,7 @@ void opengl_setup_scene_textures()
17311741 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
17321742
17331743 glTexImage2D (GL_TEXTURE_2D, 0 , GL_DEPTH_COMPONENT24, Scene_texture_width, Scene_texture_height, 0 , GL_DEPTH_COMPONENT, GL_FLOAT, NULL );
1744+ opengl_set_object_label (GL_TEXTURE, Scene_depth_texture, " Scene depth texture" );
17341745 glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, Scene_depth_texture, 0 );
17351746
17361747 // setup main stencil buffer
@@ -1742,7 +1753,7 @@ void opengl_setup_scene_textures()
17421753 glReadBuffer (GL_COLOR_ATTACHMENT0);
17431754
17441755 if ( opengl_check_framebuffer () ) {
1745- glBindFramebuffer (GL_FRAMEBUFFER, 0 );
1756+ GL_state. BindFrameBuffer ( 0 );
17461757 glDeleteFramebuffers (1 , &Scene_framebuffer);
17471758 Scene_framebuffer = 0 ;
17481759
@@ -1779,7 +1790,7 @@ void opengl_setup_scene_textures()
17791790 if (Cmdline_fb_thrusters || Cmdline_fb_explosions)
17801791 {
17811792 glGenFramebuffers (1 , &Distortion_framebuffer);
1782- glBindFramebuffer (GL_FRAMEBUFFER, Distortion_framebuffer);
1793+ GL_state. BindFrameBuffer ( Distortion_framebuffer);
17831794
17841795 glGenTextures (2 , Distortion_texture);
17851796
@@ -1810,7 +1821,7 @@ void opengl_setup_scene_textures()
18101821
18111822
18121823 if ( opengl_check_framebuffer () ) {
1813- glBindFramebuffer (GL_FRAMEBUFFER, 0 );
1824+ GL_state. BindFrameBuffer ( 0 );
18141825 glDeleteFramebuffers (1 , &Distortion_framebuffer);
18151826 Distortion_framebuffer = 0 ;
18161827
@@ -1829,7 +1840,7 @@ void opengl_setup_scene_textures()
18291840 return ;
18301841 }
18311842
1832- glBindFramebuffer (GL_FRAMEBUFFER, 0 );
1843+ GL_state. BindFrameBuffer ( 0 );
18331844
18341845 Scene_texture_initialized = 1 ;
18351846 Scene_framebuffer_in_frame = false ;
@@ -1900,7 +1911,11 @@ void gr_opengl_scene_texture_begin()
19001911 return ;
19011912 }
19021913
1903- glBindFramebuffer (GL_FRAMEBUFFER, Scene_framebuffer);
1914+ GR_DEBUG_SCOPE (" Begin scene texture" );
1915+
1916+ GL_state.PushFramebufferState ();
1917+ GL_state.BindFrameBuffer (Scene_framebuffer);
1918+ // glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, Scene_depth_texture, 0);
19041919
19051920 if (GL_rendering_to_texture)
19061921 {
@@ -1965,7 +1980,7 @@ void gr_opengl_scene_texture_end()
19651980 GLboolean blend = GL_state.Blend (GL_FALSE);
19661981 GLboolean cull = GL_state.CullFace (GL_FALSE);
19671982
1968- glBindFramebuffer (GL_FRAMEBUFFER, opengl_get_rtt_framebuffer () );
1983+ GL_state. PopFramebufferState ( );
19691984
19701985 GL_state.Texture .SetActiveUnit (0 );
19711986 GL_state.Texture .SetTarget (GL_TEXTURE_2D);
@@ -2016,6 +2031,8 @@ void gr_opengl_copy_effect_texture()
20162031
20172032void opengl_clear_deferred_buffers ()
20182033{
2034+ GR_DEBUG_SCOPE (" Clear deferred buffers" );
2035+
20192036 GLboolean depth = GL_state.DepthTest (GL_FALSE);
20202037 GLboolean depth_mask = GL_state.DepthMask (GL_FALSE);
20212038 GLboolean blend = GL_state.Blend (GL_FALSE);
@@ -2042,6 +2059,8 @@ void gr_opengl_deferred_lighting_begin()
20422059 if ( Cmdline_no_deferred_lighting)
20432060 return ;
20442061
2062+ GR_DEBUG_SCOPE (" Deferred lighting begin" );
2063+
20452064 Deferred_lighting = true ;
20462065 glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
20472066
@@ -2053,6 +2072,9 @@ void gr_opengl_deferred_lighting_end()
20532072{
20542073 if (!Deferred_lighting)
20552074 return ;
2075+
2076+ GR_DEBUG_SCOPE (" Deferred lighting end" );
2077+
20562078 Deferred_lighting = false ;
20572079 glDrawBuffer (GL_COLOR_ATTACHMENT0);
20582080
@@ -2067,6 +2089,7 @@ extern float static_tube_factor;
20672089
20682090void gr_opengl_deferred_lighting_finish ()
20692091{
2092+ GR_DEBUG_SCOPE (" Deferred lighting finish" );
20702093 TRACE_SCOPE (tracing::ApplyLights);
20712094
20722095 if ( Cmdline_no_deferred_lighting ) {
@@ -2118,6 +2141,8 @@ void gr_opengl_deferred_lighting_finish()
21182141
21192142 for (int i = 0 ; i < Num_lights; ++i)
21202143 {
2144+ GR_DEBUG_SCOPE (" Deferred apply single light" );
2145+
21212146 light *l = &lights_copy[i];
21222147 Current_shader->program ->Uniforms .setUniformi ( " lightType" , 0 );
21232148 switch (l->type )
@@ -2205,6 +2230,7 @@ void gr_opengl_deferred_lighting_finish()
22052230 GL_state.Texture .Enable (Scene_luminance_texture);
22062231
22072232 GL_state.SetAlphaBlendMode ( ALPHA_BLEND_ADDITIVE );
2233+ GL_state.DepthMask (GL_FALSE);
22082234
22092235 opengl_draw_textured_quad (0 .0f , 0 .0f , 0 .0f , Scene_texture_v_scale, (float )gr_screen.max_w , (float )gr_screen.max_h , Scene_texture_u_scale, 0 .0f );
22102236
@@ -2266,7 +2292,9 @@ void gr_opengl_update_distortion()
22662292 GLboolean cull = GL_state.CullFace (GL_FALSE);
22672293
22682294 opengl_shader_set_passthrough (true , false );
2269- glBindFramebuffer (GL_FRAMEBUFFER, Distortion_framebuffer);
2295+
2296+ GL_state.PushFramebufferState ();
2297+ GL_state.BindFrameBuffer (Distortion_framebuffer);
22702298 glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, Distortion_texture[!Distortion_switch], 0 );
22712299 glDrawBuffer (GL_COLOR_ATTACHMENT0);
22722300
@@ -2335,7 +2363,7 @@ void gr_opengl_update_distortion()
23352363 Distortion_switch = !Distortion_switch;
23362364
23372365 // reset state
2338- glBindFramebuffer (GL_FRAMEBUFFER, Scene_framebuffer );
2366+ GL_state. PopFramebufferState ( );
23392367
23402368 glViewport (0 ,0 ,gr_screen.max_w ,gr_screen.max_h );
23412369
@@ -2347,6 +2375,8 @@ void gr_opengl_update_distortion()
23472375
23482376void opengl_render_primitives (primitive_type prim_type, vertex_layout* layout, int n_verts, int buffer_handle, size_t vert_offset, size_t byte_offset)
23492377{
2378+ GR_DEBUG_SCOPE (" Render primitives" );
2379+
23502380 if ( buffer_handle >= 0 ) {
23512381 opengl_bind_buffer_object (buffer_handle);
23522382 } else {
0 commit comments