MeVisLabToolboxReference
|
00001 // **InsertLicense** code 00002 //---------------------------------------------------------------------------------- 00005 00010 //---------------------------------------------------------------------------------- 00011 00012 #ifndef __mlGLResources_H 00013 #define __mlGLResources_H 00014 00015 #include "mlOpenGL.h" 00016 #include "mlOpenGLSystem.h" 00017 00018 ML_OPENGL_START_NAMESPACE 00019 00020 //------------------------------------------------------------------------------------- 00021 00023 class MLOPENGL_EXPORT GLResource { 00024 public: 00025 GLResource(); 00026 virtual ~GLResource(); 00027 00029 virtual void contextDestroyed() = 0; 00030 00032 static GLenum getGLError(); 00033 00034 protected: 00035 GLResource* _next; 00036 GLResource* _previous; 00037 00038 friend class GLResourceManager; 00039 }; 00040 00041 //------------------------------------------------------------------------------------- 00042 00044 class MLOPENGL_EXPORT GLTexture : public GLResource 00045 { 00046 public: 00047 GLTexture() { _id = 0; }; 00048 ~GLTexture() { destroy(); }; 00049 00051 GLuint getHandle() const { return _id; } 00052 00054 bool isValid() const { return _id!=0; } 00055 00057 void create(); 00058 00060 void destroy(); 00061 00063 virtual void contextDestroyed() { _id = 0; } 00064 00065 private: 00066 GLuint _id; 00067 }; 00068 00069 //------------------------------------------------------------------------------------- 00070 00072 class MLOPENGL_EXPORT GLTextures : public GLResource { 00073 public: 00074 GLTextures() {}; 00075 ~GLTextures() { destroy(); }; 00076 00078 GLuint getHandle(int i) const { return _ids[i]; } 00079 00081 int getNumTextures() const { return static_cast<int>(_ids.size()); } 00082 00084 bool isValid() const { return !_ids.empty(); } 00085 00087 void create(unsigned int i); 00088 00090 void destroy(); 00091 00093 virtual void contextDestroyed() { _ids.clear(); } 00094 00095 private: 00096 std::vector<GLuint> _ids; 00097 }; 00098 00099 //------------------------------------------------------------------------------------- 00100 00102 class MLOPENGL_EXPORT GLFragmentProgramARB : public GLResource { 00103 public: 00104 GLFragmentProgramARB() { _id = 0; }; 00105 ~GLFragmentProgramARB() { destroy(); }; 00106 00108 GLuint getHandle() const { return _id; } 00109 00111 bool isValid() const { return _id!=0; } 00112 00114 void create(); 00115 00117 void destroy(); 00118 00120 virtual void contextDestroyed() { _id = 0; } 00121 00122 private: 00123 GLuint _id; 00124 }; 00125 00126 00127 //------------------------------------------------------------------------------------- 00128 00130 class MLOPENGL_EXPORT GLRenderBuffer : public GLResource { 00131 public: 00132 GLRenderBuffer() { _id = 0; }; 00133 ~GLRenderBuffer() { destroy(); }; 00134 00136 GLuint getHandle() const { return _id; } 00137 00139 bool isValid() const { return _id!=0; } 00140 00142 void create(); 00143 00145 void destroy(); 00146 00148 virtual void contextDestroyed() { _id = 0; } 00149 00150 private: 00151 GLuint _id; 00152 }; 00153 00154 00155 //------------------------------------------------------------------------------------- 00156 00158 class MLOPENGL_EXPORT GLFrameBuffer : public GLResource { 00159 public: 00160 GLFrameBuffer() { _id = 0; }; 00161 ~GLFrameBuffer() { destroy(); }; 00162 00164 GLuint getHandle() const { return _id; } 00165 00167 bool isValid() const { return _id!=0; } 00168 00170 void create(); 00171 00173 void destroy(); 00174 00176 virtual void contextDestroyed() { _id = 0; } 00177 00178 private: 00179 GLuint _id; 00180 }; 00181 00182 //------------------------------------------------------------------------------------- 00183 00186 class MLOPENGL_EXPORT GLVertexBuffer : public GLResource { 00187 public: 00188 GLVertexBuffer() { _id = 0; }; 00189 ~GLVertexBuffer() { destroy(); }; 00190 00192 GLuint getHandle() const { return _id; } 00193 00195 bool isValid() const { return _id!=0; } 00196 00198 void create(); 00199 00201 void destroy(); 00202 00204 virtual void contextDestroyed() { _id = 0; } 00205 00206 private: 00207 GLuint _id; 00208 }; 00209 //------------------------------------------------------------------------------------- 00210 00215 class MLOPENGL_EXPORT GLPixelBuffer : public GLResource { 00216 public: 00217 GLPixelBuffer() { _id = 0; }; 00218 ~GLPixelBuffer() { destroy(); }; 00219 00221 GLuint getHandle() const { return _id; } 00222 00224 bool isValid() const { return _id!=0; } 00225 00227 void create(); 00228 00230 void destroy(); 00231 00233 virtual void contextDestroyed() { _id = 0; } 00234 00235 private: 00236 GLuint _id; 00237 }; 00238 00239 //------------------------------------------------------------------------------------- 00240 00242 class MLOPENGL_EXPORT GLDisplayList : public GLResource { 00243 public: 00244 GLDisplayList() { _id = 0; }; 00245 ~GLDisplayList() { destroy(); }; 00246 00248 GLuint getHandle() const { return _id; } 00249 00251 bool isValid() const { return _id!=0; } 00252 00254 void create(); 00255 00257 void destroy(); 00258 00260 virtual void contextDestroyed() { _id = 0; } 00261 00262 private: 00263 GLuint _id; 00264 }; 00265 00266 //------------------------------------------------------------------------------------- 00267 00269 class MLOPENGL_EXPORT GLSLShader : public GLResource { 00270 public: 00271 GLSLShader(GLenum shaderType) : _shaderType(shaderType), _id(0) {} 00272 virtual ~GLSLShader() { destroy(); } 00273 00275 inline GLuint getHandle() const { return _id; } 00276 00278 inline bool isValid() const { return _id!=0; } 00279 00281 void create(); 00282 00284 void destroy(); 00285 00287 virtual void contextDestroyed() { _id = 0; } 00288 00289 private: 00291 GLSLShader() : _shaderType(GL_NONE), _id(0) {} 00292 00294 GLSLShader(const GLSLShader &) : GLResource() {} 00295 GLSLShader &operator = (const GLSLShader &) { return *this; } 00296 00297 GLenum _shaderType; 00298 GLuint _id; 00299 }; 00300 00301 //------------------------------------------------------------------------------------- 00302 00304 class MLOPENGL_EXPORT GLSLVertexShader : public GLSLShader { 00305 public: 00306 GLSLVertexShader() : GLSLShader(GL_VERTEX_SHADER) {} 00307 virtual ~GLSLVertexShader() {} 00308 private: 00310 GLSLVertexShader(const GLSLVertexShader &) : GLSLShader(GL_VERTEX_SHADER) {} 00311 GLSLVertexShader &operator = (const GLSLVertexShader &) { return *this; } 00312 }; 00313 00314 //------------------------------------------------------------------------------------- 00315 00317 class MLOPENGL_EXPORT GLSLFragmentShader : public GLSLShader { 00318 public: 00319 GLSLFragmentShader() : GLSLShader(GL_FRAGMENT_SHADER) {} 00320 virtual ~GLSLFragmentShader() {} 00321 private: 00323 GLSLFragmentShader(const GLSLFragmentShader &) : GLSLShader(GL_FRAGMENT_SHADER) {} 00324 GLSLFragmentShader &operator = (const GLSLFragmentShader &) { return *this; } 00325 }; 00326 00327 //------------------------------------------------------------------------------------- 00328 00330 class MLOPENGL_EXPORT GLSLGeometryShader : public GLSLShader { 00331 public: 00332 GLSLGeometryShader() : GLSLShader(GL_GEOMETRY_SHADER_EXT) {} 00333 virtual ~GLSLGeometryShader() {} 00334 private: 00336 GLSLGeometryShader(const GLSLGeometryShader &) : GLSLShader(GL_GEOMETRY_SHADER_EXT) {} 00337 GLSLGeometryShader &operator = (const GLSLGeometryShader &) { return *this; } 00338 }; 00339 00340 //------------------------------------------------------------------------------------- 00341 00343 class MLOPENGL_EXPORT GLSLProgram : public GLResource { 00344 public: 00345 GLSLProgram() { _id = 0; } 00346 virtual ~GLSLProgram() { destroy(); } 00347 00349 void disable(); 00350 00352 void detachShader(GLSLShader& shader); 00353 00355 void detachShader(GLuint shader); 00356 00358 inline GLuint getHandle() const { return _id; } 00359 00361 inline bool isValid() const { return _id!=0; } 00362 00364 void create(); 00365 00367 void destroy(); 00368 00370 virtual void contextDestroyed() { _id = 0; } 00371 00372 private: 00373 GLuint _id; 00374 00376 GLSLProgram(const GLSLProgram &) : GLResource() {} 00377 GLSLProgram &operator = (const GLSLProgram &) { return *this; } 00378 }; 00379 00380 00381 00382 ML_OPENGL_END_NAMESPACE 00383 00384 #endif