ccFrameBufferObject.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #pragma once
  2. //##########################################################################
  3. //# #
  4. //# CCFBO #
  5. //# #
  6. //# This program is free software; you can redistribute it and/or modify #
  7. //# it under the terms of the GNU Library General Public License as #
  8. //# published by the Free Software Foundation; version 2 or later of the License. #
  9. //# #
  10. //# This program is distributed in the hope that it will be useful, #
  11. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  12. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  13. //# GNU General Public License for more details. #
  14. //# #
  15. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  16. //# #
  17. //##########################################################################
  18. #include "CCFbo.h"
  19. //Qt
  20. #include <QOpenGLExtensions>
  21. #include <QOpenGLFunctions_2_1>
  22. //! F.B.O. encapsulation
  23. /** Compared to the QOpenGLFramebufferObject class, this one offers the possibility to:
  24. - get the attached depth texture ID
  25. - attach a custom COLOR texture
  26. **/
  27. class CCFBO_LIB_API ccFrameBufferObject
  28. {
  29. public:
  30. ccFrameBufferObject();
  31. ~ccFrameBufferObject();
  32. bool init(unsigned w, unsigned h);
  33. void reset();
  34. bool start();
  35. void stop();
  36. inline bool isValid() const { return m_fboId; }
  37. bool initColor( GLint internalformat = GL_RGBA,
  38. GLenum format = GL_RGBA,
  39. GLenum type = GL_UNSIGNED_BYTE,
  40. GLint minMagFilter = GL_NEAREST,
  41. GLenum target = GL_TEXTURE_2D);
  42. bool attachColor( GLuint texID,
  43. bool ownTexture = false,
  44. GLenum target = GL_TEXTURE_2D);
  45. bool initDepth( GLint wrapParam = GL_CLAMP_TO_BORDER,
  46. GLenum internalFormat = GL_DEPTH_COMPONENT32F,
  47. GLint minMagFilter = GL_NEAREST,
  48. GLenum textureTarget = GL_TEXTURE_2D);
  49. bool attachDepth( GLuint texID,
  50. bool ownTexture = false,
  51. GLenum target = GL_TEXTURE_2D);
  52. inline GLuint getID() const { return m_fboId; }
  53. inline GLuint getColorTexture() const { return m_colorTexture; }
  54. inline GLuint getDepthTexture() const { return m_depthTexture; }
  55. //! Returns width
  56. inline unsigned width() const { return m_width; }
  57. //! Returns height
  58. inline unsigned height() const { return m_height; }
  59. protected: //methods
  60. //! Deletes/releases the color texture
  61. void deleteColorTexture();
  62. //! Deletes/releases the depth texture
  63. void deleteDepthTexture();
  64. protected: //members
  65. //! FBO validity
  66. bool m_isValid;
  67. //! Width
  68. unsigned m_width;
  69. //! Height
  70. unsigned m_height;
  71. //! Depth texture GL ID
  72. GLuint m_depthTexture;
  73. //! Whether the depth texture is owned by this FBO or not
  74. bool m_ownDepthTexture;
  75. //! Color texture GL ID
  76. GLuint m_colorTexture;
  77. //! Whether the color texture is owned by this FBO or not
  78. bool m_ownColorTexture;
  79. //! ID
  80. GLuint m_fboId;
  81. // For portability, we need to use 2.1 + extensions to get FBOs
  82. QOpenGLFunctions_2_1 m_glFunc;
  83. QOpenGLExtension_ARB_framebuffer_object m_glExtFunc;
  84. };