From bb693756b9aace889f806a768b54655023d163ab Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 9 Jan 2024 20:17:55 +0000 Subject: Add the Illuminator (type) and Light (instance) classes --- game/scenary/illuminator.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ game/scenary/illuminator.h | 26 ++++++++++++++++++++++++++ game/scenary/light.cpp | 7 +++++++ game/scenary/light.h | 19 +++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 game/scenary/illuminator.cpp create mode 100644 game/scenary/illuminator.h create mode 100644 game/scenary/light.cpp create mode 100644 game/scenary/light.h (limited to 'game/scenary') 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(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(count)); + } +} + +void +Illuminator::lights(const SceneShader &) const +{ + if (const auto count = instances.size()) { + // shader.pointLight.use(); + // bodyMesh->DrawInstanced(instanceVAO, static_cast(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 { + Mesh::Ptr bodyMesh; + std::shared_ptr texture; + glVertexArray instanceVAO; + +public: + using LocationVertex = std::pair; + mutable InstanceVertices instances; + void render(const SceneShader &) const override; + void lights(const SceneShader &) const override; + +protected: + friend Persistence::SelectionPtrBase>; + 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 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 type; + InstanceVertices::InstanceProxy location; + + void + tick(TickDuration) override + { + } + +public: + Light(std::shared_ptr type, const Location & position); +}; -- cgit v1.2.3