VVISF & VVGL
GLCachedProperty.hpp
1 #ifndef VVGL_GLCachedUni_h
2 #define VVGL_GLCachedUni_h
3 
4 #include "VVGL_Defines.hpp"
5 
6 #include <iostream>
7 
8 #include "VVGL_StringUtils.hpp"
9 
10 
11 
12 
13 namespace VVGL
14 {
15 
16 
17 
18 
19 using namespace std;
20 
21 
22 
23 
25 
34 struct VVGL_EXPORT GLCachedProperty {
35  // these vars are public and that's technically not safe in multi-threaded situations, but practically speaking this works out because everything GL-related has to be serialized such that access is one-context-per-thread anyway...
36  public:
37  // The location of the property (attribute/uniform/etc), derived by quering a GL program (the id of which is also cached). read-only outside this object!
38  int32_t loc = -1;
39  // The name of the attribute
40  string name;
41  // The id of the GLSL program that was checked to create the current loc
42  int32_t prog = -1;
43  public:
44  GLCachedProperty(string & inName) : name(inName) {}
45  GLCachedProperty(const string & inName) : name(inName) {}
46  GLCachedProperty(const GLCachedProperty & n) : loc(n.loc), name(n.name), prog(n.prog) {}
47  virtual ~GLCachedProperty();
48  public:
50  virtual void cacheTheLoc(const int32_t & inPgmToCheck);
51  inline void purgeCache() { loc=-1; prog=-1; }
52  public:
54  int32_t location(const int32_t & inGLProgram) { if (loc<0 || inGLProgram<0 || inGLProgram!=prog) cacheTheLoc(inGLProgram); return loc; }
55  string getDescriptionString() const { return FmtString("<GLCachedProperty \"%s\", %d>",this->name.c_str(),this->loc); }
56  friend ostream & operator<<(ostream & os, const GLCachedProperty & n) { os<<n.getDescriptionString();return os; }
57 };
58 
59 
60 
61 
66 struct VVGL_EXPORT GLCachedAttrib : GLCachedProperty {
67  public:
68  GLCachedAttrib(string & inName) : GLCachedProperty(inName) {}
69  GLCachedAttrib(const string & inName) : GLCachedProperty(inName) {}
71  public:
72  string getDescriptionString() const { return FmtString("<GLCachedAttrib \"%s\", %d>",this->name.c_str(),this->loc); }
74  void enable();
76  void disable();
77 
79  void cacheTheLoc(const int32_t & inPgmToCheck) override;
80 };
81 
82 
83 
84 
89 struct VVGL_EXPORT GLCachedUni : GLCachedProperty {
90  public:
91  GLCachedUni(string & inName) : GLCachedProperty(inName) {}
92  GLCachedUni(const string & inName) : GLCachedProperty(inName) {}
93  GLCachedUni(const GLCachedUni & n) : GLCachedProperty(n) {}
94  //~GLCachedUni() {}
95  public:
96  string getDescriptionString() const { return FmtString("<GLCachedUni \"%s\", %d>",this->name.c_str(),this->loc); }
97 
99  void cacheTheLoc(const int32_t & inPgmToCheck) override;
100 };
101 
102 
103 
104 
105 }
106 
107 
108 #endif /* VVGL_GLCachedUni_h */
int32_t location(const int32_t &inGLProgram)
Returns the location of the property cached by the receiver. A valid GL context must be current befor...
Definition: GLCachedProperty.hpp:54
Definition: GLBuffer.hpp:13
Subclass of GLCachedProperty that caches the location of a uniform variable in a GLSL program...
Definition: GLCachedProperty.hpp:89
STL namespace.
Subclass of GLCachedProperty that caches the location of an attribute in a GLSL program.
Definition: GLCachedProperty.hpp:66
Abstract base class that caches the location of an arbitrary GL "object" that we do not own...
Definition: GLCachedProperty.hpp:34