Unravel Engine C++ Reference
Loading...
Searching...
No Matches
frame_buffer.cpp
Go to the documentation of this file.
1#include "frame_buffer.h"
2
3namespace gfx
4{
5namespace
6{
7}
8frame_buffer::frame_buffer(std::uint16_t _width,
9 std::uint16_t _height,
10 texture_format _format,
11 std::uint32_t _textureFlags)
12 : frame_buffer(std::vector<texture::ptr>{
13 std::make_shared<texture>(_width, _height, false, 1, _format, _textureFlags),
14 })
15{
16}
17
18frame_buffer::frame_buffer(const std::vector<texture::ptr>& textures)
19{
20 populate(textures);
21}
22
23frame_buffer::frame_buffer(const std::vector<fbo_attachment>& textures)
24{
25 populate(textures);
26}
27
29 uint16_t _width,
30 uint16_t _height,
31 texture_format _format,
32 texture_format _depth_format)
33{
34 handle_ = create_frame_buffer(_nwh, _width, _height, _format, _depth_format);
35
36 cached_size_ = {_width, _height};
37}
38
39void frame_buffer::populate(const std::vector<texture::ptr>& textures)
40{
41 std::vector<fbo_attachment> attachments;
42 attachments.reserve(textures.size());
43 for(const auto& tex : textures)
44 {
45 attachments.emplace_back();
46 auto& back = attachments.back();
47 back.texture = tex;
48 back.generate_mips = tex->info.format < texture_format::UnknownDepth;
49 }
50
51 populate(attachments);
52}
53
54void frame_buffer::populate(const std::vector<fbo_attachment>& textures)
55{
56 std::vector<attachment> buffer;
57 buffer.reserve(textures.size());
58
59 usize32_t size = {0, 0};
60 for(const auto& tex : textures)
61 {
62 size = {tex.texture->info.width, tex.texture->info.height};
63
64 buffer.emplace_back();
65 auto& att = buffer.back();
66 att.init(tex.texture->native_handle(), access::Write, tex.layer, 1, tex.mip, (tex.generate_mips ? BGFX_RESOLVE_AUTO_GEN_MIPS : BGFX_RESOLVE_NONE));
67 }
68 textures_ = textures;
69
70 dispose();
71 handle_ = create_frame_buffer(static_cast<std::uint8_t>(buffer.size()), buffer.data(), false);
72 cached_size_ = size;
73}
74
76{
77 return cached_size_;
78}
79
80auto frame_buffer::get_attachment(std::uint32_t index) const -> const fbo_attachment&
81{
82 return textures_[index];
83}
84
85auto frame_buffer::get_attachments() const -> const std::vector<fbo_attachment>&
86{
87 return textures_;
88}
89
90
91auto frame_buffer::get_texture(uint32_t index) const -> const texture::ptr&
92{
93 return get_attachment(index).texture;
94}
95
97{
98 return textures_.size();
99}
100} // namespace gfx
uint16_t index
bgfx::TextureFormat::Enum texture_format
Definition format.h:10
frame_buffer_handle create_frame_buffer(uint16_t _width, uint16_t _height, texture_format _format, uint64_t _textureFlags)
Definition graphics.cpp:774
Hash specialization for batch_key to enable use in std::unordered_map.
auto get_texture(std::uint32_t index=0) const -> const gfx::texture::ptr &
auto get_attachment_count() const -> size_t
auto get_attachments() const -> const std::vector< fbo_attachment > &
void populate(const std::vector< texture::ptr > &textures)
auto get_attachment(std::uint32_t index=0) const -> const fbo_attachment &
auto get_size() const -> usize32_t
frame_buffer()=default
float size