wren
Vulkan-based game engine
Loading...
Searching...
No Matches
graph.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <string>
5#include <tl/expected.hpp>
6#include <vector>
7#include <vulkan/vulkan.hpp>
9#include <wren/vk/image.hpp>
10
11#include "render_pass.hpp"
12
13namespace wren {
14
15struct Node {
16 std::string name;
17 std::shared_ptr<RenderPass> render_pass;
18};
19
20using node_t = std::shared_ptr<Node>;
21using edge_t = std::pair<node_t, node_t>;
22
23struct Graph {
24 auto begin() { return nodes.begin(); }
25 auto end() { return nodes.end(); }
26
27 [[nodiscard]] auto node_by_name(const std::string &name) const -> node_t {
28 const auto node = std::ranges::find_if(
29 nodes, [name](const node_t &node) { return name == node->name; });
30 if (node != nodes.end()) return *node;
31
32 return nullptr;
33 }
34
35 std::vector<node_t> nodes;
36 std::vector<edge_t> edges;
37};
38
40 public:
41 explicit GraphBuilder(const std::shared_ptr<Context> &ctx) : ctx_(ctx) {}
42
43 [[nodiscard]] auto compile() const -> expected<Graph>;
44
45 auto add_pass(const std::string &name, const PassResources &resources,
46 const RenderPass::execute_fn_t &fn) -> GraphBuilder &;
47
48 private:
49 [[nodiscard]] auto create_target() const
50 -> expected<std::pair<vk::Image, std::shared_ptr<RenderTarget>>>;
51
52 std::shared_ptr<Context> ctx_;
53 std::vector<std::tuple<std::string, PassResources, RenderPass::execute_fn_t>>
54 passes_;
55};
56
57} // namespace wren
Definition graph.hpp:39
auto add_pass(const std::string &name, const PassResources &resources, const RenderPass::execute_fn_t &fn) -> GraphBuilder &
Definition graph.cpp:12
auto compile() const -> expected< Graph >
Definition graph.cpp:20
GraphBuilder(const std::shared_ptr< Context > &ctx)
Definition graph.hpp:41
Definition render_pass.hpp:29
Definition render_target.hpp:9
Definition ui.hpp:5
Definition editor.hpp:14
tl::expected< T, Err > expected
Definition errors.hpp:49
std::pair< node_t, node_t > edge_t
Definition graph.hpp:21
std::shared_ptr< Node > node_t
Definition graph.hpp:20
Definition context.hpp:13
Definition graph.hpp:23
std::vector< edge_t > edges
Definition graph.hpp:36
auto node_by_name(const std::string &name) const -> node_t
Definition graph.hpp:27
std::vector< node_t > nodes
Definition graph.hpp:35
auto end()
Definition graph.hpp:25
auto begin()
Definition graph.hpp:24
Definition graph.hpp:15
std::shared_ptr< RenderPass > render_pass
Definition graph.hpp:17
std::string name
Definition graph.hpp:16
Definition render_pass.hpp:23