summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-01-10 01:10:44 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-01-10 01:10:44 +0000
commit8740d30b01f6c12e2fcea0450df73736cd17dc87 (patch)
treede7715148889aba33d1ccca6740a0e661c866087 /game
parentAdd lights resource set and test scene (diff)
downloadilt-8740d30b01f6c12e2fcea0450df73736cd17dc87.tar.bz2
ilt-8740d30b01f6c12e2fcea0450df73736cd17dc87.tar.xz
ilt-8740d30b01f6c12e2fcea0450df73736cd17dc87.zip
Add spot light definition, loader, and rendering
Rendering is untested, data is passed to whatever GL program is currently active.
Diffstat (limited to 'game')
-rw-r--r--game/scenary/illuminator.cpp27
-rw-r--r--game/scenary/illuminator.h21
2 files changed, 44 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;
};