From 72ab29786f6d4c97a92cb95c75091537490e2d0f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 6 May 2023 16:42:08 +0100 Subject: Templated BufferedLocation and single buffer storage for RVC locations --- gfx/gl/bufferedLocation.h | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'gfx/gl/bufferedLocation.h') diff --git a/gfx/gl/bufferedLocation.h b/gfx/gl/bufferedLocation.h index 6d148cd..8096489 100644 --- a/gfx/gl/bufferedLocation.h +++ b/gfx/gl/bufferedLocation.h @@ -1,14 +1,16 @@ #pragma once -#include "instanceVertices.h" #include "location.h" +#include #include #include +#include class BufferedLocation { public: - BufferedLocation(InstanceVertices &, glm::vec3 = {}, glm::vec3 = {}); - BufferedLocation(InstanceVertices &, const Location &); + BufferedLocation(glm::vec3 = {}, glm::vec3 = {}); + BufferedLocation(const Location &); + virtual ~BufferedLocation() = default; BufferedLocation & operator=(const Location &); @@ -23,8 +25,28 @@ public: glm::mat4 getTransform() const; private: - void updateBuffer(); + virtual void updateBuffer() = 0; Location loc; - InstanceVertices::InstanceProxy buffer; +}; + +template class BufferedLocationT : public BufferedLocation { +public: + template + BufferedLocationT(Target &&... target, LocationArgs &&... t) : + BufferedLocation {std::forward(t)...}, target {std::forward(target)...} + { + updateBuffer(); + } + + using BufferedLocation::operator=; + +private: + void + updateBuffer() override + { + std::apply(std::invoke, target) = getTransform(); + } + + std::tuple target; }; -- cgit v1.2.3