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 }
49
50 populate(attachments);
51}
52
53void frame_buffer::populate(const std::vector<fbo_attachment>& textures)
54{
55 std::vector<attachment> buffer;
56 buffer.reserve(textures.size());
57
58 usize32_t size = {0, 0};
59 for(const auto& tex : textures)
60 {
61 size = {tex.texture->info.width, tex.texture->info.height};
62
63 buffer.emplace_back();
64 auto& att = buffer.back();
65 att.init(tex.texture->native_handle(), access::Write, tex.layer, 1, tex.mip, (tex.generate_mips ? BGFX_RESOLVE_AUTO_GEN_MIPS : BGFX_RESOLVE_NONE));
66 }
67 textures_ = textures;
68
69 dispose();
70 handle_ = create_frame_buffer(static_cast<std::uint8_t>(buffer.size()), buffer.data(), false);
71 cached_size_ = size;
72}
73
75{
76 return cached_size_;
77}
78
79auto frame_buffer::get_attachment(std::uint32_t index) const -> const fbo_attachment&
80{
81 return textures_[index];
82}
83
84auto frame_buffer::get_attachments() const -> const std::vector<fbo_attachment>&
85{
86 return textures_;
87}
88
89
90auto frame_buffer::get_texture(uint32_t index) const -> const texture::ptr&
91{
92 return get_attachment(index).texture;
93}
94
96{
97 return textures_.size();
98}
99} // namespace gfx
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:605
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