HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_ContextSpecificObject.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: RE_ContextSpecificObject.h ( RE Library, C++)
7  *
8  * COMMENTS:
9  * This base class is for OpenGL objects that are context-specific,
10  * rather than shared. Example objects are:
11  *
12  * - Vertex Array Objects
13  * - Occlusion Query Objects
14  * - Timer Objects
15  *
16  * These objects are defined to be non-sharable by the OpenGL spec, even
17  * if two contexts belong to the same share-set.
18  */
19 #ifndef RE_ContextSpecificObject_h
20 #define RE_ContextSpecificObject_h
21 
22 #include <UT/UT_Assert.h>
23 #include "RE_Render.h"
24 
26 {
27 public:
28  RE_ContextSpecificObject() : myContext(nullptr) {}
30 
31  virtual bool init(RE_Render *r) = 0;
32 
33  void initContext(RE_Render *r);
34  bool matchesContext(RE_Render *r) const;
35  void clearContext() { myContext = nullptr; }
36 
37 protected:
38  RE_Render *getMyRender();
39 
40  // Call in subclasses to ensure that the incoming render context matches
41  // the context this object was created with.
43  {
44  UT_ASSERT(r);
45  if(myContext == nullptr)
46  {
47  myContext = r->getContext();
48  return true;
49  }
50  else if(myContext == r->getContext())
51  return true;
52 
53  UT_ASSERT(!"Mismatched GL context with context-specific object");
54  return false;
55  }
56 
57 private:
58  RE_OGLContext myContext;
59 };
60 
61 // To be used within derived classes.
62 #define RE_CONTEXT_CHECK(r) UT_ASSERT(matchesContext(r))
63 
64 #endif
#define RE_API
Definition: RE_API.h:10
RE_OGLContext getContext() const
Definition: RE_OGLRender.h:261
bool initOrCheckRender(RE_Render *r)
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
GLboolean r
Definition: glcorearb.h:1222
QOpenGLContext * RE_OGLContext
Definition: RE_Types.h:941