MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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{
29public:
31 virtual ~GLResource();
32
33 GLResource(const GLResource&) = delete;
34 GLResource& operator=(const GLResource&) = delete;
35
36 // Moving is currently not supported by GLResourceManager
39
41 virtual void contextDestroyed() = 0;
42
44 static GLenum getGLError();
45
47 GLResource* _next;
48 GLResource* _previous;
49
51};
52
53//-------------------------------------------------------------------------------------
54
57{
58public:
60 {
61 _id = 0;
62 };
63 ~GLTexture() override
64 {
65 destroy();
66 };
67
70 {
71 return _id;
72 }
73
75 bool isValid() const
76 {
77 return _id != 0;
78 }
79
81 void create();
82
84 void destroy();
85
87 void contextDestroyed() override
88 {
89 _id = 0;
90 }
91
92private:
93 GLuint _id;
94};
95
96//-------------------------------------------------------------------------------------
97
100{
101public:
103 ~GLTextures() override
104 {
105 destroy();
106 };
107
110
113 {
114 return static_cast<GLsizei>(_ids.size());
115 }
116
118 bool isValid() const
119 {
120 return !_ids.empty();
121 }
122
125
127 void destroy();
128
130 void contextDestroyed() override
131 {
132 _ids.clear();
133 }
134
135private:
136 std::vector<GLuint> _ids;
137};
138
139//-------------------------------------------------------------------------------------
140
143{
144public:
146 {
147 _id = 0;
148 };
150 {
151 destroy();
152 };
153
156 {
157 return _id;
158 }
159
161 bool isValid() const
162 {
163 return _id != 0;
164 }
165
167 void create();
168
170 void destroy();
171
173 void contextDestroyed() override
174 {
175 _id = 0;
176 }
177
178private:
179 GLuint _id;
180};
181
182
183//-------------------------------------------------------------------------------------
184
187{
188public:
190 {
191 _id = 0;
192 };
194 {
195 destroy();
196 };
197
200 {
201 return _id;
202 }
203
205 bool isValid() const
206 {
207 return _id != 0;
208 }
209
211 void create();
212
214 void destroy();
215
217 void contextDestroyed() override
218 {
219 _id = 0;
220 }
221
222private:
223 GLuint _id;
224};
225
226
227//-------------------------------------------------------------------------------------
228
231{
232public:
234 {
235 _id = 0;
236 };
237 ~GLFrameBuffer() override
238 {
239 destroy();
240 };
241
244 {
245 return _id;
246 }
247
249 bool isValid() const
250 {
251 return _id != 0;
252 }
253
255 void create();
256
258 void destroy();
259
261 void contextDestroyed() override
262 {
263 _id = 0;
264 }
265
266private:
267 GLuint _id;
268};
269
270//-------------------------------------------------------------------------------------
271
274{
275
276public:
278 {
279 _id = 0;
280 };
281 ~GLBuffer() override
282 {
283 destroy();
284 };
285
288 {
289 return _id;
290 }
291
293 bool isValid() const
294 {
295 return _id != 0;
296 }
297
299 void create();
300
302 void destroy();
303
305 void contextDestroyed() override
306 {
307 _id = 0;
308 }
309
310private:
311 GLuint _id;
312};
313
317{
318};
319
323{
324};
325
326//-------------------------------------------------------------------------------------
327
330{
331public:
332 GLSLShader(GLenum shaderType)
333 : _shaderType(shaderType)
334 , _id(0)
335 {}
336 ~GLSLShader() override
337 {
338 destroy();
339 }
340
342 inline GLuint getHandle() const
343 {
344 return _id;
345 }
346
348 inline bool isValid() const
349 {
350 return _id != 0;
351 }
352
354 void create();
355
357 void destroy();
358
360 void contextDestroyed() override
361 {
362 _id = 0;
363 }
364
365private:
367 GLSLShader()
368 : _shaderType(GL_NONE)
369 , _id(0)
370 {}
371
373 GLSLShader(const GLSLShader&)
374 : GLResource()
375 {}
376 GLSLShader& operator=(const GLSLShader&)
377 {
378 return *this;
379 }
380
381 GLenum _shaderType;
382 GLuint _id;
383};
384
385//-------------------------------------------------------------------------------------
386
389{
390public:
395 {}
396
397private:
401 {}
402 GLSLVertexShader& operator=(const GLSLVertexShader&)
403 {
404 return *this;
405 }
406};
407
408//-------------------------------------------------------------------------------------
409
412{
413public:
418 {}
419
420private:
424 {}
425 GLSLFragmentShader& operator=(const GLSLFragmentShader&)
426 {
427 return *this;
428 }
429};
430
431//-------------------------------------------------------------------------------------
432
435{
436public:
441 {}
442
443private:
447 {}
448 GLSLGeometryShader& operator=(const GLSLGeometryShader&)
449 {
450 return *this;
451 }
452};
453
454//-------------------------------------------------------------------------------------
455
458{
459public:
461 {
462 _id = 0;
463 }
464 ~GLSLProgram() override
465 {
466 destroy();
467 }
468
470 void disable();
471
474
477
479 inline GLuint getHandle() const
480 {
481 return _id;
482 }
483
485 inline bool isValid() const
486 {
487 return _id != 0;
488 }
489
491 void create();
492
494 void destroy();
495
497 void contextDestroyed() override
498 {
499 _id = 0;
500 }
501
502private:
503 GLuint _id;
504
507 : GLResource()
508 {}
509 GLSLProgram& operator=(const GLSLProgram&)
510 {
511 return *this;
512 }
513};
514
515
517
518#endif
Manages a generic OpenGL buffer object.
~GLBuffer() override
void contextDestroyed() override
Forgets the resource; the context was destroyed.
bool isValid() const
Checks whether the program is valid.
GLuint getHandle() const
Returns the buffers's handle (you need to create() the buffer before you get a handle).
void create()
Creates the pixel buffer (requires valid GL context).
void destroy()
Destroys the resource.
ARB_FRAGMENT_PROGRAM resource.
void destroy()
Destroys the resource.
void contextDestroyed() override
Forgets the resource; the context was destroyed.
~GLFragmentProgramARB() override
GLuint getHandle() const
Returns the program's handle (you need to create() the texture before you get a handle).
bool isValid() const
Checks whether the program is valid.
void create()
Creates the program (requires valid GL context).
FrameBufferObject resource (frame_buffer_object extension)
~GLFrameBuffer() override
void destroy()
Destroys the resource.
GLuint getHandle() const
Returns the program's handle (you need to create() the buffer before you get a handle).
bool isValid() const
Checks whether the program is valid.
void create()
Creates the program (requires valid GL context).
void contextDestroyed() override
Forgets the resource; the context was destroyed.
PixelBuffer resource (pixel_buffer_object).
RenderBuffer resource (frame_buffer_object extension)
void create()
Creates the program (requires valid GL context).
void destroy()
Destroys the resource.
void contextDestroyed() override
Forgets the resource; the context was destroyed.
bool isValid() const
Check whether the program is valid.
GLuint getHandle() const
Returns 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.
GLResource(GLResource &&) noexcept=delete
virtual ~GLResource()
GLResource & operator=(const GLResource &)=delete
GLResource(const GLResource &)=delete
GLSL FragmentShader resource.
~GLSLFragmentShader() override
GLSL GeometryShader resource.
~GLSLGeometryShader() override
GLSL Program resource.
~GLSLProgram() override
bool isValid() const
Checks whether the program is valid.
void detachShader(GLSLShader &shader)
Detaches the given shader (this is safe to be called outside of a valid GL context).
void destroy()
Destroys the resource.
void detachShader(GLuint shader)
Detaches the given shader (this is safe to be called outside of a valid GL context).
void disable()
Disables program.
GLuint getHandle() const
Returns the program's handle (you need to create() the buffer before you get a handle).
void contextDestroyed() override
Forgets the resource; the context was destroyed.
void create()
Creates the program (requires valid GL context).
GLSL Shader resource.
~GLSLShader() override
void contextDestroyed() override
Forgets the resource; the context was destroyed.
GLSLShader(GLenum shaderType)
void create()
Creates the program (requires valid GL context).
bool isValid() const
Checks whether the program is valid.
void destroy()
Destroys the resource.
GLuint getHandle() const
Returns 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
Forgets the resource; the context was destroyed.
void create()
Creates the texture (requires valid GL context).
GLuint getHandle() const
Returns the texture's handle (you need to create() the texture before you get a handle).
bool isValid() const
Checks whether the texture is valid.
void destroy()
Destroys the resource.
Texture class that manages multiple texture IDs.
GLuint getHandle(GLsizei i) const
Returns the texture's handle (you need to create() the texture before you get a handle).
void destroy()
Destroys the resource.
~GLTextures() override
void contextDestroyed() override
Forgets the resource; the context was destroyed.
void create(GLsizei numberOfTextures)
Creates the textures (requires valid GL context).
GLsizei getNumTextures() const
Returns the number of created textures.
bool isValid() const
Checks whether the texture is valid.
VertexBuffer resource (vertex_buffer_object extension).
#define ML_OPENGL_END_NAMESPACE
Closes the namespace for all ML code after the usage of ML_UTILS_START_NAMESPACE.
#define ML_OPENGL_START_NAMESPACE
Macro to put all following code into the namespace ML_NAMESPACE to avoid collisions with symbols of o...
#define MLOPENGL_EXPORT
Target mlrange_cast(Source arg)
Generic version of checked ML casts.