objectManager.h

00001 
00002 /* Copyright (c) 2007-2009, 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 EQ_OBJECTMANAGER_H
00019 #define EQ_OBJECTMANAGER_H
00020 
00021 #include <eq/client/windowSystem.h>   // OpenGL types
00022 #include <eq/base/base.h>             // EQ_EXPORT definition
00023 #include <eq/base/debug.h>            // EQASSERT definition
00024 #include <eq/base/hash.h>             // member
00025 #include <eq/base/nonCopyable.h>      // base class
00026 #include <eq/base/referenced.h>       // base class
00027 
00028 namespace eq
00029 {
00030     class FrameBufferObject;
00031     class Texture;
00032 
00046     template< typename T >
00047     class ObjectManager : public base::NonCopyable
00048     {
00049     public:
00050         enum
00051         {
00052             INVALID = 0 //<! return value for failed operations.
00053         };
00054 
00056         EQ_EXPORT ObjectManager( GLEWContext* const glewContext );
00057 
00059         EQ_EXPORT ObjectManager( GLEWContext* const glewContext, ObjectManager* shared );
00060 
00061         EQ_EXPORT virtual ~ObjectManager();
00062 
00064         int getSharedUsage() const { return _data->getRefCount(); }
00065 
00066         EQ_EXPORT void deleteAll();
00067 
00068         EQ_EXPORT GLuint getList( const T& key );
00069         EQ_EXPORT GLuint newList( const T& key, const GLsizei num = 1 );
00070         EQ_EXPORT GLuint obtainList( const T& key, const GLsizei num = 1 );
00071         EQ_EXPORT void   deleteList( const T& key );
00072 
00073         EQ_EXPORT GLuint getTexture( const T& key );
00074         EQ_EXPORT GLuint newTexture( const T& key );
00075         EQ_EXPORT GLuint obtainTexture( const T& key );
00076         EQ_EXPORT void   deleteTexture( const T& key );
00077 
00078         EQ_EXPORT bool   supportsBuffers() const;
00079         EQ_EXPORT GLuint getBuffer( const T& key );
00080         EQ_EXPORT GLuint newBuffer( const T& key );
00081         EQ_EXPORT GLuint obtainBuffer( const T& key );
00082         EQ_EXPORT void   deleteBuffer( const T& key );
00083 
00084         EQ_EXPORT bool   supportsPrograms() const;
00085         EQ_EXPORT GLuint getProgram( const T& key );
00086         EQ_EXPORT GLuint newProgram( const T& key );
00087         EQ_EXPORT GLuint obtainProgram( const T& key );
00088         EQ_EXPORT void   deleteProgram( const T& key );
00089 
00090         EQ_EXPORT bool   supportsShaders() const;
00091         EQ_EXPORT GLuint getShader( const T& key );
00092         EQ_EXPORT GLuint newShader( const T& key, const GLenum type );
00093         EQ_EXPORT GLuint obtainShader( const T& key, const GLenum type );
00094         EQ_EXPORT void   deleteShader( const T& key );
00095 
00096         EQ_EXPORT bool     supportsEqTexture() const;
00097         EQ_EXPORT Texture* getEqTexture( const T& key );
00098         EQ_EXPORT Texture* newEqTexture( const T& key );
00099         EQ_EXPORT Texture* obtainEqTexture( const T& key );
00100         EQ_EXPORT void     deleteEqTexture( const T& key );
00101 
00102         EQ_EXPORT bool               supportsEqFrameBufferObject() const;
00103         EQ_EXPORT FrameBufferObject* getEqFrameBufferObject( const T& key );
00104         EQ_EXPORT FrameBufferObject* newEqFrameBufferObject( const T& key );
00105         EQ_EXPORT FrameBufferObject* obtainEqFrameBufferObject( const T& key );
00106         EQ_EXPORT void               deleteEqFrameBufferObject( const T& key );
00107 
00108         const GLEWContext* glewGetContext() const { return _glewContext; }
00109         GLEWContext* glewGetContext()             { return _glewContext; }
00110 
00111     private:
00112         GLEWContext* const _glewContext;
00113 
00114         struct Object
00115         {
00116             GLuint   id;
00117             GLuint   num;
00118         };
00119 
00120         typedef stde::hash_map< T, Object >     ObjectHash;
00121         typedef stde::hash_map< T, Texture* >   TextureHash;
00122         typedef stde::hash_map< T, FrameBufferObject* > FrameBufferObjectHash;
00123 
00124         struct SharedData : public base::Referenced
00125         {
00126             virtual ~SharedData();
00127 
00128             ObjectHash lists;
00129             ObjectHash textures;
00130             ObjectHash buffers;
00131             ObjectHash programs;
00132             ObjectHash shaders;
00133             TextureHash eqTextures;
00134             FrameBufferObjectHash eqFrameBufferObjects;
00135 
00136             union // placeholder for binary-compatible changes
00137             {
00138                 char dummy[64];
00139             };
00140         };
00141 
00142         typedef base::RefPtr< SharedData > SharedDataPtr;
00143         SharedDataPtr _data;
00144 
00145         union // placeholder for binary-compatible changes
00146         {
00147             char dummy[16];
00148         };
00149 
00150     };
00151 }
00152 
00153 #endif // EQ_OBJECTMANAGER_H
00154 
Generated on Mon Aug 10 18:58:40 2009 for Equalizer 0.9 by  doxygen 1.5.8