From: Mikko Rasa Date: Sat, 28 Aug 2021 08:41:08 +0000 (+0300) Subject: Remove the Bindable class X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=715672cf2c64dab0744db676fdee255ee3a4cef7;p=libs%2Fgl.git Remove the Bindable class It's no longer used anywere --- diff --git a/source/core/batch.cpp b/source/core/batch.cpp index 2bc44c9d..51746b37 100644 --- a/source/core/batch.cpp +++ b/source/core/batch.cpp @@ -1,7 +1,6 @@ #include #include #include "batch.h" -#include "bindable.h" #include "buffer.h" #include "error.h" #include "mesh.h" diff --git a/source/core/bindable.h b/source/core/bindable.h deleted file mode 100644 index b2634ea9..00000000 --- a/source/core/bindable.h +++ /dev/null @@ -1,225 +0,0 @@ -#ifndef MSP_GL_BINDABLE_H_ -#define MSP_GL_BINDABLE_H_ - -namespace Msp { -namespace GL { - -/** -A helper class for single-point binding. Provides tracking of the currently -bound object. -*/ -template -class Bindable -{ -protected: - static const T *cur_obj; - - Bindable() { } - ~Bindable() { if(cur_obj==this) T::unbind(); } - - static bool set_current(const T *obj) - { - if(obj==cur_obj) - return false; - - cur_obj = obj; - return true; - } - -public: - static const T *current() { return cur_obj; } -}; - -template -const T *Bindable::cur_obj; - - -/** -A helper class for Bindables that revert to a default object on unbind. -*/ -template -class BindableWithDefault: protected Bindable -{ - friend class Bindable; - -protected: - BindableWithDefault() { } - ~BindableWithDefault() { if(this==&default_object()) Bindable::set_current(0); } - -public: - static const T *current() - { - if(!Bindable::cur_obj) - Bindable::cur_obj = &default_object(); - return Bindable::cur_obj; - } - - static void unbind() - { - if(Bindable::cur_obj) - default_object().bind(); - } - - static const T &default_object() - { - static T obj; - return obj; - } -}; - - -/** -RAII class for binding things. Binds the thing upon construction and unbinds -it upon destruction. If a null pointer is given, unbinds upon construction and -does nothing upon destruction. -*/ -class Bind -{ -private: - typedef void CleanupFunc(int); - - int slot; - CleanupFunc *cleanup; - -public: - template - Bind(T *o) { init(o); } - - template - Bind(const T *o) { init(o); } - - template - Bind(const T &o) { init(&o); } - - template - Bind(T *o, S s) { init(o, s); } - - template - Bind(const T *o, S s) { init(o, s); } - - template - Bind(const T &o, S s) { init(&o, s); } - -private: - template - void init(const T *o) - { - cleanup = (o ? static_cast(&unbind) : 0); - slot = 0; - if(o) - o->bind(); - else - T::unbind(); - } - - template - void init(const T *o, S s) - { - cleanup = (o ? static_cast(&unbind_from) : 0); - slot = s; - if(o) - o->bind_to(s); - else - T::unbind_from(s); - } - -public: - ~Bind() - { if(cleanup) cleanup(slot); } - -private: - template - static void unbind(int) - { T::unbind(); } - - template - static void unbind_from(int s) - { T::unbind_from(static_cast(s)); } -}; - - -/** -Similar to Bind, but restores previous binding upon destruction. -*/ -class BindRestore -{ -private: - typedef void CleanupFunc(const void *, int); - - const void *old; - int slot; - CleanupFunc *cleanup; - -public: - template - BindRestore(T *o) { init(o); } - - template - BindRestore(const T *o) { init(o); } - - template - BindRestore(const T &o) { init(&o); } - - template - BindRestore(T *o, S s) { init(o, s); } - - template - BindRestore(const T *o, S s) { init(o, s); } - - template - BindRestore(const T &o, S s) { init(&o, s); } - -private: - template - void init(T *o) - { - old = T::current(); - slot = 0; - cleanup = (o!=old ? static_cast(&restore) : 0); - if(o) - o->bind(); - else if(old) - T::unbind(); - } - - template - void init(T *o, S s) - { - old = T::current(s); - slot = s; - cleanup = (o!=old ? static_cast(&restore_to) : 0); - if(o) - o->bind_to(s); - else if(old) - T::unbind_from(s); - } - -public: - ~BindRestore() - { if(cleanup) cleanup(old, slot); } - -private: - template - static void restore(const void *o, int) - { - if(o) - reinterpret_cast(o)->bind(); - else - T::unbind(); - } - - template - static void restore_to(const void *o, int si) - { - S s = static_cast(si); - if(o) - reinterpret_cast(o)->bind_to(s); - else - T::unbind_from(s); - } -}; - -} // namespace GL -} // namespace Msp - -#endif diff --git a/source/core/framebuffer.h b/source/core/framebuffer.h index 2e1b3677..275f516e 100644 --- a/source/core/framebuffer.h +++ b/source/core/framebuffer.h @@ -2,7 +2,6 @@ #define MSP_GL_FRAMEBUFFER_H_ #include -#include "bindable.h" #include "gl.h" #include "texturecube.h" #include diff --git a/source/core/program.h b/source/core/program.h index a494e079..f2d7d076 100644 --- a/source/core/program.h +++ b/source/core/program.h @@ -4,7 +4,6 @@ #include #include #include -#include "bindable.h" #include "datatype.h" #include "gl.h" #include "module.h" diff --git a/source/core/texture.cpp b/source/core/texture.cpp index 3adc511e..347634d4 100644 --- a/source/core/texture.cpp +++ b/source/core/texture.cpp @@ -3,7 +3,6 @@ #include #include #include -#include "bindable.h" #include "error.h" #include "resourcemanager.h" #include "resources.h" diff --git a/source/core/texture1d.cpp b/source/core/texture1d.cpp index 7685d39e..4c58d470 100644 --- a/source/core/texture1d.cpp +++ b/source/core/texture1d.cpp @@ -2,7 +2,6 @@ #include #include #include -#include "bindable.h" #include "error.h" #include "texture1d.h" diff --git a/source/core/texture2d.cpp b/source/core/texture2d.cpp index 528c4a58..b5194858 100644 --- a/source/core/texture2d.cpp +++ b/source/core/texture2d.cpp @@ -2,7 +2,6 @@ #include #include #include -#include "bindable.h" #include "buffer.h" #include "error.h" #include "resources.h" diff --git a/source/core/texture3d.cpp b/source/core/texture3d.cpp index ab8bca7c..768af912 100644 --- a/source/core/texture3d.cpp +++ b/source/core/texture3d.cpp @@ -5,7 +5,6 @@ #include #include #include -#include "bindable.h" #include "error.h" #include "texture3d.h" diff --git a/source/core/texturecube.cpp b/source/core/texturecube.cpp index 5c7f6102..ae06557d 100644 --- a/source/core/texturecube.cpp +++ b/source/core/texturecube.cpp @@ -5,7 +5,6 @@ #include #include #include -#include "bindable.h" #include "error.h" #include "texturecube.h" diff --git a/source/core/vertexsetup.h b/source/core/vertexsetup.h index 408d7380..7eb903ae 100644 --- a/source/core/vertexsetup.h +++ b/source/core/vertexsetup.h @@ -1,7 +1,6 @@ #ifndef MSP_GL_VERTEXSETUP_H_ #define MSP_GL_VERTEXSETUP_H_ -#include "bindable.h" #include "vertexformat.h" namespace Msp { diff --git a/source/render/object.h b/source/render/object.h index 522d3adc..b7b54953 100644 --- a/source/render/object.h +++ b/source/render/object.h @@ -2,7 +2,6 @@ #define MSP_GL_OBJECT_H_ #include -#include "bindable.h" #include "renderable.h" #include "renderpass.h" #include "resourceobserver.h"