From fcee0217538475af332bb50c7e904e104c90b5a0 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 3 Jul 2018 21:44:49 +0200 Subject: [PATCH] Fix frame buffer binding bug that caused PP textures to end up with bad data --- src/gl/renderer/gl_renderbuffers.cpp | 30 ++++++++++++------- .../postprocessing/hw_postprocess.cpp | 2 +- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/gl/renderer/gl_renderbuffers.cpp b/src/gl/renderer/gl_renderbuffers.cpp index fa8611af00..7f6cc88366 100644 --- a/src/gl/renderer/gl_renderbuffers.cpp +++ b/src/gl/renderer/gl_renderbuffers.cpp @@ -282,6 +282,8 @@ void FGLRenderBuffers::CreateEyeBuffers(int eye) PPTexture FGLRenderBuffers::Create2DTexture(const char *name, GLuint format, int width, int height, const void *data) { PPTexture tex; + tex.Width = width; + tex.Height = height; glGenTextures(1, &tex.handle); glBindTexture(GL_TEXTURE_2D, tex.handle); FGLDebug::LabelObject(GL_TEXTURE, tex.handle, name); @@ -316,6 +318,8 @@ PPTexture FGLRenderBuffers::Create2DTexture(const char *name, GLuint format, int PPTexture FGLRenderBuffers::Create2DMultisampleTexture(const char *name, GLuint format, int width, int height, int samples, bool fixedSampleLocations) { PPTexture tex; + tex.Width = width; + tex.Height = height; glGenTextures(1, &tex.handle); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, tex.handle); FGLDebug::LabelObject(GL_TEXTURE, tex.handle, name); @@ -752,6 +756,8 @@ bool FGLRenderBuffers::FailedCreate = false; void FGLRenderBuffers::UpdateEffectTextures() { + FGLPostProcessState savedState; + TMap::Iterator it(hw_postprocess.Textures); TMap::Pair *pair; while (it.NextPair(pair)) @@ -772,23 +778,24 @@ void FGLRenderBuffers::UpdateEffectTextures() if (gltexture && (gltexture.Width != pair->Value.Width || gltexture.Height != pair->Value.Height)) { - glDeleteTextures(1, &gltexture.handle); - glDeleteFramebuffers(1, &glframebuffer.handle); - gltexture.handle = 0; - glframebuffer.handle = 0; + if (gltexture.handle != 0) + { + glDeleteTextures(1, &gltexture.handle); + gltexture.handle = 0; + } + if (glframebuffer.handle != 0) + { + glDeleteFramebuffers(1, &glframebuffer.handle); + glframebuffer.handle = 0; + } } if (!gltexture) { - FGLPostProcessState savedState; - if (pair->Value.Data) gltexture = Create2DTexture(pair->Key.GetChars(), glformat, pair->Value.Width, pair->Value.Height, pair->Value.Data.get()); else gltexture = Create2DTexture(pair->Key.GetChars(), glformat, pair->Value.Width, pair->Value.Height); - gltexture.Width = pair->Value.Width; - gltexture.Height = pair->Value.Height; - glframebuffer = CreateFrameBuffer(pair->Key.GetChars(), gltexture); } } } @@ -900,7 +907,10 @@ void FGLRenderBuffers::RenderEffect(const FString &name) break; case PPTextureType::PPTexture: - GLTextureFBs[step.Output.Texture].Bind(); + if (GLTextureFBs[step.Output.Texture]) + GLTextureFBs[step.Output.Texture].Bind(); + else + GLTextureFBs[step.Output.Texture] = CreateFrameBuffer(step.Output.Texture.GetChars(), GLTextures[step.Output.Texture]); break; case PPTextureType::SceneColor: diff --git a/src/hwrenderer/postprocessing/hw_postprocess.cpp b/src/hwrenderer/postprocessing/hw_postprocess.cpp index 228c9d3fb8..9a2109a11e 100644 --- a/src/hwrenderer/postprocessing/hw_postprocess.cpp +++ b/src/hwrenderer/postprocessing/hw_postprocess.cpp @@ -442,7 +442,7 @@ void PPCameraExposure::UpdateTextures() void PPCameraExposure::UpdateSteps() { - if (!gl_bloom && gl_tonemap == 0) + if (!gl_bloom) { hw_postprocess.Effects["UpdateCameraExposure"] = {}; return;