Permalink
Browse files

Use FBOs instead of Copy To Texture.

  • Loading branch information...
1 parent f2229b1 commit 947ea446dfbb55be6dae2a05540f5fb1bc07812e @gimhael gimhael committed Feb 1, 2016
@@ -1402,7 +1402,6 @@ static void RB_SetupLightForShadowing( trRefLight_t *light, int index,
GL_Scissor( 0, 0, shadowMapResolutions[ light->shadowLOD ], shadowMapResolutions[ light->shadowLOD ] );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- backEnd.depthRenderImageValid = false;
switch ( cubeSide )
{
@@ -1523,7 +1522,6 @@ static void RB_SetupLightForShadowing( trRefLight_t *light, int index,
GL_Scissor( 0, 0, shadowMapResolutions[ light->shadowLOD ], shadowMapResolutions[ light->shadowLOD ] );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- backEnd.depthRenderImageValid = false;
GL_LoadProjectionMatrix( light->projectionMatrix );
break;
@@ -1576,7 +1574,6 @@ static void RB_SetupLightForShadowing( trRefLight_t *light, int index,
GL_Scissor( 0, 0, sunShadowMapResolutions[ splitFrustumIndex ], sunShadowMapResolutions[ splitFrustumIndex ] );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- backEnd.depthRenderImageValid = false;
VectorCopy( tr.sunDirection, lightDirection );
@@ -1794,7 +1791,7 @@ static void RB_SetupLightForLighting( trRefLight_t *light )
GLimp_LogComment( va( "----- First Light Interaction: %i -----\n", (int)( light->firstInteraction - backEnd.viewParms.interactions ) ) );
}
- R_BindNullFBO();
+ R_BindFBO( tr.mainFBO[ backEnd.currentMainFBO ] );
// set the window clipping
GL_Viewport( backEnd.viewParms.viewportX, backEnd.viewParms.viewportY,
@@ -2709,14 +2706,7 @@ void RB_RenderGlobalFog()
GL_BindToTMU( 0, tr.fogImage );
// bind u_DepthMap
- GL_SelectTexture( 1 );
-
- // depth texture is not bound to a FBO
- if( !backEnd.depthRenderImageValid ) {
- GL_Bind( tr.depthRenderImage );
- glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.depthRenderImage->uploadWidth, tr.depthRenderImage->uploadHeight );
- backEnd.depthRenderImageValid = true;
- }
+ GL_BindToTMU( 1, tr.depthRenderImage );
// set 2D virtual screen size
GL_PushMatrix();
@@ -2776,10 +2766,7 @@ void RB_RenderBloom()
gl_contrastShader->SetUniform_ModelViewProjectionMatrix( glState.modelViewProjectionMatrix[ glState.stackIndex ] );
- GL_SelectTexture( 0 );
- GL_Bind( tr.currentRenderImage );
- glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.currentRenderImage->uploadWidth,
- tr.currentRenderImage->uploadHeight );
+ GL_BindToTMU( 0, tr.currentRenderImage[ backEnd.currentMainFBO ] );
GL_PopMatrix(); // special 1/4th of the screen contrastRenderFBO ortho
@@ -2839,7 +2826,7 @@ void RB_RenderBloom()
}
}
- R_BindNullFBO();
+ R_BindFBO( tr.mainFBO[ backEnd.currentMainFBO ] );
gl_screenShader->BindProgram( 0 );
GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE );
@@ -2875,25 +2862,15 @@ void RB_RenderMotionBlur()
GL_State( GLS_DEPTHTEST_DISABLE );
GL_Cull( cullType_t::CT_TWO_SIDED );
- GL_SelectTexture( 0 );
- GL_Bind( tr.currentRenderImage );
- glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0,
- tr.currentRenderImage->uploadWidth,
- tr.currentRenderImage->uploadHeight );
-
- if( !backEnd.depthRenderImageValid ) {
- GL_Bind( tr.depthRenderImage );
- glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0,
- tr.depthRenderImage->uploadWidth,
- tr.depthRenderImage->uploadHeight );
- backEnd.depthRenderImageValid = true;
- }
+ // Swap main FBOs
+ GL_BindToTMU( 0, tr.currentRenderImage[ backEnd.currentMainFBO ] );
+ backEnd.currentMainFBO = 1 - backEnd.currentMainFBO;
+ R_BindFBO( tr.mainFBO[ backEnd.currentMainFBO ] );
gl_motionblurShader->BindProgram( 0 );
gl_motionblurShader->SetUniform_blurVec(tr.refdef.blurVec);
- GL_BindToTMU( 0, tr.currentRenderImage );
- GL_BindToTMU( 1, tr.depthRenderImage );
+ GL_BindToTMU( 1, tr.currentDepthImage );
// draw quad
Tess_InstantQuad( quadVerts );
@@ -2925,14 +2902,6 @@ void RB_RenderSSAO()
GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO );
GL_Cull( cullType_t::CT_TWO_SIDED );
- if( !backEnd.depthRenderImageValid ) {
- GL_Bind( tr.depthRenderImage );
- glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0,
- tr.depthRenderImage->uploadWidth,
- tr.depthRenderImage->uploadHeight );
- backEnd.depthRenderImageValid = true;
- }
-
if ( r_ssao->integer < 0 ) {
// clear the screen to show only SSAO
GL_ClearColor( 1.0f, 1.0f, 1.0f, 1.0f);
@@ -2947,7 +2916,7 @@ void RB_RenderSSAO()
gl_ssaoShader->SetUniform_zFar( zParams );
- GL_BindToTMU( 0, tr.depthRenderImage );
+ GL_BindToTMU( 0, tr.currentDepthImage );
// draw quad
Tess_InstantQuad( quadVerts );
@@ -2980,21 +2949,14 @@ void RB_FXAA()
GL_State( GLS_DEPTHTEST_DISABLE );
GL_Cull( cullType_t::CT_TWO_SIDED );
- // copy the framebuffer in a texture
- // TODO: it is pretty inefficient
- GL_SelectTexture( 0 );
- GL_Bind( tr.currentRenderImage );
- glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.currentRenderImage->uploadWidth,
- tr.currentRenderImage->uploadHeight );
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ // Swap main FBOs
+ GL_BindToTMU( 0, tr.currentRenderImage[ backEnd.currentMainFBO ] );
+ backEnd.currentMainFBO = 1 - backEnd.currentMainFBO;
+ R_BindFBO( tr.mainFBO[ backEnd.currentMainFBO ] );
// set the shader parameters
gl_fxaaShader->BindProgram( 0 );
- R_BindNullFBO();
-
Tess_InstantQuad( quadVerts );
GL_CheckErrors();
@@ -3032,12 +2994,10 @@ void RB_CameraPostFX()
gl_cameraEffectsShader->SetUniform_InverseGamma( 1.0 / r_gamma->value );
- // bind u_CurrentMap
- GL_SelectTexture( 0 );
- GL_Bind( tr.occlusionRenderFBOImage );
-
- glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, tr.occlusionRenderFBOImage->uploadWidth, tr.occlusionRenderFBOImage->uploadHeight );
-
+ // This shader is run last, so let it render to screen instead of
+ // tr.mainFBO
+ R_BindNullFBO();
+ GL_BindToTMU( 0, tr.currentRenderImage[ backEnd.currentMainFBO ] );
GL_BindToTMU( 3, tr.colorGradeImage );
// draw viewport
@@ -4418,7 +4378,7 @@ static void RB_RenderView()
}
// disable offscreen rendering
- R_BindNullFBO();
+ R_BindFBO( tr.mainFBO[ backEnd.currentMainFBO ] );
// we will need to change the projection matrix before drawing
// 2D images again
@@ -4434,7 +4394,6 @@ static void RB_RenderView()
clearBits = GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
glClear( clearBits );
- backEnd.depthRenderImageValid = false;
if ( ( backEnd.refdef.rdflags & RDF_HYPERSPACE ) )
{
@@ -5419,7 +5378,6 @@ const void *RB_DrawBuffer( const void *data )
// GL_ClearColor(1, 0, 0.5, 1);
GL_ClearColor( 0, 0, 0, 1 );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- backEnd.depthRenderImageValid = false;
}
glState.finishCalled = false;
@@ -420,6 +420,18 @@ void R_InitFBOs()
height = NearestPowerOfTwo( glConfig.vidHeight );
}
+ tr.mainFBO[0] = R_CreateFBO( "_main[0]", width, height );
+ R_BindFBO( tr.mainFBO[0] );
+ R_AttachFBOTexture2D( GL_TEXTURE_2D, tr.currentRenderImage[0]->texnum, 0 );
+ R_AttachFBOTextureDepth( tr.currentDepthImage->texnum );
+ R_CheckFBO( tr.mainFBO[0] );
+
+ tr.mainFBO[1] = R_CreateFBO( "_main[1]", width, height );
+ R_BindFBO( tr.mainFBO[1] );
+ R_AttachFBOTexture2D( GL_TEXTURE_2D, tr.currentRenderImage[1]->texnum, 0 );
+ R_AttachFBOTextureDepth( tr.currentDepthImage->texnum );
+ R_CheckFBO( tr.mainFBO[1] );
+
tr.occlusionRenderFBO = R_CreateFBO( "_occlusionRender", width, height );
R_BindFBO( tr.occlusionRenderFBO );
@@ -2652,7 +2652,9 @@ static void R_CreateCurrentRenderImage()
height = NearestPowerOfTwo( glConfig.vidHeight );
}
- tr.currentRenderImage = R_CreateImage( "_currentRender", nullptr, width, height, 1, IF_NOPICMIP | IF_NOCOMPRESSION, filterType_t::FT_NEAREST, wrapTypeEnum_t::WT_CLAMP );
+ tr.currentRenderImage[0] = R_CreateImage( "_currentRender[0]", nullptr, width, height, 1, IF_NOPICMIP | IF_NOCOMPRESSION, filterType_t::FT_NEAREST, wrapTypeEnum_t::WT_CLAMP );
+ tr.currentRenderImage[1] = R_CreateImage( "_currentRender[1]", nullptr, width, height, 1, IF_NOPICMIP | IF_NOCOMPRESSION, filterType_t::FT_NEAREST, wrapTypeEnum_t::WT_CLAMP );
+ tr.currentDepthImage = R_CreateImage( "_currentDepth", nullptr, width, height, 1, IF_NOPICMIP | IF_NOCOMPRESSION | IF_DEPTH24, filterType_t::FT_NEAREST, wrapTypeEnum_t::WT_CLAMP );
}
static void R_CreateDepthRenderImage()
@@ -2493,7 +2493,6 @@ static inline void halfToFloat( const f16vec4_t in, vec4_t out )
backEndCounters_t pc;
visTestQueries_t visTestQueries[ MAX_VISTESTS ];
bool isHyperspace;
- bool depthRenderImageValid;
trRefEntity_t *currentEntity;
trRefLight_t *currentLight; // only used when lighting interactions
bool skyRenderedThisView; // flag for drawing sun
@@ -2502,6 +2501,7 @@ static inline void halfToFloat( const f16vec4_t in, vec4_t out )
Color::Color32Bit color2D;
bool vertexes2D; // shader needs to be finished
trRefEntity_t entity2D; // currentEntity will point at this when doing 2D rendering
+ int currentMainFBO;
};
struct visTest_t
@@ -2596,7 +2596,8 @@ static inline void halfToFloat( const f16vec4_t in, vec4_t out )
image_t *contrastRenderFBOImage;
image_t *bloomRenderFBOImage[ 2 ];
- image_t *currentRenderImage;
+ image_t *currentRenderImage[ 2 ];
+ image_t *currentDepthImage;
image_t *depthRenderImage;
image_t *portalRenderImage;
@@ -2618,6 +2619,7 @@ static inline void halfToFloat( const f16vec4_t in, vec4_t out )
GLuint colorGradePBO;
// framebuffer objects
+ FBO_t *mainFBO[ 2 ];
FBO_t *portalRenderFBO; // holds a copy of the last currentRender that was rendered into a FBO
FBO_t *occlusionRenderFBO; // used for overlapping visibility determination
FBO_t *downScaleFBO_quarter;
Oops, something went wrong.

0 comments on commit 947ea44

Please sign in to comment.