frame_buffer.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Harry Storbacka
28 */
29
30
31 #pragma once
32
33 #include <memory>
34
35 namespace clan
36 {
39
40 class Size;
41 class Rect;
42 class Texture1D;
43 class Texture1DArray;
44 class Texture2D;
45 class Texture2DArray;
46 class Texture3D;
47 class TextureCube;
48 class RenderBuffer;
49 class GraphicContext;
50 class FrameBufferProvider;
51 class FrameBuffer_Impl;
52
54 enum TextureSubtype
55 {
56 subtype_cube_map_positive_x,
57 subtype_cube_map_negative_x,
58 subtype_cube_map_positive_y,
59 subtype_cube_map_negative_y,
60 subtype_cube_map_positive_z,
61 subtype_cube_map_negative_z
62 };
63
65 enum FrameBufferBindTarget
66 {
67 framebuffer_draw,
68 framebuffer_read
69 };
70
72 class FrameBuffer
73 {
76 public:
78 FrameBuffer();
79
85 FrameBuffer(GraphicContext &context);
86
90 public:
92 bool is_null() const { return !impl; }
93
95 void throw_if_null() const;
96
100 FrameBufferProvider *get_provider() const;
101
105 Size get_size() const;
106
110 FrameBufferBindTarget get_bind_target() const;
111
115 public:
117 bool operator==(const FrameBuffer &other) const;
118
123 void attach_color(int attachment_index, const RenderBuffer &render_buffer);
124
130 void attach_color(int attachment_index, const Texture1D &texture, int level = 0);
131
138 void attach_color(int attachment_index, const Texture1DArray &texture, int array_index = -1, int level = 0);
139
145 void attach_color(int attachment_index, const Texture2D &texture, int level = 0);
146
153 void attach_color(int attachment_index, const Texture2DArray &texture, int array_index = -1, int level = 0);
154
161 void attach_color(int attachment_index, const Texture3D &texture, int depth, int level = 0);
162
170 void attach_color(int attachment_index, const TextureCube &texture, TextureSubtype subtype, int level = 0);
171
178 void detach_color(int attachment_index);
179
180 void attach_stencil(const RenderBuffer &render_buffer);
181 void attach_stencil(const Texture2D &texture, int level = 0);
182 void attach_stencil(const TextureCube &texture, TextureSubtype subtype, int level = 0);
183 void detach_stencil();
184
185 void attach_depth(const RenderBuffer &render_buffer);
186 void attach_depth(const Texture2D &texture, int level = 0);
187 void attach_depth(const TextureCube &texture, TextureSubtype subtype, int level = 0);
188 void detach_depth();
189
190 void attach_depth_stencil(const RenderBuffer &render_buffer);
191 void attach_depth_stencil(const Texture2D &texture, int level = 0);
192 void attach_depth_stencil(const TextureCube &texture, TextureSubtype subtype, int level = 0);
193 void detach_depth_stencil();
194
200 void set_bind_target(FrameBufferBindTarget target);
201
206 float get_pixel_ratio() const;
207
208
212 private:
213 std::shared_ptr<FrameBuffer_Impl> impl;
215 };
216
217 }
218
clan::Texture3D
3D texture object class.
Definition: texture_3d.h:41
clan::subtype_cube_map_positive_x
Definition: frame_buffer.h:56
clan
Definition: clanapp.h:35
clan::FrameBuffer
Frame-buffer object class.
Definition: frame_buffer.h:72
clan::FrameBuffer::operator==
bool operator==(const FrameBuffer &other) const
Equality operator.
clan::Texture1DArray
1D texture array object class.
Definition: texture_1d_array.h:41
clan::TextureCube
2D texture cube object class.
Definition: texture_cube.h:52
clan::FrameBuffer::attach_color
void attach_color(int attachment_index, const RenderBuffer &render_buffer)
Attach color buffer.
clan::subtype_cube_map_positive_z
Definition: frame_buffer.h:60
clan::FrameBuffer::set_bind_target
void set_bind_target(FrameBufferBindTarget target)
Set the bind target of the framebuffer to either drawn to or read from.
clan::FrameBuffer::is_null
bool is_null() const
Returns true if this object is invalid.
Definition: frame_buffer.h:92
clan::Texture2D
2D texture object class.
Definition: texture_2d.h:41
clan::framebuffer_read
Definition: frame_buffer.h:68
clan::FrameBuffer::detach_color
void detach_color(int attachment_index)
Detach color buffer.
clan::FrameBuffer::FrameBuffer
FrameBuffer()
Constructs a null instance.
clan::subtype_cube_map_negative_z
Definition: frame_buffer.h:61
clan::FrameBufferBindTarget
FrameBufferBindTarget
Framebuffer bind target.
Definition: frame_buffer.h:65
clan::subtype_cube_map_positive_y
Definition: frame_buffer.h:58
clan::FrameBuffer::detach_depth_stencil
void detach_depth_stencil()
clan::GraphicContext
Interface to drawing graphics.
Definition: graphic_context.h:257
clan::TextureSubtype
TextureSubtype
Texture Subtype.
Definition: frame_buffer.h:54
clan::FrameBuffer::get_provider
FrameBufferProvider * get_provider() const
Get Provider.
clan::FrameBuffer::get_size
Size get_size() const
Get the minumum size of all the frame buffer attachments.
clan::FrameBuffer::attach_stencil
void attach_stencil(const RenderBuffer &render_buffer)
clan::FrameBuffer::throw_if_null
void throw_if_null() const
Throw an exception if this object is invalid.
clan::FrameBuffer::get_pixel_ratio
float get_pixel_ratio() const
clan::FrameBuffer::attach_depth
void attach_depth(const RenderBuffer &render_buffer)
clan::framebuffer_draw
Definition: frame_buffer.h:67
clan::Size
2D (width,height) size structure - Integer
Definition: size.h:156
clan::FrameBufferProvider
Interface for implementing a FrameBuffer target.
Definition: frame_buffer_provider.h:45
clan::subtype_cube_map_negative_y
Definition: frame_buffer.h:59
clan::FrameBuffer::attach_depth_stencil
void attach_depth_stencil(const RenderBuffer &render_buffer)
clan::FrameBuffer::get_bind_target
FrameBufferBindTarget get_bind_target() const
Get the bind target of the framebuffer.
clan::FrameBuffer::detach_stencil
void detach_stencil()
clan::Texture1D
1D texture object class.
Definition: texture_1d.h:41
clan::Texture2DArray
2D texture array object class.
Definition: texture_2d_array.h:43
clan::RenderBuffer
Render-buffer object class.
Definition: render_buffer.h:47
clan::subtype_cube_map_negative_x
Definition: frame_buffer.h:57
clan::FrameBuffer::detach_depth
void detach_depth()