@@ -47,12 +47,10 @@ GLuint Scene_luminance_texture;
4747GLuint Scene_depth_texture;
4848GLuint Scene_depth_texture_ms;
4949GLuint Cockpit_depth_texture;
50- GLuint Scene_stencil_buffer;
5150
5251GLuint Back_framebuffer;
5352GLuint Back_texture;
5453GLuint Back_depth_texture;
55- GLuint Back_stencil_buffer;
5654
5755GLuint Distortion_framebuffer = 0 ;
5856GLuint Distortion_texture[2 ];
@@ -284,10 +282,18 @@ void opengl_setup_scene_textures()
284282 glTexParameteri (GL_TEXTURE_2D , GL_TEXTURE_WRAP_R , GL_CLAMP_TO_EDGE );
285283 glTexParameteri (GL_TEXTURE_2D , GL_TEXTURE_COMPARE_MODE , GL_NONE );
286284
287- glTexImage2D (GL_TEXTURE_2D , 0 , GL_DEPTH_COMPONENT24 , Scene_texture_width, Scene_texture_height, 0 , GL_DEPTH_COMPONENT , GL_FLOAT , NULL );
285+ glTexImage2D (GL_TEXTURE_2D ,
286+ 0 ,
287+ GL_DEPTH24_STENCIL8 ,
288+ Scene_texture_width,
289+ Scene_texture_height,
290+ 0 ,
291+ GL_DEPTH_COMPONENT ,
292+ GL_FLOAT ,
293+ nullptr );
288294 opengl_set_object_label (GL_TEXTURE , Cockpit_depth_texture, " Cockpit depth texture" );
289295
290- glFramebufferTexture2D (GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_TEXTURE_2D , Cockpit_depth_texture, 0 );
296+ glFramebufferTexture2D (GL_FRAMEBUFFER , GL_DEPTH_STENCIL_ATTACHMENT , GL_TEXTURE_2D , Cockpit_depth_texture, 0 );
291297 gr_zbuffer_set (GR_ZBUFF_FULL );
292298 glClear (GL_DEPTH_BUFFER_BIT );
293299
@@ -305,15 +311,17 @@ void opengl_setup_scene_textures()
305311 glTexParameteri (GL_TEXTURE_2D , GL_TEXTURE_WRAP_R , GL_CLAMP_TO_EDGE );
306312 glTexParameteri (GL_TEXTURE_2D , GL_TEXTURE_COMPARE_MODE , GL_NONE );
307313
308- glTexImage2D (GL_TEXTURE_2D , 0 , GL_DEPTH_COMPONENT24 , Scene_texture_width, Scene_texture_height, 0 , GL_DEPTH_COMPONENT , GL_FLOAT , NULL );
314+ glTexImage2D (GL_TEXTURE_2D ,
315+ 0 ,
316+ GL_DEPTH24_STENCIL8 ,
317+ Scene_texture_width,
318+ Scene_texture_height,
319+ 0 ,
320+ GL_DEPTH_COMPONENT ,
321+ GL_FLOAT ,
322+ nullptr );
309323 opengl_set_object_label (GL_TEXTURE , Scene_depth_texture, " Scene depth texture" );
310- glFramebufferTexture2D (GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_TEXTURE_2D , Scene_depth_texture, 0 );
311-
312- // setup main stencil buffer
313- glGenRenderbuffers (1 , &Scene_stencil_buffer);
314- glBindRenderbuffer (GL_RENDERBUFFER , Scene_stencil_buffer);
315- glRenderbufferStorage (GL_RENDERBUFFER , GL_DEPTH24_STENCIL8 , Scene_texture_width, Scene_texture_height);
316- // glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, Scene_stencil_buffer);
324+ glFramebufferTexture2D (GL_FRAMEBUFFER , GL_DEPTH_STENCIL_ATTACHMENT , GL_TEXTURE_2D , Scene_depth_texture, 0 );
317325
318326 glReadBuffer (GL_COLOR_ATTACHMENT0 );
319327
@@ -492,13 +500,13 @@ void opengl_setup_scene_textures()
492500
493501 glTexImage2DMultisample (GL_TEXTURE_2D_MULTISAMPLE ,
494502 Cmdline_msaa_enabled,
495- GL_DEPTH_COMPONENT24 ,
503+ GL_DEPTH24_STENCIL8 ,
496504 Scene_texture_width,
497505 Scene_texture_height,
498506 GL_TRUE );
499507 opengl_set_object_label (GL_TEXTURE , Scene_depth_texture_ms, " Scene depth texture multisample" );
500508 glFramebufferTexture2D (GL_FRAMEBUFFER ,
501- GL_DEPTH_ATTACHMENT ,
509+ GL_DEPTH_STENCIL_ATTACHMENT ,
502510 GL_TEXTURE_2D_MULTISAMPLE ,
503511 Scene_depth_texture_ms,
504512 0 );
@@ -546,17 +554,20 @@ void opengl_setup_scene_textures()
546554 glTexParameteri (GL_TEXTURE_2D , GL_TEXTURE_WRAP_R , GL_CLAMP_TO_EDGE );
547555 glTexParameteri (GL_TEXTURE_2D , GL_TEXTURE_COMPARE_MODE , GL_NONE );
548556
549- glTexImage2D (GL_TEXTURE_2D , 0 , GL_DEPTH_COMPONENT24 , gr_screen.max_w , gr_screen.max_h , 0 , GL_DEPTH_COMPONENT , GL_FLOAT , NULL );
557+ glTexImage2D (GL_TEXTURE_2D ,
558+ 0 ,
559+ GL_DEPTH24_STENCIL8 ,
560+ gr_screen.max_w ,
561+ gr_screen.max_h ,
562+ 0 ,
563+ GL_DEPTH_STENCIL ,
564+ GL_UNSIGNED_INT_24_8 ,
565+ nullptr );
550566 opengl_set_object_label (GL_TEXTURE , Back_depth_texture, " Backbuffer depth texture" );
551567
552- glFramebufferTexture2D (GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_TEXTURE_2D , Back_depth_texture, 0 );
568+ glFramebufferTexture2D (GL_FRAMEBUFFER , GL_DEPTH_STENCIL_ATTACHMENT , GL_TEXTURE_2D , Back_depth_texture, 0 );
553569 gr_zbuffer_set (GR_ZBUFF_FULL );
554570 glClear (GL_DEPTH_BUFFER_BIT );
555-
556- glGenRenderbuffers (1 , &Back_stencil_buffer);
557- glBindRenderbuffer (GL_RENDERBUFFER , Back_stencil_buffer);
558- glRenderbufferStorage (GL_RENDERBUFFER , GL_DEPTH24_STENCIL8 , gr_screen.max_w , gr_screen.max_h );
559- glFramebufferRenderbuffer (GL_FRAMEBUFFER , GL_DEPTH_STENCIL_ATTACHMENT , GL_RENDERBUFFER , Back_stencil_buffer);
560571 }
561572
562573 // Setup thruster distortion framebuffer
@@ -660,6 +671,21 @@ void opengl_scene_texture_shutdown()
660671 Scene_framebuffer = 0 ;
661672 }
662673
674+ if (Back_texture) {
675+ glDeleteTextures (1 , &Back_texture);
676+ Back_texture = 0 ;
677+ }
678+
679+ if (Back_depth_texture) {
680+ glDeleteTextures (1 , &Back_depth_texture);
681+ Back_depth_texture = 0 ;
682+ }
683+
684+ if (Back_framebuffer) {
685+ glDeleteFramebuffers (1 , &Back_framebuffer);
686+ Back_framebuffer = 0 ;
687+ }
688+
663689 glDeleteTextures (2 , Distortion_texture);
664690 Distortion_texture[0 ] = 0 ;
665691 Distortion_texture[1 ] = 0 ;
0 commit comments