mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-12-03 17:32:54 +00:00
Merge remote-tracking branch 'origin/ssao' into qzdoom
This commit is contained in:
commit
2ba7915d1a
5 changed files with 32 additions and 28 deletions
|
@ -205,12 +205,12 @@ FGLRenderer::~FGLRenderer()
|
||||||
}
|
}
|
||||||
if (mBuffers) delete mBuffers;
|
if (mBuffers) delete mBuffers;
|
||||||
if (mPresentShader) delete mPresentShader;
|
if (mPresentShader) delete mPresentShader;
|
||||||
if (mPresent3dCheckerShader) delete mPresent3dCheckerShader;
|
|
||||||
if (mPresent3dColumnShader) delete mPresent3dColumnShader;
|
|
||||||
if (mLinearDepthShader) delete mLinearDepthShader;
|
if (mLinearDepthShader) delete mLinearDepthShader;
|
||||||
if (mDepthBlurShader) delete mDepthBlurShader;
|
if (mDepthBlurShader) delete mDepthBlurShader;
|
||||||
if (mSSAOShader) delete mSSAOShader;
|
if (mSSAOShader) delete mSSAOShader;
|
||||||
if (mSSAOCombineShader) delete mSSAOCombineShader;
|
if (mSSAOCombineShader) delete mSSAOCombineShader;
|
||||||
|
if (mPresent3dCheckerShader) delete mPresent3dCheckerShader;
|
||||||
|
if (mPresent3dColumnShader) delete mPresent3dColumnShader;
|
||||||
if (mPresent3dRowShader) delete mPresent3dRowShader;
|
if (mPresent3dRowShader) delete mPresent3dRowShader;
|
||||||
if (mBloomExtractShader) delete mBloomExtractShader;
|
if (mBloomExtractShader) delete mBloomExtractShader;
|
||||||
if (mBloomCombineShader) delete mBloomCombineShader;
|
if (mBloomCombineShader) delete mBloomCombineShader;
|
||||||
|
|
|
@ -120,6 +120,7 @@ class FRenderState
|
||||||
FShader *activeShader;
|
FShader *activeShader;
|
||||||
|
|
||||||
EPassType mPassType = NORMAL_PASS;
|
EPassType mPassType = NORMAL_PASS;
|
||||||
|
int mNumDrawBuffers = 1;
|
||||||
|
|
||||||
bool ApplyShader();
|
bool ApplyShader();
|
||||||
|
|
||||||
|
@ -491,6 +492,22 @@ public:
|
||||||
return mPassType;
|
return mPassType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EnableDrawBuffers(int count)
|
||||||
|
{
|
||||||
|
count = MIN(count, 3);
|
||||||
|
if (mNumDrawBuffers != count)
|
||||||
|
{
|
||||||
|
static GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
|
||||||
|
glDrawBuffers(count, buffers);
|
||||||
|
mNumDrawBuffers = count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetPassDrawBufferCount()
|
||||||
|
{
|
||||||
|
return mPassType == GBUFFER_PASS ? 3 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Backwards compatibility crap follows
|
// Backwards compatibility crap follows
|
||||||
void ApplyFixedFunction();
|
void ApplyFixedFunction();
|
||||||
void DrawColormapOverlay();
|
void DrawColormapOverlay();
|
||||||
|
|
|
@ -160,9 +160,8 @@ void FGLRenderer::Set3DViewport(bool mainview)
|
||||||
{
|
{
|
||||||
bool useSSAO = (gl_ssao != 0);
|
bool useSSAO = (gl_ssao != 0);
|
||||||
mBuffers->BindSceneFB(useSSAO);
|
mBuffers->BindSceneFB(useSSAO);
|
||||||
GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
|
|
||||||
glDrawBuffers(useSSAO ? 3 : 1, buffers);
|
|
||||||
gl_RenderState.SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS);
|
gl_RenderState.SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS);
|
||||||
|
gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount());
|
||||||
gl_RenderState.Apply();
|
gl_RenderState.Apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,6 +478,11 @@ void FGLRenderer::DrawScene(int drawmode)
|
||||||
static int recursion=0;
|
static int recursion=0;
|
||||||
static int ssao_portals_available = 0;
|
static int ssao_portals_available = 0;
|
||||||
|
|
||||||
|
if (drawmode == DM_MAINVIEW)
|
||||||
|
ssao_portals_available = gl_ssao_portals + 1;
|
||||||
|
else if (drawmode == DM_OFFSCREEN)
|
||||||
|
ssao_portals_available = 0;
|
||||||
|
|
||||||
if (camera != nullptr)
|
if (camera != nullptr)
|
||||||
{
|
{
|
||||||
ActorRenderFlags savedflags = camera->renderflags;
|
ActorRenderFlags savedflags = camera->renderflags;
|
||||||
|
@ -495,35 +499,14 @@ void FGLRenderer::DrawScene(int drawmode)
|
||||||
}
|
}
|
||||||
GLRenderer->mClipPortal = NULL; // this must be reset before any portal recursion takes place.
|
GLRenderer->mClipPortal = NULL; // this must be reset before any portal recursion takes place.
|
||||||
|
|
||||||
// Decide if we need to do ssao for this scene
|
|
||||||
bool applySSAO = gl_ssao != 0 && FGLRenderBuffers::IsEnabled();
|
|
||||||
switch (drawmode)
|
|
||||||
{
|
|
||||||
case DM_MAINVIEW: ssao_portals_available = gl_ssao_portals; break;
|
|
||||||
case DM_OFFSCREEN: ssao_portals_available = 0; applySSAO = false; break;
|
|
||||||
case DM_PORTAL: applySSAO = applySSAO && (ssao_portals_available > 0); ssao_portals_available--; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If SSAO is active, switch to gbuffer shaders and use the framebuffer with gbuffers
|
|
||||||
if (applySSAO)
|
|
||||||
{
|
|
||||||
GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
|
|
||||||
glDrawBuffers(3, buffers);
|
|
||||||
gl_RenderState.SetPassType(GBUFFER_PASS);
|
|
||||||
gl_RenderState.Apply();
|
|
||||||
gl_RenderState.ApplyMatrices();
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderScene(recursion);
|
RenderScene(recursion);
|
||||||
|
|
||||||
// Apply ambient occlusion and switch back to shaders without gbuffer output
|
if (ssao_portals_available > 0 && gl_RenderState.GetPassType() == GBUFFER_PASS)
|
||||||
if (applySSAO)
|
|
||||||
{
|
{
|
||||||
GLenum buffers[] = { GL_COLOR_ATTACHMENT0 };
|
gl_RenderState.EnableDrawBuffers(1);
|
||||||
glDrawBuffers(1, buffers);
|
|
||||||
AmbientOccludeScene();
|
AmbientOccludeScene();
|
||||||
mBuffers->BindSceneFB(true);
|
mBuffers->BindSceneFB(true);
|
||||||
gl_RenderState.SetPassType(NORMAL_PASS);
|
gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount());
|
||||||
gl_RenderState.Apply();
|
gl_RenderState.Apply();
|
||||||
gl_RenderState.ApplyMatrices();
|
gl_RenderState.ApplyMatrices();
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,6 +227,7 @@ void GLWall::RenderFogBoundary()
|
||||||
{
|
{
|
||||||
int rel = rellight + getExtraLight();
|
int rel = rellight + getExtraLight();
|
||||||
gl_SetFog(lightlevel, rel, &Colormap, false);
|
gl_SetFog(lightlevel, rel, &Colormap, false);
|
||||||
|
gl_RenderState.EnableDrawBuffers(1);
|
||||||
gl_RenderState.SetEffect(EFF_FOGBOUNDARY);
|
gl_RenderState.SetEffect(EFF_FOGBOUNDARY);
|
||||||
gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f);
|
gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f);
|
||||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||||
|
@ -235,6 +236,7 @@ void GLWall::RenderFogBoundary()
|
||||||
glPolygonOffset(0.0f, 0.0f);
|
glPolygonOffset(0.0f, 0.0f);
|
||||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||||
gl_RenderState.SetEffect(EFF_NONE);
|
gl_RenderState.SetEffect(EFF_NONE);
|
||||||
|
gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,8 +41,10 @@ public:
|
||||||
gl_RenderState.GetColorMask(saved[0], saved[1], saved[2], saved[3]);
|
gl_RenderState.GetColorMask(saved[0], saved[1], saved[2], saved[3]);
|
||||||
gl_RenderState.SetColorMask(r, g, b, a);
|
gl_RenderState.SetColorMask(r, g, b, a);
|
||||||
gl_RenderState.ApplyColorMask();
|
gl_RenderState.ApplyColorMask();
|
||||||
|
gl_RenderState.EnableDrawBuffers(1);
|
||||||
}
|
}
|
||||||
~ScopedColorMask() {
|
~ScopedColorMask() {
|
||||||
|
gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount());
|
||||||
gl_RenderState.SetColorMask(saved[0], saved[1], saved[2], saved[3]);
|
gl_RenderState.SetColorMask(saved[0], saved[1], saved[2], saved[3]);
|
||||||
gl_RenderState.ApplyColorMask();
|
gl_RenderState.ApplyColorMask();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue