Unravel Engine C++ Reference
Loading...
Searching...
No Matches
render_window.cpp
Go to the documentation of this file.
1#include "render_window.h"
2#include <graphics/graphics.h>
3
4namespace unravel
5{
6
7render_window::render_window(os::window&& win) : window_(std::move(win))
8{
10}
11
13{
14 // Flush destruction of swap chain before destroying window!
16}
17
19{
20 // force internal handle destruction
21 if(surface_)
22 {
23 surface_.reset();
24
25
26 // Before we reattach a SwapChain to the window
27 // we must actually free up the previous one.
28 // The DestroyFrameBuffer command goes in the
29 // cmdPost CommandBuffer, which happens after
30 // the frame. The CreateFrameBuffer command goes
31 // int the cmdPre CommandBuffer, which happens
32 // at the beginning of the frame. Without this
33 // bgfx::frame() call, the creation would happen
34 // before it's destroyed, which would cause
35 // the platform window to have two SwapChains
36 // associated with it.
37 // Ideally, we have an operation of ResizeFrameBuffer.
38 gfx::frames(frames);
39 }
40}
41
42void render_window::resize(uint32_t w, uint32_t h)
43{
44 window_.set_size(w, h);
46}
47
49{
50 auto size = window_.get_size();
51
52 bool needs_recreate = true;
53 if(surface_)
54 {
55 auto surf_size = surface_->get_size();
56 needs_recreate = surf_size.width != size.w || surf_size.height != size.h;
57 }
58
59 if(needs_recreate)
60 {
62 surface_ = std::make_shared<gfx::frame_buffer>(window_.get_native_handle(),
63 static_cast<std::uint16_t>(size.w),
64 static_cast<std::uint16_t>(size.h));
65 }
66}
67
68auto render_window::get_window() -> os::window&
69{
70 return window_;
71}
73{
74 return surface_;
75}
76
78{
79 pass_.reset();
80 pass_ = std::make_unique<gfx::render_pass>("Present to Window Pass");
81 pass_->bind(surface_.get());
82
83 return *pass_;
84}
85
87{
88 return *pass_;
89}
90} // namespace unravel
void frames(int _count, int32_t _flags)
Hash specialization for batch_key to enable use in std::unordered_map.
T height
Definition basetypes.hpp:56
~render_window()
Destructor for the render window.
std::shared_ptr< gfx::frame_buffer > graphics_surface_t
auto get_surface() -> graphics_surface_t &
Gets the rendering surface.
void prepare_surface()
Prepares the rendering surface.
auto begin_present_pass() -> gfx::render_pass &
Begins the present render pass.
void resize(uint32_t w, uint32_t h)
Resizes the render window to the specified width and height.
auto get_window() -> os::window &
Gets the associated OS window.
render_window(os::window &&win)
Constructs a render window with the specified OS window.
void destroy_surface(int frames)
Destroys the rendering surface.
auto get_present_pass() -> gfx::render_pass &
Gets the present render pass.