Keep using render buffers when ssao is off, for better performance

This commit is contained in:
Magnus Norddahl 2016-10-05 03:56:58 +02:00
parent ecb57d6cd9
commit 490dd612b3
2 changed files with 70 additions and 25 deletions

View file

@ -83,10 +83,19 @@ void FGLRenderBuffers::ClearScene()
{ {
DeleteFrameBuffer(mSceneFB); DeleteFrameBuffer(mSceneFB);
DeleteFrameBuffer(mSceneDataFB); DeleteFrameBuffer(mSceneDataFB);
if (mSceneUsesTextures)
{
DeleteTexture(mSceneMultisample); DeleteTexture(mSceneMultisample);
DeleteTexture(mSceneData); DeleteTexture(mSceneData);
DeleteTexture(mSceneDepthStencil); DeleteTexture(mSceneDepthStencil);
} }
else
{
DeleteRenderBuffer(mSceneMultisample);
DeleteRenderBuffer(mSceneData);
DeleteRenderBuffer(mSceneDepthStencil);
}
}
void FGLRenderBuffers::ClearPipeline() void FGLRenderBuffers::ClearPipeline()
{ {
@ -188,6 +197,7 @@ bool FGLRenderBuffers::Setup(int width, int height, int sceneWidth, int sceneHei
I_FatalError("Requested invalid render buffer sizes: screen = %dx%d", width, height); I_FatalError("Requested invalid render buffer sizes: screen = %dx%d", width, height);
int samples = clamp((int)gl_multisample, 0, mMaxSamples); int samples = clamp((int)gl_multisample, 0, mMaxSamples);
bool needsSceneTextures = (gl_ssao != 0);
GLint activeTex; GLint activeTex;
GLint textureBinding; GLint textureBinding;
@ -195,19 +205,16 @@ bool FGLRenderBuffers::Setup(int width, int height, int sceneWidth, int sceneHei
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding); glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
if (width == mWidth && height == mHeight && mSamples != samples) if (width != mWidth || height != mHeight)
{
CreateScene(mWidth, mHeight, samples);
mSamples = samples;
}
else if (width != mWidth || height != mHeight)
{
CreatePipeline(width, height); CreatePipeline(width, height);
CreateScene(width, height, samples);
if (width != mWidth || height != mHeight || mSamples != samples || mSceneUsesTextures != needsSceneTextures)
CreateScene(width, height, samples, needsSceneTextures);
mWidth = width; mWidth = width;
mHeight = height; mHeight = height;
mSamples = samples; mSamples = samples;
} mSceneUsesTextures = needsSceneTextures;
// Bloom bluring buffers need to match the scene to avoid bloom bleeding artifacts // Bloom bluring buffers need to match the scene to avoid bloom bleeding artifacts
if (mSceneWidth != sceneWidth || mSceneHeight != sceneHeight) if (mSceneWidth != sceneWidth || mSceneHeight != sceneHeight)
@ -247,24 +254,44 @@ bool FGLRenderBuffers::Setup(int width, int height, int sceneWidth, int sceneHei
// //
//========================================================================== //==========================================================================
void FGLRenderBuffers::CreateScene(int width, int height, int samples) void FGLRenderBuffers::CreateScene(int width, int height, int samples, bool needsSceneTextures)
{ {
ClearScene(); ClearScene();
if (samples > 1) if (samples > 1)
{
if (needsSceneTextures)
{ {
mSceneMultisample = Create2DMultisampleTexture("SceneMultisample", GL_RGBA16F, width, height, samples, false); mSceneMultisample = Create2DMultisampleTexture("SceneMultisample", GL_RGBA16F, width, height, samples, false);
mSceneDepthStencil = Create2DMultisampleTexture("SceneDepthStencil", GL_DEPTH24_STENCIL8, width, height, samples, false); mSceneDepthStencil = Create2DMultisampleTexture("SceneDepthStencil", GL_DEPTH24_STENCIL8, width, height, samples, false);
mSceneData = Create2DMultisampleTexture("SceneSSAOData", GL_RGBA8, width, height, samples, false); mSceneData = Create2DMultisampleTexture("SceneSSAOData", GL_RGBA8, width, height, samples, false);
mSceneFB = CreateFrameBuffer("SceneFB", mSceneMultisample, 0, mSceneDepthStencil, true);
mSceneDataFB = CreateFrameBuffer("SSAOSceneFB", mSceneMultisample, mSceneData, mSceneDepthStencil, true);
} }
else else
{
mSceneMultisample = CreateRenderBuffer("SceneMultisample", GL_RGBA16F, width, height, samples);
mSceneDepthStencil = CreateRenderBuffer("SceneDepthStencil", GL_DEPTH24_STENCIL8, width, height, samples);
mSceneFB = CreateFrameBuffer("SceneFB", mSceneMultisample, mSceneDepthStencil, true);
mSceneDataFB = CreateFrameBuffer("SSAOSceneFB", mSceneMultisample, mSceneDepthStencil, true);
}
}
else
{
if (needsSceneTextures)
{ {
mSceneDepthStencil = Create2DTexture("SceneDepthStencil", GL_DEPTH24_STENCIL8, width, height); mSceneDepthStencil = Create2DTexture("SceneDepthStencil", GL_DEPTH24_STENCIL8, width, height);
mSceneData = Create2DTexture("SceneSSAOData", GL_RGBA8, width, height); mSceneData = Create2DTexture("SceneSSAOData", GL_RGBA8, width, height);
mSceneFB = CreateFrameBuffer("SceneFB", mPipelineTexture[0], 0, mSceneDepthStencil, false);
mSceneDataFB = CreateFrameBuffer("SSAOSceneFB", mPipelineTexture[0], mSceneData, mSceneDepthStencil, false);
}
else
{
mSceneDepthStencil = CreateRenderBuffer("SceneDepthStencil", GL_DEPTH24_STENCIL8, width, height);
mSceneFB = CreateFrameBuffer("SceneFB", mPipelineTexture[0], mSceneDepthStencil, false);
mSceneDataFB = CreateFrameBuffer("SSAOSceneFB", mPipelineTexture[0], mSceneDepthStencil, false);
}
} }
mSceneFB = CreateFrameBuffer("SceneFB", samples > 1 ? mSceneMultisample : mPipelineTexture[0], 0, mSceneDepthStencil, samples > 1);
mSceneDataFB = CreateFrameBuffer("SSAOSceneFB", samples > 1 ? mSceneMultisample : mPipelineTexture[0], mSceneData, mSceneDepthStencil, samples > 1);
} }
//========================================================================== //==========================================================================
@ -517,6 +544,22 @@ GLuint FGLRenderBuffers::CreateFrameBuffer(const FString &name, GLuint colorbuff
return handle; return handle;
} }
GLuint FGLRenderBuffers::CreateFrameBuffer(const FString &name, GLuint colorbuffer, GLuint depthstencil, bool colorIsARenderBuffer)
{
GLuint handle = 0;
glGenFramebuffers(1, &handle);
glBindFramebuffer(GL_FRAMEBUFFER, handle);
FGLDebug::LabelObject(GL_FRAMEBUFFER, handle, name);
if (colorIsARenderBuffer)
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorbuffer);
else
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthstencil);
if (CheckFrameBufferCompleteness())
ClearFrameBuffer(true, true);
return handle;
}
GLuint FGLRenderBuffers::CreateFrameBuffer(const FString &name, GLuint colorbuffer0, GLuint colorbuffer1, GLuint depthstencil, bool multisample) GLuint FGLRenderBuffers::CreateFrameBuffer(const FString &name, GLuint colorbuffer0, GLuint colorbuffer1, GLuint depthstencil, bool multisample)
{ {
GLuint handle = 0; GLuint handle = 0;

View file

@ -81,7 +81,7 @@ private:
void ClearBloom(); void ClearBloom();
void ClearExposureLevels(); void ClearExposureLevels();
void ClearAmbientOcclusion(); void ClearAmbientOcclusion();
void CreateScene(int width, int height, int samples); void CreateScene(int width, int height, int samples, bool needsSceneTextures);
void CreatePipeline(int width, int height); void CreatePipeline(int width, int height);
void CreateBloom(int width, int height); void CreateBloom(int width, int height);
void CreateExposureLevels(int width, int height); void CreateExposureLevels(int width, int height);
@ -92,6 +92,7 @@ private:
GLuint CreateRenderBuffer(const FString &name, GLuint format, int width, int height); GLuint CreateRenderBuffer(const FString &name, GLuint format, int width, int height);
GLuint CreateRenderBuffer(const FString &name, GLuint format, int samples, int width, int height); GLuint CreateRenderBuffer(const FString &name, GLuint format, int samples, int width, int height);
GLuint CreateFrameBuffer(const FString &name, GLuint colorbuffer); GLuint CreateFrameBuffer(const FString &name, GLuint colorbuffer);
GLuint CreateFrameBuffer(const FString &name, GLuint colorbuffer, GLuint depthstencil, bool colorIsARenderBuffer);
GLuint CreateFrameBuffer(const FString &name, GLuint colorbuffer0, GLuint colorbuffer1, GLuint depthstencil, bool multisample); GLuint CreateFrameBuffer(const FString &name, GLuint colorbuffer0, GLuint colorbuffer1, GLuint depthstencil, bool multisample);
bool CheckFrameBufferCompleteness(); bool CheckFrameBufferCompleteness();
void ClearFrameBuffer(bool stencil, bool depth); void ClearFrameBuffer(bool stencil, bool depth);
@ -115,6 +116,7 @@ private:
GLuint mSceneData = 0; GLuint mSceneData = 0;
GLuint mSceneFB = 0; GLuint mSceneFB = 0;
GLuint mSceneDataFB = 0; GLuint mSceneDataFB = 0;
bool mSceneUsesTextures = false;
// Effect/HUD buffers // Effect/HUD buffers
GLuint mPipelineTexture[NumPipelineTextures]; GLuint mPipelineTexture[NumPipelineTextures];