Equalizer  1.6.1
objectManager.h
1 
2 /* Copyright (c) 2007-2013, Stefan Eilemann <eile@equalizergraphics.com>
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License version 2.1 as published
6  * by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11  * details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16  */
17 
18 #ifndef EQUTIL_OBJECTMANAGER_H
19 #define EQUTIL_OBJECTMANAGER_H
20 
21 #include <eq/util/types.h>
22 #include <eq/client/api.h>
23 
24 #include <lunchbox/api.h> // EQ_API definition
25 #include <lunchbox/debug.h> // LBASSERT definition
26 #include <lunchbox/hash.h> // member
27 #include <lunchbox/nonCopyable.h> // base class
28 #include <lunchbox/referenced.h> // base class
29 
30 //#define EQ_OM_TRACE_ALLOCATIONS
31 
32 namespace eq
33 {
34 namespace util
35 {
58  template< class T > class ObjectManager : public lunchbox::NonCopyable
59  {
60  public:
61  enum
62  {
63  INVALID = 0 //<! return value for failed operations.
64  };
65 
67  EQ_API ObjectManager( const GLEWContext* const glewContext );
68 
70  EQ_API ObjectManager( ObjectManager* shared );
71 
72  EQ_API virtual ~ObjectManager();
73 
75  bool isShared() const { return _data->getRefCount() > 1; }
76 
81  EQ_API void deleteAll();
82 
83  EQ_API unsigned getList( const T& key ) const;
84  EQ_API unsigned newList( const T& key, const int num = 1 );
85  EQ_API unsigned obtainList( const T& key, const int num = 1 );
86  EQ_API void deleteList( const T& key );
87 
88  EQ_API unsigned getTexture( const T& key ) const;
89  EQ_API unsigned newTexture( const T& key );
90  EQ_API unsigned obtainTexture( const T& key );
91  EQ_API void deleteTexture( const T& key );
92 
93  EQ_API bool supportsBuffers() const;
94  EQ_API unsigned getBuffer( const T& key ) const;
95  EQ_API unsigned newBuffer( const T& key );
96  EQ_API unsigned obtainBuffer( const T& key );
97  EQ_API void deleteBuffer( const T& key );
98 
99  EQ_API bool supportsPrograms() const;
100  EQ_API unsigned getProgram( const T& key ) const;
101  EQ_API unsigned newProgram( const T& key );
102  EQ_API unsigned obtainProgram( const T& key );
103  EQ_API void deleteProgram( const T& key );
104 
105  EQ_API bool supportsShaders() const;
106  EQ_API unsigned getShader( const T& key ) const;
107  EQ_API unsigned newShader( const T& key, const unsigned type );
108  EQ_API unsigned obtainShader( const T& key, const unsigned type );
109  EQ_API void deleteShader( const T& key );
110 
111  EQ_API Accum* getEqAccum( const T& key ) const;
112  EQ_API Accum* newEqAccum( const T& key );
113  EQ_API Accum* obtainEqAccum( const T& key );
114  EQ_API void deleteEqAccum( const T& key );
115 
117  EQ_API lunchbox::Uploader* getEqUploader( const T& key ) const;
119  EQ_API lunchbox::Uploader* newEqUploader( const T& key );
121  EQ_API lunchbox::Uploader* obtainEqUploader( const T& key );
123  EQ_API void deleteEqUploader( const T& key );
124 
125  EQ_API bool supportsEqTexture() const;
126  EQ_API Texture* getEqTexture( const T& key ) const;
127  EQ_API Texture* newEqTexture( const T& key, const unsigned target );
128  EQ_API Texture* obtainEqTexture( const T& key, const unsigned target );
129  EQ_API void deleteEqTexture( const T& key );
130 
131  EQ_API bool supportsEqFrameBufferObject() const;
132  EQ_API FrameBufferObject* getEqFrameBufferObject(const T& key) const;
133  EQ_API FrameBufferObject* newEqFrameBufferObject( const T& key );
134  EQ_API FrameBufferObject* obtainEqFrameBufferObject( const T& key );
135  EQ_API void deleteEqFrameBufferObject( const T& key );
136 
137  EQ_API bool supportsEqPixelBufferObject() const;
138  EQ_API PixelBufferObject* getEqPixelBufferObject(const T& key) const;
139  EQ_API PixelBufferObject* newEqPixelBufferObject( const T& key,
140  const bool threadSafe );
141  EQ_API PixelBufferObject* obtainEqPixelBufferObject( const T& key,
142  const bool threadSafe );
143  EQ_API void deleteEqPixelBufferObject( const T& key );
144 
145  EQ_API util::BitmapFont< T >* getEqBitmapFont( const T& key ) const;
146  EQ_API util::BitmapFont< T >* newEqBitmapFont( const T& key );
147  EQ_API util::BitmapFont< T >* obtainEqBitmapFont( const T& key );
148  EQ_API void deleteEqBitmapFont( const T& key );
149 
150  const GLEWContext* glewGetContext() const { return _data->glewContext; }
151 
152  private:
153  struct Object
154  {
155  unsigned id;
156  unsigned num;
157  };
158 
159  typedef stde::hash_map< T, Object > ObjectHash;
160  typedef stde::hash_map< T, Texture* > TextureHash;
161  typedef stde::hash_map< T, FrameBufferObject* > FBOHash;
162  typedef stde::hash_map< T, PixelBufferObject* > PBOHash;
163  typedef stde::hash_map< T, util::BitmapFont< T >* > FontHash;
164  typedef stde::hash_map< T, Accum* > AccumHash;
165  typedef stde::hash_map< T, lunchbox::Uploader* > UploaderHash;
166 # ifdef EQ_OM_TRACE_ALLOCATIONS
167  typedef stde::hash_map< T, std::string > UploaderAllocs;
168 # endif
169 
170  struct SharedData : public lunchbox::Referenced
171  {
172  SharedData( const GLEWContext* glewContext );
173  virtual ~SharedData();
174 
175  GLEWContext* const glewContext;
176  ObjectHash lists;
177  ObjectHash textures;
178  ObjectHash buffers;
179  ObjectHash programs;
180  ObjectHash shaders;
181  ObjectHash uploaderDatas;
182  AccumHash accums;
183  TextureHash eqTextures;
184  FBOHash eqFrameBufferObjects;
185  PBOHash eqPixelBufferObjects;
186  FontHash eqFonts;
187  UploaderHash eqUploaders;
188 # ifdef EQ_OM_TRACE_ALLOCATIONS
189  UploaderAllocs eqUploaderAllocs;
190 # endif
191 
192  union // placeholder for binary-compatible changes
193  {
194  char dummy[64];
195  };
196  };
197 
198  typedef lunchbox::RefPtr< SharedData > SharedDataPtr;
199  SharedDataPtr _data;
200 
201  struct Private;
202  Private* _private; // placeholder for binary-compatible changes
203  };
204 }
205 }
206 
207 #endif // EQUTIL_OBJECTMANAGER_H
bool isShared() const
Definition: objectManager.h:75
A C++ class to abstract OpenGL frame buffer objects.
ObjectManager(const GLEWContext *const glewContext)
Construct a new object manager.
A wrapper around AGL, WGL and GLX bitmap fonts.
void deleteAll()
Delete all managed objects and associated GL objects.
A C++ class to abstract an accumulation buffer.
Definition: accum.h:39
A wrapper around OpenGL textures.
Definition: texture.h:38
util::ObjectManager< const void * > ObjectManager
The OpenGL object manager used in the client library.
A C++ class to abstract OpenGL pixel buffer objects.