2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2005-06-16 19:45:50 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// initial FBO support written by Marco Jez, June 2005.
|
|
|
|
|
2005-06-16 19:42:59 +08:00
|
|
|
#ifndef OSG_FRAMEBUFFEROBJECT
|
|
|
|
#define OSG_FRAMEBUFFEROBJECT 1
|
|
|
|
|
|
|
|
#include <osg/GL>
|
|
|
|
#include <osg/Texture>
|
|
|
|
#include <osg/buffered_value>
|
2006-11-27 22:52:07 +08:00
|
|
|
#include <osg/Camera>
|
2005-06-16 19:42:59 +08:00
|
|
|
|
|
|
|
#ifndef GL_EXT_framebuffer_object
|
|
|
|
#define GL_EXT_framebuffer_object 1
|
|
|
|
#define GL_FRAMEBUFFER_EXT 0x8D40
|
|
|
|
#define GL_RENDERBUFFER_EXT 0x8D41
|
2008-11-25 18:57:14 +08:00
|
|
|
// #define GL_STENCIL_INDEX_EXT 0x8D45 // removed in rev. #114 of the spec
|
2005-06-16 19:42:59 +08:00
|
|
|
#define GL_STENCIL_INDEX1_EXT 0x8D46
|
|
|
|
#define GL_STENCIL_INDEX4_EXT 0x8D47
|
|
|
|
#define GL_STENCIL_INDEX8_EXT 0x8D48
|
|
|
|
#define GL_STENCIL_INDEX16_EXT 0x8D49
|
|
|
|
#define GL_RENDERBUFFER_WIDTH_EXT 0x8D42
|
|
|
|
#define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43
|
|
|
|
#define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44
|
|
|
|
#define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50
|
|
|
|
#define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51
|
|
|
|
#define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52
|
|
|
|
#define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53
|
|
|
|
#define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54
|
|
|
|
#define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55
|
|
|
|
#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0
|
|
|
|
#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1
|
|
|
|
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2
|
|
|
|
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3
|
|
|
|
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4
|
2007-09-07 19:21:02 +08:00
|
|
|
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT 0x8CD4
|
2005-06-16 19:42:59 +08:00
|
|
|
#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
|
|
|
|
#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1
|
|
|
|
#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2
|
|
|
|
#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3
|
|
|
|
#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4
|
|
|
|
#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5
|
|
|
|
#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6
|
|
|
|
#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7
|
|
|
|
#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8
|
|
|
|
#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9
|
|
|
|
#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA
|
|
|
|
#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB
|
|
|
|
#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC
|
|
|
|
#define GL_COLOR_ATTACHMENT13_EXT 0x8CED
|
|
|
|
#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE
|
|
|
|
#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF
|
|
|
|
#define GL_DEPTH_ATTACHMENT_EXT 0x8D00
|
|
|
|
#define GL_STENCIL_ATTACHMENT_EXT 0x8D20
|
|
|
|
#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5
|
|
|
|
#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6
|
|
|
|
#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7
|
|
|
|
#define GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT 0x8CD8
|
|
|
|
#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9
|
|
|
|
#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA
|
|
|
|
#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB
|
|
|
|
#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC
|
|
|
|
#define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD
|
|
|
|
#define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6
|
|
|
|
#define GL_RENDERBUFFER_BINDING_EXT 0x8CA7
|
|
|
|
#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF
|
|
|
|
#define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8
|
|
|
|
#define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506
|
|
|
|
#endif
|
|
|
|
|
2008-06-18 22:09:11 +08:00
|
|
|
#ifndef GL_EXT_framebuffer_blit
|
|
|
|
#define GL_EXT_framebuffer_blit 1
|
|
|
|
#define GL_DRAW_FRAMEBUFFER_BINDING_EXT 0x8CA6
|
|
|
|
#define GL_READ_FRAMEBUFFER_EXT 0x8CA8
|
|
|
|
#define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9
|
|
|
|
#define GL_READ_FRAMEBUFFER_BINDING_EXT 0x8CAA
|
|
|
|
#endif
|
|
|
|
|
2008-06-19 04:24:12 +08:00
|
|
|
#ifndef GL_EXT_framebuffer_multisample
|
|
|
|
#define GL_EXT_framebuffer_multisample 1
|
|
|
|
#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB
|
|
|
|
#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56
|
|
|
|
#define GL_MAX_SAMPLES_EXT 0x8D57
|
|
|
|
#endif
|
|
|
|
|
2008-08-04 22:01:42 +08:00
|
|
|
#ifndef GL_MAX_SAMPLES_EXT
|
|
|
|
// Workaround for Centos 5 and other distros that define
|
|
|
|
// GL_EXT_framebuffer_multisample but not GL_MAX_SAMPLES_EXT
|
|
|
|
#define GL_MAX_SAMPLES_EXT 0x8D57
|
|
|
|
#endif
|
|
|
|
|
2008-06-19 04:24:12 +08:00
|
|
|
#ifndef GL_NV_framebuffer_multisample_coverage
|
|
|
|
#define GL_NV_framebuffer_multisample_coverage 1
|
|
|
|
#define GL_RENDERBUFFER_COVERAGE_SAMPLES_NV 0x8CAB
|
|
|
|
#define GL_RENDERBUFFER_COLOR_SAMPLES_NV 0x8E10
|
|
|
|
#define GL_MAX_MULTISAMPLE_COVERAGE_MODES_NV 0x8E11
|
|
|
|
#define GL_MULTISAMPLE_COVERAGE_MODES_NV 0x8E12
|
|
|
|
#endif
|
|
|
|
|
2009-10-29 04:31:57 +08:00
|
|
|
#ifndef GL_DEPTH_COMPONENT
|
|
|
|
#define GL_DEPTH_COMPONENT 0x1902
|
|
|
|
#endif
|
|
|
|
|
2005-06-16 19:42:59 +08:00
|
|
|
#ifndef GL_VERSION_1_4
|
|
|
|
#define GL_DEPTH_COMPONENT16 0x81A5
|
|
|
|
#define GL_DEPTH_COMPONENT24 0x81A6
|
|
|
|
#define GL_DEPTH_COMPONENT32 0x81A7
|
|
|
|
#endif
|
|
|
|
|
2010-04-22 00:37:28 +08:00
|
|
|
#ifndef GL_DEPTH_COMPONENT32F
|
|
|
|
#define GL_DEPTH_COMPONENT32F 0x8CAC
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GL_DEPTH_COMPONENT32F_NV
|
|
|
|
#define GL_DEPTH_COMPONENT32F_NV 0x8DAB
|
|
|
|
#endif
|
|
|
|
|
2008-11-09 19:55:11 +08:00
|
|
|
#ifndef GL_EXT_packed_depth_stencil
|
|
|
|
#define GL_EXT_packed_depth_stencil 1
|
|
|
|
#define GL_DEPTH_STENCIL_EXT 0x84F9
|
|
|
|
#define GL_UNSIGNED_INT_24_8_EXT 0x84FA
|
|
|
|
#define GL_DEPTH24_STENCIL8_EXT 0x88F0
|
|
|
|
#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1
|
|
|
|
#endif
|
|
|
|
|
2005-06-16 19:42:59 +08:00
|
|
|
namespace osg
|
|
|
|
{
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* FBOExtensions
|
|
|
|
**************************************************************************/
|
|
|
|
|
2006-01-03 18:44:14 +08:00
|
|
|
class OSG_EXPORT FBOExtensions : public osg::Referenced
|
2005-06-16 19:42:59 +08:00
|
|
|
{
|
|
|
|
public:
|
2009-11-11 01:01:08 +08:00
|
|
|
typedef void APIENTRY TglBindRenderbuffer(GLenum, GLuint);
|
|
|
|
typedef void APIENTRY TglDeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers);
|
|
|
|
typedef void APIENTRY TglGenRenderbuffers(GLsizei, GLuint *);
|
|
|
|
typedef void APIENTRY TglRenderbufferStorage(GLenum, GLenum, GLsizei, GLsizei);
|
|
|
|
typedef void APIENTRY TglRenderbufferStorageMultisample(GLenum, GLsizei, GLenum, GLsizei, GLsizei);
|
2008-06-18 22:09:11 +08:00
|
|
|
typedef void APIENTRY TglRenderbufferStorageMultisampleCoverageNV(GLenum, GLsizei, GLsizei, GLenum, GLsizei, GLsizei);
|
2009-11-11 01:01:08 +08:00
|
|
|
typedef void APIENTRY TglBindFramebuffer(GLenum, GLuint);
|
|
|
|
typedef void APIENTRY TglDeleteFramebuffers(GLsizei n, const GLuint *framebuffers);
|
|
|
|
typedef void APIENTRY TglGenFramebuffers(GLsizei, GLuint *);
|
|
|
|
typedef GLenum APIENTRY TglCheckFramebufferStatus(GLenum);
|
|
|
|
typedef void APIENTRY TglFramebufferTexture1D(GLenum, GLenum, GLenum, GLuint, GLint);
|
|
|
|
typedef void APIENTRY TglFramebufferTexture2D(GLenum, GLenum, GLenum, GLuint, GLint);
|
|
|
|
typedef void APIENTRY TglFramebufferTexture3D(GLenum, GLenum, GLenum, GLuint, GLint, GLint);
|
|
|
|
typedef void APIENTRY TglFramebufferTextureLayer(GLenum, GLenum, GLuint, GLint, GLint);
|
|
|
|
typedef void APIENTRY TglFramebufferRenderbuffer(GLenum, GLenum, GLenum, GLuint);
|
|
|
|
typedef void APIENTRY TglGenerateMipmap(GLenum);
|
|
|
|
typedef void APIENTRY TglBlitFramebuffer(GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum);
|
2010-04-19 19:43:06 +08:00
|
|
|
typedef void APIENTRY TglGetRenderbufferParameteriv(GLenum, GLenum, GLint*);
|
2009-11-11 01:01:08 +08:00
|
|
|
|
|
|
|
TglBindRenderbuffer* glBindRenderbuffer;
|
|
|
|
TglGenRenderbuffers* glGenRenderbuffers;
|
|
|
|
TglDeleteRenderbuffers* glDeleteRenderbuffers;
|
|
|
|
TglRenderbufferStorage* glRenderbufferStorage;
|
|
|
|
TglRenderbufferStorageMultisample* glRenderbufferStorageMultisample;
|
2007-09-07 19:21:02 +08:00
|
|
|
TglRenderbufferStorageMultisampleCoverageNV* glRenderbufferStorageMultisampleCoverageNV;
|
2009-11-11 01:01:08 +08:00
|
|
|
TglBindFramebuffer* glBindFramebuffer;
|
|
|
|
TglDeleteFramebuffers* glDeleteFramebuffers;
|
|
|
|
TglGenFramebuffers* glGenFramebuffers;
|
|
|
|
TglCheckFramebufferStatus* glCheckFramebufferStatus;
|
|
|
|
TglFramebufferTexture1D* glFramebufferTexture1D;
|
|
|
|
TglFramebufferTexture2D* glFramebufferTexture2D;
|
|
|
|
TglFramebufferTexture3D* glFramebufferTexture3D;
|
|
|
|
TglFramebufferTextureLayer* glFramebufferTextureLayer;
|
|
|
|
TglFramebufferRenderbuffer* glFramebufferRenderbuffer;
|
|
|
|
TglGenerateMipmap* glGenerateMipmap;
|
|
|
|
TglBlitFramebuffer* glBlitFramebuffer;
|
2010-04-19 19:43:06 +08:00
|
|
|
TglGetRenderbufferParameteriv* glGetRenderbufferParameteriv;
|
2005-11-24 23:18:12 +08:00
|
|
|
|
2006-01-03 18:44:14 +08:00
|
|
|
static FBOExtensions* instance(unsigned contextID, bool createIfNotInitalized);
|
2005-06-16 19:42:59 +08:00
|
|
|
|
|
|
|
bool isSupported() const { return _supported; }
|
2009-11-11 01:01:08 +08:00
|
|
|
bool isMultisampleSupported() const { return glRenderbufferStorageMultisample != 0; }
|
2008-06-18 22:09:11 +08:00
|
|
|
bool isMultisampleCoverageSupported() const { return glRenderbufferStorageMultisampleCoverageNV != 0; }
|
2008-11-09 19:55:11 +08:00
|
|
|
bool isPackedDepthStencilSupported() const { return _packed_depth_stencil_supported; }
|
2005-06-16 19:42:59 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
FBOExtensions(unsigned int contextID);
|
|
|
|
|
|
|
|
bool _supported;
|
2008-11-09 19:55:11 +08:00
|
|
|
bool _packed_depth_stencil_supported;
|
2005-06-16 19:42:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* RenderBuffer
|
|
|
|
**************************************************************************/
|
|
|
|
|
2005-06-20 18:16:30 +08:00
|
|
|
class OSG_EXPORT RenderBuffer: public Object
|
2005-06-16 19:42:59 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
RenderBuffer();
|
2008-06-18 22:09:11 +08:00
|
|
|
RenderBuffer(int width, int height, GLenum internalFormat, int samples=0, int colorSamples=0);
|
2005-11-24 23:18:12 +08:00
|
|
|
RenderBuffer(const RenderBuffer& copy, const CopyOp& copyop = CopyOp::SHALLOW_COPY);
|
2005-06-16 19:42:59 +08:00
|
|
|
|
|
|
|
META_Object(osg, RenderBuffer);
|
|
|
|
|
|
|
|
inline int getWidth() const;
|
|
|
|
inline int getHeight() const;
|
|
|
|
inline void setWidth(int w);
|
|
|
|
inline void setHeight(int h);
|
|
|
|
inline void setSize(int w, int h);
|
|
|
|
inline GLenum getInternalFormat() const;
|
|
|
|
inline void setInternalFormat(GLenum format);
|
2008-06-18 22:09:11 +08:00
|
|
|
inline int getSamples() const;
|
|
|
|
inline int getColorSamples() const;
|
|
|
|
inline void setSamples(int samples);
|
|
|
|
inline void setColorSamples(int colorSamples);
|
2005-06-16 19:42:59 +08:00
|
|
|
|
|
|
|
GLuint getObjectID(unsigned int contextID, const FBOExtensions *ext) const;
|
|
|
|
inline int compare(const RenderBuffer &rb) const;
|
|
|
|
|
2005-11-24 23:18:12 +08:00
|
|
|
/** Mark internal RenderBuffer for deletion.
|
|
|
|
* Deletion requests are queued until they can be executed
|
|
|
|
* in the proper GL context. */
|
|
|
|
static void deleteRenderBuffer(unsigned int contextID, GLuint rb);
|
|
|
|
|
|
|
|
/** flush all the cached RenderBuffers which need to be deleted
|
|
|
|
* in the OpenGL context related to contextID.*/
|
|
|
|
static void flushDeletedRenderBuffers(unsigned int contextID,double currentTime, double& availableTime);
|
|
|
|
|
2008-01-08 21:24:29 +08:00
|
|
|
/** discard all the cached RenderBuffers which need to be deleted in the OpenGL context related to contextID.
|
|
|
|
* Note, unlike flush no OpenGL calls are made, instead the handles are all removed.
|
|
|
|
* this call is useful for when an OpenGL context has been destroyed. */
|
|
|
|
static void discardDeletedRenderBuffers(unsigned int contextID);
|
2005-11-24 23:18:12 +08:00
|
|
|
|
2008-06-19 04:24:12 +08:00
|
|
|
static int getMaxSamples(unsigned int contextID, const FBOExtensions *ext);
|
|
|
|
|
2005-06-16 19:42:59 +08:00
|
|
|
protected:
|
2005-11-24 23:18:12 +08:00
|
|
|
virtual ~RenderBuffer();
|
2005-06-16 19:42:59 +08:00
|
|
|
RenderBuffer &operator=(const RenderBuffer &) { return *this; }
|
|
|
|
|
|
|
|
inline void dirtyAll() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
mutable buffered_value<GLuint> _objectID;
|
|
|
|
mutable buffered_value<int> _dirty;
|
2008-06-18 22:09:11 +08:00
|
|
|
|
2005-06-16 19:42:59 +08:00
|
|
|
GLenum _internalFormat;
|
|
|
|
int _width;
|
|
|
|
int _height;
|
2008-06-18 22:09:11 +08:00
|
|
|
// "samples" in the framebuffer_multisample extension is equivalent to
|
|
|
|
// "coverageSamples" in the framebuffer_multisample_coverage extension.
|
|
|
|
int _samples;
|
|
|
|
int _colorSamples;
|
2005-06-16 19:42:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// INLINE METHODS
|
|
|
|
|
|
|
|
inline int RenderBuffer::getWidth() const
|
|
|
|
{
|
|
|
|
return _width;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int RenderBuffer::getHeight() const
|
|
|
|
{
|
|
|
|
return _height;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void RenderBuffer::setWidth(int w)
|
|
|
|
{
|
|
|
|
_width = w;
|
|
|
|
dirtyAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void RenderBuffer::setHeight(int h)
|
|
|
|
{
|
|
|
|
_height = h;
|
|
|
|
dirtyAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void RenderBuffer::setSize(int w, int h)
|
|
|
|
{
|
|
|
|
_width = w;
|
|
|
|
_height = h;
|
|
|
|
dirtyAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline GLenum RenderBuffer::getInternalFormat() const
|
|
|
|
{
|
|
|
|
return _internalFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void RenderBuffer::setInternalFormat(GLenum format)
|
|
|
|
{
|
|
|
|
_internalFormat = format;
|
|
|
|
dirtyAll();
|
|
|
|
}
|
|
|
|
|
2008-06-18 22:09:11 +08:00
|
|
|
inline int RenderBuffer::getSamples() const
|
|
|
|
{
|
|
|
|
return _samples;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int RenderBuffer::getColorSamples() const
|
|
|
|
{
|
|
|
|
return _colorSamples;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void RenderBuffer::setSamples(int samples)
|
|
|
|
{
|
|
|
|
_samples = samples;
|
|
|
|
dirtyAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void RenderBuffer::setColorSamples(int colorSamples)
|
|
|
|
{
|
|
|
|
_colorSamples = colorSamples;
|
|
|
|
dirtyAll();
|
|
|
|
}
|
|
|
|
|
2005-06-16 19:42:59 +08:00
|
|
|
inline void RenderBuffer::dirtyAll() const
|
|
|
|
{
|
|
|
|
_dirty.setAllElementsTo(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int RenderBuffer::compare(const RenderBuffer &rb) const
|
|
|
|
{
|
|
|
|
if (&rb == this) return 0;
|
|
|
|
if (_internalFormat < rb._internalFormat) return -1;
|
|
|
|
if (_internalFormat > rb._internalFormat) return 1;
|
|
|
|
if (_width < rb._width) return -1;
|
|
|
|
if (_width > rb._width) return 1;
|
|
|
|
if (_height < rb._height) return -1;
|
|
|
|
if (_height > rb._height) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* FrameBufferAttachement
|
|
|
|
**************************************************************************/
|
|
|
|
class Texture1D;
|
|
|
|
class Texture2D;
|
2010-04-23 01:02:22 +08:00
|
|
|
class Texture2DMultisample;
|
2005-06-16 19:42:59 +08:00
|
|
|
class Texture3D;
|
2007-09-07 19:21:02 +08:00
|
|
|
class Texture2DArray;
|
2005-06-16 19:42:59 +08:00
|
|
|
class TextureCubeMap;
|
|
|
|
class TextureRectangle;
|
|
|
|
|
2005-06-20 18:16:30 +08:00
|
|
|
class OSG_EXPORT FrameBufferAttachment
|
2005-06-16 19:42:59 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
FrameBufferAttachment();
|
2005-11-24 23:18:12 +08:00
|
|
|
FrameBufferAttachment(const FrameBufferAttachment& copy);
|
2005-06-16 19:42:59 +08:00
|
|
|
|
|
|
|
explicit FrameBufferAttachment(RenderBuffer* target);
|
|
|
|
explicit FrameBufferAttachment(Texture1D* target, int level = 0);
|
|
|
|
explicit FrameBufferAttachment(Texture2D* target, int level = 0);
|
2010-04-23 01:02:22 +08:00
|
|
|
explicit FrameBufferAttachment(Texture2DMultisample* target, int level = 0);
|
2005-06-16 19:42:59 +08:00
|
|
|
explicit FrameBufferAttachment(Texture3D* target, int zoffset, int level = 0);
|
2007-09-07 19:21:02 +08:00
|
|
|
explicit FrameBufferAttachment(Texture2DArray* target, int layer, int level = 0);
|
2005-06-16 19:42:59 +08:00
|
|
|
explicit FrameBufferAttachment(TextureCubeMap* target, int face, int level = 0);
|
|
|
|
explicit FrameBufferAttachment(TextureRectangle* target);
|
2006-11-27 22:52:07 +08:00
|
|
|
explicit FrameBufferAttachment(Camera::Attachment& attachment);
|
2005-06-16 19:42:59 +08:00
|
|
|
|
|
|
|
~FrameBufferAttachment();
|
|
|
|
|
2005-11-24 23:18:12 +08:00
|
|
|
FrameBufferAttachment&operator = (const FrameBufferAttachment& copy);
|
2005-06-16 19:42:59 +08:00
|
|
|
|
2008-06-18 22:09:11 +08:00
|
|
|
bool isMultisample() const;
|
2005-11-24 23:18:12 +08:00
|
|
|
void createRequiredTexturesAndApplyGenerateMipMap(State& state, const FBOExtensions* ext) const;
|
2008-06-18 22:09:11 +08:00
|
|
|
void attach(State &state, GLenum target, GLenum attachment_point, const FBOExtensions* ext) const;
|
2005-06-16 19:42:59 +08:00
|
|
|
int compare(const FrameBufferAttachment &fa) const;
|
|
|
|
|
2008-11-06 22:46:11 +08:00
|
|
|
RenderBuffer* getRenderBuffer();
|
|
|
|
const RenderBuffer* getRenderBuffer() const;
|
|
|
|
|
|
|
|
Texture* getTexture();
|
|
|
|
const Texture* getTexture() const;
|
|
|
|
|
2008-11-06 22:29:35 +08:00
|
|
|
int getCubeMapFace() const;
|
|
|
|
int getTextureLevel() const;
|
|
|
|
int getTexture3DZOffset() const;
|
|
|
|
int getTextureArrayLayer() const;
|
|
|
|
|
2005-06-16 19:42:59 +08:00
|
|
|
private:
|
|
|
|
// use the Pimpl idiom to avoid dependency from
|
|
|
|
// all Texture* headers
|
|
|
|
struct Pimpl;
|
|
|
|
Pimpl* _ximpl;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* FrameBufferObject
|
|
|
|
**************************************************************************/
|
2005-06-20 18:16:30 +08:00
|
|
|
class OSG_EXPORT FrameBufferObject: public StateAttribute
|
2005-06-16 19:42:59 +08:00
|
|
|
{
|
|
|
|
public:
|
2008-04-18 21:25:14 +08:00
|
|
|
typedef std::map<Camera::BufferComponent, FrameBufferAttachment> AttachmentMap;
|
2008-04-16 03:36:40 +08:00
|
|
|
typedef std::vector<GLenum> MultipleRenderingTargets;
|
2008-04-18 21:25:14 +08:00
|
|
|
|
|
|
|
typedef Camera::BufferComponent BufferComponent;
|
2005-06-16 19:42:59 +08:00
|
|
|
|
|
|
|
FrameBufferObject();
|
2005-11-24 23:18:12 +08:00
|
|
|
FrameBufferObject(const FrameBufferObject& copy, const CopyOp& copyop = CopyOp::SHALLOW_COPY);
|
2005-06-16 19:42:59 +08:00
|
|
|
|
|
|
|
META_StateAttribute(osg, FrameBufferObject, (StateAttribute::Type)0x101010/*FrameBufferObject*/);
|
|
|
|
|
2008-04-16 03:36:40 +08:00
|
|
|
inline const AttachmentMap& getAttachmentMap() const;
|
2008-04-18 21:25:14 +08:00
|
|
|
|
2008-04-16 03:36:40 +08:00
|
|
|
|
2008-04-18 21:25:14 +08:00
|
|
|
void setAttachment(BufferComponent attachment_point, const FrameBufferAttachment &attachment);
|
|
|
|
inline const FrameBufferAttachment& getAttachment(BufferComponent attachment_point) const;
|
|
|
|
inline bool hasAttachment(BufferComponent attachment_point) const;
|
|
|
|
|
2008-04-16 03:36:40 +08:00
|
|
|
inline bool hasMultipleRenderingTargets() const { return !_drawBuffers.empty(); }
|
|
|
|
inline const MultipleRenderingTargets& getMultipleRenderingTargets() const { return _drawBuffers; }
|
2005-06-16 19:42:59 +08:00
|
|
|
|
2008-06-18 22:09:11 +08:00
|
|
|
bool isMultisample() const;
|
|
|
|
|
2005-06-16 19:42:59 +08:00
|
|
|
int compare(const StateAttribute &sa) const;
|
2008-04-16 03:36:40 +08:00
|
|
|
|
2005-06-16 19:42:59 +08:00
|
|
|
void apply(State &state) const;
|
|
|
|
|
2008-06-18 22:09:11 +08:00
|
|
|
enum BindTarget
|
|
|
|
{
|
|
|
|
READ_FRAMEBUFFER = GL_READ_FRAMEBUFFER_EXT,
|
|
|
|
DRAW_FRAMEBUFFER = GL_DRAW_FRAMEBUFFER_EXT,
|
|
|
|
READ_DRAW_FRAMEBUFFER = GL_FRAMEBUFFER_EXT
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Bind the FBO as either the read or draw target, or both. */
|
|
|
|
void apply(State &state, BindTarget target) const;
|
|
|
|
|
2005-11-24 23:18:12 +08:00
|
|
|
/** Mark internal FBO for deletion.
|
|
|
|
* Deletion requests are queued until they can be executed
|
|
|
|
* in the proper GL context. */
|
|
|
|
static void deleteFrameBufferObject(unsigned int contextID, GLuint program);
|
|
|
|
|
|
|
|
/** flush all the cached FBOs which need to be deleted
|
|
|
|
* in the OpenGL context related to contextID.*/
|
|
|
|
static void flushDeletedFrameBufferObjects(unsigned int contextID,double currentTime, double& availableTime);
|
|
|
|
|
2008-01-08 21:24:29 +08:00
|
|
|
/** discard all the cached FBOs which need to be deleted
|
|
|
|
* in the OpenGL context related to contextID.*/
|
|
|
|
static void discardDeletedFrameBufferObjects(unsigned int contextID);
|
|
|
|
|
2005-06-16 19:42:59 +08:00
|
|
|
protected:
|
2005-11-24 23:18:12 +08:00
|
|
|
virtual ~FrameBufferObject();
|
|
|
|
FrameBufferObject& operator = (const FrameBufferObject&) { return *this; }
|
2005-06-16 19:42:59 +08:00
|
|
|
|
2008-04-18 21:25:14 +08:00
|
|
|
void updateDrawBuffers();
|
|
|
|
|
2005-06-16 19:42:59 +08:00
|
|
|
inline void dirtyAll();
|
|
|
|
|
2008-07-15 22:24:21 +08:00
|
|
|
GLenum convertBufferComponentToGLenum(BufferComponent attachment_point) const;
|
|
|
|
|
2005-06-16 19:42:59 +08:00
|
|
|
private:
|
2008-04-16 03:36:40 +08:00
|
|
|
AttachmentMap _attachments;
|
|
|
|
|
|
|
|
// Buffers passed to glDrawBuffers when using multiple render targets.
|
|
|
|
MultipleRenderingTargets _drawBuffers;
|
|
|
|
|
|
|
|
mutable buffered_value<int> _dirtyAttachmentList;
|
|
|
|
mutable buffered_value<int> _unsupported;
|
|
|
|
mutable buffered_value<GLuint> _fboID;
|
|
|
|
|
2005-06-16 19:42:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// INLINE METHODS
|
|
|
|
|
|
|
|
inline const FrameBufferObject::AttachmentMap &FrameBufferObject::getAttachmentMap() const
|
|
|
|
{
|
|
|
|
return _attachments;
|
|
|
|
}
|
|
|
|
|
2008-04-18 21:25:14 +08:00
|
|
|
inline bool FrameBufferObject::hasAttachment(FrameBufferObject::BufferComponent attachment_point) const
|
2005-06-16 19:42:59 +08:00
|
|
|
{
|
|
|
|
return _attachments.find(attachment_point) != _attachments.end();
|
|
|
|
}
|
|
|
|
|
2008-04-18 21:25:14 +08:00
|
|
|
inline const FrameBufferAttachment &FrameBufferObject::getAttachment(FrameBufferObject::BufferComponent attachment_point) const
|
2005-06-16 19:42:59 +08:00
|
|
|
{
|
|
|
|
return _attachments.find(attachment_point)->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void FrameBufferObject::dirtyAll()
|
|
|
|
{
|
|
|
|
_dirtyAttachmentList.setAllElementsTo(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|