16 #ifndef OSG_FRAMEBUFFEROBJECT
17 #define OSG_FRAMEBUFFEROBJECT 1
20 #include <osg/Texture>
21 #include <osg/buffered_value>
24 #ifndef GL_EXT_framebuffer_object
25 #define GL_EXT_framebuffer_object 1
26 #define GL_FRAMEBUFFER_EXT 0x8D40
27 #define GL_RENDERBUFFER_EXT 0x8D41
29 #define GL_STENCIL_INDEX1_EXT 0x8D46
30 #define GL_STENCIL_INDEX4_EXT 0x8D47
31 #define GL_STENCIL_INDEX8_EXT 0x8D48
32 #define GL_STENCIL_INDEX16_EXT 0x8D49
33 #define GL_RENDERBUFFER_WIDTH_EXT 0x8D42
34 #define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43
35 #define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44
36 #define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50
37 #define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51
38 #define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52
39 #define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53
40 #define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54
41 #define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55
42 #define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0
43 #define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1
44 #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2
45 #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3
46 #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4
47 #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT 0x8CD4
48 #define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
49 #define GL_COLOR_ATTACHMENT1_EXT 0x8CE1
50 #define GL_COLOR_ATTACHMENT2_EXT 0x8CE2
51 #define GL_COLOR_ATTACHMENT3_EXT 0x8CE3
52 #define GL_COLOR_ATTACHMENT4_EXT 0x8CE4
53 #define GL_COLOR_ATTACHMENT5_EXT 0x8CE5
54 #define GL_COLOR_ATTACHMENT6_EXT 0x8CE6
55 #define GL_COLOR_ATTACHMENT7_EXT 0x8CE7
56 #define GL_COLOR_ATTACHMENT8_EXT 0x8CE8
57 #define GL_COLOR_ATTACHMENT9_EXT 0x8CE9
58 #define GL_COLOR_ATTACHMENT10_EXT 0x8CEA
59 #define GL_COLOR_ATTACHMENT11_EXT 0x8CEB
60 #define GL_COLOR_ATTACHMENT12_EXT 0x8CEC
61 #define GL_COLOR_ATTACHMENT13_EXT 0x8CED
62 #define GL_COLOR_ATTACHMENT14_EXT 0x8CEE
63 #define GL_COLOR_ATTACHMENT15_EXT 0x8CEF
64 #define GL_DEPTH_ATTACHMENT_EXT 0x8D00
65 #define GL_STENCIL_ATTACHMENT_EXT 0x8D20
66 #define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5
67 #define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6
68 #define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7
69 #define GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT 0x8CD8
70 #define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9
71 #define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA
72 #define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB
73 #define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC
74 #define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD
75 #define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6
76 #define GL_RENDERBUFFER_BINDING_EXT 0x8CA7
77 #define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF
78 #define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8
79 #define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506
82 #ifndef GL_EXT_framebuffer_blit
83 #define GL_EXT_framebuffer_blit 1
84 #define GL_DRAW_FRAMEBUFFER_BINDING_EXT 0x8CA6
85 #define GL_READ_FRAMEBUFFER_EXT 0x8CA8
86 #define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9
87 #define GL_READ_FRAMEBUFFER_BINDING_EXT 0x8CAA
90 #ifndef GL_EXT_framebuffer_multisample
91 #define GL_EXT_framebuffer_multisample 1
92 #define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB
93 #define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56
94 #define GL_MAX_SAMPLES_EXT 0x8D57
97 #ifndef GL_MAX_SAMPLES_EXT
100 #define GL_MAX_SAMPLES_EXT 0x8D57
103 #ifndef GL_NV_framebuffer_multisample_coverage
104 #define GL_NV_framebuffer_multisample_coverage 1
105 #define GL_RENDERBUFFER_COVERAGE_SAMPLES_NV 0x8CAB
106 #define GL_RENDERBUFFER_COLOR_SAMPLES_NV 0x8E10
107 #define GL_MAX_MULTISAMPLE_COVERAGE_MODES_NV 0x8E11
108 #define GL_MULTISAMPLE_COVERAGE_MODES_NV 0x8E12
111 #ifndef GL_EXT_packed_depth_stencil
112 #define GL_EXT_packed_depth_stencil 1
113 #define GL_DEPTH_STENCIL_EXT 0x84F9
114 #define GL_UNSIGNED_INT_24_8_EXT 0x84FA
115 #define GL_DEPTH24_STENCIL8_EXT 0x88F0
116 #define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1
135 inline int getWidth()
const;
136 inline int getHeight()
const;
137 inline void setWidth(
int w);
138 inline void setHeight(
int h);
139 inline void setSize(
int w,
int h);
140 inline GLenum getInternalFormat()
const;
141 inline void setInternalFormat(GLenum
format);
142 inline int getSamples()
const;
143 inline int getColorSamples()
const;
144 inline void setSamples(
int samples);
145 inline void setColorSamples(
int colorSamples);
147 GLuint getObjectID(
unsigned int contextID,
const GLExtensions *ext)
const;
153 static void deleteRenderBuffer(
unsigned int contextID, GLuint rb);
157 static void flushDeletedRenderBuffers(
unsigned int contextID,
double currentTime,
double& availableTime);
162 static void discardDeletedRenderBuffers(
unsigned int contextID);
164 static int getMaxSamples(
unsigned int contextID,
const GLExtensions* ext);
167 virtual void resizeGLObjectBuffers(
unsigned int maxSize);
172 virtual void releaseGLObjects(
osg::State* = 0)
const;
178 inline void dirtyAll()
const;
184 GLenum _internalFormat;
226 return _internalFormat;
242 return _colorSamples;
253 _colorSamples = colorSamples;
264 if (&rb ==
this)
return 0;
265 if (_internalFormat < rb._internalFormat)
return -1;
266 if (_internalFormat > rb._internalFormat)
return 1;
267 if (_width < rb._width)
return -1;
268 if (_width > rb._width)
return 1;
269 if (_height < rb._height)
return -1;
270 if (_height > rb._height)
return 1;
305 bool isMultisample()
const;
306 void createRequiredTexturesAndApplyGenerateMipMap(
State& state,
const GLExtensions* ext)
const;
307 void attach(
State &state, GLenum target, GLenum attachment_point,
const GLExtensions* ext)
const;
314 const Texture* getTexture()
const;
316 unsigned int getCubeMapFace()
const;
317 unsigned int getTextureLevel()
const;
318 unsigned int getTexture3DZOffset()
const;
319 unsigned int getTextureArrayLayer()
const;
334 typedef std::map<Camera::BufferComponent, FrameBufferAttachment>
AttachmentMap;
344 inline const AttachmentMap& getAttachmentMap()
const;
349 inline bool hasAttachment(BufferComponent attachment_point)
const;
354 bool isMultisample()
const;
358 void apply(
State &state)
const;
362 return _fboID[contextID];
373 void apply(
State &state, BindTarget target)
const;
378 static void deleteFrameBufferObject(
unsigned int contextID, GLuint program);
382 static void flushDeletedFrameBufferObjects(
unsigned int contextID,
double currentTime,
double& availableTime);
386 static void discardDeletedFrameBufferObjects(
unsigned int contextID);
389 virtual void resizeGLObjectBuffers(
unsigned int maxSize);
394 virtual void releaseGLObjects(
osg::State* = 0)
const;
400 void updateDrawBuffers();
402 inline void dirtyAll();
404 GLenum convertBufferComponentToGLenum(BufferComponent attachment_point)
const;
407 AttachmentMap _attachments;
410 MultipleRenderingTargets _drawBuffers;
427 return _attachments.find(attachment_point) != _attachments.end();
432 return _attachments.find(attachment_point)->second;
int compare(const RenderBuffer &rb) const
#define GL_FRAMEBUFFER_EXT
void setColorSamples(int colorSamples)
GLint GLenum internalFormat
const FrameBufferAttachment & getAttachment(BufferComponent attachment_point) const
GLenum getInternalFormat() const
Camera::BufferComponent BufferComponent
#define GL_DRAW_FRAMEBUFFER_EXT
void setInternalFormat(GLenum format)
#define GL_READ_FRAMEBUFFER_EXT
#define META_Object(library, name)
GLint GLenum GLsizei width
bool hasAttachment(BufferComponent attachment_point) const
void setAllElementsTo(const T &t)
int getColorSamples() const
GLuint getHandle(unsigned int contextID) const
#define META_StateAttribute(library, name, type)
std::vector< GLenum > MultipleRenderingTargets
GLint GLenum GLsizei GLsizei height
const AttachmentMap & getAttachmentMap() const
bool hasMultipleRenderingTargets() const
void setSize(int w, int h)
std::map< Camera::BufferComponent, FrameBufferAttachment > AttachmentMap
void setSamples(int samples)
RenderBuffer & operator=(const RenderBuffer &)
const MultipleRenderingTargets & getMultipleRenderingTargets() const
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format