MeVisLab Resolution Independence API
mlGLResourceManager.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_GLRESOURCE_MANAGER_H
14#define ML_GLRESOURCE_MANAGER_H
15
17
18#include "mlOpenGLSystem.h"
19#include "mlOpenGL.h"
20
21class FTFont;
22
23ML_OPENGL_START_NAMESPACE
24
25class GLResource;
26
29public:
32
33public:
35 static void init();
36
38 static void cleanup();
39
41 static GLResourceManager* self() { return _self; }
42
44 bool isContextActive() const { return !_contextLocked; }
45
47 void destroyTextures(int num, GLuint* textures);
49 void destroyFragmentProgramARB(GLuint program);
51 void destroyRenderBuffer(GLuint id);
53 void destroyFrameBuffer(GLuint id);
55 void destroyBuffer(GLuint id);
57 void destroyPixelBuffer(GLuint id) { destroyBuffer(id); }
59 void destroyVertexBuffer(GLuint id) { destroyBuffer(id); }
61 void destroyGLSLShader(GLuint id);
63 void destroyGLSLProgram(GLuint id);
65 void destroyFTFont(FTFont* font);
66
68 void detachGLSLShader(GLuint program, GLuint shader);
69
72
74 void unlockContext(unsigned int cacheContextId);
75
78
80 unsigned int cacheContextID() { return _cacheContextID; };
81
83 GLenum getGLError() const;
84
85protected:
87 void addResource(GLResource* program);
89 void removeResource(GLResource* program);
90
93
96
99 public:
100 GLResourceList() { _head = nullptr; _tail = nullptr; _length = 0; }
101
105 };
106
107 void add(GLResourceList& list, GLResource* resource);
108 void remove(GLResourceList& list, GLResource* resource);
109
110 friend class GLResource;
111
113 unsigned int _cacheContextID;
114
116
117 typedef std::pair<GLuint, GLuint> GLSLProgramShaderPair;
118
119 std::vector<GLuint> _texturesToFree;
120 std::vector<GLuint> _programsARBToFree;
121 std::vector<GLuint> _frameBuffersToFree;
122 std::vector<GLuint> _renderBuffersToFree;
123 std::vector<GLuint> _buffersToFree;
124 std::vector<GLuint> _GLSLProgramsToFree;
125 std::vector<GLuint> _GLSLShadersToFree;
126 std::vector<GLSLProgramShaderPair> _GLSLShadersToDetach;
127 std::vector<FTFont*> _FTFontsToFree;
128
130};
131
132ML_OPENGL_END_NAMESPACE
133
134#endif
Dynamic list of GLResource objects.
Manages OpenGL resources.
std::vector< GLuint > _GLSLProgramsToFree
void detachGLSLShader(GLuint program, GLuint shader)
detach the given shader from the program (this is done later of the GL context is not currently activ...
static void init()
create singleton
GLenum getGLError() const
check for OpenGL error (returns GL_INVALID_OPERATION if there is no valid OpenGL context)
std::vector< FTFont * > _FTFontsToFree
void destroyGLSLProgram(GLuint id)
destroy the given program (destroys it later if no GL context is currently active)
std::vector< GLuint > _GLSLShadersToFree
std::vector< GLuint > _texturesToFree
bool isContextActive() const
check if the current context is ac
std::vector< GLSLProgramShaderPair > _GLSLShadersToDetach
std::vector< GLuint > _programsARBToFree
void add(GLResourceList &list, GLResource *resource)
void unlockContext(unsigned int cacheContextId)
set that the context is active
void destroyBuffer(GLuint id)
destroy the given vertex buffer (destroys it later if no GL context is currently active)
void destroyGLSLShader(GLuint id)
destroy the given shader (destroys it later if no GL context is currently active)
void addResource(GLResource *program)
add the given resource
void lockContext()
set that the context is locked
void removeResource(GLResource *program)
remove the given resource
std::vector< GLuint > _frameBuffersToFree
void destroyRenderBuffer(GLuint id)
destroy the given render buffer (destroys it later if no GL context is currently active)
void disableGLSLProgram()
remove currently active program
void destroyPixelBuffer(GLuint id)
destroy the given pixel buffer (destroys it later if no GL context is currently active)
virtual ~GLResourceManager()
static void cleanup()
destroy singleton
void destroyVertexBuffer(GLuint id)
destroy the given pixel buffer (destroys it later if no GL context is currently active)
void contextDestroyed()
forget about all resources, the shared context was destroyed
static GLResourceManager * self()
get singleton instance
void freeResources()
free resources that could not be destroyed earlier
void destroyFTFont(FTFont *font)
destroy the given font (destroys it later if no GL context is currently active)
void destroyFragmentProgramARB(GLuint program)
destroy the given fragment program id (destroys it later if no GL context is currently active)
unsigned int cacheContextID()
get the current cache context id
void remove(GLResourceList &list, GLResource *resource)
std::vector< GLuint > _renderBuffersToFree
void destroyFrameBuffer(GLuint id)
destroy the given render buffer (destroys it later if no GL context is currently active)
void destroyTextures(int num, GLuint *textures)
destroy the given texture ids (destroys them later if no GL context is currently active)
std::vector< GLuint > _buffersToFree
static GLResourceManager * _self
std::pair< GLuint, GLuint > GLSLProgramShaderPair
Abstract base class for GLResources.
#define MLOPENGL_EXPORT
Macro to put all following stuff into the namespace ML_NAMESPACE to avoid collisions with symbols of ...