summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game/scenary/illuminator.cpp27
-rw-r--r--game/scenary/illuminator.h21
-rw-r--r--res/lights.xml1
-rw-r--r--test/test-assetFactory.cpp1
4 files changed, 46 insertions, 4 deletions
diff --git a/game/scenary/illuminator.cpp b/game/scenary/illuminator.cpp
index 4989933..43b6e4e 100644
--- a/game/scenary/illuminator.cpp
+++ b/game/scenary/illuminator.cpp
@@ -5,9 +5,17 @@
#include "location.h"
bool
+Illuminator::SpotLight::persist(Persistence::PersistenceStore & store)
+{
+ return STORE_TYPE && STORE_MEMBER(position) && STORE_MEMBER(direction) && STORE_MEMBER(colour) && STORE_MEMBER(kq)
+ && STORE_MEMBER(arc);
+}
+
+bool
Illuminator::persist(Persistence::PersistenceStore & store)
{
- return STORE_TYPE && STORE_HELPER(bodyMesh, Asset::MeshConstruct) && Asset::persist(store);
+ return STORE_TYPE && STORE_HELPER(bodyMesh, Asset::MeshConstruct)
+ && STORE_HELPER(spotLight, Persistence::Appender<decltype(spotLight)>) && Asset::persist(store);
}
void
@@ -16,6 +24,14 @@ Illuminator::postLoad()
texture = getTexture();
bodyMesh->configureVAO(instanceVAO)
.addAttribs<LocationVertex, &LocationVertex::first, &LocationVertex::second>(instances.bufferName(), 1);
+ VertexArrayObject {instancesSpotLightVAO}
+ .addAttribs<LocationVertex, &LocationVertex::first, &LocationVertex::second>(instances.bufferName(), 0)
+ .addAttribs<SpotLightVertex, &SpotLightVertex::position, &SpotLightVertex::direction,
+ &SpotLightVertex::colour, &SpotLightVertex::kq, &SpotLightVertex::arc>(
+ instancesSpotLight.bufferName(), 1);
+ std::transform(spotLight.begin(), spotLight.end(), std::back_inserter(spotLightInstances), [this](const auto & s) {
+ return instancesSpotLight.acquire(*s);
+ });
}
void
@@ -34,7 +50,12 @@ void
Illuminator::lights(const SceneShader &) const
{
if (const auto count = instances.size()) {
- // shader.pointLight.use();
- // bodyMesh->DrawInstanced(instanceVAO, static_cast<GLsizei>(count));
+ if (const auto scount = instancesSpotLight.size()) {
+ // shader.pointLight.use();
+ glBindVertexArray(instancesSpotLightVAO);
+ glDrawArraysInstanced(GL_POINTS, 0, static_cast<GLsizei>(count), static_cast<GLsizei>(scount));
+ }
+
+ glBindVertexArray(0);
}
}
diff --git a/game/scenary/illuminator.h b/game/scenary/illuminator.h
index db9acfb..99b87eb 100644
--- a/game/scenary/illuminator.h
+++ b/game/scenary/illuminator.h
@@ -11,11 +11,27 @@ class Texture;
class Illuminator : public Asset, public Renderable, public StdTypeDefs<Illuminator> {
Mesh::Ptr bodyMesh;
std::shared_ptr<Texture> texture;
- glVertexArray instanceVAO;
+ glVertexArray instanceVAO, instancesSpotLightVAO;
+
+public:
+ struct SpotLightVertex {
+ RelativePosition3D position;
+ Direction3D direction;
+ RGB colour;
+ RelativeDistance kq;
+ Angle arc;
+ };
+
+ struct SpotLight : Persistence::Persistable, SpotLightVertex, StdTypeDefs<SpotLight> {
+ private:
+ friend Persistence::SelectionPtrBase<std::shared_ptr<SpotLight>>;
+ bool persist(Persistence::PersistenceStore & store) override;
+ };
public:
using LocationVertex = std::pair<glm::mat4, GlobalPosition3D>;
mutable InstanceVertices<LocationVertex> instances;
+ mutable InstanceVertices<SpotLightVertex> instancesSpotLight;
void render(const SceneShader &) const override;
void lights(const SceneShader &) const override;
@@ -23,4 +39,7 @@ protected:
friend Persistence::SelectionPtrBase<std::shared_ptr<Illuminator>>;
bool persist(Persistence::PersistenceStore & store) override;
void postLoad() override;
+
+ std::vector<SpotLight::Ptr> spotLight;
+ std::vector<InstanceVertices<SpotLightVertex>::InstanceProxy> spotLightInstances;
};
diff --git a/res/lights.xml b/res/lights.xml
index 137137d..5c11fdf 100644
--- a/res/lights.xml
+++ b/res/lights.xml
@@ -6,6 +6,7 @@
<use type="cylinder" scale="0.07,0.07,3" position="0,0,1" colour="lightslategray"/>
<use type="cylinder" scale="0.05,0.05,1.5" position="0,0.1,4" rotation="1.5,0,0" colour="lightslategray"/>
</bodyMesh>
+ <spotLight position="0,1.4,4.1" direction="0,0,-1" colour=".9,.9,.9" kq="8000" arc="1.5"/>
</asset>
<!-- yes I'm hacking some floor to light up as though its a bush -->
<asset p.typeid="Foliage" id="floor" name="floor">
diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp
index e7ba19c..91a5321 100644
--- a/test/test-assetFactory.cpp
+++ b/test/test-assetFactory.cpp
@@ -49,6 +49,7 @@ public:
lights(const SceneShader & shader) const override
{
shader.pointLight.add({-3, 1, 5}, {1, 1, 1}, .1F);
+ objects.apply(&Renderable::lights, shader);
}
void