Equalizer
1.4.1
|
00001 00002 /* Copyright (c) 2007-2012, Stefan Eilemann <eile@equalizergraphics.com> 00003 * 00004 * This library is free software; you can redistribute it and/or modify it under 00005 * the terms of the GNU Lesser General Public License version 2.1 as published 00006 * by the Free Software Foundation. 00007 * 00008 * This library is distributed in the hope that it will be useful, but WITHOUT 00009 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00010 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00011 * details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public License 00014 * along with this library; if not, write to the Free Software Foundation, Inc., 00015 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00016 */ 00017 00018 #ifndef EQUTIL_OBJECTMANAGER_H 00019 #define EQUTIL_OBJECTMANAGER_H 00020 00021 #include <eq/util/types.h> 00022 #include <eq/client/api.h> 00023 00024 #include <lunchbox/api.h> // EQ_API definition 00025 #include <lunchbox/debug.h> // LBASSERT definition 00026 #include <lunchbox/hash.h> // member 00027 #include <lunchbox/nonCopyable.h> // base class 00028 #include <lunchbox/referenced.h> // base class 00029 00030 //#define EQ_OM_TRACE_ALLOCATIONS 00031 00032 namespace eq 00033 { 00034 namespace util 00035 { 00058 template< class T > class ObjectManager : public lunchbox::NonCopyable 00059 { 00060 public: 00061 enum 00062 { 00063 INVALID = 0 //<! return value for failed operations. 00064 }; 00065 00067 EQ_API ObjectManager( const GLEWContext* const glewContext ); 00068 00070 EQ_API ObjectManager( ObjectManager* shared ); 00071 00072 EQ_API virtual ~ObjectManager(); 00073 00075 bool isShared() const { return _data->getRefCount() > 1; } 00076 00081 EQ_API void deleteAll(); 00082 00083 EQ_API unsigned getList( const T& key ) const; 00084 EQ_API unsigned newList( const T& key, const int num = 1 ); 00085 EQ_API unsigned obtainList( const T& key, const int num = 1 ); 00086 EQ_API void deleteList( const T& key ); 00087 00088 EQ_API unsigned getTexture( const T& key ) const; 00089 EQ_API unsigned newTexture( const T& key ); 00090 EQ_API unsigned obtainTexture( const T& key ); 00091 EQ_API void deleteTexture( const T& key ); 00092 00093 EQ_API bool supportsBuffers() const; 00094 EQ_API unsigned getBuffer( const T& key ) const; 00095 EQ_API unsigned newBuffer( const T& key ); 00096 EQ_API unsigned obtainBuffer( const T& key ); 00097 EQ_API void deleteBuffer( const T& key ); 00098 00099 EQ_API bool supportsPrograms() const; 00100 EQ_API unsigned getProgram( const T& key ) const; 00101 EQ_API unsigned newProgram( const T& key ); 00102 EQ_API unsigned obtainProgram( const T& key ); 00103 EQ_API void deleteProgram( const T& key ); 00104 00105 EQ_API bool supportsShaders() const; 00106 EQ_API unsigned getShader( const T& key ) const; 00107 EQ_API unsigned newShader( const T& key, const unsigned type ); 00108 EQ_API unsigned obtainShader( const T& key, const unsigned type ); 00109 EQ_API void deleteShader( const T& key ); 00110 00111 EQ_API Accum* getEqAccum( const T& key ) const; 00112 EQ_API Accum* newEqAccum( const T& key ); 00113 EQ_API Accum* obtainEqAccum( const T& key ); 00114 EQ_API void deleteEqAccum( const T& key ); 00115 00116 #ifdef EQUALIZER_SHARED 00117 00118 EQ_API GPUCompressor* getEqUploader( const T& key ) const; 00120 EQ_API GPUCompressor* newEqUploader( const T& key ); 00122 EQ_API GPUCompressor* obtainEqUploader( const T& key ); 00124 EQ_API void deleteEqUploader( const T& key ); 00125 #endif 00126 00127 EQ_API bool supportsEqTexture() const; 00128 EQ_API Texture* getEqTexture( const T& key ) const; 00129 EQ_API Texture* newEqTexture( const T& key, const unsigned target ); 00130 EQ_API Texture* obtainEqTexture( const T& key, const unsigned target ); 00131 EQ_API void deleteEqTexture( const T& key ); 00132 00133 EQ_API bool supportsEqFrameBufferObject() const; 00134 EQ_API FrameBufferObject* getEqFrameBufferObject(const T& key) const; 00135 EQ_API FrameBufferObject* newEqFrameBufferObject( const T& key ); 00136 EQ_API FrameBufferObject* obtainEqFrameBufferObject( const T& key ); 00137 EQ_API void deleteEqFrameBufferObject( const T& key ); 00138 00139 EQ_API bool supportsEqPixelBufferObject() const; 00140 EQ_API PixelBufferObject* getEqPixelBufferObject(const T& key) const; 00141 EQ_API PixelBufferObject* newEqPixelBufferObject( const T& key, 00142 const bool threadSafe ); 00143 EQ_API PixelBufferObject* obtainEqPixelBufferObject( const T& key, 00144 const bool threadSafe ); 00145 EQ_API void deleteEqPixelBufferObject( const T& key ); 00146 00147 EQ_API util::BitmapFont< T >* getEqBitmapFont( const T& key ) const; 00148 EQ_API util::BitmapFont< T >* newEqBitmapFont( const T& key ); 00149 EQ_API util::BitmapFont< T >* obtainEqBitmapFont( const T& key ); 00150 EQ_API void deleteEqBitmapFont( const T& key ); 00151 00152 const GLEWContext* glewGetContext() const { return _data->glewContext; } 00153 00154 private: 00155 struct Object 00156 { 00157 unsigned id; 00158 unsigned num; 00159 }; 00160 00161 typedef stde::hash_map< T, Object > ObjectHash; 00162 typedef stde::hash_map< T, Texture* > TextureHash; 00163 typedef stde::hash_map< T, FrameBufferObject* > FBOHash; 00164 typedef stde::hash_map< T, PixelBufferObject* > PBOHash; 00165 typedef stde::hash_map< T, util::BitmapFont< T >* > FontHash; 00166 typedef stde::hash_map< T, Accum* > AccumHash; 00167 typedef stde::hash_map< T, GPUCompressor* > UploaderHash; 00168 00169 # ifdef EQ_OM_TRACE_ALLOCATIONS 00170 typedef stde::hash_map< T, std::string > UploaderAllocs; 00171 # endif 00172 00173 00174 00175 struct SharedData : public lunchbox::Referenced 00176 { 00177 SharedData( const GLEWContext* glewContext ); 00178 virtual ~SharedData(); 00179 00180 GLEWContext* const glewContext; 00181 ObjectHash lists; 00182 ObjectHash textures; 00183 ObjectHash buffers; 00184 ObjectHash programs; 00185 ObjectHash shaders; 00186 ObjectHash uploaderDatas; 00187 AccumHash accums; 00188 TextureHash eqTextures; 00189 FBOHash eqFrameBufferObjects; 00190 PBOHash eqPixelBufferObjects; 00191 FontHash eqFonts; 00192 UploaderHash eqUploaders; 00193 00194 # ifdef EQ_OM_TRACE_ALLOCATIONS 00195 UploaderAllocs eqUploaderAllocs; 00196 # endif 00197 00198 union // placeholder for binary-compatible changes 00199 { 00200 char dummy[64]; 00201 }; 00202 }; 00203 00204 typedef lunchbox::RefPtr< SharedData > SharedDataPtr; 00205 SharedDataPtr _data; 00206 00207 struct Private; 00208 Private* _private; // placeholder for binary-compatible changes 00209 }; 00210 } 00211 } 00212 00213 #endif // EQUTIL_OBJECTMANAGER_H 00214