renderergl2: reimplement greyscale as backend post after all 2D+3D draws
Fixes #654 - HUD/UI previously bypassed greyscale. r_greyscale now supports partial desaturation [0-1]. Removed unused legacy logic from tr_shade.c
This commit is contained in:
1 parent
7bd2c17f9d
commit
453705553b
9 files changed
+166
-111
No files matched your search
@@ -394,6 +394,9 @@ void RB_BeginDrawingView (void) {
|
||||
// we will only draw a sun if there was sky rendered in this view
|
||||
backEnd.skyRenderedThisView = qfalse;
|
||||
|
||||
// cache the clamped greyscale value
|
||||
backEnd.greyscale = Com_Clamp(0.0f, 1.0f, r_greyscale->value);
|
||||
|
||||
// clip to the plane of the portal
|
||||
if ( backEnd.viewParms.isPortal ) {
|
||||
#if 0
|
||||
@@ -1357,6 +1360,84 @@ const void *RB_ClearDepth(const void *data)
|
||||
return (const void *)(cmd + 1);
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
RB_DrawGreyscale
|
||||
|
||||
=============
|
||||
*/
|
||||
static void RB_DrawGreyscale(const FBO_t *src)
|
||||
{
|
||||
if (!src || !src->colorImage[0])
|
||||
return;
|
||||
|
||||
FBO_Bind(NULL);
|
||||
qglViewport(0, 0, glConfig.vidWidth, glConfig.vidHeight);
|
||||
qglScissor(0, 0, glConfig.vidWidth, glConfig.vidHeight);
|
||||
GL_State(GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO);
|
||||
|
||||
GLSL_BindProgram(&tr.greyscaleShader);
|
||||
GLSL_SetUniformInt(&tr.greyscaleShader, UNIFORM_TEXTUREMAP, 0);
|
||||
GLSL_SetUniformFloat(&tr.greyscaleShader, UNIFORM_GREYSCALE, backEnd.greyscale);
|
||||
GL_BindToTMU(src->colorImage[0], 0);
|
||||
|
||||
vec4_t quadVerts[4] = {
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f },
|
||||
{ (float)glConfig.vidWidth, 0.0f, 0.0f, 1.0f },
|
||||
{ (float)glConfig.vidWidth, (float)glConfig.vidHeight, 0.0f, 1.0f },
|
||||
{ 0.0f, (float)glConfig.vidHeight, 0.0f, 1.0f },
|
||||
};
|
||||
|
||||
vec2_t texCoords[4] = { {0.0f, 1.0f}, {1.0f, 1.0f}, {1.0f, 0.0f}, {0.0f, 0.0f} };
|
||||
|
||||
RB_InstantQuad2(quadVerts, texCoords);
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
RB_PresentToScreen
|
||||
|
||||
=============
|
||||
*/
|
||||
static void RB_PresentToScreen(void)
|
||||
{
|
||||
if (!glRefConfig.framebufferObject)
|
||||
return;
|
||||
|
||||
const FBO_t *src = NULL;
|
||||
|
||||
if (tr.renderFbo && tr.renderFbo->colorImage[0])
|
||||
{
|
||||
// texture-backed render FBO
|
||||
src = tr.renderFbo;
|
||||
}
|
||||
else if (tr.msaaResolveFbo && r_hdr->integer)
|
||||
{
|
||||
// Resolving an RGB16F MSAA FBO to the screen messes with the brightness, so resolve to an RGB16F FBO first
|
||||
FBO_FastBlit(tr.renderFbo, NULL, tr.msaaResolveFbo, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
src = tr.msaaResolveFbo;
|
||||
}
|
||||
|
||||
if (src)
|
||||
{
|
||||
if (backEnd.greyscale > 0.0f)
|
||||
{
|
||||
RB_DrawGreyscale(src);
|
||||
}
|
||||
else
|
||||
{
|
||||
FBO_FastBlit(src, NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (tr.renderFbo)
|
||||
{
|
||||
FBO_FastBlit(tr.renderFbo, NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
=============
|
||||
@@ -1397,19 +1478,7 @@ const void *RB_SwapBuffers( const void *data ) {
|
||||
ri.Hunk_FreeTempMemory( stencilReadback );
|
||||
}
|
||||
|
||||
if (glRefConfig.framebufferObject)
|
||||
{
|
||||
if (tr.msaaResolveFbo && r_hdr->integer)
|
||||
{
|
||||
// Resolving an RGB16F MSAA FBO to the screen messes with the brightness, so resolve to an RGB16F FBO first
|
||||
FBO_FastBlit(tr.renderFbo, NULL, tr.msaaResolveFbo, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
FBO_FastBlit(tr.msaaResolveFbo, NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
}
|
||||
else if (tr.renderFbo)
|
||||
{
|
||||
FBO_FastBlit(tr.renderFbo, NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
}
|
||||
}
|
||||
RB_PresentToScreen();
|
||||
|
||||
if ( !glState.finishCalled ) {
|
||||
qglFinish();
|
||||
|
||||
Reference in new issue
Block a user