Equalizer 1.0

objectManager.h

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/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         EQ_API GPUCompressor* getEqUploader( const T& key ) const;
00111         EQ_API GPUCompressor* newEqUploader( const T& key );
00112         EQ_API GPUCompressor* obtainEqUploader( const T& key );
00113         EQ_API void   deleteEqUploader( const T& key );
00114 
00115         EQ_API bool     supportsEqTexture() const;
00116         EQ_API Texture* getEqTexture( const T& key ) const;
00117         EQ_API Texture* newEqTexture( const T& key, const GLenum target );
00118         EQ_API Texture* obtainEqTexture( const T& key, const GLenum target );
00119         EQ_API void     deleteEqTexture( const T& key );
00120 
00121         EQ_API bool               supportsEqFrameBufferObject() const;
00122         EQ_API FrameBufferObject* getEqFrameBufferObject(const T& key) const;
00123         EQ_API FrameBufferObject* newEqFrameBufferObject( const T& key );
00124         EQ_API FrameBufferObject* obtainEqFrameBufferObject( const T& key );
00125         EQ_API void               deleteEqFrameBufferObject( const T& key );
00126 
00127         EQ_API util::BitmapFont< T >* getEqBitmapFont( const T& key ) const;
00128         EQ_API util::BitmapFont< T >* newEqBitmapFont( const T& key );
00129         EQ_API util::BitmapFont< T >* obtainEqBitmapFont( const T& key );
00130         EQ_API void                   deleteEqBitmapFont( const T& key );
00131 
00132         const GLEWContext* glewGetContext() const { return _data->glewContext; }
00133 
00134     private:
00135         struct Object
00136         {
00137             GLuint   id;
00138             GLuint   num;
00139         };
00140 
00141         typedef stde::hash_map< T, Object >     ObjectHash;
00142         typedef stde::hash_map< T, Texture* >   TextureHash;
00143         typedef stde::hash_map< T, FrameBufferObject* > FBOHash;
00144         typedef stde::hash_map< T, util::BitmapFont< T >* > FontHash;
00145         typedef stde::hash_map< T, Accum* > AccumHash;
00146         typedef stde::hash_map< T, GPUCompressor* > UploaderHash;
00147 
00148         struct SharedData : public co::base::Referenced
00149         {
00150             SharedData( const GLEWContext* glewContext );
00151             virtual ~SharedData();
00152 
00153             GLEWContext* const glewContext;
00154             ObjectHash lists;
00155             ObjectHash textures;
00156             ObjectHash buffers;
00157             ObjectHash programs;
00158             ObjectHash shaders;
00159             ObjectHash uploaderDatas;
00160             AccumHash  accums;
00161             TextureHash eqTextures;
00162             FBOHash eqFrameBufferObjects;
00163             FontHash eqFonts;
00164             UploaderHash eqUploaders;
00165 
00166             union // placeholder for binary-compatible changes
00167             {
00168                 char dummy[64];
00169             };
00170         };
00171 
00172         typedef co::base::RefPtr< SharedData > SharedDataPtr;
00173         SharedDataPtr _data;
00174 
00175         struct Private;
00176         Private* _private; // placeholder for binary-compatible changes
00177     };
00178 }
00179 }
00180 
00181 #endif // EQUTIL_OBJECTMANAGER_H
00182 
Generated on Sun May 8 2011 19:11:07 for Equalizer 1.0 by  doxygen 1.7.3