reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofFbo.h
Go to the documentation of this file.
1#pragma once
2
3// depthBufferTex only
4#include "ofTexture.h"
5#include "ofGLBaseTypes.h"
6
13
15 return static_cast<ofFboMode>(short(m1) | short(m2));
16}
17
18inline bool operator & (ofFboMode m1, ofFboMode m2){
19 return static_cast<bool>(short(m1) & short(m2));
20}
21
24 int width;
25 int height;
27 std::vector<GLint> colorFormats;
28 bool useDepth;
39 ofFboSettings(std::shared_ptr<ofBaseGLRenderer> renderer=nullptr);
40 bool operator!=(const ofFboSettings & other);
41private:
42 std::weak_ptr<ofBaseGLRenderer> renderer;
43 friend class ofFbo;
44};
45
46class ofFbo : public ofBaseDraws, public ofBaseHasTexture {
47public:
48
49 ofFbo();
50 ofFbo(const ofFbo & mom);
51 ofFbo & operator=(const ofFbo & fbo);
52 ofFbo(ofFbo && mom);
53 ofFbo & operator=(ofFbo && fbo);
54 virtual ~ofFbo();
55
58
59 void allocate(int width, int height, int internalformat = GL_RGBA, int numSamples = 0);
60 //void allocateForShadow(int width, int height);
61 void allocate(ofFboSettings settings = ofFboSettings(nullptr));
62 bool isAllocated() const;
63
64 OF_DEPRECATED_MSG("Use clear() instead",void destroy());
65 void clear();
66
67#ifndef TARGET_OPENGLES
71 void clearColorBuffer(const ofFloatColor & color);
72
76 void clearColorBuffer(size_t buffer_idx, const ofFloatColor & color);
77
81 void clearDepthBuffer(float value);
82
86 void clearStencilBuffer(int value);
87
91 void clearDepthStencilBuffer(float depth, int stencil);
92#endif
93
95 void draw(float x, float y) const;
96 void draw(float x, float y, float width, float height) const;
97
98 void setAnchorPercent(float xPct, float yPct);
99 void setAnchorPoint(float x, float y);
100 void resetAnchor();
101
102 void setDefaultTextureIndex(int defaultTexture);
103 int getDefaultTextureIndex() const;
104
105 OF_DEPRECATED_MSG("Use getTexture()",ofTexture & getTextureReference());
106 OF_DEPRECATED_MSG("Use getTexture()",ofTexture & getTextureReference(int attachmentPoint));
108 ofTexture & getTexture(int attachmentPoint);
110 OF_DEPRECATED_MSG("Use getTexture()",const ofTexture & getTextureReference() const);
111 OF_DEPRECATED_MSG("Use getTexture()",const ofTexture & getTextureReference(int attachmentPoint) const);
112 const ofTexture & getTexture() const ;
113 const ofTexture & getTexture(int attachmentPoint) const;
114 const ofTexture & getDepthTexture() const;
115 void setUseTexture(bool){ /*irrelevant*/ };
116 bool isUsingTexture() const {return true;}
117
126 OF_DEPRECATED_MSG("Use begin(OF_FBOMODE_NODEFAULTS) instead", void begin(bool setupScreen) const);
127
154
157 void end() const;
158
159 void readToPixels(ofPixels & pixels, int attachmentPoint = 0) const;
160 void readToPixels(ofShortPixels & pixels, int attachmentPoint = 0) const;
161 void readToPixels(ofFloatPixels & pixels, int attachmentPoint = 0) const;
162
163#ifndef TARGET_OPENGLES
166 void copyTo(ofBufferObject & buffer) const;
167#endif
168
169 float getWidth() const;
170 float getHeight() const;
171
172 // advanced functions
173
184 void bind() const;
185
190 void unbind() const;
191
192 void flagDirty() const;
193
199 void updateTexture(int attachmentPoint);
200
201 bool checkStatus() const;
202 void createAndAttachTexture(GLenum internalFormat, GLenum attachmentPoint);
203 void attachTexture(ofTexture & texture, GLenum internalFormat, GLenum attachmentPoint);
204 GLuint createAndAttachRenderbuffer(GLenum internalFormat, GLenum attachmentPoint);
205 void createAndAttachDepthStencilTexture(GLenum target, GLint internalformat, GLenum attachment );
206 void createAndAttachDepthStencilTexture(GLenum target, GLint internalformat, GLenum attachment, GLenum transferFormat, GLenum transferType );
207
208 int getNumTextures() const;
209
210 void setActiveDrawBuffer(int i);
211 void setActiveDrawBuffers(const std::vector<int>& i);
213
214 OF_DEPRECATED_MSG("Use getId()", GLuint getFbo() const);
215
217 GLuint getId() const;
218
221 GLuint getIdDrawBuffer() const;
222
223 static bool checkGLSupport();
224 static int maxColorAttachments(); // return max color attachments
225 static int maxDrawBuffers(); // return max simultaneous draw buffers
226 static int maxSamples(); // return max MSAA samples
227
228 GLuint getDepthBuffer() const { return depthBuffer; }
229 GLuint getStencilBuffer() const { return stencilBuffer; }
230
231private:
232 ofFboSettings settings;
233
234 GLuint fbo; // main fbo which we bind for drawing into, all renderbuffers are attached to this
235 GLuint fboTextures; // textures are attached to this (if MSAA is disabled, this is equal to fbo, otherwise it's a new fbo)
236 GLuint depthBuffer;
237 GLuint stencilBuffer;
238
239 std::vector<GLuint> colorBuffers;
240 std::vector<ofTexture> textures;
241
242 ofTexture depthBufferTex;
243
244 static int _maxColorAttachments;
245 static int _maxDrawBuffers;
246 static int _maxSamples;
247
248 std::vector<GLenum> activeDrawBuffers;
249
258 mutable std::vector<bool> dirty;
259
260 int defaultTextureIndex; //used for getTextureReference
261 bool bIsAllocated;
262 void reloadFbo();
263#ifdef TARGET_OPENGLES
264 static bool bglFunctionsInitialized;
265#endif
266
267};
268
269
Definition ofGraphicsBaseTypes.h:139
virtual void draw(float x, float y) const
Draw at a position at the native size.
Definition ofGraphicsBaseTypes.h:150
An abstract class representing an object that can have an ofTexture.
Definition ofGLBaseTypes.h:11
Definition ofBufferObject.h:8
Definition ofFbo.h:46
void updateTexture(int attachmentPoint)
Explicityl resolve MSAA render buffers into textures.
Definition ofFbo.cpp:1103
static bool checkGLSupport()
Definition ofFbo.cpp:490
void setActiveDrawBuffer(int i)
Definition ofFbo.cpp:935
OF_DEPRECATED_MSG("Use getTexture()", const ofTexture &getTextureReference() const)
ofFbo()
Definition ofFbo.cpp:232
void activateAllDrawBuffers()
Definition ofFbo.cpp:965
void clearDepthBuffer(float value)
Definition ofFbo.cpp:469
bool checkStatus() const
Definition ofFbo.cpp:1177
void unbind() const
Unbinds OpenGL framebuffer target and restores the OpenGL framebuffer render target to whatever this ...
Definition ofFbo.cpp:904
OF_DEPRECATED_MSG("Use getTexture()", const ofTexture &getTextureReference(int attachmentPoint) const)
void allocate(int width, int height, int internalformat=GL_RGBA, int numSamples=0)
Definition ofFbo.cpp:525
void attachTexture(ofTexture &texture, GLenum internalFormat, GLenum attachmentPoint)
Definition ofFbo.cpp:775
static int maxColorAttachments()
Definition ofFbo.cpp:405
OF_DEPRECATED_MSG("Use getId()", GLuint getFbo() const)
GLuint getDepthBuffer() const
Definition ofFbo.h:228
void copyTo(ofBufferObject &buffer) const
Copy the fbo to an ofBufferObject.
Definition ofFbo.cpp:1092
void clearStencilBuffer(int value)
Definition ofFbo.cpp:474
virtual ~ofFbo()
Definition ofFbo.cpp:400
void clearDepthStencilBuffer(float depth, int stencil)
Definition ofFbo.cpp:479
ofTexture & getTexture()
Definition ofFbo.cpp:1009
void clear()
Definition ofFbo.cpp:424
float getWidth() const
Get the width.
Definition ofFbo.cpp:1165
void clearColorBuffer(const ofFloatColor &color)
Definition ofFbo.cpp:459
ofTexture & getDepthTexture()
Definition ofFbo.cpp:1221
void readToPixels(ofPixels &pixels, int attachmentPoint=0) const
Definition ofFbo.cpp:1049
bool isAllocated() const
Definition ofFbo.cpp:725
GLuint createAndAttachRenderbuffer(GLenum internalFormat, GLenum attachmentPoint)
Definition ofFbo.cpp:730
void setAnchorPercent(float xPct, float yPct)
Set the anchor point the item is drawn around as a percentage.
Definition ofFbo.cpp:1034
GLuint getIdDrawBuffer() const
Definition ofFbo.cpp:1160
void setAnchorPoint(float x, float y)
Set the anchor point the item is drawn around in pixels.
Definition ofFbo.cpp:1039
ofFboSettings Settings
ofFbo::Settings is currently deprecated in favor of the ofFboSettings struct
Definition ofFbo.h:57
GLuint getStencilBuffer() const
Definition ofFbo.h:229
void draw(float x, float y) const
Draw at a position at the native size.
Definition ofFbo.cpp:1139
void createAndAttachDepthStencilTexture(GLenum target, GLint internalformat, GLenum attachment)
Definition ofFbo.cpp:820
void setDefaultTextureIndex(int defaultTexture)
Definition ofFbo.cpp:977
OF_DEPRECATED_MSG("Use begin(OF_FBOMODE_NODEFAULTS) instead", void begin(bool setupScreen) const)
float getHeight() const
Get the height.
Definition ofFbo.cpp:1171
void begin(ofFboMode mode=OF_FBOMODE_PERSPECTIVE|OF_FBOMODE_MATRIXFLIP) const
Definition ofFbo.cpp:835
int getNumTextures() const
Definition ofFbo.cpp:930
void flagDirty() const
check whether attached MSAA buffers need updating
Definition ofFbo.cpp:912
void setUseTexture(bool)
Enable or disable internal ofTexture use.
Definition ofFbo.h:115
bool isUsingTexture() const
Definition ofFbo.h:116
int getDefaultTextureIndex() const
Definition ofFbo.cpp:983
OF_DEPRECATED_MSG("Use clear() instead", void destroy())
void end() const
Ends the current framebuffer render context.
Definition ofFbo.cpp:888
void setActiveDrawBuffers(const std::vector< int > &i)
Definition ofFbo.cpp:944
static int maxDrawBuffers()
Definition ofFbo.cpp:411
OF_DEPRECATED_MSG("Use getTexture()", ofTexture &getTextureReference(int attachmentPoint))
void resetAnchor()
Reset the anchor point to (0, 0).
Definition ofFbo.cpp:1044
void createAndAttachTexture(GLenum internalFormat, GLenum attachmentPoint)
Definition ofFbo.cpp:752
ofFbo & operator=(const ofFbo &fbo)
Definition ofFbo.cpp:306
OF_DEPRECATED_MSG("Use getTexture()", ofTexture &getTextureReference())
void bind() const
Bind OpenGL GL_FRAMEBUFFER target to this ofFbo.
Definition ofFbo.cpp:896
GLuint getId() const
returns id of the underlying GL object for advanced actions
Definition ofFbo.cpp:1155
static int maxSamples()
Definition ofFbo.cpp:417
A wrapper class for an OpenGL texture.
Definition ofTexture.h:253
unsigned int height
Definition ofAppEGLWindow.cpp:125
unsigned int width
Definition ofAppEGLWindow.cpp:124
ofFboMode operator|(ofFboMode m1, ofFboMode m2)
Definition ofFbo.h:14
bool operator&(ofFboMode m1, ofFboMode m2)
Definition ofFbo.h:18
ofFboMode
ofFbo mode(s) when binding
Definition ofFbo.h:8
@ OF_FBOMODE_MATRIXFLIP
flip vertically
Definition ofFbo.h:11
@ OF_FBOMODE_NODEFAULTS
base GL fbo, no OF defaults
Definition ofFbo.h:9
@ OF_FBOMODE_PERSPECTIVE
set OF perspective and viewport
Definition ofFbo.h:10
ofFbo internal settings
Definition ofFbo.h:23
bool operator!=(const ofFboSettings &other)
Definition ofFbo.cpp:99
GLenum textureTarget
GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE_ARB.
Definition ofFbo.h:31
int numSamples
number of samples for multisampling (set 0 to disable)
Definition ofFbo.h:38
int height
height of images attached to fbo
Definition ofFbo.h:25
GLint internalformat
GL_RGBA, GL_RGBA16F_ARB, GL_RGBA32F_ARB, GL_LUMINANCE32F_ARB etc.
Definition ofFbo.h:32
int numColorbuffers
how many color buffers to create
Definition ofFbo.h:26
bool useDepth
whether to use depth buffer or not
Definition ofFbo.h:28
int wrapModeHorizontal
GL_REPEAT, GL_MIRRORED_REPEAT, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER etc.
Definition ofFbo.h:34
int minFilter
GL_NEAREST, GL_LINEAR etc.
Definition ofFbo.h:36
int width
width of images attached to fbo
Definition ofFbo.h:24
std::vector< GLint > colorFormats
format of the color attachments for MRT.
Definition ofFbo.h:27
GLint depthStencilInternalFormat
GL_DEPTH_COMPONENT(16/24/32)
Definition ofFbo.h:33
int maxFilter
GL_NEAREST, GL_LINEAR etc.
Definition ofFbo.h:37
bool depthStencilAsTexture
use a texture instead of a renderbuffer for depth (useful to draw it or use it in a shader later)
Definition ofFbo.h:30
bool useStencil
whether to use stencil buffer or not
Definition ofFbo.h:29
int wrapModeVertical
GL_REPEAT, GL_MIRRORED_REPEAT, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER etc.
Definition ofFbo.h:35