CHAI3D  3.0.0
CFrameBuffer.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2015, 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.0.0 $Rev: 1242 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 #ifndef CFrameBufferH
46 #define CFrameBufferH
47 //------------------------------------------------------------------------------
48 #include "graphics/CImage.h"
49 #include "graphics/CColor.h"
50 #include "materials/CTexture2d.h"
51 #include "world/CWorld.h"
52 //------------------------------------------------------------------------------
53 #include <string>
54 #include <stdio.h>
55 //------------------------------------------------------------------------------
56 
57 //------------------------------------------------------------------------------
58 namespace chai3d {
59 //------------------------------------------------------------------------------
60 
61 //==============================================================================
68 //==============================================================================
69 
70 //------------------------------------------------------------------------------
72 typedef std::shared_ptr<cFrameBuffer> cFrameBufferPtr;
73 //------------------------------------------------------------------------------
74 
75 //==============================================================================
86 //==============================================================================
88 {
89  //--------------------------------------------------------------------------
90  // CONSTRUCTOR & DESTRUCTOR:
91  //--------------------------------------------------------------------------
92 
93 public:
94 
96  cFrameBuffer();
97 
99  virtual ~cFrameBuffer();
100 
102  static cFrameBufferPtr create() { return (std::make_shared<cFrameBuffer>()); }
103 
104 
105  //--------------------------------------------------------------------------
106  // PUBLIC METHODS
107  //--------------------------------------------------------------------------
108 
109 public:
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  const int a_displayContext = 0);
121 
123  void copyImageBuffer(cImagePtr a_image, const int a_displayContext = 0);
124 
126  void copyDepthBuffer(cImagePtr a_image, const int a_displayContext = 0);
127 
128 
129  //--------------------------------------------------------------------------
130  // PUBLIC METHODS - CAMERA
131  //--------------------------------------------------------------------------
132 
133 public:
134 
136  void setCamera(cCamera* a_camera) { m_camera = a_camera; }
137 
139  cCamera* getCamera() { return (m_camera); }
140 
141 
142  //--------------------------------------------------------------------------
143  // PUBLIC METHODS - RESOLUTION
144  //--------------------------------------------------------------------------
145 
146 public:
147 
148 
150  inline unsigned int getWidth() const { return (m_width); }
151 
153  inline unsigned int getHeight() const { return (m_height); }
154 
156  void setSize(const unsigned int a_width, const unsigned int a_height);
157 
158 
159  //--------------------------------------------------------------------------
160  // PUBLIC METHODS - EXPERTS ONLY
161  //--------------------------------------------------------------------------
162 
163 public:
164 
166  bool renderInitialize(const int a_displayContext = 0);
167 
169  bool renderFinalize(const int a_displayContext = 0);
170 
171 
172  //--------------------------------------------------------------------------
173  // PUBLIC MEMBERS - BUFFERS
174  //--------------------------------------------------------------------------
175 
176 public:
177 
180 
183 
184 
185  //--------------------------------------------------------------------------
186  // PROTECTED MEMBERS:
187  //--------------------------------------------------------------------------
188 
189 protected:
190 
193 
196 
198  unsigned int m_width;
199 
201  unsigned int m_height;
202 
204  unsigned int m_prevWidth;
205 
207  unsigned int m_prevHeight;
208 
211 
213  GLuint m_fbo[C_MAX_DISPLAY_CONTEXTS];
214 };
215 
216 //------------------------------------------------------------------------------
217 } // namespace chai3d
218 //------------------------------------------------------------------------------
219 
220 //------------------------------------------------------------------------------
221 #endif
222 //------------------------------------------------------------------------------
223 
std::shared_ptr< cTexture2d > cTexture2dPtr
Definition: CTexture2d.h:68
Definition: CCamera.h:75
unsigned int m_width
Width in pixels of the frame buffer.
Definition: CFrameBuffer.h:198
void setCamera(cCamera *a_camera)
This method attaches a camera to the framebuffer.
Definition: CFrameBuffer.h:136
std::shared_ptr< cFrameBuffer > cFrameBufferPtr
Definition: CFrameBuffer.h:71
unsigned int m_prevHeight
Last height value that was used when allocating texture size.
Definition: CFrameBuffer.h:207
cTexture2dPtr m_imageBuffer
Image buffer.
Definition: CFrameBuffer.h:179
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:106
virtual ~cFrameBuffer()
Destructor of cFrameBuffer.
Definition: CFrameBuffer.cpp:81
unsigned int getHeight() const
This method returns the height in pixels of the framebuffer.
Definition: CFrameBuffer.h:153
unsigned int m_prevWidth
Last width value that was used when allocating texture size.
Definition: CFrameBuffer.h:204
cTexture2dPtr m_depthBuffer
Depth buffer.
Definition: CFrameBuffer.h:182
bool renderInitialize(const int a_displayContext=0)
This method initializes rendering to the framebuffer.
Definition: CFrameBuffer.cpp:265
This class implements an OpenGL framebuffer.
Definition: CFrameBuffer.h:87
GLuint m_fbo[C_MAX_DISPLAY_CONTEXTS]
OpenGL frame buffer object.
Definition: CFrameBuffer.h:213
Implementation of a virtual world.
bool m_useImageBuffer
If true then image buffer is enabled, false otherwise.
Definition: CFrameBuffer.h:192
cFrameBuffer()
Constructor of cFrameBuffer.
Definition: CFrameBuffer.cpp:57
cCamera * m_camera
Camera associated with this framebuffer.
Definition: CFrameBuffer.h:210
unsigned int m_height
Height in pixels of the frame buffer.
Definition: CFrameBuffer.h:201
cCamera * getCamera()
This method returns a pointer to the camera attached to the framebuffer.
Definition: CFrameBuffer.h:139
This class implements a virtual camera.
Definition: CCamera.h:110
void copyDepthBuffer(cImagePtr a_image, const int a_displayContext=0)
This method copies the depth buffer content to an image.
Definition: CFrameBuffer.cpp:221
void copyImageBuffer(cImagePtr a_image, const int a_displayContext=0)
This method copies the framebuffer content to an image.
Definition: CFrameBuffer.cpp:181
Implements color properties.
std::shared_ptr< cImage > cImagePtr
Definition: CImage.h:63
static cFrameBufferPtr create()
Shared cFrameBuffer allocator.
Definition: CFrameBuffer.h:102
Definition: CAudioBuffer.cpp:56
cEyeMode
Definition: CCamera.h:73
bool renderFinalize(const int a_displayContext=0)
This method finalizes the rendering to the framebuffer.
Definition: CFrameBuffer.cpp:445
Implements 2D textures.
bool m_useDepthBuffer
If true then image buffer is enabled, false otherwise.
Definition: CFrameBuffer.h:195
void renderView(const cEyeMode a_eyeMode=C_STEREO_LEFT_EYE, const int a_displayContext=0)
This method renders the framebuffer view.
Definition: CFrameBuffer.cpp:472
Implements a 2D image data structure.
unsigned int getWidth() const
This method returns the width in pixels of the framebuffer.
Definition: CFrameBuffer.h:150
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:153

CHAI3D 3.0.0 documentation
Please address any questions to support@chai3d.org
(C) 2003-2015 - CHAI3D
All Rights Reserved.