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