My Project
Loading...
Searching...
No Matches
CFrameBuffer.h
Go to the documentation of this file.
1//==============================================================================
2/*
3 Software License Agreement (BSD License)
4 Copyright (c) 2003-2024, CHAI3D
5 (www.chai3d.org)
6
7 All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
11 are met:
12
13 * Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the following
18 disclaimer in the documentation and/or other materials provided
19 with the distribution.
20
21 * Neither the name of CHAI3D nor the names of its contributors may
22 be used to endorse or promote products derived from this software
23 without specific prior written permission.
24
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 POSSIBILITY OF SUCH DAMAGE.
37
38 \author <http://www.chai3d.org>
39 \author Francois Conti
40 \version 3.3.0
41*/
42//==============================================================================
43
44//------------------------------------------------------------------------------
45#ifndef CFrameBufferH
46#define CFrameBufferH
47//------------------------------------------------------------------------------
48#include "graphics/CImage.h"
49#include "graphics/CColor.h"
51#include "world/CWorld.h"
52//------------------------------------------------------------------------------
53#include <string>
54#include <stdio.h>
55//------------------------------------------------------------------------------
56
57//------------------------------------------------------------------------------
58namespace chai3d {
59//------------------------------------------------------------------------------
60
61//==============================================================================
68//==============================================================================
69
70//------------------------------------------------------------------------------
71class cFrameBuffer;
72typedef std::shared_ptr<cFrameBuffer> cFrameBufferPtr;
73//------------------------------------------------------------------------------
74
75//==============================================================================
86//==============================================================================
88{
89 //--------------------------------------------------------------------------
90 // CONSTRUCTOR & DESTRUCTOR:
91 //--------------------------------------------------------------------------
92
93public:
94
97
99 virtual ~cFrameBuffer();
100
102 static cFrameBufferPtr create() { return (std::make_shared<cFrameBuffer>()); }
103
104
105 //--------------------------------------------------------------------------
106 // PUBLIC METHODS
107 //--------------------------------------------------------------------------
108
109public:
110
112 void setup(cCamera* a_camera = NULL,
113 const unsigned int a_width = 0,
114 const unsigned int a_height = 0,
115 const bool a_enableImageBuffer = true,
116 const bool a_enableDepthBuffer = true);
117
119 void renderView(const cEyeMode a_eyeMode = C_STEREO_LEFT_EYE);
120
122 void copyImageBuffer(cImagePtr a_image);
123
125 void copyDepthBuffer(cImagePtr a_image);
126
127
128 //--------------------------------------------------------------------------
129 // PUBLIC METHODS - CAMERA
130 //--------------------------------------------------------------------------
131
132public:
133
135 void setCamera(cCamera* a_camera) { m_camera = a_camera; }
136
138 cCamera* getCamera() { return (m_camera); }
139
140
141 //--------------------------------------------------------------------------
142 // PUBLIC METHODS - RESOLUTION
143 //--------------------------------------------------------------------------
144
145public:
146
147
149 inline unsigned int getWidth() const { return (m_width); }
150
152 inline unsigned int getHeight() const { return (m_height); }
153
155 void setSize(const unsigned int a_width, const unsigned int a_height);
156
157
158 //--------------------------------------------------------------------------
159 // PUBLIC METHODS - EXPERTS ONLY
160 //--------------------------------------------------------------------------
161
162public:
163
165 bool renderInitialize();
166
168 bool renderFinalize();
169
170
171 //--------------------------------------------------------------------------
172 // PUBLIC MEMBERS - BUFFERS
173 //--------------------------------------------------------------------------
174
175public:
176
179
182
183
184 //--------------------------------------------------------------------------
185 // PROTECTED MEMBERS:
186 //--------------------------------------------------------------------------
187
188protected:
189
192
195
197 unsigned int m_width;
198
200 unsigned int m_height;
201
203 unsigned int m_prevWidth;
204
206 unsigned int m_prevHeight;
207
210
212 GLuint m_fbo;
213};
214
215//------------------------------------------------------------------------------
216} // namespace chai3d
217//------------------------------------------------------------------------------
218
219//------------------------------------------------------------------------------
220#endif
221//------------------------------------------------------------------------------
222
Implements color properties.
Implements a 2D image data structure.
Implements 2D textures.
Implementation of a virtual world.
This class implements a virtual camera.
Definition CCamera.h:111
This class implements an OpenGL framebuffer.
Definition CFrameBuffer.h:88
void setSize(const unsigned int a_width, const unsigned int a_height)
This method sets the resolution of the framebuffer by defining its width and height in pixels.
Definition CFrameBuffer.cpp:147
unsigned int m_width
Width in pixels of the frame buffer.
Definition CFrameBuffer.h:197
unsigned int m_prevWidth
Last width value that was used when allocating texture size.
Definition CFrameBuffer.h:203
bool m_useDepthBuffer
If true then image buffer is enabled, false otherwise.
Definition CFrameBuffer.h:194
void copyDepthBuffer(cImagePtr a_image)
This method copies the depth buffer content to an image.
Definition CFrameBuffer.cpp:219
void copyImageBuffer(cImagePtr a_image)
This method copies the framebuffer content to an image.
Definition CFrameBuffer.cpp:180
bool renderFinalize()
This method finalizes the rendering to the framebuffer.
Definition CFrameBuffer.cpp:439
cTexture2dPtr m_imageBuffer
Image buffer.
Definition CFrameBuffer.h:178
void renderView(const cEyeMode a_eyeMode=C_STEREO_LEFT_EYE)
This method renders the framebuffer view.
Definition CFrameBuffer.cpp:465
GLuint m_fbo
OpenGL frame buffer object.
Definition CFrameBuffer.h:212
unsigned int m_prevHeight
Last height value that was used when allocating texture size.
Definition CFrameBuffer.h:206
cTexture2dPtr m_depthBuffer
Depth buffer.
Definition CFrameBuffer.h:181
unsigned int m_height
Height in pixels of the frame buffer.
Definition CFrameBuffer.h:200
bool renderInitialize()
This method initializes rendering to the framebuffer.
Definition CFrameBuffer.cpp:261
void setCamera(cCamera *a_camera)
This method attaches a camera to the framebuffer.
Definition CFrameBuffer.h:135
cFrameBuffer()
Constructor of cFrameBuffer.
Definition CFrameBuffer.cpp:57
virtual ~cFrameBuffer()
Destructor of cFrameBuffer.
Definition CFrameBuffer.cpp:75
void setup(cCamera *a_camera=NULL, const unsigned int a_width=0, const unsigned int a_height=0, const bool a_enableImageBuffer=true, const bool a_enableDepthBuffer=true)
This method initializes the framebuffer.
Definition CFrameBuffer.cpp:100
static cFrameBufferPtr create()
Shared cFrameBuffer allocator.
Definition CFrameBuffer.h:102
unsigned int getWidth() const
This method returns the width in pixels of the framebuffer.
Definition CFrameBuffer.h:149
cCamera * getCamera()
This method returns a pointer to the camera attached to the framebuffer.
Definition CFrameBuffer.h:138
cCamera * m_camera
Camera associated with this framebuffer.
Definition CFrameBuffer.h:209
bool m_useImageBuffer
If true then image buffer is enabled, false otherwise.
Definition CFrameBuffer.h:191
unsigned int getHeight() const
This method returns the height in pixels of the framebuffer.
Definition CFrameBuffer.h:152
Definition CAudioBuffer.cpp:57
cEyeMode
Definition CCamera.h:74
@ C_STEREO_LEFT_EYE
Definition CCamera.h:75
std::shared_ptr< cFrameBuffer > cFrameBufferPtr
Definition CFrameBuffer.h:72
std::shared_ptr< cImage > cImagePtr
Definition CImage.h:64
std::shared_ptr< cTexture2d > cTexture2dPtr
Definition CTexture2d.h:69