Skip to content

Commit f9547e4

Browse files
committed
OpenGL2: Don't mix drawing to default framebuffer and FBO
Don't draw the world scene to a separate FBO from the rest of the screen. This fixes the world scene having HOM instead of seeing through to the previously drawn content. World of Padman uses this to have a separate 3D scene for the sky and world in wop_padship for dynamic skybox. This also makes r_ext_framebuffer_multisample apply to HUD models instead of depending on r_ext_multisample (which doesn't work on Linux with some Intel graphics).
1 parent 2cd1a7e commit f9547e4

File tree

4 files changed

+50
-51
lines changed

4 files changed

+50
-51
lines changed

code/renderergl2/tr_backend.c

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ void RB_BeginDrawingView (void) {
342342
{
343343
FBO_t *fbo = backEnd.viewParms.targetFbo;
344344

345-
if (fbo == NULL && (!r_postProcess->integer || !(backEnd.refdef.rdflags & RDF_NOWORLDMODEL)))
345+
if (fbo == NULL)
346346
fbo = tr.renderFbo;
347347

348348
if (tr.renderCubeFbo && fbo == tr.renderCubeFbo)
@@ -708,7 +708,7 @@ void RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *
708708

709709
if (glRefConfig.framebufferObject)
710710
{
711-
FBO_Bind(r_postProcess->integer ? NULL : tr.renderFbo);
711+
FBO_Bind(tr.renderFbo);
712712
}
713713

714714
RB_SetGL2D();
@@ -793,7 +793,7 @@ const void *RB_StretchPic ( const void *data ) {
793793
cmd = (const stretchPicCommand_t *)data;
794794

795795
if (glRefConfig.framebufferObject)
796-
FBO_Bind(r_postProcess->integer ? NULL : tr.renderFbo);
796+
FBO_Bind(tr.renderFbo);
797797

798798
RB_SetGL2D();
799799

@@ -1202,15 +1202,12 @@ const void *RB_DrawBuffer( const void *data ) {
12021202

12031203
// clear screen for debugging
12041204
if ( r_clear->integer ) {
1205-
qglClearColor( 1, 0, 0.5, 1 );
1206-
qglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1207-
12081205
if (glRefConfig.framebufferObject && tr.renderFbo) {
12091206
FBO_Bind(tr.renderFbo);
1210-
1211-
qglClearColor( 1, 0, 0.5, 1 );
1212-
qglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
12131207
}
1208+
1209+
qglClearColor( 1, 0, 0.5, 1 );
1210+
qglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
12141211
}
12151212

12161213
return (const void *)(cmd + 1);
@@ -1381,18 +1378,15 @@ const void *RB_SwapBuffers( const void *data ) {
13811378

13821379
if (glRefConfig.framebufferObject)
13831380
{
1384-
if (!r_postProcess->integer)
1381+
if (tr.msaaResolveFbo && r_hdr->integer)
13851382
{
1386-
if (tr.msaaResolveFbo && r_hdr->integer)
1387-
{
1388-
// Resolving an RGB16F MSAA FBO to the screen messes with the brightness, so resolve to an RGB16F FBO first
1389-
FBO_FastBlit(tr.renderFbo, NULL, tr.msaaResolveFbo, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1390-
FBO_FastBlit(tr.msaaResolveFbo, NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1391-
}
1392-
else if (tr.renderFbo)
1393-
{
1394-
FBO_FastBlit(tr.renderFbo, NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1395-
}
1383+
// Resolving an RGB16F MSAA FBO to the screen messes with the brightness, so resolve to an RGB16F FBO first
1384+
FBO_FastBlit(tr.renderFbo, NULL, tr.msaaResolveFbo, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1385+
FBO_FastBlit(tr.msaaResolveFbo, NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1386+
}
1387+
else if (tr.renderFbo)
1388+
{
1389+
FBO_FastBlit(tr.renderFbo, NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
13961390
}
13971391
}
13981392

@@ -1454,7 +1448,7 @@ RB_PostProcess
14541448
const void *RB_PostProcess(const void *data)
14551449
{
14561450
const postProcessCommand_t *cmd = data;
1457-
FBO_t *srcFbo;
1451+
FBO_t *srcFbo, *dstFbo;
14581452
ivec4_t srcBox, dstBox;
14591453
qboolean autoExposure;
14601454

@@ -1475,6 +1469,8 @@ const void *RB_PostProcess(const void *data)
14751469
}
14761470

14771471
srcFbo = tr.renderFbo;
1472+
dstFbo = tr.renderFbo;
1473+
14781474
if (tr.msaaResolveFbo)
14791475
{
14801476
// Resolve the MSAA before anything else
@@ -1508,13 +1504,13 @@ const void *RB_PostProcess(const void *data)
15081504
if (r_hdr->integer && (r_toneMap->integer || r_forceToneMap->integer))
15091505
{
15101506
autoExposure = r_autoExposure->integer || r_forceAutoExposure->integer;
1511-
RB_ToneMap(srcFbo, srcBox, NULL, dstBox, autoExposure);
1507+
1508+
// Use an intermediate FBO because it can't blit to the same FBO directly
1509+
// and can't read from an MSAA dstFbo later.
1510+
RB_ToneMap(srcFbo, srcBox, tr.screenScratchFbo, srcBox, autoExposure);
1511+
FBO_FastBlit(tr.screenScratchFbo, srcBox, srcFbo, srcBox, GL_COLOR_BUFFER_BIT, GL_NEAREST);
15121512
}
1513-
else if (r_cameraExposure->value == 0.0f)
1514-
{
1515-
FBO_FastBlit(srcFbo, srcBox, NULL, dstBox, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1516-
}
1517-
else
1513+
else if (r_cameraExposure->value != 0.0f)
15181514
{
15191515
vec4_t color;
15201516

@@ -1523,17 +1519,20 @@ const void *RB_PostProcess(const void *data)
15231519
color[2] = pow(2, r_cameraExposure->value); //exp2(r_cameraExposure->value);
15241520
color[3] = 1.0f;
15251521

1526-
FBO_Blit(srcFbo, srcBox, NULL, NULL, dstBox, NULL, color, 0);
1522+
FBO_BlitFromTexture(tr.whiteImage, NULL, NULL, srcFbo, srcBox, NULL, color, GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO);
15271523
}
15281524
}
15291525

15301526
if (r_drawSunRays->integer)
1531-
RB_SunRays(NULL, srcBox, NULL, dstBox);
1527+
RB_SunRays(srcFbo, srcBox, srcFbo, srcBox);
15321528

15331529
if (1)
1534-
RB_BokehBlur(NULL, srcBox, NULL, dstBox, backEnd.refdef.blurFactor);
1530+
RB_BokehBlur(srcFbo, srcBox, srcFbo, srcBox, backEnd.refdef.blurFactor);
15351531
else
1536-
RB_GaussianBlur(backEnd.refdef.blurFactor);
1532+
RB_GaussianBlur(srcFbo, srcFbo, backEnd.refdef.blurFactor);
1533+
1534+
if (srcFbo != dstFbo)
1535+
FBO_FastBlit(srcFbo, srcBox, dstFbo, dstBox, GL_COLOR_BUFFER_BIT, GL_NEAREST);
15371536

15381537
#if 0
15391538
if (0)
@@ -1549,7 +1548,7 @@ const void *RB_PostProcess(const void *data)
15491548
if (scale < 0.01f)
15501549
scale = 5.0f;
15511550

1552-
FBO_FastBlit(NULL, NULL, tr.quarterFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR);
1551+
FBO_FastBlit(dstFbo, NULL, tr.quarterFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR);
15531552

15541553
iQtrBox[0] = backEnd.viewParms.viewportX * tr.quarterImage[0]->width / (float)glConfig.vidWidth;
15551554
iQtrBox[1] = backEnd.viewParms.viewportY * tr.quarterImage[0]->height / (float)glConfig.vidHeight;
@@ -1595,7 +1594,7 @@ const void *RB_PostProcess(const void *data)
15951594

15961595
SetViewportAndScissor();
15971596

1598-
FBO_FastBlit(tr.quarterFbo[1], NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR);
1597+
FBO_FastBlit(tr.quarterFbo[1], NULL, dstFbo, NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR);
15991598
FBO_Bind(NULL);
16001599
}
16011600
#endif
@@ -1604,42 +1603,42 @@ const void *RB_PostProcess(const void *data)
16041603
{
16051604
ivec4_t dstBox;
16061605
VectorSet4(dstBox, 0, glConfig.vidHeight - 128, 128, 128);
1607-
FBO_BlitFromTexture(tr.sunShadowDepthImage[0], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
1606+
FBO_BlitFromTexture(tr.sunShadowDepthImage[0], NULL, NULL, dstFbo, dstBox, NULL, NULL, 0);
16081607
VectorSet4(dstBox, 128, glConfig.vidHeight - 128, 128, 128);
1609-
FBO_BlitFromTexture(tr.sunShadowDepthImage[1], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
1608+
FBO_BlitFromTexture(tr.sunShadowDepthImage[1], NULL, NULL, dstFbo, dstBox, NULL, NULL, 0);
16101609
VectorSet4(dstBox, 256, glConfig.vidHeight - 128, 128, 128);
1611-
FBO_BlitFromTexture(tr.sunShadowDepthImage[2], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
1610+
FBO_BlitFromTexture(tr.sunShadowDepthImage[2], NULL, NULL, dstFbo, dstBox, NULL, NULL, 0);
16121611
VectorSet4(dstBox, 384, glConfig.vidHeight - 128, 128, 128);
1613-
FBO_BlitFromTexture(tr.sunShadowDepthImage[3], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
1612+
FBO_BlitFromTexture(tr.sunShadowDepthImage[3], NULL, NULL, dstFbo, dstBox, NULL, NULL, 0);
16141613
}
16151614

16161615
if (0 && r_shadows->integer == 4)
16171616
{
16181617
ivec4_t dstBox;
16191618
VectorSet4(dstBox, 512 + 0, glConfig.vidHeight - 128, 128, 128);
1620-
FBO_BlitFromTexture(tr.pshadowMaps[0], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
1619+
FBO_BlitFromTexture(tr.pshadowMaps[0], NULL, NULL, dstFbo, dstBox, NULL, NULL, 0);
16211620
VectorSet4(dstBox, 512 + 128, glConfig.vidHeight - 128, 128, 128);
1622-
FBO_BlitFromTexture(tr.pshadowMaps[1], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
1621+
FBO_BlitFromTexture(tr.pshadowMaps[1], NULL, NULL, dstFbo, dstBox, NULL, NULL, 0);
16231622
VectorSet4(dstBox, 512 + 256, glConfig.vidHeight - 128, 128, 128);
1624-
FBO_BlitFromTexture(tr.pshadowMaps[2], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
1623+
FBO_BlitFromTexture(tr.pshadowMaps[2], NULL, NULL, dstFbo, dstBox, NULL, NULL, 0);
16251624
VectorSet4(dstBox, 512 + 384, glConfig.vidHeight - 128, 128, 128);
1626-
FBO_BlitFromTexture(tr.pshadowMaps[3], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
1625+
FBO_BlitFromTexture(tr.pshadowMaps[3], NULL, NULL, dstFbo, dstBox, NULL, NULL, 0);
16271626
}
16281627

16291628
if (0)
16301629
{
16311630
ivec4_t dstBox;
16321631
VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256);
1633-
FBO_BlitFromTexture(tr.renderDepthImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0);
1632+
FBO_BlitFromTexture(tr.renderDepthImage, NULL, NULL, dstFbo, dstBox, NULL, NULL, 0);
16341633
VectorSet4(dstBox, 512, glConfig.vidHeight - 256, 256, 256);
1635-
FBO_BlitFromTexture(tr.screenShadowImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0);
1634+
FBO_BlitFromTexture(tr.screenShadowImage, NULL, NULL, dstFbo, dstBox, NULL, NULL, 0);
16361635
}
16371636

16381637
if (0)
16391638
{
16401639
ivec4_t dstBox;
16411640
VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256);
1642-
FBO_BlitFromTexture(tr.sunRaysImage, NULL, NULL, NULL, dstBox, NULL, NULL, 0);
1641+
FBO_BlitFromTexture(tr.sunRaysImage, NULL, NULL, dstFbo, dstBox, NULL, NULL, 0);
16431642
}
16441643

16451644
#if 0
@@ -1651,8 +1650,8 @@ const void *RB_PostProcess(const void *data)
16511650
if (cubemapIndex)
16521651
{
16531652
VectorSet4(dstBox, 0, glConfig.vidHeight - 256, 256, 256);
1654-
//FBO_BlitFromTexture(tr.renderCubeImage, NULL, NULL, NULL, dstBox, &tr.testcubeShader, NULL, 0);
1655-
FBO_BlitFromTexture(tr.cubemaps[cubemapIndex - 1].image, NULL, NULL, NULL, dstBox, &tr.testcubeShader, NULL, 0);
1653+
//FBO_BlitFromTexture(tr.renderCubeImage, NULL, NULL, dstFbo, dstBox, &tr.testcubeShader, NULL, 0);
1654+
FBO_BlitFromTexture(tr.cubemaps[cubemapIndex - 1].image, NULL, NULL, dstFbo, dstBox, &tr.testcubeShader, NULL, 0);
16561655
}
16571656
}
16581657
#endif

code/renderergl2/tr_image.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2766,7 +2766,7 @@ void R_CreateBuiltinImages( void ) {
27662766

27672767
tr.renderImage = R_CreateImage("_render", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, hdrFormat);
27682768

2769-
if (r_shadowBlur->integer)
2769+
if (r_shadowBlur->integer || r_hdr->integer)
27702770
tr.screenScratchImage = R_CreateImage("screenScratch", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, rgbFormat);
27712771

27722772
if (r_shadowBlur->integer || r_ssao->integer)

code/renderergl2/tr_postprocess.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ static void RB_VBlur(FBO_t *srcFbo, FBO_t *dstFbo, float strength)
447447
RB_BlurAxis(srcFbo, dstFbo, strength, qfalse);
448448
}
449449

450-
void RB_GaussianBlur(float blur)
450+
void RB_GaussianBlur(FBO_t *srcFbo, FBO_t *dstFbo, float blur)
451451
{
452452
//float mul = 1.f;
453453
float factor = Com_Clamp(0.f, 1.f, blur);
@@ -462,7 +462,7 @@ void RB_GaussianBlur(float blur)
462462
VectorSet4(color, 1, 1, 1, 1);
463463

464464
// first, downsample the framebuffer
465-
FBO_FastBlit(NULL, NULL, tr.quarterFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR);
465+
FBO_FastBlit(srcFbo, NULL, tr.quarterFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR);
466466
FBO_FastBlit(tr.quarterFbo[0], NULL, tr.textureScratchFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR);
467467

468468
// set the alpha channel
@@ -478,6 +478,6 @@ void RB_GaussianBlur(float blur)
478478
VectorSet4(srcBox, 0, 0, tr.textureScratchFbo[0]->width, tr.textureScratchFbo[0]->height);
479479
VectorSet4(dstBox, 0, 0, glConfig.vidWidth, glConfig.vidHeight);
480480
color[3] = factor;
481-
FBO_Blit(tr.textureScratchFbo[0], srcBox, NULL, NULL, dstBox, NULL, color, GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA);
481+
FBO_Blit(tr.textureScratchFbo[0], srcBox, NULL, dstFbo, dstBox, NULL, color, GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA);
482482
}
483483
}

code/renderergl2/tr_postprocess.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2828
void RB_ToneMap(FBO_t *hdrFbo, ivec4_t hdrBox, FBO_t *ldrFbo, ivec4_t ldrBox, int autoExposure);
2929
void RB_BokehBlur(FBO_t *src, ivec4_t srcBox, FBO_t *dst, ivec4_t dstBox, float blur);
3030
void RB_SunRays(FBO_t *srcFbo, ivec4_t srcBox, FBO_t *dstFbo, ivec4_t dstBox);
31-
void RB_GaussianBlur(float blur);
31+
void RB_GaussianBlur(FBO_t *srcFbo, FBO_t *dstFbo, float blur);
3232

3333
#endif

0 commit comments

Comments
 (0)