diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2026-04-01 20:21:23 +0100 |
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2026-04-01 20:21:23 +0100 |
| commit | 30fcb8bce7b60b6754a0d35f2f15b627d0fba4cb (patch) | |
| tree | 7e782f51affa8a2a40cf47e6ba69335a1289b2be /game | |
| parent | Fix VertexArrayConfigurator with derived classes (diff) | |
| download | ilt-30fcb8bce7b60b6754a0d35f2f15b627d0fba4cb.tar.bz2 ilt-30fcb8bce7b60b6754a0d35f2f15b627d0fba4cb.tar.xz ilt-30fcb8bce7b60b6754a0d35f2f15b627d0fba4cb.zip | |
Have Renderable manage all instance lights
Spot and point lights now existing in Renderable, the vertex data
contains the owning parent object's index in CommonLocationData, the
render step is just a single draw call.
Diffstat (limited to 'game')
| -rw-r--r-- | game/scenary/illuminator.cpp | 55 | ||||
| -rw-r--r-- | game/scenary/illuminator.h | 16 | ||||
| -rw-r--r-- | game/scenary/light.cpp | 9 | ||||
| -rw-r--r-- | game/scenary/light.h | 3 |
4 files changed, 19 insertions, 64 deletions
diff --git a/game/scenary/illuminator.cpp b/game/scenary/illuminator.cpp index 3b73cd3..55791a5 100644 --- a/game/scenary/illuminator.cpp +++ b/game/scenary/illuminator.cpp @@ -6,8 +6,7 @@ static_assert(std::is_constructible_v<Illuminator>); -std::weak_ptr<glVertexArray> Illuminator::commonInstanceVAO, Illuminator::commonInstancesSpotLightVAO, - Illuminator::commonInstancesPointLightVAO; +std::weak_ptr<glVertexArray> Illuminator::commonInstanceVAO; std::any Illuminator::createAt(const Location & position) const @@ -48,32 +47,6 @@ Illuminator::postLoad() if (createIfRequired(instanceVAO, commonInstanceVAO)) { bodyMesh->configureVAO(*instanceVAO, 0).addAttribs<InstanceVertex, &InstanceVertex::location>(1); } - if (!spotLight.empty()) { - if (!(instancesSpotLightVAO = commonInstancesSpotLightVAO.lock())) { - commonInstancesSpotLightVAO = instancesSpotLightVAO = std::make_shared<glVertexArray>(); - instancesSpotLightVAO->configure() - .addAttribs<SpotLightVertex, &SpotLightVertex::position, &SpotLightVertex::direction, - &SpotLightVertex::colour, &SpotLightVertex::kq, &SpotLightVertex::arc>(0) - .addAttribs<InstanceVertex, &InstanceVertex::location>(1); - } - std::transform( - spotLight.begin(), spotLight.end(), std::back_inserter(spotLightInstances), [this](const auto & s) { - return instancesSpotLight.acquire(*s); - }); - } - if (!pointLight.empty()) { - if (!(instancesPointLightVAO = commonInstancesPointLightVAO.lock())) { - commonInstancesPointLightVAO = instancesPointLightVAO = std::make_shared<glVertexArray>(); - instancesPointLightVAO->configure() - .addAttribs<PointLightVertex, &PointLightVertex::position, &PointLightVertex::colour, - &PointLightVertex::kq>(0) - .addAttribs<InstanceVertex, &InstanceVertex::location>(1); - } - std::transform( - pointLight.begin(), pointLight.end(), std::back_inserter(pointLightInstances), [this](const auto & s) { - return instancesPointLight.acquire(*s); - }); - } } void @@ -89,29 +62,3 @@ Illuminator::render(const SceneShader & shader, const Frustum &) const bodyMesh->drawInstanced(*instanceVAO, static_cast<GLsizei>(count)); } } - -void -Illuminator::lights(const SceneShader & shader) const -{ - if (const auto count = instances.size()) { - glDebugScope _ {*instanceVAO}; - if (const auto scount = instancesSpotLight.size()) { - glDebugScope _ {*instancesSpotLightVAO, "Spot lights"}; - shader.spotLightInst.use(); - glBindVertexArray(*instancesSpotLightVAO); - instancesSpotLightVAO->useBuffer(0, instancesSpotLight); - instancesSpotLightVAO->useBuffer(1, instances); - glDrawArraysInstanced(GL_POINTS, 0, static_cast<GLsizei>(scount), static_cast<GLsizei>(count)); - } - if (const auto pcount = instancesPointLight.size()) { - glDebugScope _ {*instancesPointLightVAO, "Point llights"}; - shader.pointLightInst.use(); - glBindVertexArray(*instancesPointLightVAO); - instancesPointLightVAO->useBuffer(0, instancesPointLight); - instancesPointLightVAO->useBuffer(1, instances); - glDrawArraysInstanced(GL_POINTS, 0, static_cast<GLsizei>(pcount), static_cast<GLsizei>(count)); - } - - glBindVertexArray(0); - } -} diff --git a/game/scenary/illuminator.h b/game/scenary/illuminator.h index c342bd4..b99a19e 100644 --- a/game/scenary/illuminator.h +++ b/game/scenary/illuminator.h @@ -2,7 +2,7 @@ #include "assetFactory/asset.h" #include "gfx/gl/instanceVertices.h" -#include "gfx/gl/lights.h" +#include "gfx/models/lights.h" #include "gfx/models/texture.h" #include "gfx/renderable.h" @@ -12,19 +12,19 @@ class Location; class Illuminator : public Asset, public Renderable, public StdTypeDefs<Illuminator> { Mesh::Ptr bodyMesh; Texture::Ptr texture; - std::shared_ptr<glVertexArray> instanceVAO, instancesSpotLightVAO, instancesPointLightVAO; - static std::weak_ptr<glVertexArray> commonInstanceVAO, commonInstancesSpotLightVAO, commonInstancesPointLightVAO; + std::shared_ptr<glVertexArray> instanceVAO; + static std::weak_ptr<glVertexArray> commonInstanceVAO; public: [[nodiscard]] std::any createAt(const Location &) const override; - struct SpotLight : Persistence::Persistable, SpotLightVertex, StdTypeDefs<SpotLight> { + struct SpotLight : Persistence::Persistable, SpotLightDef, StdTypeDefs<SpotLight> { private: friend Persistence::SelectionPtrBase<std::shared_ptr<SpotLight>>; bool persist(Persistence::PersistenceStore & store) override; }; - struct PointLight : Persistence::Persistable, PointLightVertex, StdTypeDefs<PointLight> { + struct PointLight : Persistence::Persistable, PointLightDef, StdTypeDefs<PointLight> { private: friend Persistence::SelectionPtrBase<std::shared_ptr<PointLight>>; bool persist(Persistence::PersistenceStore & store) override; @@ -35,18 +35,14 @@ public: }; mutable InstanceVertices<InstanceVertex> instances; - mutable InstanceVertices<SpotLightVertex> instancesSpotLight; - mutable InstanceVertices<PointLightVertex> instancesPointLight; void render(const SceneShader &, const Frustum &) 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; +public: std::vector<SpotLight::Ptr> spotLight; std::vector<PointLight::Ptr> pointLight; - std::vector<InstanceVertices<SpotLightVertex>::InstanceProxy> spotLightInstances; - std::vector<InstanceVertices<PointLightVertex>::InstanceProxy> pointLightInstances; }; diff --git a/game/scenary/light.cpp b/game/scenary/light.cpp index 7c38ca2..bd83f04 100644 --- a/game/scenary/light.cpp +++ b/game/scenary/light.cpp @@ -5,4 +5,13 @@ Light::Light(std::shared_ptr<const Illuminator> type, const Location & position) type {std::move(type)}, instance {this->type->instances.acquire(Renderable::commonLocationData.lock()->acquire(position))} { + std::ranges::transform(this->type->spotLight, std::back_inserter(spotLightInstances), + [spotLights = Renderable::commonSpotLights.lock(), this](const Illuminator::SpotLight::CPtr & spotLight) { + return spotLights->acquire(*spotLight, instance->location.index); + }); + std::ranges::transform(this->type->pointLight, std::back_inserter(pointLightInstances), + [pointLights = Renderable::commonPointLights.lock(), this]( + const Illuminator::PointLight::CPtr & pointLight) { + return pointLights->acquire(*pointLight, instance->location.index); + }); } diff --git a/game/scenary/light.h b/game/scenary/light.h index afb7e03..b1ea469 100644 --- a/game/scenary/light.h +++ b/game/scenary/light.h @@ -14,6 +14,9 @@ class Light : public WorldObject { { } + std::vector<InstanceVertices<SpotLightVertex>::InstanceProxy> spotLightInstances; + std::vector<InstanceVertices<PointLightVertex>::InstanceProxy> pointLightInstances; + public: Light(std::shared_ptr<const Illuminator> type, const Location & position); }; |
