HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_ContextSpecificTable.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_ContextSpecificTable.h ( RE Library, C++)
7  *
8  * COMMENTS:
9  * Contains context-specific objects, creating them as needed for new
10  * GL contexts.
11  */
12 #ifndef RE_ContextSpecificTable_h
13 #define RE_ContextSpecificTable_h
14 
15 #include "RE_API.h"
16 #include <UT/UT_ValArray.h>
17 
19 #include "RE_Render.h"
20 #include "RE_Server.h"
21 
22 template <class CObj>
24 {
25 public:
28  {
29  for(int i=0; i<myObjects.entries(); i++)
30  if(myObjects(i))
31  {
32  // avoid an attempt to clear the GL object, since deleting
33  // the table implies we're exiting and contexts are not
34  // likely to be valid. Use clear() if you need to free
35  // the GL objects themselves.
37  myObjects(i)->clearContext();
38  delete myObjects(i);
39  }
40  }
41 
42  CObj *get(RE_Render *r)
43  {
44  int id = r->getContextID();
45  RE_ContextSpecificObject *obj = myObjects.forcedRef(id);
46  if(!obj)
47  {
48  obj = myObjects(id) = new CObj;
49  obj->init(r);
50  }
51 
52  return static_cast<CObj *>(obj);
53  }
54  CObj *peek(RE_Render *r)
55  {
56  int id = r->getContextID();
57  if(id < myObjects.entries())
58  return static_cast<CObj *>(myObjects(id));
59  return nullptr;
60  }
61 
62  void free(RE_Render *r)
63  {
64  int id = r->getContextID();
65 
66  if(id >= myObjects.entries())
67  return;
68 
69  delete myObjects(id);
70  myObjects(id) = nullptr;
71  }
72 
73  void clear()
74  {
75  for(int i=0; i<myObjects.entries(); i++)
76  {
77  delete myObjects(i);
78  myObjects(i) = nullptr;
79  }
80  myObjects.entries(0);
81  }
82 
83  /// Returns the amount of main memory (NOT graphics memory!)
84  /// owned by this RE_ContextSpecificTable.
85  int64 getMemoryUsage(bool inclusive) const
86  {
87  int64 mem = inclusive ? sizeof(*this) : 0;
88  mem += myObjects.getMemoryUsage(false);
89  return mem;
90  }
91 
92 private:
94 
95  friend class RE_OGLRender;
96 };
97 
98 #endif
virtual bool init(RE_Render *r)=0
int64 getMemoryUsage(bool inclusive=false) const
Definition: UT_Array.h:657
int getContextID() const
Definition: RE_OGLRender.h:118
int64 getMemoryUsage(bool inclusive) const
static bool isAppExiting()
long long int64
Definition: SYS_Types.h:116
exint entries() const
Alias of size(). size() is preferred.
Definition: UT_Array.h:648
GLboolean r
Definition: glcorearb.h:1222
T & forcedRef(exint i)
Definition: UT_Array.h:801