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 "RE_API.h"
23 #include "RE_Render.h"
24 #include "RE_Server.h"
25 #include <UT/UT_Assert.h>
26 #include <UT/UT_NonCopyable.h>
27 
29 {
30 public:
31  RE_ContextSpecificObject() : myContext(nullptr) {}
33 
35 
36  virtual bool init(RE_Render *r) = 0;
37 
38  void initContext(RE_Render *r);
39  bool matchesContext(RE_Render *r) const;
40  void clearContext() { myContext = nullptr; }
41 
42 protected:
43  RE_Render *getMyRender();
44 
45  // Call in subclasses to ensure that the incoming render context matches
46  // the context this object was created with.
48  {
49  UT_ASSERT(r);
50 
51  auto render_context = (RE_Server::useNewWindowDrawable()
52  ? r->getDrawableContext() : r->getContext());
53 
54  if (myContext == nullptr)
55  {
56  myContext = render_context;
57  return true;
58  }
59  else if (myContext == render_context)
60  return true;
61 
62  UT_ASSERT(!"Mismatched GL context with context-specific object");
63  return false;
64  }
65 
66 private:
67  RE_OGLContext myContext;
68 };
69 
70 // To be used within derived classes.
71 #define RE_CONTEXT_CHECK(r) UT_ASSERT(matchesContext(r))
72 
73 #endif
#define RE_API
Definition: RE_API.h:10
RE_OGLContext getDrawableContext() const
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
RE_OGLContext getContext() const
Definition: RE_OGLRender.h:290
bool initOrCheckRender(RE_Render *r)
static bool useNewWindowDrawable()
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
GLboolean r
Definition: glcorearb.h:1222
QOpenGLContext * RE_OGLContext
Definition: RE_Types.h:949