From bea113a908bd2b695e0d15607cb04065dc2810b7 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Mon, 28 Nov 2016 02:32:57 +0100 Subject: [PATCH] Fix tonemap texture filtering (black screen) regression --- src/gl/renderer/gl_postprocess.cpp | 30 ++++++++++++++---------------- src/gl/renderer/gl_renderer.h | 2 +- src/gl/textures/gl_hwtexture.cpp | 5 +++++ src/gl/textures/gl_hwtexture.h | 1 + 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index dd8bccc8b9..f15171c533 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -468,7 +468,10 @@ void FGLRenderer::TonemapScene() FGLDebug::PushGroup("TonemapScene"); + CreateTonemapPalette(); + FGLPostProcessState savedState; + savedState.SaveTextureBindings(2); mBuffers->BindNextFB(); mBuffers->BindCurrentTexture(0); @@ -477,12 +480,18 @@ void FGLRenderer::TonemapScene() if (mTonemapShader->IsPaletteMode()) { + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, mTonemapPalette->GetTextureHandle(0)); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glActiveTexture(GL_TEXTURE0); + mTonemapShader->PaletteLUT.Set(1); - BindTonemapPalette(1); } else { - savedState.SaveTextureBindings(2); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, mBuffers->ExposureTexture); glActiveTexture(GL_TEXTURE0); @@ -496,13 +505,9 @@ void FGLRenderer::TonemapScene() FGLDebug::PopGroup(); } -void FGLRenderer::BindTonemapPalette(int texunit) +void FGLRenderer::CreateTonemapPalette() { - if (mTonemapPalette) - { - mTonemapPalette->Bind(texunit, 0, false); - } - else + if (!mTonemapPalette) { TArray lut; lut.Resize(512 * 512 * 4); @@ -523,14 +528,7 @@ void FGLRenderer::BindTonemapPalette(int texunit) } mTonemapPalette = new FHardwareTexture(512, 512, true); - mTonemapPalette->CreateTexture(&lut[0], 512, 512, texunit, false, 0, "mTonemapPalette"); - - glActiveTexture(GL_TEXTURE0 + texunit); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glActiveTexture(GL_TEXTURE0); + mTonemapPalette->CreateTexture(&lut[0], 512, 512, 0, false, 0, "mTonemapPalette"); } } diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index 7eedd46940..869b46d2d0 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -195,7 +195,7 @@ public: void BloomScene(); void TonemapScene(); void ColormapScene(); - void BindTonemapPalette(int texunit); + void CreateTonemapPalette(); void ClearTonemapPalette(); void LensDistortScene(); void ApplyFXAA(); diff --git a/src/gl/textures/gl_hwtexture.cpp b/src/gl/textures/gl_hwtexture.cpp index edcda4398b..477d1986be 100644 --- a/src/gl/textures/gl_hwtexture.cpp +++ b/src/gl/textures/gl_hwtexture.cpp @@ -374,6 +374,11 @@ unsigned int FHardwareTexture::Bind(int texunit, int translation, bool needmipma return 0; } +unsigned int FHardwareTexture::GetTextureHandle(int translation) +{ + TranslatedTexture *pTex = GetTexID(translation); + return pTex->glTexID; +} void FHardwareTexture::Unbind(int texunit) { diff --git a/src/gl/textures/gl_hwtexture.h b/src/gl/textures/gl_hwtexture.h index 96eff02643..59fc981698 100644 --- a/src/gl/textures/gl_hwtexture.h +++ b/src/gl/textures/gl_hwtexture.h @@ -83,6 +83,7 @@ public: unsigned int Bind(int texunit, int translation, bool needmipmap); unsigned int CreateTexture(unsigned char * buffer, int w, int h, int texunit, bool mipmap, int translation, const FString &name); + unsigned int GetTextureHandle(int translation); void Clean(bool all); void CleanUnused(SpriteHits &usedtranslations);