MeVisLab Toolbox Reference
mlGLResources.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_GLRESOURCES_H
14#define ML_GLRESOURCES_H
15
18
19#include "mlOpenGL.h"
20#include "mlOpenGLSystem.h"
21
23
24//-------------------------------------------------------------------------------------
25
28 public:
30 virtual ~GLResource();
31
33 virtual void contextDestroyed() = 0;
34
37
38 protected:
41
42 friend class GLResourceManager;
43};
44
45//-------------------------------------------------------------------------------------
46
49{
50public:
51 GLTexture() { _id = 0; };
52 ~GLTexture() override { destroy(); };
53
55 GLuint getHandle() const { return _id; }
56
58 bool isValid() const { return _id!=0; }
59
61 void create();
62
64 void destroy();
65
67 void contextDestroyed() override { _id = 0; }
68
69private:
70 GLuint _id;
71};
72
73//-------------------------------------------------------------------------------------
74
77public:
79 ~GLTextures() override { destroy(); };
80
83
85 GLsizei getNumTextures() const { return static_cast<GLsizei>(_ids.size()); }
86
88 bool isValid() const { return !_ids.empty(); }
89
92
94 void destroy();
95
97 void contextDestroyed() override { _ids.clear(); }
98
99private:
100 std::vector<GLuint> _ids;
101};
102
103//-------------------------------------------------------------------------------------
104
107public:
108 GLFragmentProgramARB() { _id = 0; };
109 ~GLFragmentProgramARB() override { destroy(); };
110
112 GLuint getHandle() const { return _id; }
113
115 bool isValid() const { return _id!=0; }
116
118 void create();
119
121 void destroy();
122
124 void contextDestroyed() override { _id = 0; }
125
126private:
127 GLuint _id;
128};
129
130
131//-------------------------------------------------------------------------------------
132
135public:
136 GLRenderBuffer() { _id = 0; };
137 ~GLRenderBuffer() override { destroy(); };
138
140 GLuint getHandle() const { return _id; }
141
143 bool isValid() const { return _id!=0; }
144
146 void create();
147
149 void destroy();
150
152 void contextDestroyed() override { _id = 0; }
153
154private:
155 GLuint _id;
156};
157
158
159//-------------------------------------------------------------------------------------
160
163public:
164 GLFrameBuffer() { _id = 0; };
165 ~GLFrameBuffer() override { destroy(); };
166
168 GLuint getHandle() const { return _id; }
169
171 bool isValid() const { return _id!=0; }
172
174 void create();
175
177 void destroy();
178
180 void contextDestroyed() override { _id = 0; }
181
182private:
183 GLuint _id;
184};
185
186//-------------------------------------------------------------------------------------
187
190
191public:
192 GLBuffer() { _id = 0; };
193 ~GLBuffer() override { destroy(); };
194
196 GLuint getHandle() const { return _id; }
197
199 bool isValid() const { return _id!=0; }
200
202 void create();
203
205 void destroy();
206
208 void contextDestroyed() override { _id = 0; }
209
210private:
211 GLuint _id;
212};
213
218
223
224//-------------------------------------------------------------------------------------
225
228public:
229 GLSLShader(GLenum shaderType) : _shaderType(shaderType), _id(0) {}
230 ~GLSLShader() override { destroy(); }
231
233 inline GLuint getHandle() const { return _id; }
234
236 inline bool isValid() const { return _id!=0; }
237
239 void create();
240
242 void destroy();
243
245 void contextDestroyed() override { _id = 0; }
246
247private:
249 GLSLShader() : _shaderType(GL_NONE), _id(0) {}
250
252 GLSLShader(const GLSLShader &) : GLResource() {}
253 GLSLShader &operator = (const GLSLShader &) { return *this; }
254
255 GLenum _shaderType;
256 GLuint _id;
257};
258
259//-------------------------------------------------------------------------------------
260
263public:
265 ~GLSLVertexShader() override {}
266private:
269 GLSLVertexShader &operator = (const GLSLVertexShader &) { return *this; }
270};
271
272//-------------------------------------------------------------------------------------
273
284
285//-------------------------------------------------------------------------------------
286
297
298//-------------------------------------------------------------------------------------
299
302public:
303 GLSLProgram() { _id = 0; }
304 ~GLSLProgram() override { destroy(); }
305
307 void disable();
308
311
314
316 inline GLuint getHandle() const { return _id; }
317
319 inline bool isValid() const { return _id!=0; }
320
322 void create();
323
325 void destroy();
326
328 void contextDestroyed() override { _id = 0; }
329
330private:
331 GLuint _id;
332
334 GLSLProgram(const GLSLProgram &) : GLResource() {}
335 GLSLProgram &operator = (const GLSLProgram &) { return *this; }
336};
337
338
339
341
342#endif
Manages a generic OpenGL buffer object.
~GLBuffer() override
void contextDestroyed() override
forget the resource, the context was destroyed
bool isValid() const
check if the program is valid
GLuint getHandle() const
get the buffers's handle (you need to create() the buffer before you get a handle)
void create()
create the pixel buffer (requires valid GL context)
void destroy()
destroy the resource
ARB_FRAGMENT_PROGRAM resource.
void destroy()
destroy the resource
void contextDestroyed() override
forget the resource, the context was destroyed
~GLFragmentProgramARB() override
GLuint getHandle() const
get the program's handle (you need to create() the texture before you get a handle)
bool isValid() const
check if the program is valid
void create()
create the program (requires valid GL context)
FrameBufferObject resource (frame_buffer_object extension)
~GLFrameBuffer() override
void destroy()
destroy the resource
GLuint getHandle() const
get the program's handle (you need to create() the buffer before you get a handle)
bool isValid() const
check if the program is valid
void create()
create the program (requires valid GL context)
void contextDestroyed() override
forget the resource, the context was destroyed
PixelBuffer resource (pixel_buffer_object) http://www.opengl.org/registry/specs/ARB/pixel_buffer_obje...
RenderBuffer resource (frame_buffer_object extension)
void create()
create the program (requires valid GL context)
void destroy()
destroy the resource
void contextDestroyed() override
forget the resource, the context was destroyed
bool isValid() const
check if the program is valid
GLuint getHandle() const
get the program's handle (you need to create() the buffer before you get a handle)
~GLRenderBuffer() override
Manages OpenGL resources.
Collection of OpenGL related resource classes, such as textures, buffers, fragment programs etc.
virtual ~GLResource()
virtual void contextDestroyed()=0
forget the resource, the context was destroyed
static GLenum getGLError()
check for OpenGL error (returns GL_INVALID_OPERATION if there is no valid OpenGL context)
GLResource * _next
GLResource * _previous
GLSL FragmentShader resource.
~GLSLFragmentShader() override
GLSL GeometryShader resource.
~GLSLGeometryShader() override
GLSL Program resource.
~GLSLProgram() override
bool isValid() const
check if the program is valid
void detachShader(GLSLShader &shader)
detach the given shader (this is safe to be called outside of a valid GL context)
void destroy()
destroy the resource
void detachShader(GLuint shader)
detach the given shader (this is safe to be called outside of a valid GL context)
void disable()
disable program
GLuint getHandle() const
get the program's handle (you need to create() the buffer before you get a handle)
void contextDestroyed() override
forget the resource, the context was destroyed
void create()
create the program (requires valid GL context)
GLSL Shader resource.
~GLSLShader() override
void contextDestroyed() override
forget the resource, the context was destroyed
GLSLShader(GLenum shaderType)
void create()
create the program (requires valid GL context)
bool isValid() const
check if the program is valid
void destroy()
destroy the resource
GLuint getHandle() const
get the program's handle (you need to create() the buffer before you get a handle)
GLSL VertexShader resource.
~GLSLVertexShader() override
Texture class.
~GLTexture() override
void contextDestroyed() override
forget the resource, the context was destroyed
void create()
create the texture (requires valid GL context)
GLuint getHandle() const
get the texture's handle (you need to create() the texture before you get a handle)
bool isValid() const
check if the texture is valid
void destroy()
destroy the resource
Texture class that manages multiple texture ids.
GLuint getHandle(GLsizei i) const
get the texture's handle (you need to create() the texture before you get a handle)
void destroy()
destroy the resource
~GLTextures() override
void contextDestroyed() override
forget the resource, the context was destroyed
void create(GLsizei numberOfTextures)
create the textures (requires valid GL context)
GLsizei getNumTextures() const
get the number of created textures
bool isValid() const
check if the texture is valid
VertexBuffer resource (vertex_buffer_object extension) http://www.opengl.org/registry/specs/ARB/verte...
#define ML_OPENGL_END_NAMESPACE
Closes the namespace for all ML stuff after the usage of ML_UTILS_START_NAMESPACE.
#define ML_OPENGL_START_NAMESPACE
Macro to put all following stuff into the namespace ML_NAMESPACE to avoid collisions with symbols of ...
#define MLOPENGL_EXPORT
Target mlrange_cast(Source arg)
Generic version of checked ML casts.