@@ -199,6 +199,53 @@ GLuint64 GL_BindToTMU( int unit, image_t *image )
199199 return 0 ;
200200}
201201
202+ void GL_BlitFBOToMSAA ( FBO_t* fbo ) {
203+ glState.currentFBO = nullptr ;
204+
205+ R_BindFBO ( GL_READ_FRAMEBUFFER, fbo );
206+ R_BindFBO ( GL_DRAW_FRAMEBUFFER, tr.msaaFBO );
207+ glBlitFramebuffer ( 0 , 0 , fbo->width , fbo->height , 0 , 0 , tr.msaaFBO ->width , tr.msaaFBO ->height ,
208+ GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST );
209+
210+ glState.currentFBO = nullptr ;
211+ R_BindFBO ( GL_DRAW_FRAMEBUFFER, fbo );
212+ glState.currentFBO = fbo;
213+ }
214+
215+ void GL_BlitMSAAToFBO ( FBO_t* fbo ) {
216+ glState.currentFBO = nullptr ;
217+
218+ R_BindFBO ( GL_READ_FRAMEBUFFER, tr.msaaFBO );
219+ R_BindFBO ( GL_DRAW_FRAMEBUFFER, fbo );
220+ glBlitFramebuffer ( 0 , 0 , tr.msaaFBO ->width , tr.msaaFBO ->height , 0 , 0 , fbo->width , fbo->height ,
221+ GL_COLOR_BUFFER_BIT /* | GL_DEPTH_BUFFER_BIT */ , GL_NEAREST );
222+
223+ glState.currentFBO = nullptr ;
224+ R_BindFBO ( GL_READ_FRAMEBUFFER, fbo );
225+ glState.currentFBO = fbo;
226+ }
227+
228+ void TransitionMainToMSAA () {
229+ if ( r_msaa.Get () ) {
230+ GL_BlitFBOToMSAA ( tr.mainFBO [backEnd.currentMainFBO ] );
231+ R_BindFBO ( tr.msaaFBO );
232+ }
233+ }
234+
235+ void TransitionMSAAToMain () {
236+ if ( r_msaa.Get () ) {
237+ GL_BlitMSAAToFBO ( tr.mainFBO [backEnd.currentMainFBO ] );
238+ }
239+ }
240+
241+ void BindMSAAOrMainFBO () {
242+ if ( r_msaa.Get () ) {
243+ R_BindFBO ( tr.msaaFBO );
244+ } else {
245+ R_BindFBO ( tr.mainFBO [backEnd.currentMainFBO ] );
246+ }
247+ }
248+
202249void GL_BlendFunc ( GLenum sfactor, GLenum dfactor )
203250{
204251 if ( glState.blendSrc != ( signed ) sfactor || glState.blendDst != ( signed ) dfactor )
@@ -797,7 +844,13 @@ void GL_TexImage2D( GLenum target, GLint level, GLint internalFormat, GLsizei wi
797844 GLint finalFormat = GL_ToSRGB ( internalFormat, isSRGB );
798845
799846 glTexImage2D ( target, level, finalFormat, width, height, border, format, type, data );
847+ }
848+
849+ void GL_TexImage2DMultisample ( GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, bool fixedSampleLocations, bool isSRGB )
850+ {
851+ GLint finalFormat = GL_ToSRGB ( internalFormat, isSRGB );
800852
853+ glTexImage2DMultisample ( target, samples, finalFormat, width, height, fixedSampleLocations );
801854}
802855
803856void GL_TexImage3D ( GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *data, bool isSRGB )
@@ -1335,7 +1388,8 @@ void RB_RenderPostDepthLightTile()
13351388 Tess_Clear ();
13361389
13371390 // back to main image
1338- R_BindFBO ( tr.mainFBO [ backEnd.currentMainFBO ] );
1391+ BindMSAAOrMainFBO ();
1392+
13391393 GL_Viewport ( backEnd.viewParms .viewportX , backEnd.viewParms .viewportY ,
13401394 backEnd.viewParms .viewportWidth , backEnd.viewParms .viewportHeight );
13411395 GL_Scissor ( backEnd.viewParms .scissorX , backEnd.viewParms .scissorY ,
@@ -1431,6 +1485,8 @@ void RB_RenderBloom()
14311485 GL_BindToTMU ( 0 , tr.currentRenderImage [backEnd.currentMainFBO ] )
14321486 );
14331487
1488+ TransitionMSAAToMain ();
1489+
14341490 R_BindFBO ( tr.contrastRenderFBO );
14351491 GL_ClearColor ( 0 .0f , 0 .0f , 0 .0f , 1 .0f );
14361492 glClear ( GL_COLOR_BUFFER_BIT );
@@ -1495,6 +1551,8 @@ void RB_RenderBloom()
14951551 GL_PopMatrix ();
14961552 }
14971553
1554+ TransitionMainToMSAA ();
1555+
14981556 GL_CheckErrors ();
14991557}
15001558
@@ -1513,6 +1571,8 @@ void RB_RenderMotionBlur()
15131571
15141572 gl_motionblurShader->BindProgram ( 0 );
15151573
1574+ TransitionMSAAToMain ();
1575+
15161576 // Swap main FBOs
15171577 gl_motionblurShader->SetUniform_ColorMapBindless (
15181578 GL_BindToTMU ( 0 , tr.currentRenderImage [backEnd.currentMainFBO ] )
@@ -1528,6 +1588,8 @@ void RB_RenderMotionBlur()
15281588
15291589 Tess_InstantScreenSpaceQuad ();
15301590
1591+ TransitionMainToMSAA ();
1592+
15311593 GL_CheckErrors ();
15321594}
15331595
@@ -2648,7 +2710,7 @@ static void RB_RenderView( bool depthPass )
26482710 backEnd.pc .c_surfaces += backEnd.viewParms .numDrawSurfs ;
26492711
26502712 // disable offscreen rendering
2651- R_BindFBO ( tr. mainFBO [ backEnd. currentMainFBO ] );
2713+ BindMSAAOrMainFBO ( );
26522714
26532715 // we will need to change the projection matrix before drawing
26542716 // 2D images again
@@ -2768,6 +2830,8 @@ static void RB_RenderPostProcess()
27682830 materialSystem.EndFrame ();
27692831 }
27702832
2833+ TransitionMSAAToMain ();
2834+
27712835 RB_FXAA ();
27722836
27732837 // render chromatic aberration
@@ -3402,7 +3466,7 @@ const RenderCommand *ClearBufferCommand::ExecuteSelf( ) const
34023466 }
34033467
34043468 // disable offscreen rendering
3405- R_BindFBO ( tr.mainFBO [ backEnd.currentMainFBO ] );
3469+ R_BindFBO ( tr.mainFBO [backEnd.currentMainFBO ] );
34063470
34073471 // we will need to change the projection matrix before drawing
34083472 // 2D images again
@@ -3423,6 +3487,11 @@ const RenderCommand *ClearBufferCommand::ExecuteSelf( ) const
34233487
34243488 glClear ( clearBits );
34253489
3490+ if ( r_msaa.Get () ) {
3491+ R_BindFBO ( tr.msaaFBO );
3492+ glClear ( clearBits );
3493+ }
3494+
34263495 return this + 1 ;
34273496}
34283497
0 commit comments