objectManager.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef EQ_OBJECTMANAGER_H
00019 #define EQ_OBJECTMANAGER_H
00020
00021 #include <eq/client/windowSystem.h>
00022 #include <eq/base/base.h>
00023 #include <eq/base/debug.h>
00024 #include <eq/base/hash.h>
00025 #include <eq/base/nonCopyable.h>
00026 #include <eq/base/referenced.h>
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
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
00137 {
00138 char dummy[64];
00139 };
00140 };
00141
00142 typedef base::RefPtr< SharedData > SharedDataPtr;
00143 SharedDataPtr _data;
00144
00145 union
00146 {
00147 char dummy[16];
00148 };
00149
00150 };
00151 }
00152
00153 #endif // EQ_OBJECTMANAGER_H
00154