- change ShaderUniforms so that it just contains the uniform block and not the binding point

This commit is contained in:
Magnus Norddahl 2018-06-11 22:33:55 +02:00
parent 49073489e5
commit 9155b773cc
13 changed files with 59 additions and 41 deletions

View File

@ -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);

View File

@ -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<int>(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();
}

View File

@ -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();

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();

View File

@ -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();
}

View File

@ -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()

View File

@ -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

View File

@ -47,7 +47,6 @@ public:
FString CreateDeclaration(const char *name, const std::vector<UniformFieldDesc> &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<UniformFieldDesc> mFields;
std::vector<int> 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; }

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}