summaryrefslogtreecommitdiff
path: root/gfx/gl/sceneShader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/gl/sceneShader.cpp')
-rw-r--r--gfx/gl/sceneShader.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp
index bcd0590..00d9826 100644
--- a/gfx/gl/sceneShader.cpp
+++ b/gfx/gl/sceneShader.cpp
@@ -8,6 +8,7 @@
#include <gfx/gl/shaders/gs-pointLight.h>
#include <gfx/gl/shaders/gs-spotLight.h>
#include <gfx/gl/shaders/vs-dynamicPoint.h>
+#include <gfx/gl/shaders/vs-dynamicPointInst.h>
#include <gfx/gl/shaders/vs-fixedPoint.h>
#include <gfx/gl/shaders/vs-pointLight.h>
#include <gfx/gl/shaders/vs-spotLight.h>
@@ -18,13 +19,17 @@
#include <location.hpp>
#include <maths.h>
-SceneShader::SceneShader() : landmass {fixedPoint_vs, landmass_fs}, absolute {fixedPoint_vs, material_fs} { }
+SceneShader::SceneShader() :
+ basicInst {dynamicPointInst_vs, material_fs}, landmass {fixedPoint_vs, landmass_fs},
+ absolute {fixedPoint_vs, material_fs}
+{
+}
void
SceneShader::setViewProjection(const glm::mat4 & viewProjection) const
{
- for (const auto & prog :
- std::array<const SceneProgram *, 6> {&basic, &water, &landmass, &absolute, &pointLight, &spotLight}) {
+ for (const auto & prog : std::array<const SceneProgram *, 7> {
+ &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLight}) {
prog->setViewProjection(viewProjection);
}
}
@@ -32,8 +37,8 @@ SceneShader::setViewProjection(const glm::mat4 & viewProjection) const
void
SceneShader::setViewPort(const glm::ivec4 & viewPort) const
{
- for (const auto & prog :
- std::array<const SceneProgram *, 6> {&basic, &water, &landmass, &absolute, &pointLight, &spotLight}) {
+ for (const auto & prog : std::array<const SceneProgram *, 7> {
+ &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLight}) {
prog->setViewPort(viewPort);
}
}
@@ -83,7 +88,7 @@ SceneShader::WaterProgram::use(float waveCycle) const
SceneShader::PointLightShader::PointLightShader() :
SceneProgram {pointLight_vs, pointLight_gs, pointLight_fs}, colourLoc {*this, "colour"}, kqLoc {*this, "kq"}
{
- VertexArrayObject<glm::vec3>::configure(va, b);
+ VertexArrayObject {va}.addAttribs<glm::vec3>(b);
}
void
@@ -94,16 +99,16 @@ SceneShader::PointLightShader::add(const glm::vec3 & position, const glm::vec3 &
glBindBuffer(GL_ARRAY_BUFFER, b);
glUniform3fv(colourLoc, 1, glm::value_ptr(colour));
glUniform1f(kqLoc, kq);
- glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(glm::vec3), glm::value_ptr(position));
+ glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3), glm::value_ptr(position), GL_DYNAMIC_DRAW);
glDrawArrays(GL_POINTS, 0, 1);
}
SceneShader::SpotLightShader::SpotLightShader() :
- SceneProgram {spotLight_vs, spotLight_gs, spotLight_fs}, colourLoc {*this, "colour"}, kqLoc {*this, "kq"},
- arcLoc {*this, "arc"}
+ SceneProgram {spotLight_vs, spotLight_gs, spotLight_fs}, directionLoc {*this, "v_direction"},
+ colourLoc {*this, "colour"}, kqLoc {*this, "kq"}, arcLoc {*this, "arc"}
{
using v3pair = std::pair<glm::vec3, glm::vec3>;
- VertexArrayObject<v3pair>::configure<&v3pair::first, &v3pair::second>(va, b);
+ VertexArrayObject {va}.addAttribs<v3pair, &v3pair::first, &v3pair::second>(b);
}
void
@@ -114,9 +119,9 @@ SceneShader::SpotLightShader::add(const glm::vec3 & position, const glm::vec3 &
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);
- glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(glm::vec3), glm::value_ptr(position));
- glBufferSubData(GL_ARRAY_BUFFER, sizeof(glm::vec3), sizeof(glm::vec3), glm::value_ptr(direction));
+ glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3), glm::value_ptr(position), GL_DYNAMIC_DRAW);
glDrawArrays(GL_POINTS, 0, 1);
}