summaryrefslogtreecommitdiff
path: root/gfx/gl/sceneShader.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-01-10 19:04:30 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-01-10 19:04:30 +0000
commitb8401062e1d3f5e6554ab7fd9b983ea63cfb05c5 (patch)
treeba5c4f944cee1fa04b4aba8b018c3f1f7864490e /gfx/gl/sceneShader.cpp
parentAdd spot light definition, loader, and rendering (diff)
downloadilt-b8401062e1d3f5e6554ab7fd9b983ea63cfb05c5.tar.bz2
ilt-b8401062e1d3f5e6554ab7fd9b983ea63cfb05c5.tar.xz
ilt-b8401062e1d3f5e6554ab7fd9b983ea63cfb05c5.zip
Initial commit with working light instancing
Diffstat (limited to 'gfx/gl/sceneShader.cpp')
-rw-r--r--gfx/gl/sceneShader.cpp34
1 files changed, 5 insertions, 29 deletions
diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp
index ccc1a1d..cdb8d2f 100644
--- a/gfx/gl/sceneShader.cpp
+++ b/gfx/gl/sceneShader.cpp
@@ -21,15 +21,15 @@
SceneShader::SceneShader() :
basicInst {dynamicPointInst_vs, material_fs}, landmass {fixedPoint_vs, landmass_fs},
- absolute {fixedPoint_vs, material_fs}
+ absolute {fixedPoint_vs, material_fs}, spotLightInst {spotLight_vs, spotLight_gs, spotLight_fs}
{
}
void
SceneShader::setViewProjection(const GlobalPosition3D & viewPoint, const glm::mat4 & viewProjection) const
{
- for (const auto & prog : std::array<const SceneProgram *, 7> {
- &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLight}) {
+ for (const auto & prog : std::initializer_list<const SceneProgram *> {
+ &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLightInst}) {
prog->setViewProjection(viewPoint, viewProjection);
}
}
@@ -37,8 +37,8 @@ SceneShader::setViewProjection(const GlobalPosition3D & viewPoint, const glm::ma
void
SceneShader::setViewPort(const ViewPort & viewPort) const
{
- for (const auto & prog : std::array<const SceneProgram *, 7> {
- &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLight}) {
+ for (const auto & prog : std::initializer_list<const SceneProgram *> {
+ &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLightInst}) {
prog->setViewPort(viewPort);
}
}
@@ -106,27 +106,3 @@ SceneShader::PointLightShader::add(const Position3D & position, const RGB & colo
glBufferData(GL_ARRAY_BUFFER, sizeof(Position3D), glm::value_ptr(position), GL_DYNAMIC_DRAW);
glDrawArrays(GL_POINTS, 0, 1);
}
-
-SceneShader::SpotLightShader::SpotLightShader() :
- SceneProgram {spotLight_vs, spotLight_gs, spotLight_fs}, directionLoc {*this, "v_direction"},
- colourLoc {*this, "colour"}, kqLoc {*this, "kq"}, arcLoc {*this, "arc"}, viewPointLoc {*this, "viewPoint"}
-
-{
- using v3pair = std::pair<Position3D, Direction3D>;
- VertexArrayObject {va}.addAttribs<v3pair, &v3pair::first, &v3pair::second>(b);
-}
-
-void
-SceneShader::SpotLightShader::add(const Position3D & position, const Direction3D & direction, const RGB & colour,
- const float kq, const float arc) const
-{
- Program::use();
- glBindVertexArray(va);
- glBindBuffer(GL_ARRAY_BUFFER, b);
- glUniform3fv(colourLoc, 1, glm::value_ptr(colour));
- glUniform3fv(directionLoc, 1, glm::value_ptr(direction));
- glUniform1f(kqLoc, kq);
- glUniform1f(arcLoc, arc);
- glBufferData(GL_ARRAY_BUFFER, sizeof(Position3D), glm::value_ptr(position), GL_DYNAMIC_DRAW);
- glDrawArrays(GL_POINTS, 0, 1);
-}