Equalizer
1.2.1
|
00001 00002 /* Copyright (c) 2007-2011, 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 00023 #include <eq/client/gl.h> // OpenGL/GLEW types 00024 #include <co/base/api.h> // EQ_API definition 00025 #include <co/base/debug.h> // EQASSERT definition 00026 #include <co/base/hash.h> // member 00027 #include <co/base/nonCopyable.h> // base class 00028 #include <co/base/referenced.h> // base class 00029 00030 namespace eq 00031 { 00032 namespace util 00033 { 00056 template< class T > class ObjectManager : public co::base::NonCopyable 00057 { 00058 public: 00059 enum 00060 { 00061 INVALID = 0 //<! return value for failed operations. 00062 }; 00063 00065 EQ_API ObjectManager( const GLEWContext* const glewContext ); 00066 00068 EQ_API ObjectManager( ObjectManager* shared ); 00069 00070 EQ_API virtual ~ObjectManager(); 00071 00073 bool isShared() const { return _data->getRefCount() > 1; } 00074 00075 EQ_API void deleteAll(); 00076 00077 EQ_API GLuint getList( const T& key ) const; 00078 EQ_API GLuint newList( const T& key, const GLsizei num = 1 ); 00079 EQ_API GLuint obtainList( const T& key, const GLsizei num = 1 ); 00080 EQ_API void deleteList( const T& key ); 00081 00082 EQ_API GLuint getTexture( const T& key ) const; 00083 EQ_API GLuint newTexture( const T& key ); 00084 EQ_API GLuint obtainTexture( const T& key ); 00085 EQ_API void deleteTexture( const T& key ); 00086 00087 EQ_API bool supportsBuffers() const; 00088 EQ_API GLuint getBuffer( const T& key ) const; 00089 EQ_API GLuint newBuffer( const T& key ); 00090 EQ_API GLuint obtainBuffer( const T& key ); 00091 EQ_API void deleteBuffer( const T& key ); 00092 00093 EQ_API bool supportsPrograms() const; 00094 EQ_API GLuint getProgram( const T& key ) const; 00095 EQ_API GLuint newProgram( const T& key ); 00096 EQ_API GLuint obtainProgram( const T& key ); 00097 EQ_API void deleteProgram( const T& key ); 00098 00099 EQ_API bool supportsShaders() const; 00100 EQ_API GLuint getShader( const T& key ) const; 00101 EQ_API GLuint newShader( const T& key, const GLenum type ); 00102 EQ_API GLuint obtainShader( const T& key, const GLenum type ); 00103 EQ_API void deleteShader( const T& key ); 00104 00105 EQ_API Accum* getEqAccum( const T& key ) const; 00106 EQ_API Accum* newEqAccum( const T& key ); 00107 EQ_API Accum* obtainEqAccum( const T& key ); 00108 EQ_API void deleteEqAccum( const T& key ); 00109 00110 #ifdef EQUALIZER_SHARED 00111 00112 EQ_API GPUCompressor* getEqUploader( const T& key ) const; 00114 EQ_API GPUCompressor* newEqUploader( const T& key ); 00116 EQ_API GPUCompressor* obtainEqUploader( const T& key ); 00118 EQ_API void deleteEqUploader( const T& key ); 00119 #endif 00120 00121 EQ_API bool supportsEqTexture() const; 00122 EQ_API Texture* getEqTexture( const T& key ) const; 00123 EQ_API Texture* newEqTexture( const T& key, const GLenum target ); 00124 EQ_API Texture* obtainEqTexture( const T& key, const GLenum target ); 00125 EQ_API void deleteEqTexture( const T& key ); 00126 00127 EQ_API bool supportsEqFrameBufferObject() const; 00128 EQ_API FrameBufferObject* getEqFrameBufferObject(const T& key) const; 00129 EQ_API FrameBufferObject* newEqFrameBufferObject( const T& key ); 00130 EQ_API FrameBufferObject* obtainEqFrameBufferObject( const T& key ); 00131 EQ_API void deleteEqFrameBufferObject( const T& key ); 00132 00133 EQ_API util::BitmapFont< T >* getEqBitmapFont( const T& key ) const; 00134 EQ_API util::BitmapFont< T >* newEqBitmapFont( const T& key ); 00135 EQ_API util::BitmapFont< T >* obtainEqBitmapFont( const T& key ); 00136 EQ_API void deleteEqBitmapFont( const T& key ); 00137 00138 const GLEWContext* glewGetContext() const { return _data->glewContext; } 00139 00140 private: 00141 struct Object 00142 { 00143 GLuint id; 00144 GLuint num; 00145 }; 00146 00147 typedef stde::hash_map< T, Object > ObjectHash; 00148 typedef stde::hash_map< T, Texture* > TextureHash; 00149 typedef stde::hash_map< T, FrameBufferObject* > FBOHash; 00150 typedef stde::hash_map< T, util::BitmapFont< T >* > FontHash; 00151 typedef stde::hash_map< T, Accum* > AccumHash; 00152 typedef stde::hash_map< T, GPUCompressor* > UploaderHash; 00153 00154 struct SharedData : public co::base::Referenced 00155 { 00156 SharedData( const GLEWContext* glewContext ); 00157 virtual ~SharedData(); 00158 00159 GLEWContext* const glewContext; 00160 ObjectHash lists; 00161 ObjectHash textures; 00162 ObjectHash buffers; 00163 ObjectHash programs; 00164 ObjectHash shaders; 00165 ObjectHash uploaderDatas; 00166 AccumHash accums; 00167 TextureHash eqTextures; 00168 FBOHash eqFrameBufferObjects; 00169 FontHash eqFonts; 00170 UploaderHash eqUploaders; 00171 00172 union // placeholder for binary-compatible changes 00173 { 00174 char dummy[64]; 00175 }; 00176 }; 00177 00178 typedef co::base::RefPtr< SharedData > SharedDataPtr; 00179 SharedDataPtr _data; 00180 00181 struct Private; 00182 Private* _private; // placeholder for binary-compatible changes 00183 }; 00184 } 00185 } 00186 00187 #endif // EQUTIL_OBJECTMANAGER_H 00188