VVISF & VVGL
VVGL_Base.hpp
Go to the documentation of this file.
1 #ifndef VVGL_Base_h
2 #define VVGL_Base_h
3 
4 #include "VVGL_Defines.hpp"
5 
6 #include <vector>
7 #include <memory>
8 
9 #include "VVGL_Time.hpp"
10 #include "VVGL_Range.hpp"
11 #include "VVGL_StringUtils.hpp"
12 
20 namespace VVGL
21 {
22 
23 
24 using namespace std;
25 
26 
27 // some forward declarations used in this header
28 class GLBuffer;
29 class GLBufferPool;
30 class GLTexToTexCopier;
31 class GLContext;
32 class GLScene;
33 struct GLCachedAttrib;
34 struct GLCachedUni;
35 class GLTexToCPUCopier;
36 class GLCPUToTexCopier;
37 struct Timestamp;
38 
40 
44 using GLBufferRef = shared_ptr<GLBuffer>;
49 using GLBufferPoolRef = shared_ptr<GLBufferPool>;
54 using GLTexToTexCopierRef = shared_ptr<GLTexToTexCopier>;
55 
60 using GLContextRef = shared_ptr<GLContext>;
65 using GLSceneRef = shared_ptr<GLScene>;
70 using GLCachedAttribRef = shared_ptr<GLCachedAttrib>;
75 using GLCachedUniRef = shared_ptr<GLCachedUni>;
80 using GLTexToCPUCopierRef = shared_ptr<GLTexToCPUCopier>;
85 using GLCPUToTexCopierRef = shared_ptr<GLCPUToTexCopier>;
86 
87 
88 
89 
94 enum GLVersion {
95  GLVersion_Unknown,
96  GLVersion_2,
97  GLVersion_ES,
98  GLVersion_ES2,
99  GLVersion_ES3,
100  GLVersion_33,
101  GLVersion_4
102 };
107 inline const string GLVersionToString(const GLVersion & v) { switch (v) { case GLVersion_Unknown: return string("Unknown"); case GLVersion_2: return string("2"); case GLVersion_ES: return string("ES"); case GLVersion_ES2: return string("ES2"); case GLVersion_ES3: return string("ES3"); case GLVersion_33: return string("3.3"); case GLVersion_4: return string("4"); } return string("err"); }
108 
109 
110 
111 
116 struct GLColor {
118  float r = 0.0;
120  float g = 0.0;
122  float b = 0.0;
124  float a = 0.0;
125  GLColor() {}
126  GLColor(const float & inR, const float & inG, const float & inB, const float & inA) { r=inR;g=inG;b=inB;a=inA; }
127  bool operator==(const GLColor & n) const { return (this->r==n.r && this->g==n.g && this->b==n.b && this->a==n.a); }
128  bool operator!=(const GLColor & n) const { return !(*this==n); }
129 };
130 
131 
132 // this macro is a crude but effective way of logging GL errors on platforms that don't have dedicated GL debugging utilities
133 #ifdef GL_DEBUG
134 #define GLERRLOG { \
135  int __ASDFQWERZXCV__=glGetError(); \
136  if (__ASDFQWERZXCV__!=0){ \
137  std::string humanReadable("???"); \
138  switch(__ASDFQWERZXCV__){ \
139  case 0x0: humanReadable=std::string("no error"); break; \
140  case 0x500: humanReadable=std::string("invalid enum"); break; \
141  case 0x501: humanReadable=std::string("invalid value"); break; \
142  case 0x502: humanReadable=std::string("invalid operation"); break; \
143  case 0x503: humanReadable=std::string("stack overflow"); break; \
144  case 0x504: humanReadable=std::string("stack underflow"); break; \
145  case 0x505: humanReadable=std::string("out of memory"); break; \
146  case 0x506: humanReadable=std::string("invalid framebuffer"); break; \
147  case 0x507: humanReadable=std::string("context lost"); break; \
148  case 0x8031: humanReadable=std::string("table too large"); break; \
149  default: break; \
150  } \
151  std::cout<<"\tglGetError() returned "<<__ASDFQWERZXCV__<<" ("<<humanReadable<<") in "<<__LINE__<<" of "<<__FILE__<<endl; \
152  } \
153 }
154 #else
155 #define GLERRLOG
156 #endif
157 
158 
159 // this function dumps a 4cc to chars
160 inline void VVUnpackFourCC_toChar(unsigned long fourCC, char *destCharPtr) { if (destCharPtr==nullptr) return; for (int i=0; i<4; ++i) destCharPtr[i] = (char)((fourCC >> ((3-i)*8)) & 0xFF); }
161 
162 
163 
164 
165 } // namespace VVGL
166 
167 
168 
169 
170 #if defined(VVGL_SDK_QT)
171 #include <QThread>
172 #include <QCoreApplication>
173 // this template establishes a function for asynchronously performing a lambda on the passed
174 // object's thread (or the main thread if there's no passed object).
175 //
176 // usage:
177 // perform_async([]() { qDebug() << __PRETTY_FUNCTION__; });
178 //
179 // perform_async([&]{ o.setObjectName("hello"); }, &o);
180 // perform_async(std::bind(&QObject::setObjectName, &o, "hello"), &o);
181 template <typename FTYPE>
182 static void perform_async(FTYPE && inFunc, QObject * inObj=qApp)
183 {
184  struct Event : public QEvent
185  {
186  using Fun = typename std::decay<FTYPE>::type;
187  Fun varFunc;
188  Event(Fun && declInFunc) : QEvent(QEvent::None), varFunc(std::move(declInFunc)) {}
189  Event(const Fun & declInFunc) : QEvent(QEvent::None), varFunc(declInFunc) {}
190  ~Event() { this->varFunc(); }
191  };
192  QCoreApplication::postEvent(inObj, new Event(std::forward<FTYPE>(inFunc)));
193 }
194 #endif
195 
196 
197 
198 
199 #endif /* VVGL_Base_h */
shared_ptr< GLCachedAttrib > GLCachedAttribRef
A GLCachedAttribRef is a shared pointer around a GLCachedAttrib.
Definition: VVGL_Base.hpp:70
This struct describes an RGBA color.
Definition: VVGL_Base.hpp:116
shared_ptr< GLCPUToTexCopier > GLCPUToTexCopierRef
A GLCPUToTexCopierRef is a shared pointer around a GLCPUToTexCopier.
Definition: VVGL_Base.hpp:85
shared_ptr< GLScene > GLSceneRef
A GLSceneRef is a shared pointer around a GLScene.
Definition: VVGL_Base.hpp:65
Definition: GLBuffer.hpp:13
const string GLVersionToString(const GLVersion &v)
Returns a std::string describing the passed GLVersion.
Definition: VVGL_Base.hpp:107
STL namespace.
shared_ptr< GLBuffer > GLBufferRef
Very common- GLBufferRef is a shared pointer around a GLBuffer.
Definition: VVGL_Base.hpp:44
shared_ptr< GLTexToTexCopier > GLTexToTexCopierRef
A GLTexToTexCopierRef is a shared pointer around a GLTexToTexCopier.
Definition: VVGL_Base.hpp:54
shared_ptr< GLTexToCPUCopier > GLTexToCPUCopierRef
A GLTexToCPUCopierRef is a shared pointer around a GLTexToCPUCopier.
Definition: VVGL_Base.hpp:80
shared_ptr< GLCachedUni > GLCachedUniRef
A GLCachedUniRef is a shared pointer around a GLCachedUni.
Definition: VVGL_Base.hpp:75
shared_ptr< GLBufferPool > GLBufferPoolRef
A GLBufferPoolRef is a shared pointer around a GLBufferPool.
Definition: VVGL_Base.hpp:49
GLVersion
This enum is used to describe the GL environment of a GL context, which is determined at runtime...
Definition: VVGL_Base.hpp:94
shared_ptr< GLContext > GLContextRef
A GLContextRef is a shared pointer around a GLContext.
Definition: VVGL_Base.hpp:60