MeVisLab Resolution Independence API
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
22ML_OPENGL_START_NAMESPACE
23
24//-------------------------------------------------------------------------------------
25
28 public:
30 virtual ~GLResource();
31
33 virtual void contextDestroyed() = 0;
34
36 static GLenum getGLError();
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
82 GLuint getHandle(GLsizei i) const;
83
85 GLsizei getNumTextures() const { return static_cast<GLsizei>(_ids.size()); }
86
88 bool isValid() const { return !_ids.empty(); }
89
91 void create(GLsizei numberOfTextures);
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:
264 GLSLVertexShader() : GLSLShader(GL_VERTEX_SHADER) {}
265 ~GLSLVertexShader() override {}
266private:
268 GLSLVertexShader(const GLSLVertexShader &) : GLSLShader(GL_VERTEX_SHADER) {}
269 GLSLVertexShader &operator = (const GLSLVertexShader &) { return *this; }
270};
271
272//-------------------------------------------------------------------------------------
273
276public:
277 GLSLFragmentShader() : GLSLShader(GL_FRAGMENT_SHADER) {}
279private:
281 GLSLFragmentShader(const GLSLFragmentShader &) : GLSLShader(GL_FRAGMENT_SHADER) {}
282 GLSLFragmentShader &operator = (const GLSLFragmentShader &) { return *this; }
283};
284
285//-------------------------------------------------------------------------------------
286
289public:
290 GLSLGeometryShader() : GLSLShader(GL_GEOMETRY_SHADER_EXT) {}
292private:
294 GLSLGeometryShader(const GLSLGeometryShader &) : GLSLShader(GL_GEOMETRY_SHADER_EXT) {}
295 GLSLGeometryShader &operator = (const GLSLGeometryShader &) { return *this; }
296};
297
298//-------------------------------------------------------------------------------------
299
302public:
303 GLSLProgram() { _id = 0; }
304 ~GLSLProgram() override { destroy(); }
305
307 void disable();
308
311
313 void detachShader(GLuint shader);
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
340ML_OPENGL_END_NAMESPACE
341
342#endif
Manages a generic OpenGL buffer object.
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 contextDestroyed() override
forget the resource, the context was destroyed
void create()
create the pixel buffer (requires valid GL context)
void destroy()
destroy the resource
~GLBuffer() override
ARB_FRAGMENT_PROGRAM resource.
void destroy()
destroy the resource
void contextDestroyed() override
forget the resource, the context was destroyed
void create()
create the program (requires valid GL context)
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
FrameBufferObject resource (frame_buffer_object extension)
~GLFrameBuffer() override
void contextDestroyed() override
forget the resource, the context was destroyed
void destroy()
destroy the resource
void create()
create the program (requires valid GL context)
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)
PixelBuffer resource (pixel_buffer_object) http://www.opengl.org/registry/specs/ARB/pixel_buffer_obje...
RenderBuffer resource (frame_buffer_object extension)
bool isValid() const
check if the program is valid
void destroy()
destroy the resource
void contextDestroyed() override
forget the resource, the context was destroyed
void create()
create the program (requires valid GL context)
GLuint getHandle() const
get the program's handle (you need to create() the buffer before you get a handle)
~GLRenderBuffer() override
Manages OpenGL resources.
Abstract base class for GLResources.
static GLenum getGLError()
check for OpenGL error (returns GL_INVALID_OPERATION if there is no valid OpenGL context)
GLResource * _next
virtual void contextDestroyed()=0
forget the resource, the context was destroyed
virtual ~GLResource()
GLResource * _previous
GLSL FragmentShader resource.
GLSL GeometryShader resource.
GLSL Program resource.
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)
void create()
create the program (requires valid GL context)
void detachShader(GLSLShader &shader)
detach the given shader (this is safe to be called outside of a valid GL context)
~GLSLProgram() override
void destroy()
destroy the resource
void disable()
disable program
void contextDestroyed() override
forget the resource, the context was destroyed
void detachShader(GLuint shader)
detach the given shader (this is safe to be called outside of a valid GL context)
GLSL Shader resource.
void create()
create the program (requires valid GL context)
void destroy()
destroy the resource
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
bool isValid() const
check if the program is valid
GLSLShader(GLenum shaderType)
~GLSLShader() override
GLSL VertexShader resource.
~GLSLVertexShader() override
Texture class.
void destroy()
destroy the resource
GLuint getHandle() const
get the texture's handle (you need to create() the texture before you get a handle)
~GLTexture() override
void contextDestroyed() override
forget the resource, the context was destroyed
void create()
create the texture (requires valid GL context)
bool isValid() const
check if the texture is valid
Texture class that manages multiple texture ids.
void create(GLsizei numberOfTextures)
create the textures (requires valid GL context)
void contextDestroyed() override
forget the resource, the context was destroyed
void destroy()
destroy the resource
~GLTextures() override
GLuint getHandle(GLsizei i) 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
GLsizei getNumTextures() const
get the number of created textures
VertexBuffer resource (vertex_buffer_object extension) http://www.opengl.org/registry/specs/ARB/verte...
#define MLOPENGL_EXPORT
Macro to put all following stuff into the namespace ML_NAMESPACE to avoid collisions with symbols of ...