MeVisLabToolboxReference
MeVis/Foundation/Sources/MLOpenGL/mlGLResourceManager.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //----------------------------------------------------------------------------------
00004 
00009 //----------------------------------------------------------------------------------
00010 
00011 #ifndef __mlGLResourceManager_H
00012 #define __mlGLResourceManager_H
00013 
00014 #include "mlOpenGLSystem.h"
00015 #include "mlOpenGL.h"
00016 
00017 class FTFont;
00018 
00019 ML_OPENGL_START_NAMESPACE
00020 
00021 class GLResource;
00022 
00024 class MLOPENGL_EXPORT GLResourceManager {
00025 public:
00026   GLResourceManager();
00027   virtual ~GLResourceManager();
00028 
00029 public:
00031   static void init();
00032 
00034   static void cleanup();
00035 
00037   static GLResourceManager* self() { return _self;  }
00038 
00040   bool isContextActive() const { return !_contextLocked; }
00041 
00043   void destroyTextures(int num, GLuint* textures);
00045   void destroyFragmentProgramARB(GLuint program);
00047   void destroyRenderBuffer(GLuint id);
00049   void destroyFrameBuffer(GLuint id);
00051   void destroyVertexBuffer(GLuint id);
00053   void destroyPixelBuffer(GLuint id);
00055   void destroyDisplayList(GLuint id);
00057   void destroyGLSLShader(GLuint id);
00059   void destroyGLSLProgram(GLuint id);
00061   void destroyFTFont(FTFont* font);
00062 
00064   void detachGLSLShader(GLuint program, GLuint shader);
00065   
00067   void disableGLSLProgram();
00068 
00070   void unlockContext(unsigned int cacheContextId);
00071 
00073   void lockContext();
00074 
00076   unsigned int cacheContextID() { return _cacheContextID; };
00077   
00079   GLenum getGLError() const;
00080 
00081 protected:
00083   void addResource(GLResource* program);
00085   void removeResource(GLResource* program);
00086 
00088   void contextDestroyed();
00089 
00091   void freeResources();
00092 
00094   class MLOPENGL_EXPORT GLResourceList {
00095   public:
00096     GLResourceList() { _head = NULL; _tail = NULL; _length = 0; }
00097     
00098     GLResource* _head;
00099     GLResource* _tail;
00100     int _length;
00101   };
00102 
00103   void add(GLResourceList& list, GLResource* resource);
00104   void remove(GLResourceList& list, GLResource* resource);
00105 
00106   friend class GLResource;
00107 
00108   bool         _contextLocked;
00109   unsigned int _cacheContextID;
00110 
00111   GLResourceList _resources;
00112 
00113   typedef std::pair<GLuint, GLuint> GLSLProgramShaderPair;
00114 
00115   std::vector<GLuint> _texturesToFree;
00116   std::vector<GLuint> _programsARBToFree;
00117   std::vector<GLuint> _frameBuffersToFree;
00118   std::vector<GLuint> _renderBuffersToFree;
00119   std::vector<GLuint> _vertexBuffersToFree;
00120   std::vector<GLuint> _pixelBuffersToFree;
00121   std::vector<GLuint> _displayListsToFree;
00122   std::vector<GLuint> _GLSLProgramsToFree;
00123   std::vector<GLuint> _GLSLShadersToFree;
00124   std::vector<GLSLProgramShaderPair> _GLSLShadersToDetach;
00125   std::vector<FTFont*> _FTFontsToFree;
00126 
00127   static GLResourceManager* _self;
00128 };
00129 
00130 ML_OPENGL_END_NAMESPACE
00131 
00132 #endif