From fb78c88576d9fed90ee69dfa35a9fbd3179ff486 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 30 Mar 2026 13:04:36 +0100 Subject: Use a single buffer for the location/rotation data of all renderable objects Removes the BufferedLocation and BufferedLocationUpdater mess. Note: appears to break bogie rendering in asset factory test only, same symptom as broken network render test? (out of date buffer data) --- game/scenary/foliage.cpp | 21 ++++++++++----------- game/scenary/foliage.h | 12 ++++++------ game/scenary/illuminator.cpp | 11 +++++------ game/scenary/illuminator.h | 7 +++++-- game/scenary/light.cpp | 3 ++- game/scenary/light.h | 2 +- game/scenary/plant.cpp | 2 +- game/scenary/plant.h | 2 +- 8 files changed, 31 insertions(+), 29 deletions(-) (limited to 'game/scenary') diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp index ff00af4..5902e09 100644 --- a/game/scenary/foliage.cpp +++ b/game/scenary/foliage.cpp @@ -25,8 +25,8 @@ std::weak_ptr Foliage::commonInstanceVAO, Foliage::commonInstance std::any Foliage::createAt(const Location & position) const { - return std::make_shared::InstanceProxy>( - instances.acquire(position.getRotationTransform(), position.rot.y, position.pos)); + return std::make_shared::InstanceProxy>( + instances.acquire(locationData->acquire(position))); } bool @@ -42,12 +42,11 @@ Foliage::postLoad() glDebugScope _ {0}; if (!(instanceVAO = commonInstanceVAO.lock())) { commonInstanceVAO = instanceVAO = std::make_shared(); - bodyMesh->configureVAO(*instanceVAO, 0) - .addAttribs(1); + bodyMesh->configureVAO(*instanceVAO, 0).addAttribs(1); } if (!(instancePointVAO = commonInstancePointVAO.lock())) { commonInstancePointVAO = instancePointVAO = std::make_shared(); - instancePointVAO->configure().addAttribs(0); + instancePointVAO->configure().addAttribs(0); } const auto & size = bodyMesh->getDimensions().size; billboardSize = billboardTextureSizeForObject(size); @@ -82,14 +81,14 @@ Foliage::preFrame(const Frustum & frustum, const Frustum & lighting) if (instances.size() > 0) { const auto & dims = bodyMesh->getDimensions(); instancePartitions = instances.partition( - [&frustum, &dims](const auto & location) { - return frustum.contains(location.position + dims.centre, dims.size); + [&frustum, &dims](const auto & instance) { + return frustum.contains(instance.location->position.xyz() + dims.centre, dims.size); }, - [&frustum, this](const auto & location) { - return distance(frustum.getPosition(), location.position) < useMeshClipDist; + [&frustum, this](const auto & instance) { + return distance(frustum.getPosition(), instance.location->position.xyz()) < useMeshClipDist; }, - [&lighting, &dims](const auto & location) { - return lighting.contains(location.position + dims.centre, dims.size); + [&lighting, &dims](const auto & instance) { + return lighting.contains(instance.location->position.xyz() + dims.centre, dims.size); }); // In view frustum / Outside view frustum / // Close to view / Far from view / Casts shadow into view / No shadow in view / diff --git a/game/scenary/foliage.h b/game/scenary/foliage.h index c599649..f424ffc 100644 --- a/game/scenary/foliage.h +++ b/game/scenary/foliage.h @@ -18,13 +18,13 @@ class Foliage : public Asset, public Renderable, public StdTypeDefs { public: [[nodiscard]] std::any createAt(const Location &) const override; - struct LocationVertex { - glm::mat3 rotation; - float yaw; - GlobalPosition3D position; + struct InstanceVertex { + CommonLocationInstance location; + // float scale; + // something colorBias; }; - mutable InstanceVertices instances; + mutable InstanceVertices instances; void preFrame(const Frustum &, const Frustum &) override; void render(const SceneShader &, const Frustum &) const override; void shadows(const ShadowMapper &, const Frustum &) const override; @@ -43,5 +43,5 @@ protected: glTextures billboard; private: - InstanceVertices::PartitionResult instancePartitions; + InstanceVertices::PartitionResult instancePartitions; }; diff --git a/game/scenary/illuminator.cpp b/game/scenary/illuminator.cpp index 4398853..e991baa 100644 --- a/game/scenary/illuminator.cpp +++ b/game/scenary/illuminator.cpp @@ -11,8 +11,8 @@ std::weak_ptr Illuminator::commonInstanceVAO, Illuminator::common std::any Illuminator::createAt(const Location & position) const { - return std::make_shared::InstanceProxy>( - instances.acquire(position.getRotationTransform(), position.pos)); + return std::make_shared::InstanceProxy>( + instances.acquire(locationData->acquire(position))); } bool @@ -46,8 +46,7 @@ Illuminator::postLoad() glDebugScope _ {0}; if (!(instanceVAO = commonInstanceVAO.lock())) { commonInstanceVAO = instanceVAO = std::make_shared(); - bodyMesh->configureVAO(*instanceVAO, 0) - .addAttribs(1); + bodyMesh->configureVAO(*instanceVAO, 0).addAttribs(1); } if (!spotLight.empty()) { if (!(instancesSpotLightVAO = commonInstancesSpotLightVAO.lock())) { @@ -55,7 +54,7 @@ Illuminator::postLoad() instancesSpotLightVAO->configure() .addAttribs(0) - .addAttribs(1); + .addAttribs(1); } std::transform( spotLight.begin(), spotLight.end(), std::back_inserter(spotLightInstances), [this](const auto & s) { @@ -68,7 +67,7 @@ Illuminator::postLoad() instancesPointLightVAO->configure() .addAttribs(0) - .addAttribs(1); + .addAttribs(1); } std::transform( pointLight.begin(), pointLight.end(), std::back_inserter(pointLightInstances), [this](const auto & s) { diff --git a/game/scenary/illuminator.h b/game/scenary/illuminator.h index 7b6e7ad..53a7981 100644 --- a/game/scenary/illuminator.h +++ b/game/scenary/illuminator.h @@ -42,8 +42,11 @@ public: bool persist(Persistence::PersistenceStore & store) override; }; - using LocationVertex = std::pair; - mutable InstanceVertices instances; + struct InstanceVertex { + CommonLocationInstance location; + }; + + mutable InstanceVertices instances; mutable InstanceVertices instancesSpotLight; mutable InstanceVertices instancesPointLight; void render(const SceneShader &, const Frustum &) const override; diff --git a/game/scenary/light.cpp b/game/scenary/light.cpp index 6207497..7c38ca2 100644 --- a/game/scenary/light.cpp +++ b/game/scenary/light.cpp @@ -2,6 +2,7 @@ #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)} + type {std::move(type)}, + instance {this->type->instances.acquire(Renderable::commonLocationData.lock()->acquire(position))} { } diff --git a/game/scenary/light.h b/game/scenary/light.h index 0b19535..afb7e03 100644 --- a/game/scenary/light.h +++ b/game/scenary/light.h @@ -7,7 +7,7 @@ class Location; class Light : public WorldObject { std::shared_ptr type; - InstanceVertices::InstanceProxy location; + InstanceVertices::InstanceProxy instance; void tick(TickDuration) override diff --git a/game/scenary/plant.cpp b/game/scenary/plant.cpp index 2006225..b0e7d16 100644 --- a/game/scenary/plant.cpp +++ b/game/scenary/plant.cpp @@ -3,6 +3,6 @@ Plant::Plant(std::shared_ptr type, const Location & position) : type {std::move(type)}, - location {this->type->instances.acquire(position.getRotationTransform(), position.rot.y, position.pos)} + instance {this->type->instances.acquire(Renderable::commonLocationData.lock()->acquire(position))} { } diff --git a/game/scenary/plant.h b/game/scenary/plant.h index 77c9ff7..cc690c5 100644 --- a/game/scenary/plant.h +++ b/game/scenary/plant.h @@ -7,7 +7,7 @@ class Location; class Plant : public WorldObject { std::shared_ptr type; - InstanceVertices::InstanceProxy location; + InstanceVertices::InstanceProxy instance; void tick(TickDuration) override -- cgit v1.3