diff --git a/src/gl/dynlights/gl_shadowmap.cpp b/src/gl/dynlights/gl_shadowmap.cpp index 910b620d1..13f534bb2 100644 --- a/src/gl/dynlights/gl_shadowmap.cpp +++ b/src/gl/dynlights/gl_shadowmap.cpp @@ -53,7 +53,7 @@ void FShadowMap::Update() GLRenderer->mShadowMapShader->Bind(); GLRenderer->mShadowMapShader->Uniforms->ShadowmapQuality = gl_shadowmap_quality; - GLRenderer->mShadowMapShader->Uniforms.Set(); + GLRenderer->mShadowMapShader->Uniforms.Set(POSTPROCESS_BINDINGPOINT); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, mLightList); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, mNodesBuffer); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, mLinesBuffer); diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index 06ac1cae3..6b7ce120c 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -125,7 +125,7 @@ void FGLRenderer::AmbientOccludeScene() mLinearDepthShader->Uniforms->InverseDepthRangeB = 0.0f; mLinearDepthShader->Uniforms->Scale = { sceneScaleX, sceneScaleY }; mLinearDepthShader->Uniforms->Offset = { sceneOffsetX, sceneOffsetY }; - mLinearDepthShader->Uniforms.Set(); + mLinearDepthShader->Uniforms.Set(POSTPROCESS_BINDINGPOINT); RenderScreenQuad(); // Apply ambient occlusion @@ -148,7 +148,7 @@ void FGLRenderer::AmbientOccludeScene() mSSAOShader->Uniforms->AOStrength = aoStrength; mSSAOShader->Uniforms->Scale = { sceneScaleX, sceneScaleY }; mSSAOShader->Uniforms->Offset = { sceneOffsetX, sceneOffsetY }; - mSSAOShader->Uniforms.Set(); + mSSAOShader->Uniforms.Set(POSTPROCESS_BINDINGPOINT); RenderScreenQuad(); // Blur SSAO texture @@ -159,7 +159,7 @@ void FGLRenderer::AmbientOccludeScene() mDepthBlurShader->Bind(false); mDepthBlurShader->Uniforms[false]->BlurSharpness = blurSharpness; mDepthBlurShader->Uniforms[false]->InvFullResolution = { 1.0f / mBuffers->AmbientWidth, 1.0f / mBuffers->AmbientHeight }; - mDepthBlurShader->Uniforms[false].Set(); + mDepthBlurShader->Uniforms[false].Set(POSTPROCESS_BINDINGPOINT); RenderScreenQuad(); mBuffers->AmbientFB1.Bind(); @@ -168,7 +168,7 @@ void FGLRenderer::AmbientOccludeScene() mDepthBlurShader->Uniforms[true]->BlurSharpness = blurSharpness; mDepthBlurShader->Uniforms[true]->InvFullResolution = { 1.0f / mBuffers->AmbientWidth, 1.0f / mBuffers->AmbientHeight }; mDepthBlurShader->Uniforms[true]->PowExponent = gl_ssao_exponent; - mDepthBlurShader->Uniforms[true].Set(); + mDepthBlurShader->Uniforms[true].Set(POSTPROCESS_BINDINGPOINT); RenderScreenQuad(); } @@ -191,7 +191,7 @@ void FGLRenderer::AmbientOccludeScene() if (gl_multisample > 1) mSSAOCombineShader->Uniforms->SampleCount = gl_multisample; mSSAOCombineShader->Uniforms->Scale = { sceneScaleX, sceneScaleY }; mSSAOCombineShader->Uniforms->Offset = { sceneOffsetX, sceneOffsetY }; - mSSAOCombineShader->Uniforms.Set(); + mSSAOCombineShader->Uniforms.Set(POSTPROCESS_BINDINGPOINT); RenderScreenQuad(); FGLDebug::PopGroup(); @@ -225,7 +225,7 @@ void FGLRenderer::UpdateCameraExposure() mExposureExtractShader->SceneTexture.Set(0); mExposureExtractShader->Uniforms->Scale = { mSceneViewport.width / (float)mScreenViewport.width, mSceneViewport.height / (float)mScreenViewport.height }; mExposureExtractShader->Uniforms->Offset = { mSceneViewport.left / (float)mScreenViewport.width, mSceneViewport.top / (float)mScreenViewport.height }; - mExposureExtractShader->Uniforms.Set(); + mExposureExtractShader->Uniforms.Set(POSTPROCESS_BINDINGPOINT); RenderScreenQuad(); // Find the average value: @@ -262,7 +262,7 @@ void FGLRenderer::UpdateCameraExposure() mExposureCombineShader->Uniforms->ExposureMin = gl_exposure_min; mExposureCombineShader->Uniforms->ExposureScale = gl_exposure_scale; mExposureCombineShader->Uniforms->ExposureSpeed = gl_exposure_speed; - mExposureCombineShader->Uniforms.Set(); + mExposureCombineShader->Uniforms.Set(POSTPROCESS_BINDINGPOINT); RenderScreenQuad(); glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height); @@ -304,7 +304,7 @@ void FGLRenderer::BloomScene(int fixedcm) mBloomExtractShader->ExposureTexture.Set(1); mBloomExtractShader->Uniforms->Scale = { mSceneViewport.width / (float)mScreenViewport.width, mSceneViewport.height / (float)mScreenViewport.height }; mBloomExtractShader->Uniforms->Offset = { mSceneViewport.left / (float)mScreenViewport.width, mSceneViewport.top / (float)mScreenViewport.height }; - mBloomExtractShader->Uniforms.Set(); + mBloomExtractShader->Uniforms.Set(POSTPROCESS_BINDINGPOINT); RenderScreenQuad(); // Blur and downscale: @@ -534,7 +534,7 @@ void FGLRenderer::ColormapScene(int fixedcm) mColormapShader->Uniforms->MapStart = { scm->ColorizeStart[0], scm->ColorizeStart[1], scm->ColorizeStart[2], 0.f }; mColormapShader->Uniforms->MapRange = m; - mColormapShader->Uniforms.Set(); + mColormapShader->Uniforms.Set(POSTPROCESS_BINDINGPOINT); RenderScreenQuad(); mBuffers->NextTexture(); @@ -590,7 +590,7 @@ void FGLRenderer::LensDistortScene() mLensShader->Uniforms->Scale = scale; mLensShader->Uniforms->LensDistortionCoefficient = k; mLensShader->Uniforms->CubicDistortionValue = kcube; - mLensShader->Uniforms.Set(); + mLensShader->Uniforms.Set(POSTPROCESS_BINDINGPOINT); RenderScreenQuad(); mBuffers->NextTexture(); @@ -626,7 +626,7 @@ void FGLRenderer::ApplyFXAA() mFXAAShader->Bind(); mFXAAShader->InputTexture.Set(0); mFXAAShader->Uniforms->ReciprocalResolution = { 1.0f / mBuffers->GetWidth(), 1.0f / mBuffers->GetHeight() }; - mFXAAShader->Uniforms.Set(); + mFXAAShader->Uniforms.Set(POSTPROCESS_BINDINGPOINT); RenderScreenQuad(); mBuffers->NextTexture(); @@ -745,7 +745,7 @@ void FGLRenderer::DrawPresentTexture(const IntRect &box, bool applyGamma) mPresentShader->Uniforms->GrayFormula = static_cast(gl_satformula); } mPresentShader->Uniforms->Scale = { screen->mScreenViewport.width / (float)mBuffers->GetWidth(), screen->mScreenViewport.height / (float)mBuffers->GetHeight() }; - mPresentShader->Uniforms.Set(); + mPresentShader->Uniforms.Set(POSTPROCESS_BINDINGPOINT); RenderScreenQuad(); } diff --git a/src/gl/shaders/gl_ambientshader.cpp b/src/gl/shaders/gl_ambientshader.cpp index 49765915d..c7242c82b 100644 --- a/src/gl/shaders/gl_ambientshader.cpp +++ b/src/gl/shaders/gl_ambientshader.cpp @@ -42,9 +42,10 @@ void FLinearDepthShader::Bind() mShader->SetFragDataLocation(0, "FragColor"); mShader->Link("shaders/glsl/lineardepth"); mShader->SetAttribLocation(0, "PositionInProjection"); + mShader->SetUniformBufferLocation(POSTPROCESS_BINDINGPOINT, "Uniforms"); DepthTexture.Init(*mShader, "DepthTexture"); ColorTexture.Init(*mShader, "ColorTexture"); - Uniforms.Init(*mShader); + Uniforms.Init(); mMultisample = multisample; } mShader->Bind(); @@ -67,10 +68,11 @@ void FSSAOShader::Bind() mShader->SetFragDataLocation(0, "FragColor"); mShader->Link("shaders/glsl/ssao"); mShader->SetAttribLocation(0, "PositionInProjection"); + mShader->SetUniformBufferLocation(POSTPROCESS_BINDINGPOINT, "Uniforms"); DepthTexture.Init(*mShader, "DepthTexture"); NormalTexture.Init(*mShader, "NormalTexture"); RandomTexture.Init(*mShader, "RandomTexture"); - Uniforms.Init(*mShader); + Uniforms.Init(); mMultisample = multisample; } mShader->Bind(); @@ -117,8 +119,9 @@ void FDepthBlurShader::Bind(bool vertical) shader.SetFragDataLocation(0, "FragColor"); shader.Link("shaders/glsl/depthblur"); shader.SetAttribLocation(0, "PositionInProjection"); + shader.SetUniformBufferLocation(POSTPROCESS_BINDINGPOINT, "Uniforms"); AODepthTexture[vertical].Init(shader, "AODepthTexture"); - Uniforms[vertical].Init(shader); + Uniforms[vertical].Init(); } shader.Bind(); } @@ -141,9 +144,10 @@ void FSSAOCombineShader::Bind() mShader->SetFragDataLocation(0, "FragColor"); mShader->Link("shaders/glsl/ssaocombine"); mShader->SetAttribLocation(0, "PositionInProjection"); + mShader->SetUniformBufferLocation(POSTPROCESS_BINDINGPOINT, "Uniforms"); AODepthTexture.Init(*mShader, "AODepthTexture"); SceneFogTexture.Init(*mShader, "SceneFogTexture"); - Uniforms.Init(*mShader); + Uniforms.Init(); mMultisample = multisample; } mShader->Bind(); diff --git a/src/gl/shaders/gl_bloomshader.cpp b/src/gl/shaders/gl_bloomshader.cpp index 920a140c1..8e5a2f5ea 100644 --- a/src/gl/shaders/gl_bloomshader.cpp +++ b/src/gl/shaders/gl_bloomshader.cpp @@ -40,9 +40,10 @@ void FBloomExtractShader::Bind() mShader.SetFragDataLocation(0, "FragColor"); mShader.Link("shaders/glsl/bloomextract"); mShader.SetAttribLocation(0, "PositionInProjection"); + mShader.SetUniformBufferLocation(POSTPROCESS_BINDINGPOINT, "Uniforms"); SceneTexture.Init(mShader, "SceneTexture"); ExposureTexture.Init(mShader, "ExposureTexture"); - Uniforms.Init(mShader); + Uniforms.Init(); } mShader.Bind(); } diff --git a/src/gl/shaders/gl_colormapshader.cpp b/src/gl/shaders/gl_colormapshader.cpp index a288d9f04..6979860d6 100644 --- a/src/gl/shaders/gl_colormapshader.cpp +++ b/src/gl/shaders/gl_colormapshader.cpp @@ -41,7 +41,8 @@ void FColormapShader::Bind() shader.SetFragDataLocation(0, "FragColor"); shader.Link("shaders/glsl/colormap"); shader.SetAttribLocation(0, "PositionInProjection"); - Uniforms.Init(shader); + shader.SetUniformBufferLocation(POSTPROCESS_BINDINGPOINT, "Uniforms"); + Uniforms.Init(); } shader.Bind(); } diff --git a/src/gl/shaders/gl_fxaashader.cpp b/src/gl/shaders/gl_fxaashader.cpp index 844f803f1..2fbc0e2f0 100644 --- a/src/gl/shaders/gl_fxaashader.cpp +++ b/src/gl/shaders/gl_fxaashader.cpp @@ -91,8 +91,9 @@ void FFXAAShader::Bind() shader.SetFragDataLocation(0, "FragColor"); shader.Link("shaders/glsl/fxaa"); shader.SetAttribLocation(0, "PositionInProjection"); + shader.SetUniformBufferLocation(POSTPROCESS_BINDINGPOINT, "Uniforms"); InputTexture.Init(shader, "InputTexture"); - Uniforms.Init(shader); + Uniforms.Init(); } shader.Bind(); diff --git a/src/gl/shaders/gl_lensshader.cpp b/src/gl/shaders/gl_lensshader.cpp index 13945e8eb..7bfbbfa19 100644 --- a/src/gl/shaders/gl_lensshader.cpp +++ b/src/gl/shaders/gl_lensshader.cpp @@ -40,8 +40,9 @@ void FLensShader::Bind() mShader.SetFragDataLocation(0, "FragColor"); mShader.Link("shaders/glsl/lensdistortion"); mShader.SetAttribLocation(0, "PositionInProjection"); + mShader.SetUniformBufferLocation(POSTPROCESS_BINDINGPOINT, "Uniforms"); InputTexture.Init(mShader, "InputTexture"); - Uniforms.Init(mShader); + Uniforms.Init(); } mShader.Bind(); } diff --git a/src/gl/shaders/gl_presentshader.cpp b/src/gl/shaders/gl_presentshader.cpp index e1b2142b1..7f3ca148d 100644 --- a/src/gl/shaders/gl_presentshader.cpp +++ b/src/gl/shaders/gl_presentshader.cpp @@ -39,7 +39,8 @@ void FPresentShaderBase::Init(const char * vtx_shader_name, const char * program mShader.Link(program_name); mShader.SetAttribLocation(0, "PositionInProjection"); mShader.SetAttribLocation(1, "UV"); - Uniforms.Init(mShader); + mShader.SetUniformBufferLocation(POSTPROCESS_BINDINGPOINT, "Uniforms"); + Uniforms.Init(); } void FPresentShader::Bind() diff --git a/src/gl/shaders/gl_shaderprogram.cpp b/src/gl/shaders/gl_shaderprogram.cpp index ae973cb3e..35f4cfef4 100644 --- a/src/gl/shaders/gl_shaderprogram.cpp +++ b/src/gl/shaders/gl_shaderprogram.cpp @@ -159,6 +159,19 @@ void FShaderProgram::SetAttribLocation(int index, const char *name) glBindAttribLocation(mProgram, index, name); } +//========================================================================== +// +// Set uniform buffer location +// +//========================================================================== + +void FShaderProgram::SetUniformBufferLocation(int index, const char *name) +{ + GLuint uniformBlockIndex = glGetUniformBlockIndex(mProgram, name); + if (uniformBlockIndex != GL_INVALID_INDEX) + glUniformBlockBinding(mProgram, uniformBlockIndex, index); +} + //========================================================================== // // Makes the shader the active program diff --git a/src/gl/shaders/gl_shaderprogram.h b/src/gl/shaders/gl_shaderprogram.h index 74e1ea9c0..705af5375 100644 --- a/src/gl/shaders/gl_shaderprogram.h +++ b/src/gl/shaders/gl_shaderprogram.h @@ -47,7 +47,6 @@ public: FString CreateDeclaration(const char *name, const std::vector &fields) { - mName = name; mFields = fields; FString decl; @@ -61,23 +60,18 @@ public: return decl; } - void Init(GLuint hShader, int index = POSTPROCESS_BINDINGPOINT) + void Init() { - GLuint uniformBlockIndex = glGetUniformBlockIndex(hShader, mName); - if (uniformBlockIndex != GL_INVALID_INDEX) - { - glUniformBlockBinding(hShader, uniformBlockIndex, index); + if (!mBufferHandle) glGenBuffers(1, (GLuint*)&mBufferHandle); - mIndex = index; - } } - void Set() + void Set(int index) { glBindBuffer(GL_UNIFORM_BUFFER, mBufferHandle); glBufferData(GL_UNIFORM_BUFFER, sizeof(T), &Values, GL_STREAM_DRAW); - glBindBufferBase(GL_UNIFORM_BUFFER, mIndex, mBufferHandle); + glBindBufferBase(GL_UNIFORM_BUFFER, index, mBufferHandle); } T *operator->() { return &Values; } @@ -109,8 +103,6 @@ private: } } - const char *mName = nullptr; - int mIndex = -1; GLuint mBufferHandle = 0; std::vector mFields; std::vector mUniformLocations; @@ -134,6 +126,7 @@ public: void SetFragDataLocation(int index, const char *name); void Link(const char *name); void SetAttribLocation(int index, const char *name); + void SetUniformBufferLocation(int index, const char *name); void Bind(); operator GLuint() const { return mProgram; } diff --git a/src/gl/shaders/gl_shadowmapshader.cpp b/src/gl/shaders/gl_shadowmapshader.cpp index d5eb82f82..6541f59ac 100644 --- a/src/gl/shaders/gl_shadowmapshader.cpp +++ b/src/gl/shaders/gl_shadowmapshader.cpp @@ -35,7 +35,8 @@ void FShadowMapShader::Bind() mShader.SetFragDataLocation(0, "FragColor"); mShader.Link("shaders/glsl/shadowmap"); mShader.SetAttribLocation(0, "PositionInProjection"); - Uniforms.Init(mShader); + mShader.SetUniformBufferLocation(POSTPROCESS_BINDINGPOINT, "Uniforms"); + Uniforms.Init(); } mShader.Bind(); } diff --git a/src/gl/shaders/gl_tonemapshader.cpp b/src/gl/shaders/gl_tonemapshader.cpp index d1254edb5..41c3c7297 100644 --- a/src/gl/shaders/gl_tonemapshader.cpp +++ b/src/gl/shaders/gl_tonemapshader.cpp @@ -76,8 +76,9 @@ void FExposureExtractShader::Bind() mShader.SetFragDataLocation(0, "FragColor"); mShader.Link("shaders/glsl/exposureextract"); mShader.SetAttribLocation(0, "PositionInProjection"); + mShader.SetUniformBufferLocation(POSTPROCESS_BINDINGPOINT, "Uniforms"); SceneTexture.Init(mShader, "SceneTexture"); - Uniforms.Init(mShader); + Uniforms.Init(); } mShader.Bind(); } @@ -107,8 +108,9 @@ void FExposureCombineShader::Bind() mShader.SetFragDataLocation(0, "FragColor"); mShader.Link("shaders/glsl/exposurecombine"); mShader.SetAttribLocation(0, "PositionInProjection"); + mShader.SetUniformBufferLocation(POSTPROCESS_BINDINGPOINT, "Uniforms"); ExposureTexture.Init(mShader, "ExposureTexture"); - Uniforms.Init(mShader); + Uniforms.Init(); } mShader.Bind(); } \ No newline at end of file diff --git a/src/gl/stereo3d/gl_interleaved3d.cpp b/src/gl/stereo3d/gl_interleaved3d.cpp index ed1d6d381..3fc665931 100644 --- a/src/gl/stereo3d/gl_interleaved3d.cpp +++ b/src/gl/stereo3d/gl_interleaved3d.cpp @@ -118,7 +118,7 @@ static void prepareInterleavedPresent(FPresentStereoShaderBase& shader) screen->mScreenViewport.width / (float)GLRenderer->mBuffers->GetWidth(), screen->mScreenViewport.height / (float)GLRenderer->mBuffers->GetHeight() }; - shader.Uniforms.Set(); + shader.Uniforms.Set(POSTPROCESS_BINDINGPOINT); } // fixme: I don't know how to get absolute window position on Mac and Linux @@ -155,7 +155,7 @@ void CheckerInterleaved3D::Present() const + screen->mOutputLetterbox.height + 1 // +1 because of origin at bottom ) % 2; // because we want the top pixel offset, but gl_FragCoord.y is the bottom pixel offset - GLRenderer->mPresent3dCheckerShader->Uniforms.Set(); + GLRenderer->mPresent3dCheckerShader->Uniforms.Set(POSTPROCESS_BINDINGPOINT); GLRenderer->RenderScreenQuad(); } @@ -193,7 +193,7 @@ void ColumnInterleaved3D::Present() const #endif // _WIN32 GLRenderer->mPresent3dColumnShader->Uniforms->WindowPositionParity = windowHOffset; - GLRenderer->mPresent3dColumnShader->Uniforms.Set(); + GLRenderer->mPresent3dColumnShader->Uniforms.Set(POSTPROCESS_BINDINGPOINT); GLRenderer->RenderScreenQuad(); } @@ -220,7 +220,7 @@ void RowInterleaved3D::Present() const + screen->mOutputLetterbox.height + 1 // +1 because of origin at bottom ) % 2; - GLRenderer->mPresent3dColumnShader->Uniforms.Set(); + GLRenderer->mPresent3dColumnShader->Uniforms.Set(POSTPROCESS_BINDINGPOINT); GLRenderer->RenderScreenQuad(); }