summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
Diffstat (limited to 'game')
-rw-r--r--game/scenary/illuminator.cpp40
-rw-r--r--game/scenary/illuminator.h26
-rw-r--r--game/scenary/light.cpp7
-rw-r--r--game/scenary/light.h19
4 files changed, 92 insertions, 0 deletions
diff --git a/game/scenary/illuminator.cpp b/game/scenary/illuminator.cpp
new file mode 100644
index 0000000..4989933
--- /dev/null
+++ b/game/scenary/illuminator.cpp
@@ -0,0 +1,40 @@
+#include "illuminator.h"
+#include "gfx/gl/sceneShader.h"
+#include "gfx/gl/vertexArrayObject.h"
+#include "gfx/models/texture.h"
+#include "location.h"
+
+bool
+Illuminator::persist(Persistence::PersistenceStore & store)
+{
+ return STORE_TYPE && STORE_HELPER(bodyMesh, Asset::MeshConstruct) && Asset::persist(store);
+}
+
+void
+Illuminator::postLoad()
+{
+ texture = getTexture();
+ bodyMesh->configureVAO(instanceVAO)
+ .addAttribs<LocationVertex, &LocationVertex::first, &LocationVertex::second>(instances.bufferName(), 1);
+}
+
+void
+Illuminator::render(const SceneShader & shader) const
+{
+ if (const auto count = instances.size()) {
+ shader.basicInst.use();
+ if (texture) {
+ texture->bind();
+ }
+ bodyMesh->DrawInstanced(instanceVAO, static_cast<GLsizei>(count));
+ }
+}
+
+void
+Illuminator::lights(const SceneShader &) const
+{
+ if (const auto count = instances.size()) {
+ // shader.pointLight.use();
+ // bodyMesh->DrawInstanced(instanceVAO, static_cast<GLsizei>(count));
+ }
+}
diff --git a/game/scenary/illuminator.h b/game/scenary/illuminator.h
new file mode 100644
index 0000000..db9acfb
--- /dev/null
+++ b/game/scenary/illuminator.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include "assetFactory/asset.h"
+#include "gfx/gl/instanceVertices.h"
+#include "gfx/renderable.h"
+
+class SceneShader;
+class Location;
+class Texture;
+
+class Illuminator : public Asset, public Renderable, public StdTypeDefs<Illuminator> {
+ Mesh::Ptr bodyMesh;
+ std::shared_ptr<Texture> texture;
+ glVertexArray instanceVAO;
+
+public:
+ using LocationVertex = std::pair<glm::mat4, GlobalPosition3D>;
+ mutable InstanceVertices<LocationVertex> instances;
+ void render(const SceneShader &) const override;
+ void lights(const SceneShader &) const override;
+
+protected:
+ friend Persistence::SelectionPtrBase<std::shared_ptr<Illuminator>>;
+ bool persist(Persistence::PersistenceStore & store) override;
+ void postLoad() override;
+};
diff --git a/game/scenary/light.cpp b/game/scenary/light.cpp
new file mode 100644
index 0000000..6207497
--- /dev/null
+++ b/game/scenary/light.cpp
@@ -0,0 +1,7 @@
+#include "light.h"
+#include "location.h"
+
+Light::Light(std::shared_ptr<const Illuminator> type, const Location & position) :
+ type {std::move(type)}, location {this->type->instances.acquire(position.getRotationTransform(), position.pos)}
+{
+}
diff --git a/game/scenary/light.h b/game/scenary/light.h
new file mode 100644
index 0000000..0b19535
--- /dev/null
+++ b/game/scenary/light.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "game/worldobject.h"
+#include "illuminator.h"
+
+class Location;
+
+class Light : public WorldObject {
+ std::shared_ptr<const Illuminator> type;
+ InstanceVertices<Illuminator::LocationVertex>::InstanceProxy location;
+
+ void
+ tick(TickDuration) override
+ {
+ }
+
+public:
+ Light(std::shared_ptr<const Illuminator> type, const Location & position);
+};