summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/bufferedLocation.cpp16
-rw-r--r--gfx/gl/bufferedLocation.h32
2 files changed, 29 insertions, 19 deletions
diff --git a/gfx/gl/bufferedLocation.cpp b/gfx/gl/bufferedLocation.cpp
index 7027b4c..eb3dac3 100644
--- a/gfx/gl/bufferedLocation.cpp
+++ b/gfx/gl/bufferedLocation.cpp
@@ -3,15 +3,9 @@
#include "maths.h"
#include <glm/gtx/transform.hpp>
-BufferedLocation::BufferedLocation(InstanceVertices<glm::mat4> & i, glm::vec3 p, glm::vec3 r) :
- BufferedLocation {i, Location {p, r}}
-{
-}
+BufferedLocation::BufferedLocation(glm::vec3 p, glm::vec3 r) : BufferedLocation {Location {p, r}} { }
-BufferedLocation::BufferedLocation(InstanceVertices<glm::mat4> & i, const Location & l) :
- loc {l}, buffer {i.acquire(getTransform())}
-{
-}
+BufferedLocation::BufferedLocation(const Location & l) : loc {l} { }
BufferedLocation::operator const Location &() const
{
@@ -64,12 +58,6 @@ BufferedLocation::setLocation(glm::vec3 p, glm::vec3 r)
updateBuffer();
}
-void
-BufferedLocation::updateBuffer()
-{
- buffer = getTransform();
-}
-
glm::mat4
BufferedLocation::getTransform() const
{
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 <functional>
#include <glm/mat4x4.hpp>
#include <glm/vec3.hpp>
+#include <tuple>
class BufferedLocation {
public:
- BufferedLocation(InstanceVertices<glm::mat4> &, glm::vec3 = {}, glm::vec3 = {});
- BufferedLocation(InstanceVertices<glm::mat4> &, 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<glm::mat4>::InstanceProxy buffer;
+};
+
+template<typename... Target> class BufferedLocationT : public BufferedLocation {
+public:
+ template<typename... LocationArgs>
+ BufferedLocationT(Target &&... target, LocationArgs &&... t) :
+ BufferedLocation {std::forward<LocationArgs>(t)...}, target {std::forward<Target>(target)...}
+ {
+ updateBuffer();
+ }
+
+ using BufferedLocation::operator=;
+
+private:
+ void
+ updateBuffer() override
+ {
+ std::apply(std::invoke<const Target &...>, target) = getTransform();
+ }
+
+ std::tuple<Target...> target;
};