cgv
Loading...
Searching...
No Matches
managed_frame_buffer.h
1#pragma once
2
3#include <unordered_map>
4
5#include <cgv/render/frame_buffer.h>
6
7#include "lib_begin.h"
8
9namespace cgv {
10namespace render {
11
13class CGV_API managed_frame_buffer
14{
15private:
16 ivec2 get_actual_size(context& ctx);
17
18 bool create_and_validate(context& ctx, const ivec2& size);
19
20protected:
21 struct attachment {
22 unsigned index;
23 bool attach;
24 std::string format;
26 TextureWrap tw;
27 texture tex;
28
29 bool is_depth_attachment() const {
30 return
31 format == "[D]" ||
32 format == "uint16[D]" ||
33 format == "uint32[D:24]" ||
34 format == "uint32[D]";
35 }
36 };
37
38 frame_buffer fb;
39 unsigned index_counter = 0;
40 std::unordered_map<std::string, attachment> attachments;
41 ivec2 size;
42
43public:
44 managed_frame_buffer();
45
46 void destruct(const context& ctx);
47
48 ivec2 get_size();
49
55 void set_size(const ivec2& size);
56
57 void add_attachment(const std::string& name, const std::string& format = "uint8[R,G,B]", TextureFilter tf = TF_NEAREST, TextureWrap tw = TW_CLAMP_TO_EDGE, bool attach = true);
58
59 bool enable_attachment(context& ctx, const std::string& name, int tex_unit = -1);
60
61 bool disable_attachment(context& ctx, const std::string& name);
62
63 texture* attachment_texture_ptr(const std::string& name);
64
69 bool ensure(context& ctx);
70
71 bool enable(context& ctx, bool push_viewport=true);
72
73 bool disable(context& ctx, bool pop_viewport=true);
74
75 frame_buffer& ref_frame_buffer() { return fb; }
76};
77
78}
79}
80
81#include <cgv/config/lib_end.h>
base class for all drawables, which is independent of the used rendering API.
Definition context.h:670
this class encapsulate frame buffers that live on the GPU and can be used as destination for the rend...
bool ensure(context &ctx)
Ensure the framebuffer is constructed with the specified size.
void set_size(const ivec2 &size)
Set the size of the framebuffer attachments.
the texture class encapsulates all functionality independent of the rendering api.
Definition texture.h:15
namespace for api independent GPU programming
TextureFilter
different texture filter
Definition context.h:245
TextureWrap
different texture wrap modes
Definition context.h:229
this header is dependency free
Definition print.h:11
cgv::math::fvec< int32_t, 2 > ivec2
declare type of 2d 32 bit integer vectors
Definition fvec.h:719