diff --git a/src/gl/dynlights/gl_shadowmap.cpp b/src/gl/dynlights/gl_shadowmap.cpp index 15a537010e..910b620d17 100644 --- a/src/gl/dynlights/gl_shadowmap.cpp +++ b/src/gl/dynlights/gl_shadowmap.cpp @@ -52,7 +52,8 @@ void FShadowMap::Update() GLRenderer->mBuffers->BindShadowMapFB(); GLRenderer->mShadowMapShader->Bind(); - GLRenderer->mShadowMapShader->ShadowmapQuality.Set(gl_shadowmap_quality); + GLRenderer->mShadowMapShader->Uniforms->ShadowmapQuality = gl_shadowmap_quality; + GLRenderer->mShadowMapShader->Uniforms.Set(); 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 caeeaa0450..a47b1beccf 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -735,20 +735,21 @@ void FGLRenderer::DrawPresentTexture(const IntRect &box, bool applyGamma) mPresentShader->InputTexture.Set(0); if (!applyGamma || framebuffer->IsHWGammaActive()) { - mPresentShader->InvGamma.Set(1.0f); - mPresentShader->Contrast.Set(1.0f); - mPresentShader->Brightness.Set(0.0f); - mPresentShader->Saturation.Set(1.0f); + mPresentShader->Uniforms->InvGamma = 1.0f; + mPresentShader->Uniforms->Contrast = 1.0f; + mPresentShader->Uniforms->Brightness = 0.0f; + mPresentShader->Uniforms->Saturation = 1.0f; } else { - mPresentShader->InvGamma.Set(1.0f / clamp(Gamma, 0.1f, 4.f)); - mPresentShader->Contrast.Set(clamp(vid_contrast, 0.1f, 3.f)); - mPresentShader->Brightness.Set(clamp(vid_brightness, -0.8f, 0.8f)); - mPresentShader->Saturation.Set(clamp(vid_saturation, -15.0f, 15.f)); - mPresentShader->GrayFormula.Set(static_cast(gl_satformula)); + mPresentShader->Uniforms->InvGamma = 1.0f / clamp(Gamma, 0.1f, 4.f); + mPresentShader->Uniforms->Contrast = clamp(vid_contrast, 0.1f, 3.f); + mPresentShader->Uniforms->Brightness = clamp(vid_brightness, -0.8f, 0.8f); + mPresentShader->Uniforms->Saturation = clamp(vid_saturation, -15.0f, 15.f); + mPresentShader->Uniforms->GrayFormula = static_cast(gl_satformula); } - mPresentShader->Scale.Set(screen->mScreenViewport.width / (float)mBuffers->GetWidth(), screen->mScreenViewport.height / (float)mBuffers->GetHeight()); + mPresentShader->Uniforms->Scale = { screen->mScreenViewport.width / (float)mBuffers->GetWidth(), screen->mScreenViewport.height / (float)mBuffers->GetHeight() }; + mPresentShader->Uniforms.Set(); RenderScreenQuad(); } diff --git a/src/gl/shaders/gl_present3dRowshader.cpp b/src/gl/shaders/gl_present3dRowshader.cpp index 12b7b28439..2945032878 100644 --- a/src/gl/shaders/gl_present3dRowshader.cpp +++ b/src/gl/shaders/gl_present3dRowshader.cpp @@ -35,7 +35,6 @@ void FPresentStereoShaderBase::Init(const char * vtx_shader_name, const char * p FPresentShaderBase::Init(vtx_shader_name, program_name); LeftEyeTexture.Init(mShader, "LeftEyeTexture"); RightEyeTexture.Init(mShader, "RightEyeTexture"); - WindowPositionParity.Init(mShader, "WindowPositionParity"); } void FPresent3DCheckerShader::Bind() diff --git a/src/gl/shaders/gl_present3dRowshader.h b/src/gl/shaders/gl_present3dRowshader.h index 10419d7f5a..16142fd1b5 100644 --- a/src/gl/shaders/gl_present3dRowshader.h +++ b/src/gl/shaders/gl_present3dRowshader.h @@ -36,7 +36,6 @@ class FPresentStereoShaderBase : public FPresentShaderBase public: FBufferedUniformSampler LeftEyeTexture; FBufferedUniformSampler RightEyeTexture; - FBufferedUniform1i WindowPositionParity; protected: void Init(const char * vtx_shader_name, const char * program_name) override; diff --git a/src/gl/shaders/gl_presentshader.cpp b/src/gl/shaders/gl_presentshader.cpp index 119a24d08f..e1b2142b1e 100644 --- a/src/gl/shaders/gl_presentshader.cpp +++ b/src/gl/shaders/gl_presentshader.cpp @@ -31,18 +31,15 @@ void FPresentShaderBase::Init(const char * vtx_shader_name, const char * program_name) { - mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquadscale.vp", "", 330); - mShader.Compile(FShaderProgram::Fragment, vtx_shader_name, "", 330); + FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc()); + + mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquadscale.vp", prolog, 330); + mShader.Compile(FShaderProgram::Fragment, vtx_shader_name, prolog, 330); mShader.SetFragDataLocation(0, "FragColor"); mShader.Link(program_name); mShader.SetAttribLocation(0, "PositionInProjection"); mShader.SetAttribLocation(1, "UV"); - InvGamma.Init(mShader, "InvGamma"); - Contrast.Init(mShader, "Contrast"); - Brightness.Init(mShader, "Brightness"); - Saturation.Init(mShader, "Saturation"); - GrayFormula.Init(mShader, "GrayFormula"); - Scale.Init(mShader, "UVScale"); + Uniforms.Init(mShader); } void FPresentShader::Bind() diff --git a/src/gl/shaders/gl_presentshader.h b/src/gl/shaders/gl_presentshader.h index 377a6a4f29..f0e67d1cdc 100644 --- a/src/gl/shaders/gl_presentshader.h +++ b/src/gl/shaders/gl_presentshader.h @@ -9,12 +9,32 @@ public: virtual ~FPresentShaderBase() {} virtual void Bind() = 0; - FBufferedUniform1f InvGamma; - FBufferedUniform1f Contrast; - FBufferedUniform1f Brightness; - FBufferedUniform1f Saturation; - FBufferedUniform1i GrayFormula; - FBufferedUniform2f Scale; + struct UniformBlock + { + float InvGamma; + float Contrast; + float Brightness; + float Saturation; + int GrayFormula; + int WindowPositionParity; // top-of-window might not be top-of-screen + FVector2 Scale; + + static std::vector Desc() + { + return + { + { "InvGamma", UniformType::Float, offsetof(UniformBlock, InvGamma) }, + { "Contrast", UniformType::Float, offsetof(UniformBlock, Contrast) }, + { "Brightness", UniformType::Float, offsetof(UniformBlock, Brightness) }, + { "Saturation", UniformType::Float, offsetof(UniformBlock, Saturation) }, + { "GrayFormula", UniformType::Int, offsetof(UniformBlock, GrayFormula) }, + { "WindowPositionParity", UniformType::Int, offsetof(UniformBlock, WindowPositionParity) }, + { "UVScale", UniformType::Vec2, offsetof(UniformBlock, Scale) }, + }; + } + }; + + ShaderUniforms Uniforms; protected: virtual void Init(const char * vtx_shader_name, const char * program_name); diff --git a/src/gl/shaders/gl_shadowmapshader.cpp b/src/gl/shaders/gl_shadowmapshader.cpp index bed204d924..d5eb82f828 100644 --- a/src/gl/shaders/gl_shadowmapshader.cpp +++ b/src/gl/shaders/gl_shadowmapshader.cpp @@ -28,12 +28,14 @@ void FShadowMapShader::Bind() { if (!mShader) { + FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc()); + mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 430); - mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/shadowmap.fp", "", 430); + mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/shadowmap.fp", prolog, 430); mShader.SetFragDataLocation(0, "FragColor"); mShader.Link("shaders/glsl/shadowmap"); mShader.SetAttribLocation(0, "PositionInProjection"); - ShadowmapQuality.Init(mShader, "ShadowmapQuality"); + Uniforms.Init(mShader); } mShader.Bind(); } diff --git a/src/gl/shaders/gl_shadowmapshader.h b/src/gl/shaders/gl_shadowmapshader.h index 309dccb525..a36ffabd02 100644 --- a/src/gl/shaders/gl_shadowmapshader.h +++ b/src/gl/shaders/gl_shadowmapshader.h @@ -8,7 +8,24 @@ class FShadowMapShader public: void Bind(); - FBufferedUniform1f ShadowmapQuality; + struct UniformBlock + { + float ShadowmapQuality; + float Padding0, Padding1, Padding2; + + static std::vector Desc() + { + return + { + { "ShadowmapQuality", UniformType::Float, offsetof(UniformBlock, ShadowmapQuality) }, + { "Padding0", UniformType::Float, offsetof(UniformBlock, Padding0) }, + { "Padding1", UniformType::Float, offsetof(UniformBlock, Padding1) }, + { "Padding2", UniformType::Float, offsetof(UniformBlock, Padding2) }, + }; + } + }; + + ShaderUniforms Uniforms; private: FShaderProgram mShader; diff --git a/src/gl/stereo3d/gl_interleaved3d.cpp b/src/gl/stereo3d/gl_interleaved3d.cpp index 804eea6d17..ed1d6d381e 100644 --- a/src/gl/stereo3d/gl_interleaved3d.cpp +++ b/src/gl/stereo3d/gl_interleaved3d.cpp @@ -101,22 +101,24 @@ static void prepareInterleavedPresent(FPresentStereoShaderBase& shader) if ( GLRenderer->framebuffer->IsHWGammaActive() ) { - shader.InvGamma.Set(1.0f); - shader.Contrast.Set(1.0f); - shader.Brightness.Set(0.0f); - shader.Saturation.Set(1.0f); + shader.Uniforms->InvGamma = 1.0f; + shader.Uniforms->Contrast = 1.0f; + shader.Uniforms->Brightness = 0.0f; + shader.Uniforms->Saturation = 1.0f; } else { - shader.InvGamma.Set(1.0f / clamp(Gamma, 0.1f, 4.f)); - shader.Contrast.Set(clamp(vid_contrast, 0.1f, 3.f)); - shader.Brightness.Set(clamp(vid_brightness, -0.8f, 0.8f)); - shader.Saturation.Set(clamp(vid_saturation, -15.0f, 15.0f)); - shader.GrayFormula.Set(static_cast(gl_satformula)); + shader.Uniforms->InvGamma = 1.0f / clamp(Gamma, 0.1f, 4.f); + shader.Uniforms->Contrast = clamp(vid_contrast, 0.1f, 3.f); + shader.Uniforms->Brightness = clamp(vid_brightness, -0.8f, 0.8f); + shader.Uniforms->Saturation = clamp(vid_saturation, -15.0f, 15.0f); + shader.Uniforms->GrayFormula = static_cast(gl_satformula); } - shader.Scale.Set( + shader.Uniforms->Scale = { screen->mScreenViewport.width / (float)GLRenderer->mBuffers->GetWidth(), - screen->mScreenViewport.height / (float)GLRenderer->mBuffers->GetHeight()); + screen->mScreenViewport.height / (float)GLRenderer->mBuffers->GetHeight() + }; + shader.Uniforms.Set(); } // fixme: I don't know how to get absolute window position on Mac and Linux @@ -147,13 +149,13 @@ void CheckerInterleaved3D::Present() const } #endif // _WIN32 - GLRenderer->mPresent3dCheckerShader->WindowPositionParity.Set( + GLRenderer->mPresent3dCheckerShader->Uniforms->WindowPositionParity = (windowVOffset + windowHOffset + 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 - ); + ) % 2; // because we want the top pixel offset, but gl_FragCoord.y is the bottom pixel offset + GLRenderer->mPresent3dCheckerShader->Uniforms.Set(); GLRenderer->RenderScreenQuad(); } @@ -190,7 +192,8 @@ void ColumnInterleaved3D::Present() const } #endif // _WIN32 - GLRenderer->mPresent3dColumnShader->WindowPositionParity.Set(windowHOffset); + GLRenderer->mPresent3dColumnShader->Uniforms->WindowPositionParity = windowHOffset; + GLRenderer->mPresent3dColumnShader->Uniforms.Set(); GLRenderer->RenderScreenQuad(); } @@ -212,12 +215,12 @@ void RowInterleaved3D::Present() const } #endif // _WIN32 - GLRenderer->mPresent3dRowShader->WindowPositionParity.Set( + GLRenderer->mPresent3dRowShader->Uniforms->WindowPositionParity = (windowVOffset + screen->mOutputLetterbox.height + 1 // +1 because of origin at bottom - ) % 2 - ); + ) % 2; + GLRenderer->mPresent3dColumnShader->Uniforms.Set(); GLRenderer->RenderScreenQuad(); } diff --git a/wadsrc/static/shaders/glsl/present.fp b/wadsrc/static/shaders/glsl/present.fp index 4690895c20..cacd42e64b 100644 --- a/wadsrc/static/shaders/glsl/present.fp +++ b/wadsrc/static/shaders/glsl/present.fp @@ -3,11 +3,6 @@ in vec2 TexCoord; out vec4 FragColor; uniform sampler2D InputTexture; -uniform float InvGamma; -uniform float Contrast; -uniform float Brightness; -uniform float Saturation; -uniform int GrayFormula; vec4 ApplyGamma(vec4 c) { diff --git a/wadsrc/static/shaders/glsl/present_checker3d.fp b/wadsrc/static/shaders/glsl/present_checker3d.fp index 5247261e0f..5f02050385 100644 --- a/wadsrc/static/shaders/glsl/present_checker3d.fp +++ b/wadsrc/static/shaders/glsl/present_checker3d.fp @@ -4,10 +4,6 @@ out vec4 FragColor; uniform sampler2D LeftEyeTexture; uniform sampler2D RightEyeTexture; -uniform float InvGamma; -uniform float Contrast; -uniform float Brightness; -uniform int WindowPositionParity; // top-of-window might not be top-of-screen vec4 ApplyGamma(vec4 c) { diff --git a/wadsrc/static/shaders/glsl/present_column3d.fp b/wadsrc/static/shaders/glsl/present_column3d.fp index b46246cf0b..6670038060 100644 --- a/wadsrc/static/shaders/glsl/present_column3d.fp +++ b/wadsrc/static/shaders/glsl/present_column3d.fp @@ -4,10 +4,6 @@ out vec4 FragColor; uniform sampler2D LeftEyeTexture; uniform sampler2D RightEyeTexture; -uniform float InvGamma; -uniform float Contrast; -uniform float Brightness; -uniform int WindowPositionParity; // top-of-window might not be top-of-screen vec4 ApplyGamma(vec4 c) { diff --git a/wadsrc/static/shaders/glsl/present_row3d.fp b/wadsrc/static/shaders/glsl/present_row3d.fp index 50b27ac26e..a318560c8b 100644 --- a/wadsrc/static/shaders/glsl/present_row3d.fp +++ b/wadsrc/static/shaders/glsl/present_row3d.fp @@ -4,10 +4,6 @@ out vec4 FragColor; uniform sampler2D LeftEyeTexture; uniform sampler2D RightEyeTexture; -uniform float InvGamma; -uniform float Contrast; -uniform float Brightness; -uniform int WindowPositionParity; // top-of-window might not be top-of-screen vec4 ApplyGamma(vec4 c) { diff --git a/wadsrc/static/shaders/glsl/screenquadscale.vp b/wadsrc/static/shaders/glsl/screenquadscale.vp index 2d7f505b49..8ae1809101 100644 --- a/wadsrc/static/shaders/glsl/screenquadscale.vp +++ b/wadsrc/static/shaders/glsl/screenquadscale.vp @@ -1,7 +1,6 @@ in vec4 PositionInProjection; in vec2 UV; -uniform vec2 UVScale; out vec2 TexCoord; void main() diff --git a/wadsrc/static/shaders/glsl/shadowmap.fp b/wadsrc/static/shaders/glsl/shadowmap.fp index 47696aa74d..b578a78ce0 100644 --- a/wadsrc/static/shaders/glsl/shadowmap.fp +++ b/wadsrc/static/shaders/glsl/shadowmap.fp @@ -2,11 +2,6 @@ in vec2 TexCoord; out vec4 FragColor; -// This constant must match the same constant in gl_shadowmap.h -// #define ShadowmapQuality 1024 -//#define ShadowmapQuality 128 -uniform float ShadowmapQuality; - struct GPUNode { vec2 aabb_min;