hx3d  1
2D/3D Simple Game Framework
framebuffer.hpp
1 /*
2  Framebuffer.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #ifndef HX3D_GRAPHICS_FRAMEBUFFER
22 #define HX3D_GRAPHICS_FRAMEBUFFER
23 
24 #include "hx3d/graphics/gl.hpp"
25 #include "hx3d/graphics/color.hpp"
26 
27 #include "hx3d/utils/ptr.hpp"
28 
29 namespace hx3d {
30 namespace graphics {
31 
32 class Texture;
33 
37 class Framebuffer {
38 
39 public:
43  Framebuffer();
44  ~Framebuffer();
45 
52  Framebuffer(unsigned int width, unsigned int height);
53 
60 
67  void resize(unsigned int width, unsigned int height);
68 
70 
74  static void fetchDefaultFramebuffer();
75 
81  static void use(Framebuffer& buf);
82 
86  static void useDefault();
87 
91  static void clear(Color color);
92 
93 private:
95  unsigned int _width;
97  unsigned int _height;
98 
100  GLuint _id;
102  Ptr<Texture> _colorBuffer;
104  GLuint _depthBuffer;
105 
107  static GLint _defaultID;
108 
112  void create();
113 
120  void createRenderBuffer(GLuint& id, GLenum format);
121 };
122 
123 } /* graphics */
124 } /* hx3d */
125 
126 #endif
std::string format(const std::string fmt,...)
Format a string using printf notation.
Definition: string.cpp:27
Ptr< Texture > getColorBuffer()
Get the framebuffer color buffer.
Four [0..255] components defined color.
Definition: color.hpp:32
static void fetchDefaultFramebuffer()
Fetch the default framebuffer of the application.
Definition: framebuffer.cpp:63
hx3d framework namespace
Definition: audio.hpp:26
void resize(unsigned int width, unsigned int height)
Resize the framebuffer.
Definition: framebuffer.cpp:56
Render-to-texture buffer.
Definition: framebuffer.hpp:37
Framebuffer()
Create a framebuffer at screen size.
Definition: framebuffer.cpp:36
static void useDefault()
Use the default framebuffer.
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
Definition: ptr.hpp:34
static void use(Framebuffer &buf)
Use the framebuffer as current framebuffer.
Definition: framebuffer.cpp:95
static void clear(Color color)
Clear the framebuffer.