wren
Vulkan-based game engine
Loading...
Searching...
No Matches
instance.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <queue>
4#include <vulkan/vulkan.hpp>
5#include <wren/vk/buffer.hpp>
6#include <wren/vk/shader.hpp>
7#include <wren_math/matrix.hpp>
8#include <wren_math/vector.hpp>
9
10namespace wren::gui {
11
12struct Window {
13 std::string name;
14 wren::math::vec2f pos;
15 wren::math::vec2f size;
16
17 // IO
18
19 bool hovered = false;
20 bool selected = false;
21 wren::math::vec2f mouse_offset;
22};
23
24static const std::size_t MAX_VERTICES = 10000;
25static const std::size_t MAX_INDICES = MAX_VERTICES * 10;
26
27struct Vertex {
28 wren::math::vec2f pos;
30};
31
35
36struct Inputs {
37 wren::math::vec2f mouse_position = {0.0f, 0.0f};
38 wren::math::vec2f mouse_position_rel = {0.0f, 0.0f};
39 bool left_mouse = false;
40
41 // Left mouse down this frame
42 bool left_mouse_down = false;
43};
44
45class Instance {
46 public:
47 Instance(const std::shared_ptr<vk::Shader>& shader,
48 const ::vk::Device& device, const VmaAllocator& allocator,
49 const ::vk::CommandPool& command_pool,
50 const ::vk::Queue& graphics_queue);
51
52 [[nodiscard]] auto shader() const { return shader_; }
53
54 void bind(const ::vk::CommandBuffer& cmd);
55 void flush(const ::vk::CommandBuffer& cmd);
56
57 void resize_viewport(const ::vk::Extent2D& size) { this->output_size = size; }
58
59 void Begin();
60 void End();
61
62 auto BeginWindow(const std::string& name, const wren::math::vec2f& size)
63 -> bool;
64 void EndWindow();
65
66 auto IO() -> Inputs& { return io; }
67
68 private:
69 void draw_quad(const wren::math::vec2f& pos, const wren::math::vec2f& size,
70 const wren::math::Vec4f& colour);
71
72 auto point_in_bounds(const wren::math::vec2f& p, const wren::math::vec2f& pos,
73 const wren::math::vec2f& size) -> bool;
74
75 std::shared_ptr<vk::Shader> shader_;
76 std::shared_ptr<wren::vk::Buffer> index_buffer;
77 std::shared_ptr<wren::vk::Buffer> vertex_buffer;
78 std::shared_ptr<vk::Buffer> uniform_buffer;
79
80 ::vk::Device device;
81 ::vk::Queue graphics_queue;
82 ::vk::CommandPool command_pool;
83
84 ::vk::Extent2D output_size;
85
86 VmaAllocator allocator;
87 std::vector<Vertex> vertices;
88 std::vector<uint16_t> indices;
89
90 std::map<std::string, Window> windows_;
91 std::queue<std::string> stack;
92
95};
96
97} // namespace wren::gui
Definition instance.hpp:45
void draw_quad(const wren::math::vec2f &pos, const wren::math::vec2f &size, const wren::math::Vec4f &colour)
Definition instance.cpp:155
void flush(const ::vk::CommandBuffer &cmd)
Definition instance.cpp:56
auto shader() const
Definition instance.hpp:52
::vk::Queue graphics_queue
Definition instance.hpp:81
std::queue< std::string > stack
Definition instance.hpp:91
std::vector< uint16_t > indices
Definition instance.hpp:88
Inputs io
Definition instance.hpp:93
void End()
Definition instance.cpp:54
auto point_in_bounds(const wren::math::vec2f &p, const wren::math::vec2f &pos, const wren::math::vec2f &size) -> bool
Definition instance.cpp:173
std::map< std::string, Window > windows_
Definition instance.hpp:90
std::shared_ptr< wren::vk::Buffer > vertex_buffer
Definition instance.hpp:77
std::shared_ptr< vk::Buffer > uniform_buffer
Definition instance.hpp:78
::vk::CommandPool command_pool
Definition instance.hpp:82
void resize_viewport(const ::vk::Extent2D &size)
Definition instance.hpp:57
VmaAllocator allocator
Definition instance.hpp:86
std::vector< Vertex > vertices
Definition instance.hpp:87
::vk::Device device
Definition instance.hpp:80
auto BeginWindow(const std::string &name, const wren::math::vec2f &size) -> bool
Definition instance.cpp:109
void Begin()
Definition instance.cpp:49
std::shared_ptr< wren::vk::Buffer > index_buffer
Definition instance.hpp:76
::vk::Extent2D output_size
Definition instance.hpp:84
Instance(const std::shared_ptr< vk::Shader > &shader, const ::vk::Device &device, const VmaAllocator &allocator, const ::vk::CommandPool &command_pool, const ::vk::Queue &graphics_queue)
Definition instance.cpp:12
auto IO() -> Inputs &
Definition instance.hpp:66
void EndWindow()
Definition instance.cpp:138
std::shared_ptr< vk::Shader > shader_
Definition instance.hpp:75
void bind(const ::vk::CommandBuffer &cmd)
Inputs previous_io
Definition instance.hpp:94
Definition instance.hpp:10
static const std::size_t MAX_VERTICES
Definition instance.hpp:24
static const std::size_t MAX_INDICES
Definition instance.hpp:25
Definition instance.hpp:36
wren::math::vec2f mouse_position_rel
Definition instance.hpp:38
wren::math::vec2f mouse_position
Definition instance.hpp:37
bool left_mouse_down
Definition instance.hpp:42
bool left_mouse
Definition instance.hpp:39
Definition instance.hpp:32
wren::math::Mat4f proj
Definition instance.hpp:33
Definition instance.hpp:27
wren::math::Vec4f colour
Definition instance.hpp:29
wren::math::vec2f pos
Definition instance.hpp:28
Definition instance.hpp:12
wren::math::vec2f mouse_offset
Definition instance.hpp:21
wren::math::vec2f size
Definition instance.hpp:15
bool hovered
Definition instance.hpp:19
wren::math::vec2f pos
Definition instance.hpp:14
bool selected
Definition instance.hpp:20
std::string name
Definition instance.hpp:13
Definition matrix.hpp:86
Definition vector.hpp:154