summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-07-07 23:21:25 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-07-07 23:21:25 +0100
commit07064efcfecb0f1140f829ee2481079fa02cc587 (patch)
treead9914fc74c46cacbfb6a1187ce99cb89171521a
parentAdd shadow shader which takes into account texture transparency (diff)
downloadilt-07064efcfecb0f1140f829ee2481079fa02cc587.tar.bz2
ilt-07064efcfecb0f1140f829ee2481079fa02cc587.tar.xz
ilt-07064efcfecb0f1140f829ee2481079fa02cc587.zip
Simplify setup of uniform locations and containing programs
-rw-r--r--gfx/gl/sceneRenderer.cpp8
-rw-r--r--gfx/gl/sceneRenderer.h7
-rw-r--r--gfx/gl/sceneShader.cpp14
-rw-r--r--gfx/gl/sceneShader.h24
-rw-r--r--gfx/gl/shadowMapper.cpp16
-rw-r--r--gfx/gl/shadowMapper.h18
-rw-r--r--gfx/gl/uiShader.cpp5
-rw-r--r--gfx/gl/uiShader.h2
8 files changed, 30 insertions, 64 deletions
diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp
index 517d51e..e0938f2 100644
--- a/gfx/gl/sceneRenderer.cpp
+++ b/gfx/gl/sceneRenderer.cpp
@@ -129,13 +129,7 @@ SceneRenderer::renderQuad() const
glBindVertexArray(0);
}
-SceneRenderer::DirectionalLightProgram::DirectionalLightProgram() :
- Program {lighting_vs, directionalLight_fs}, directionLoc {*this, "lightDirection"},
- colourLoc {*this, "lightColour"}, lightPointLoc {*this, "lightPoint"},
- lightViewProjectionLoc {*this, "lightViewProjection"},
- lightViewProjectionCountLoc {*this, "lightViewProjectionCount"}
-{
-}
+SceneRenderer::DirectionalLightProgram::DirectionalLightProgram() : Program {lighting_vs, directionalLight_fs} { }
const auto toTextureSpaceMat = glm::translate(glm::identity<glm::mat4>(), glm::vec3 {0.5F})
* glm::scale(glm::identity<glm::mat4>(), glm::vec3 {0.5F});
diff --git a/gfx/gl/sceneRenderer.h b/gfx/gl/sceneRenderer.h
index 021936f..4195bcf 100644
--- a/gfx/gl/sceneRenderer.h
+++ b/gfx/gl/sceneRenderer.h
@@ -42,8 +42,11 @@ protected:
const RGB &, const Direction3D &, const GlobalPosition3D &, const std::span<const glm::mat4x4>) const;
private:
- RequiredUniformLocation directionLoc, colourLoc, lightPointLoc, lightViewProjectionLoc,
- lightViewProjectionCountLoc;
+ RequiredUniformLocation directionLoc {*this, "lightDirection"};
+ RequiredUniformLocation colourLoc {*this, "lightColour"};
+ RequiredUniformLocation lightPointLoc {*this, "lightPoint"};
+ RequiredUniformLocation lightViewProjectionLoc {*this, "lightViewProjection"};
+ RequiredUniformLocation lightViewProjectionCountLoc {*this, "lightViewProjectionCount"};
};
DeferredLightProgram lighting;
diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp
index 985faa0..4cbccb3 100644
--- a/gfx/gl/sceneShader.cpp
+++ b/gfx/gl/sceneShader.cpp
@@ -71,10 +71,7 @@ SceneShader::SceneProgram::setViewPort(const ViewPort & viewPort) const
}
}
-SceneShader::BasicProgram::BasicProgram() :
- SceneProgram {dynamicPoint_vs, material_fs}, modelLoc {*this, "model"}, modelPosLoc {*this, "modelPos"}
-{
-}
+SceneShader::BasicProgram::BasicProgram() : SceneProgram {dynamicPoint_vs, material_fs} { }
void
SceneShader::BasicProgram::setModel(Location const & location) const
@@ -90,13 +87,6 @@ SceneShader::BasicProgram::use(Location const & location) const
setModel(location);
}
-template<typename... S>
-SceneShader::NetworkProgram::NetworkProgram(S &&... s) :
- AbsolutePosProgram {std::forward<S>(s)...}, profileLoc {*this, "profile"}, texturePosLoc {*this, "texturePos"},
- profileLengthLoc {*this, "profileLength"}
-{
-}
-
void
SceneShader::NetworkProgram::use(
const std::span<const glm::vec3> profile, const std::span<const float> texturePos) const
@@ -107,7 +97,7 @@ SceneShader::NetworkProgram::use(
glUniform(profileLengthLoc, static_cast<GLuint>(profile.size()));
}
-SceneShader::WaterProgram::WaterProgram() : SceneProgram {water_vs, water_fs}, waveLoc {*this, "waves"} { }
+SceneShader::WaterProgram::WaterProgram() : SceneProgram {water_vs, water_fs} { }
void
SceneShader::WaterProgram::use(float waveCycle) const
diff --git a/gfx/gl/sceneShader.h b/gfx/gl/sceneShader.h
index 07b0b26..51f0e21 100644
--- a/gfx/gl/sceneShader.h
+++ b/gfx/gl/sceneShader.h
@@ -10,19 +10,15 @@ class Location;
class SceneShader {
class SceneProgram : public Program {
public:
- template<typename... S>
- inline explicit SceneProgram(const S &... srcs) :
- Program {srcs...}, viewProjectionLoc {*this, "viewProjection"}, viewPointLoc {*this, "viewPoint"},
- viewPortLoc {*this, "viewPort"}
- {
- }
+ using Program::Program;
void setViewProjection(const GlobalPosition3D &, const glm::mat4 &) const;
void setViewPort(const ViewPort &) const;
private:
- RequiredUniformLocation viewProjectionLoc, viewPointLoc;
- UniformLocation viewPortLoc;
+ RequiredUniformLocation viewProjectionLoc {*this, "viewProjection"};
+ RequiredUniformLocation viewPointLoc {*this, "viewPoint"};
+ UniformLocation viewPortLoc {*this, "viewPort"};
};
class BasicProgram : public SceneProgram {
@@ -32,8 +28,8 @@ class SceneShader {
void use(const Location &) const;
private:
- RequiredUniformLocation modelLoc;
- RequiredUniformLocation modelPosLoc;
+ RequiredUniformLocation modelLoc {*this, "model"};
+ RequiredUniformLocation modelPosLoc {*this, "modelPos"};
};
class AbsolutePosProgram : public SceneProgram {
@@ -44,12 +40,14 @@ class SceneShader {
class NetworkProgram : public AbsolutePosProgram {
public:
- template<typename... S> explicit NetworkProgram(S &&...);
+ using AbsolutePosProgram::AbsolutePosProgram;
void use(const std::span<const glm::vec3>, const std::span<const float>) const;
private:
- RequiredUniformLocation profileLoc, texturePosLoc, profileLengthLoc;
+ RequiredUniformLocation profileLoc {*this, "profile"};
+ RequiredUniformLocation texturePosLoc {*this, "texturePos"};
+ RequiredUniformLocation profileLengthLoc {*this, "profileLength"};
};
class WaterProgram : public SceneProgram {
@@ -58,7 +56,7 @@ class SceneShader {
void use(float waveCycle) const;
private:
- RequiredUniformLocation waveLoc;
+ RequiredUniformLocation waveLoc {*this, "waves"};
};
public:
diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp
index c537314..a846a3d 100644
--- a/gfx/gl/shadowMapper.cpp
+++ b/gfx/gl/shadowMapper.cpp
@@ -108,15 +108,10 @@ ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const
return out;
}
-ShadowMapper::ShadowProgram::ShadowProgram(const Shader & vs) :
- Program {vs, commonShadowPoint_gs}, viewProjectionLoc {*this, "viewProjection"},
- viewProjectionsLoc {*this, "viewProjections"}, viewPointLoc {*this, "viewPoint"}
-{
-}
+ShadowMapper::ShadowProgram::ShadowProgram(const Shader & vs) : Program {vs, commonShadowPoint_gs} { }
ShadowMapper::ShadowProgram::ShadowProgram(const Shader & vs, const Shader & gs, const Shader & fs) :
- Program {vs, gs, fs}, viewProjectionLoc {*this, "viewProjection"}, viewProjectionsLoc {*this, "viewProjections"},
- viewPointLoc {*this, "viewPoint"}
+ Program {vs, gs, fs}
{
}
@@ -136,12 +131,7 @@ ShadowMapper::ShadowProgram::use() const
glUseProgram(*this);
}
-ShadowMapper::FixedPoint::FixedPoint(const Shader & vs) : ShadowProgram {vs} { }
-
-ShadowMapper::DynamicPoint::DynamicPoint() :
- ShadowProgram {shadowDynamicPoint_vs}, modelLoc {*this, "model"}, modelPosLoc {*this, "modelPos"}
-{
-}
+ShadowMapper::DynamicPoint::DynamicPoint() : ShadowProgram {shadowDynamicPoint_vs} { }
void
ShadowMapper::DynamicPoint::use(const Location & location) const
diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h
index 967d93b..73dadd0 100644
--- a/gfx/gl/shadowMapper.h
+++ b/gfx/gl/shadowMapper.h
@@ -30,14 +30,9 @@ public:
void use() const;
private:
- RequiredUniformLocation viewProjectionLoc;
- RequiredUniformLocation viewProjectionsLoc;
- RequiredUniformLocation viewPointLoc;
- };
-
- class FixedPoint : public ShadowProgram {
- public:
- explicit FixedPoint(const Shader & vs);
+ RequiredUniformLocation viewProjectionLoc {*this, "viewProjection"};
+ RequiredUniformLocation viewProjectionsLoc {*this, "viewProjections"};
+ RequiredUniformLocation viewPointLoc {*this, "viewPoint"};
};
class DynamicPoint : public ShadowProgram {
@@ -47,12 +42,11 @@ public:
void setModel(const Location &) const;
private:
- RequiredUniformLocation modelLoc;
- RequiredUniformLocation modelPosLoc;
+ RequiredUniformLocation modelLoc {*this, "model"};
+ RequiredUniformLocation modelPosLoc {*this, "modelPos"};
};
- FixedPoint landmess, dynamicPointInst;
- ShadowProgram dynamicPointInstWithTextures;
+ ShadowProgram landmess, dynamicPointInst, dynamicPointInstWithTextures;
DynamicPoint dynamicPoint;
// NOLINTNEXTLINE(hicpp-explicit-conversions)
diff --git a/gfx/gl/uiShader.cpp b/gfx/gl/uiShader.cpp
index bb9570e..23da9dc 100644
--- a/gfx/gl/uiShader.cpp
+++ b/gfx/gl/uiShader.cpp
@@ -10,10 +10,7 @@
UIShader::IconProgram::IconProgram(const glm::mat4 & vp) : UIProgram {vp, uiShader_vs, uiShader_fs} { }
-UIShader::TextProgram::TextProgram(const glm::mat4 & vp) :
- UIProgram {vp, uiShader_vs, uiShaderFont_fs}, colorLoc {*this, "colour"}
-{
-}
+UIShader::TextProgram::TextProgram(const glm::mat4 & vp) : UIProgram {vp, uiShader_vs, uiShaderFont_fs} { }
UIShader::UIShader(size_t width, size_t height) :
UIShader {glm::ortho<float>(0, static_cast<float>(width), 0, static_cast<float>(height))}
diff --git a/gfx/gl/uiShader.h b/gfx/gl/uiShader.h
index 99c5e17..6d00166 100644
--- a/gfx/gl/uiShader.h
+++ b/gfx/gl/uiShader.h
@@ -38,7 +38,7 @@ private:
void use(const RGB & colour) const;
private:
- RequiredUniformLocation colorLoc;
+ RequiredUniformLocation colorLoc {*this, "colour"};
};
public: