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 
36  static GLenum getGLError();
37 
38  protected:
41 
42  friend class GLResourceManager;
43 };
44 
45 //-------------------------------------------------------------------------------------
46 
49 {
50 public:
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 
69 private:
70  GLuint _id;
71 };
72 
73 //-------------------------------------------------------------------------------------
74 
77 public:
78  GLTextures() {};
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 
99 private:
100  std::vector<GLuint> _ids;
101 };
102 
103 //-------------------------------------------------------------------------------------
104 
107 public:
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 
126 private:
127  GLuint _id;
128 };
129 
130 
131 //-------------------------------------------------------------------------------------
132 
135 public:
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 
154 private:
155  GLuint _id;
156 };
157 
158 
159 //-------------------------------------------------------------------------------------
160 
163 public:
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 
182 private:
183  GLuint _id;
184 };
185 
186 //-------------------------------------------------------------------------------------
187 
190 
191 public:
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 
210 private:
211  GLuint _id;
212 };
213 
217 };
218 
222 };
223 
224 //-------------------------------------------------------------------------------------
225 
228 public:
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 
247 private:
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 
263 public:
264  GLSLVertexShader() : GLSLShader(GL_VERTEX_SHADER) {}
265  ~GLSLVertexShader() override {}
266 private:
268  GLSLVertexShader(const GLSLVertexShader &) : GLSLShader(GL_VERTEX_SHADER) {}
269  GLSLVertexShader &operator = (const GLSLVertexShader &) { return *this; }
270 };
271 
272 //-------------------------------------------------------------------------------------
273 
276 public:
277  GLSLFragmentShader() : GLSLShader(GL_FRAGMENT_SHADER) {}
278  ~GLSLFragmentShader() override {}
279 private:
281  GLSLFragmentShader(const GLSLFragmentShader &) : GLSLShader(GL_FRAGMENT_SHADER) {}
282  GLSLFragmentShader &operator = (const GLSLFragmentShader &) { return *this; }
283 };
284 
285 //-------------------------------------------------------------------------------------
286 
289 public:
290  GLSLGeometryShader() : GLSLShader(GL_GEOMETRY_SHADER_EXT) {}
291  ~GLSLGeometryShader() override {}
292 private:
294  GLSLGeometryShader(const GLSLGeometryShader &) : GLSLShader(GL_GEOMETRY_SHADER_EXT) {}
295  GLSLGeometryShader &operator = (const GLSLGeometryShader &) { return *this; }
296 };
297 
298 //-------------------------------------------------------------------------------------
299 
302 public:
303  GLSLProgram() { _id = 0; }
304  ~GLSLProgram() override { destroy(); }
305 
307  void disable();
308 
310  void detachShader(GLSLShader& shader);
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 
330 private:
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.
Definition: mlGLResources.h:27
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
Definition: mlGLResources.h:39
GLResource * _previous
Definition: mlGLResources.h:40
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.
Definition: mlGLResources.h:49
~GLTexture() override
Definition: mlGLResources.h:52
void contextDestroyed() override
forget the resource, the context was destroyed
Definition: mlGLResources.h:67
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)
Definition: mlGLResources.h:55
bool isValid() const
check if the texture is valid
Definition: mlGLResources.h:58
void destroy()
destroy the resource
Texture class that manages multiple texture ids.
Definition: mlGLResources.h:76
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
Definition: mlGLResources.h:79
void contextDestroyed() override
forget the resource, the context was destroyed
Definition: mlGLResources.h:97
void create(GLsizei numberOfTextures)
create the textures (requires valid GL context)
GLsizei getNumTextures() const
get the number of created textures
Definition: mlGLResources.h:85
bool isValid() const
check if the texture is valid
Definition: mlGLResources.h:88
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
void destroy()
Delete dynamic data structures allocated by init().