MeVisLab Resolution Independence API
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
22ML_OPENGL_START_NAMESPACE
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
37 GLResource(GLResource&&) noexcept = delete;
38 GLResource& operator=(GLResource&&) noexcept = delete;
39
41 virtual void contextDestroyed() = 0;
42
44 static GLenum getGLError();
45
46protected:
49
50 friend class GLResourceManager;
51};
52
53//-------------------------------------------------------------------------------------
54
57{
58public:
60 {
61 _id = 0;
62 };
63 ~GLTexture() override
64 {
65 destroy();
66 };
67
69 GLuint getHandle() const
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
109 GLuint getHandle(GLsizei i) const;
110
112 GLsizei getNumTextures() const
113 {
114 return static_cast<GLsizei>(_ids.size());
115 }
116
118 bool isValid() const
119 {
120 return !_ids.empty();
121 }
122
124 void create(GLsizei numberOfTextures);
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
155 GLuint getHandle() const
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
199 GLuint getHandle() const
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
243 GLuint getHandle() const
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
287 GLuint getHandle() const
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:
392 : GLSLShader(GL_VERTEX_SHADER)
393 {}
395 {}
396
397private:
400 : GLSLShader(GL_VERTEX_SHADER)
401 {}
402 GLSLVertexShader& operator=(const GLSLVertexShader&)
403 {
404 return *this;
405 }
406};
407
408//-------------------------------------------------------------------------------------
409
412{
413public:
415 : GLSLShader(GL_FRAGMENT_SHADER)
416 {}
418 {}
419
420private:
423 : GLSLShader(GL_FRAGMENT_SHADER)
424 {}
425 GLSLFragmentShader& operator=(const GLSLFragmentShader&)
426 {
427 return *this;
428 }
429};
430
431//-------------------------------------------------------------------------------------
432
435{
436public:
438 : GLSLShader(GL_GEOMETRY_SHADER_EXT)
439 {}
441 {}
442
443private:
446 : GLSLShader(GL_GEOMETRY_SHADER_EXT)
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
476 void detachShader(GLuint shader);
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
516ML_OPENGL_END_NAMESPACE
517
518#endif
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 contextDestroyed() override
Forgets the resource; the context was destroyed.
void create()
Creates the pixel buffer (requires valid GL context).
void destroy()
Destroys the resource.
~GLBuffer() override
void destroy()
Destroys the resource.
void contextDestroyed() override
Forgets the resource; the context was destroyed.
void create()
Creates the program (requires valid GL context).
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.
~GLFrameBuffer() override
void contextDestroyed() override
Forgets the resource; the context was destroyed.
void destroy()
Destroys the resource.
void create()
Creates the program (requires valid GL context).
bool isValid() const
Checks whether the program is valid.
GLuint getHandle() const
Returns the program's handle (you need to create() the buffer before you get a handle).
bool isValid() const
Check whether the program is valid.
void destroy()
Destroys the resource.
void contextDestroyed() override
Forgets the resource; the context was destroyed.
void create()
Creates the program (requires valid GL context).
GLuint getHandle() const
Returns the program's handle (you need to create() the buffer before you get a handle).
~GLRenderBuffer() override
Abstract base class for GLResources.
GLResource(const GLResource &)=delete
static GLenum getGLError()
Checks for OpenGL error (returns GL_INVALID_OPERATION if there is no valid OpenGL context).
GLResource * _next
virtual void contextDestroyed()=0
Forgets the resource; the context was destroyed.
GLResource & operator=(const GLResource &)=delete
GLResource(GLResource &&) noexcept=delete
friend class GLResourceManager
virtual ~GLResource()
GLResource * _previous
GLSL FragmentShader resource.
GLSL GeometryShader resource.
GLSL Program resource.
bool isValid() const
Checks whether the program is valid.
GLuint getHandle() const
Returns the program's handle (you need to create() the buffer before you get a handle).
void create()
Creates the program (requires valid GL context).
void detachShader(GLSLShader &shader)
Detaches the given shader (this is safe to be called outside of a valid GL context).
~GLSLProgram() override
void destroy()
Destroys the resource.
void disable()
Disables program.
void contextDestroyed() override
Forgets the resource; the context was destroyed.
void detachShader(GLuint shader)
Detaches the given shader (this is safe to be called outside of a valid GL context).
GLSL Shader resource.
void create()
Creates the program (requires valid GL context).
void destroy()
Destroys the resource.
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.
bool isValid() const
Checks whether the program is valid.
GLSLShader(GLenum shaderType)
~GLSLShader() override
GLSL VertexShader resource.
~GLSLVertexShader() override
void destroy()
Destroys the resource.
GLuint getHandle() const
Returns the texture's handle (you need to create() the texture before you get a handle).
~GLTexture() override
void contextDestroyed() override
Forgets the resource; the context was destroyed.
void create()
Creates the texture (requires valid GL context).
bool isValid() const
Checks whether the texture is valid.
void create(GLsizei numberOfTextures)
Creates the textures (requires valid GL context).
void contextDestroyed() override
Forgets the resource; the context was destroyed.
void destroy()
Destroys the resource.
~GLTextures() override
GLuint getHandle(GLsizei i) 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.
GLsizei getNumTextures() const
Returns the number of created textures.
#define MLOPENGL_EXPORT
Closes the namespace for all ML code after the usage of ML_UTILS_START_NAMESPACE.