cgv
Loading...
Searching...
No Matches
frame_buffer.cxx
1#include "frame_buffer.h"
2
3namespace cgv {
4 namespace render {
5
7{
8 width = -1;
9 height = -1;
10}
11
12void frame_buffer::blit_to(context& ctx, const ivec4& src_rect, const ivec4& dst_rect, BufferTypeBits btbs, bool interpolate) const
13{
14 ctx.frame_buffer_blit(this, src_rect, 0, dst_rect, btbs, interpolate);
15}
16
17void frame_buffer::blit_to(context& ctx, frame_buffer& dst_fbo, const ivec4& src_rect, const ivec4& dst_rect, BufferTypeBits btbs, bool interpolate) const
18{
19 ctx.frame_buffer_blit(this, src_rect, &dst_fbo, dst_rect, btbs, interpolate);
20}
21
22void frame_buffer::blit_from(context& ctx, const ivec4& dst_rect, const ivec4& src_rect, BufferTypeBits btbs, bool interpolate)
23{
24 ctx.frame_buffer_blit(0, src_rect, this, dst_rect, btbs, interpolate);
25}
26
27void frame_buffer::blit_from(context& ctx, frame_buffer& src_fbo, const ivec4& dst_rect, const ivec4& src_rect, BufferTypeBits btbs, bool interpolate)
28{
29 ctx.frame_buffer_blit(&src_fbo, src_rect, this, dst_rect, btbs, interpolate);
30}
31
34{
35 if (handle) {
36 if (ctx_ptr)
38 else
39 std::cerr << "could not destruct frame buffer properly." << std::endl;
40 }
41}
42
45{
46 if (handle)
47 ctx.frame_buffer_destruct(*this);
48}
49
51bool frame_buffer::create(const context& ctx, int _width, int _height)
52{
53 if (ctx_ptr)
55 else
56 destruct(ctx);
57
58 ctx_ptr = &ctx;
59 width = _width;
60 height = _height;
61 return ctx.frame_buffer_create(*this);
62}
63
65{
66 width = _width;
67}
68
69void frame_buffer::set_height(int _height)
70{
71 height = _height;
72}
73
75void frame_buffer::set_size(int _width, int _height)
76{
77 width = _width;
78 height = _height;
79}
80
82bool frame_buffer::attach(const context& ctx, const render_buffer& rb, int i)
83{
84 return ctx.frame_buffer_attach(*this, rb, rb.is_depth_buffer(), i);
85}
86
88bool frame_buffer::attach(const context& ctx, const texture& tex2d, int level, int i)
89{
90 if (tex2d.get_nr_dimensions() != 2) {
91 last_error = "can only attach 2d textures to a frame buffer";
92 return false;
93 }
94 tex2d.ensure_state(ctx);
95 return ctx.frame_buffer_attach(*this, tex2d,
96 tex2d.get_standard_component_format() == cgv::data::CF_D, level, i, -1);
97}
99bool frame_buffer::attach(const context& ctx, const texture& tex3d, int z_or_cube_side, int level, int i)
100{
101 if (tex3d.get_nr_dimensions() != 3) {
102 if (tex3d.tt != TT_CUBEMAP) {
103 last_error = "can only attach slices of 3d textures or cube maps to a frame buffer";
104 return false;
105 }
106 }
107 tex3d.ensure_state(ctx);
108 return ctx.frame_buffer_attach(*this, tex3d,
109 tex3d.get_standard_component_format() == cgv::data::CF_D, level, i, z_or_cube_side);
110}
111
113bool frame_buffer::is_complete(const context& ctx) const
114{
115 return ctx.frame_buffer_is_complete(*this);
116}
117
121bool frame_buffer::enable(context& ctx, int i0, int i1, int i2, int i3
122 , int i4 , int i5 , int i6 , int i7
123 , int i8 , int i9 , int i10, int i11
124 , int i12, int i13, int i14, int i15)
125{
126 enabled_color_attachments.clear();
127 if (i0 >= 0)
128 enabled_color_attachments.push_back(i0);
129 if (i1 >= 0)
130 enabled_color_attachments.push_back(i1);
131 if (i2 >= 0)
132 enabled_color_attachments.push_back(i2);
133 if (i3 >= 0)
134 enabled_color_attachments.push_back(i3);
135 if (i4 >= 0)
136 enabled_color_attachments.push_back(i4);
137 if (i5 >= 0)
138 enabled_color_attachments.push_back(i5);
139 if (i6 >= 0)
140 enabled_color_attachments.push_back(i6);
141 if (i7 >= 0)
142 enabled_color_attachments.push_back(i7);
143 if (i8 >= 0)
144 enabled_color_attachments.push_back(i8);
145 if (i9 >= 0)
146 enabled_color_attachments.push_back(i9);
147 if (i10>= 0)
148 enabled_color_attachments.push_back(i10);
149 if (i11>= 0)
150 enabled_color_attachments.push_back(i11);
151 if (i12>= 0)
152 enabled_color_attachments.push_back(i12);
153 if (i13>= 0)
154 enabled_color_attachments.push_back(i13);
155 if (i14>= 0)
156 enabled_color_attachments.push_back(i14);
157 if (i15>= 0)
158 enabled_color_attachments.push_back(i15);
159 return ctx.frame_buffer_enable(*this);
160}
161
162bool frame_buffer::enable(context& ctx, std::vector<int>& indices)
163{
164 enabled_color_attachments = indices;
165 return ctx.frame_buffer_enable(*this);
166}
167
169void frame_buffer::push_viewport(context& ctx, const dvec2& depth_range)
170{
172 ctx.set_viewport(ivec4(0, 0, get_width(), get_height()));
173 ctx.set_depth_range(depth_range);
174}
175
181
184{
185 return ctx.frame_buffer_disable(*this);
186}
187
189{
190 return ctx.frame_buffer_get_max_nr_color_attachments();
191}
192
194{
195 return ctx.frame_buffer_get_max_nr_draw_buffers();
196}
197
198
199 }
200}
ComponentFormat get_standard_component_format() const
return whether the component format is one of the standard formats
unsigned get_nr_dimensions() const
return the number of dimensions of the data set
base class for all drawables, which is independent of the used rendering API.
Definition context.h:621
void push_window_transformation_array()
push a copy of the current viewport and depth range arrays defining the window transformations
Definition context.cxx:1870
virtual void set_depth_range(const dvec2 &depth_range=dvec2(0, 1), int array_index=-1)
set the current depth range or one of the depth ranges in the window transformation array
Definition context.cxx:1908
virtual void pop_window_transformation_array()
restore previous viewport and depth range arrays defining the window transformations
Definition context.cxx:1875
virtual void set_viewport(const ivec4 &viewport, int array_index=-1)
set the current viewport or one of the viewports in the window transformation array
Definition context.cxx:1901
bool create(const context &ctx, int _width=-1, int _height=-1)
create framebuffer if extension is supported, otherwise return false.
void push_viewport(context &ctx, const dvec2 &depth_range=dvec2(0, 1))
push a new window transformation to cover the fbo onto the window transformation stack
bool is_complete(const context &ctx) const
check for completeness, if not complete, get the reason in last_error
static int get_max_nr_color_attachments(const context &ctx)
return the maximum number of color attachments supported by the GPU
int get_width() const
return the width
void set_size(int _width, int _height)
set different size
void pop_viewport(context &ctx)
recover the window transformation array active before the last call to push_viewport
void destruct(const context &ctx)
destruct the framebuffer objext
bool attach(const context &ctx, const render_buffer &rb, int i=0)
attach render buffer to depth buffer if it is a depth buffer, to stencil if it is a stencil buffer or...
bool enable(context &ctx, int i0=-1, int i1=-1, int i2=-1, int i3=-1, int i4=-1, int i5=-1, int i6=-1, int i7=-1, int i8=-1, int i9=-1, int i10=-1, int i11=-1, int i12=-1, int i13=-1, int i14=-1, int i15=-1)
enable the framebuffer either with all color attachments if no arguments are given or if arguments ar...
bool disable(context &ctx)
disable the framebuffer object
static int get_max_nr_draw_buffers(const context &ctx)
return the maximum number of simultaneous draw buffers supported by the GPU
frame_buffer()
constructor just initializes stuff
void set_height(int _height)
set a different height
void blit_to(context &ctx, BufferTypeBits btbs=BTB_ALL_BITS, bool interpolate=false) const
different variants of blitting rectangle src_rect of this frame buffer into rectangle dest_rect of de...
std::string last_error
a string that contains the last error, which is only set by the init method
void set_width(int _width)
set a different width
int get_height() const
return the height
void blit_from(context &ctx, BufferTypeBits btbs=BTB_ALL_BITS, bool interpolate=false)
different variants of blitting to rectangle dst_rect of this frame buffer from rectangle src_rect of ...
this class encapsulate render buffers that live on the GPU which must support frame buffer objects fo...
bool is_depth_buffer() const
return whether the component format corresponds to a depth buffer format
const context * ctx_ptr
keep pointer to my context
Definition context.h:307
the texture class encapsulates all functionality independent of the rendering api.
Definition texture.h:15
void ensure_state(const context &ctx) const
ensure the the texture state is synchronized with the GPU settings
Definition texture.cxx:198
@ CF_D
color format with components B, G, R and A
BufferTypeBits
Bits for the selection of different buffer types.
Definition context.h:461
the cgv namespace
Definition print.h:11
cgv::math::fvec< int32_t, 4 > ivec4
declare type of 4d 32 bit integer vectors
Definition fvec.h:698