MeVisLab Resolution Independence API
Loading...
Searching...
No Matches
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
29{
30public:
33
34public:
36 static void init();
37
39 static void cleanup();
40
43 {
44 return _self;
45 }
46
48 bool isContextActive() const
49 {
50 return !_contextLocked;
51 }
52
54 void destroyTextures(int num, GLuint* textures);
56 void destroyFragmentProgramARB(GLuint program);
58 void destroyRenderBuffer(GLuint id);
60 void destroyFrameBuffer(GLuint id);
62 void destroyBuffer(GLuint id);
64 void destroyPixelBuffer(GLuint id)
65 {
66 destroyBuffer(id);
67 }
68
69 void destroyVertexBuffer(GLuint id)
70 {
71 destroyBuffer(id);
72 }
73
74 void destroyGLSLShader(GLuint id);
76 void destroyGLSLProgram(GLuint id);
78 void destroyFTFont(FTFont* font);
79
81 void detachGLSLShader(GLuint program, GLuint shader);
82
85
87 void unlockContext(unsigned int cacheContextId);
88
91
93 unsigned int cacheContextID()
94 {
95 return _cacheContextID;
96 };
97
99 GLenum getGLError() const;
100
101protected:
103 void addResource(GLResource* program);
106
109
112
115 {
116 public:
118 {
119 _head = nullptr;
120 _tail = nullptr;
121 _length = 0;
122 }
123
127 };
128
129 void add(GLResourceList& list, GLResource* resource);
130 void remove(GLResourceList& list, GLResource* resource);
131
132 friend class GLResource;
133
135 unsigned int _cacheContextID;
136
138
139 typedef std::pair<GLuint, GLuint> GLSLProgramShaderPair;
140
141 std::vector<GLuint> _texturesToFree;
142 std::vector<GLuint> _programsARBToFree;
143 std::vector<GLuint> _frameBuffersToFree;
144 std::vector<GLuint> _renderBuffersToFree;
145 std::vector<GLuint> _buffersToFree;
146 std::vector<GLuint> _GLSLProgramsToFree;
147 std::vector<GLuint> _GLSLShadersToFree;
148 std::vector<GLSLProgramShaderPair> _GLSLShadersToDetach;
149 std::vector<FTFont*> _FTFontsToFree;
150
152};
153
154ML_OPENGL_END_NAMESPACE
155
156#endif
Dynamic list of GLResource objects.
std::vector< GLuint > _GLSLProgramsToFree
void detachGLSLShader(GLuint program, GLuint shader)
Detaches the given shader from the program (this is done later of the GL context is not currently act...
static void init()
Creates singleton.
GLenum getGLError() const
Checks for OpenGL error (returns GL_INVALID_OPERATION if there is no valid OpenGL context).
std::vector< FTFont * > _FTFontsToFree
void destroyGLSLProgram(GLuint id)
Destroys the given program (destroys it later if no GL context is currently active).
std::vector< GLuint > _GLSLShadersToFree
std::vector< GLuint > _texturesToFree
bool isContextActive() const
Checks whether the current context is active.
std::vector< GLSLProgramShaderPair > _GLSLShadersToDetach
std::vector< GLuint > _programsARBToFree
void add(GLResourceList &list, GLResource *resource)
void unlockContext(unsigned int cacheContextId)
Sets that the context is active.
void destroyBuffer(GLuint id)
Destroys the given vertex buffer (destroys it later if no GL context is currently active).
void destroyGLSLShader(GLuint id)
Destroys the given shader (destroys it later if no GL context is currently active).
void addResource(GLResource *program)
Adds the given resource.
void lockContext()
Sets that the context is locked.
void removeResource(GLResource *program)
Removes the given resource.
std::vector< GLuint > _frameBuffersToFree
void destroyRenderBuffer(GLuint id)
Destroys the given render buffer (destroys it later if no GL context is currently active).
void disableGLSLProgram()
Removes currently active program.
void destroyPixelBuffer(GLuint id)
Destroys the given pixel buffer (destroys it later if no GL context is currently active).
virtual ~GLResourceManager()
static void cleanup()
Destroys singleton.
void destroyVertexBuffer(GLuint id)
Destroys the given pixel buffer (destroys it later if no GL context is currently active).
void contextDestroyed()
Forgets about all resources; the shared context was destroyed.
static GLResourceManager * self()
Returns singleton instance.
void freeResources()
Frees resources that could not be destroyed earlier.
void destroyFTFont(FTFont *font)
Destroys the given font (destroys it later if no GL context is currently active).
void destroyFragmentProgramARB(GLuint program)
Destroys the given fragment program ID (destroys it later if no GL context is currently active).
unsigned int cacheContextID()
Returns the current cache context ID.
void remove(GLResourceList &list, GLResource *resource)
std::vector< GLuint > _renderBuffersToFree
void destroyFrameBuffer(GLuint id)
Destroys the given render buffer (destroys it later if no GL context is currently active).
void destroyTextures(int num, GLuint *textures)
Destroys 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
#define MLOPENGL_EXPORT
Closes the namespace for all ML code after the usage of ML_UTILS_START_NAMESPACE.