wren
Vulkan-based game engine
Loading...
Searching...
No Matches
renderer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <vulkan/vulkan.hpp>
5#include <vulkan/vulkan_enums.hpp>
6#include <vulkan/vulkan_structs.hpp>
7
8#include "mesh.hpp"
9#include "wren/graph.hpp"
10#include "wren/pipeline.hpp"
12
13namespace wren {
14
15struct Context;
16
17class Renderer {
18 static constexpr std::string_view kSwapchainRendertargetName =
19 "swapchain_target";
20
21 public:
22 static auto create(const std::shared_ptr<Context> &ctx)
24
25 void draw();
26
27 auto set_graph_builder(const GraphBuilder &builder) {
28 render_graph = builder.compile().value();
29 }
30 auto get_graph() const { return render_graph; }
31
33
36 auto render_targets() const { return render_targets_; }
37 auto add_target(const std::string &name,
38 const std::shared_ptr<RenderTarget> &target) {
39 render_targets_.emplace(name, target);
40 }
41
43 const std::function<void(::vk::CommandBuffer &)> &cmd_buf)
45
46 private:
47 explicit Renderer(const std::shared_ptr<Context> &ctx);
48
50 void end_frame(uint32_t image_index);
51
53
55 const std::vector<::vk::SurfaceFormatKHR> &formats)
56 -> ::vk::SurfaceFormatKHR;
58 const std::vector<::vk::PresentModeKHR> &formats) -> ::vk::PresentModeKHR;
60 const ::vk::SurfaceCapabilitiesKHR &surface_capabilities)
61 -> ::vk::Extent2D;
62
63 std::unordered_map<std::string, std::shared_ptr<Pipeline>> pipelines_;
64 std::shared_ptr<Context> ctx_;
65 ::vk::SwapchainKHR swapchain_;
66 std::vector<::vk::Image> swapchain_images_;
67 std::vector<::vk::ImageView> swapchain_image_views_;
68
69 std::unordered_map<std::string, std::shared_ptr<RenderTarget>>
71
72 ::vk::Format swapchain_image_format_ = ::vk::Format::eB8G8R8Srgb;
73 ::vk::Extent2D swapchain_extent_;
74
75 ::vk::Semaphore image_available;
76 ::vk::Semaphore render_finished;
77 ::vk::Fence in_flight_fence;
78
79 ::vk::CommandPool command_pool_;
80 ::vk::CommandBuffer one_time_cmd_buffer;
81
83
85};
86
87} // namespace wren
Definition graph.hpp:38
auto compile() const -> expected< Graph >
Definition graph.cpp:19
Definition mesh.hpp:40
Definition renderer.hpp:17
std::unordered_map< std::string, std::shared_ptr< Pipeline > > pipelines_
Definition renderer.hpp:63
static auto create(const std::shared_ptr< Context > &ctx) -> expected< std::shared_ptr< Renderer > >
Definition renderer.cpp:131
auto submit_command_buffer(const std::function< void(::vk::CommandBuffer &)> &cmd_buf) -> expected< void >
Definition renderer.cpp:92
auto render_targets() const
Get the swapchain's targets.
Definition renderer.hpp:36
static constexpr std::string_view kSwapchainRendertargetName
Definition renderer.hpp:18
::vk::CommandPool command_pool_
Definition renderer.hpp:79
void draw()
Definition renderer.cpp:19
auto recreate_swapchain() -> expected< void >
Definition renderer.cpp:178
auto swapchain_images_views() const
Definition renderer.hpp:32
Graph render_graph
Definition renderer.hpp:82
::vk::Fence in_flight_fence
Definition renderer.hpp:77
auto choose_swapchain_format(const std::vector<::vk::SurfaceFormatKHR > &formats) -> ::vk::SurfaceFormatKHR
Definition renderer.cpp:299
std::shared_ptr< Context > ctx_
Definition renderer.hpp:64
auto choose_swapchain_presentation_mode(const std::vector<::vk::PresentModeKHR > &formats) -> ::vk::PresentModeKHR
Definition renderer.cpp:314
std::unordered_map< std::string, std::shared_ptr< RenderTarget > > render_targets_
Definition renderer.hpp:70
Renderer(const std::shared_ptr< Context > &ctx)
Definition renderer.cpp:114
std::vector<::vk::Image > swapchain_images_
Definition renderer.hpp:66
::vk::SwapchainKHR swapchain_
Definition renderer.hpp:65
std::vector<::vk::ImageView > swapchain_image_views_
Definition renderer.hpp:67
auto begin_frame() -> expected< uint32_t >
Definition renderer.cpp:26
auto set_graph_builder(const GraphBuilder &builder)
Definition renderer.hpp:27
auto add_target(const std::string &name, const std::shared_ptr< RenderTarget > &target)
Definition renderer.hpp:37
::vk::Format swapchain_image_format_
Definition renderer.hpp:72
::vk::CommandBuffer one_time_cmd_buffer
Definition renderer.hpp:80
::vk::Semaphore render_finished
Definition renderer.hpp:76
auto choose_swapchain_extent(const ::vk::SurfaceCapabilitiesKHR &surface_capabilities) -> ::vk::Extent2D
Definition renderer.cpp:325
::vk::Extent2D swapchain_extent_
Definition renderer.hpp:73
auto get_graph() const
Definition renderer.hpp:30
Mesh m
Definition renderer.hpp:84
void end_frame(uint32_t image_index)
Definition renderer.cpp:57
::vk::Semaphore image_available
Definition renderer.hpp:75
Definition editor_scene.hpp:5
std::expected< T, Err > expected
Definition result.hpp:49
Definition graph.hpp:22