From b8401062e1d3f5e6554ab7fd9b983ea63cfb05c5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 10 Jan 2024 19:04:30 +0000 Subject: Initial commit with working light instancing --- gfx/gl/sceneShader.cpp | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) (limited to 'gfx/gl/sceneShader.cpp') 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 { - &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLight}) { + for (const auto & prog : std::initializer_list { + &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 { - &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLight}) { + for (const auto & prog : std::initializer_list { + &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; - VertexArrayObject {va}.addAttribs(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); -} -- cgit v1.2.3