-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathFBO.h
105 lines (81 loc) · 3.7 KB
/
FBO.h
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
/*
This file is part of the Rendering library.
Copyright (C) 2007-2012 Benjamin Eikel <[email protected]>
Copyright (C) 2007-2012 Claudius Jähn <[email protected]>
Copyright (C) 2007-2012 Ralf Petring <[email protected]>
Copyright (C) 2018 Sascha Brandt <[email protected]>
This library is subject to the terms of the Mozilla Public License, v. 2.0.
You should have received a copy of the MPL along with this library; see the
file LICENSE. If not, you can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef RENDERING_FBO_H
#define RENDERING_FBO_H
#include <Geometry/Rect.h>
#include <Util/ReferenceCounter.h>
#include <cstdint>
namespace Rendering {
class RenderingContext;
class Texture;
/*! Representation of a frame buffer object (FBO).
\see A good introduction http://www.songho.ca/opengl/gl_fbo.html
\code
// create a FBO
Util::Reference<FBO> fbo = new FBO;
// create a color and depthTexures
Util::Reference<Texture> depthTexture = TextureUtils::createDepthTexture(width, height);
Util::Reference<Texture> colorTexture = TextureUtils::createStdTexture(width, height, true);
myRenderingContext.pushFBO(fbo.get()); // enable FBO
// attach textures
fbo->attachColorTexture(colorTexture.get());
fbo->attachDepthTexture(depthTexture.get());
// check framebuffer
if(!fbo->isComplete()){
WARN( fbo->getStatusMessage() );
myRenderingContext.popFBO();
return;
}
myRenderingContext.popFBO(); // disable FBO
//...
myRenderingContext.pushFBO(fbo.get());
// ... do some rendering
myRenderingContext.popFBO();
// download a texture to access the pixel data
colorTexture->downloadGLTexture();
\endcode
@ingroup rendering_resources
*/
class FBO : public Util::ReferenceCounter<FBO> {
public:
RENDERINGAPI FBO();
RENDERINGAPI ~FBO();
//! \note is called by RenderingContext and should not be called directy
RENDERINGAPI static void _disable();
//! \note is called by RenderingContext and should not be called directy
RENDERINGAPI void _enable();
RENDERINGAPI bool isComplete(RenderingContext & context);
RENDERINGAPI const char * getStatusMessage(RenderingContext & context);
RENDERINGAPI void attachTexture(RenderingContext & context, uint32_t attachmentPoint, Texture * t, uint32_t level, int32_t layer=-1);
void detachTexture(RenderingContext & context, uint32_t attachmentPoint) { attachTexture(context,attachmentPoint,nullptr,0,-1); }
RENDERINGAPI void attachColorTexture(RenderingContext & context, Texture * t, uint32_t colorBufferId = 0, uint32_t level=0, int32_t layer=-1);
RENDERINGAPI void detachColorTexture(RenderingContext & context, uint32_t colorBufferId = 0);
RENDERINGAPI void attachDepthStencilTexture(RenderingContext & context, Texture * t, uint32_t level=0, int32_t layer=-1);
RENDERINGAPI void detachDepthStencilTexture(RenderingContext & context);
RENDERINGAPI void attachDepthTexture(RenderingContext & context, Texture * t, uint32_t level=0, int32_t layer=-1);
RENDERINGAPI void detachDepthTexture(RenderingContext & context);
/**
* Activate the given number of draw buffers.
*
* @param number Number of draw buffers to activate. Must be from [0, 8].
* @throw std::invalid_argument if @a number is greater than eight.
* @throw std::logic_error if the GL implementation does not support this functionality.
* @see function @c glDrawBuffers
*/
RENDERINGAPI void setDrawBuffers(RenderingContext & context, uint32_t number);
//! copy a block of pixels from this framebuffer to the screen
RENDERINGAPI void blitToScreen(RenderingContext & context, const Geometry::Rect_i& srcRect, const Geometry::Rect_i& tgtRect);
uint32_t getHandle() const { return glId; }
private:
uint32_t glId;
};
}
#endif // RENDERING_FBO_H