wren
Vulkan-based game engine
Toggle main menu visibility
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 <vector>
6
#include <vulkan/vulkan.hpp>
7
#include <
wren/utils/result.hpp
>
8
#include <
wren/vk/image.hpp
>
9
10
#include "
render_pass.hpp
"
11
12
namespace
wren
{
13
14
struct
Node
{
15
std::string
name
;
16
std::shared_ptr<RenderPass>
render_pass
;
17
};
18
19
using
node_t
= std::shared_ptr<Node>;
20
using
edge_t
= std::pair<node_t, node_t>;
21
22
struct
Graph
{
23
auto
begin
() {
return
nodes
.begin(); }
24
auto
end
() {
return
nodes
.end(); }
25
26
[[nodiscard]]
auto
node_by_name
(
const
std::string& name)
const
->
node_t
{
27
const
auto
node = std::ranges::find_if(
28
nodes
, [name](
const
node_t
& node) {
return
name == node->name; });
29
if
(node !=
nodes
.end())
return
*node;
30
31
return
nullptr
;
32
}
33
34
std::vector<node_t>
nodes
;
35
std::vector<edge_t>
edges
;
36
};
37
38
class
GraphBuilder
{
39
public
:
40
explicit
GraphBuilder
(
const
std::shared_ptr<Context>& ctx) :
ctx_
(ctx) {}
41
45
[[nodiscard]]
auto
build
() const ->
expected
<
void
>;
46
51
[[nodiscard]] auto
compile
() const ->
expected
<
Graph
>;
52
53
auto
add_pass
(const std::
string
& name, const
PassResources
& resources,
54
const
RenderPass
::execute_fn_t& fn) ->
GraphBuilder
&;
55
56
private:
57
[[nodiscard]] auto
create_target
() const
58
->
expected
<std::shared_ptr<
RenderTarget
>>;
59
60
std::shared_ptr<
Context
>
ctx_
;
61
std::vector<std::tuple<std::
string
,
PassResources
,
RenderPass
::execute_fn_t>>
62
passes_
;
63
};
64
65
}
// namespace wren
wren::GraphBuilder
Definition
graph.hpp:38
wren::GraphBuilder::build
auto build() const -> expected< void >
This calls compile() and then assigns the graph to the renderer.
Definition
graph.cpp:19
wren::GraphBuilder::passes_
std::vector< std::tuple< std::string, PassResources, RenderPass::execute_fn_t > > passes_
Definition
graph.hpp:62
wren::GraphBuilder::create_target
auto create_target() const -> expected< std::shared_ptr< RenderTarget > >
wren::GraphBuilder::add_pass
auto add_pass(const std::string &name, const PassResources &resources, const RenderPass::execute_fn_t &fn) -> GraphBuilder &
Definition
graph.cpp:11
wren::GraphBuilder::compile
auto compile() const -> expected< Graph >
Compiles the builder into an actual graph, it creates missing resources for targets and binds targets...
Definition
graph.cpp:27
wren::GraphBuilder::GraphBuilder
GraphBuilder(const std::shared_ptr< Context > &ctx)
Definition
graph.hpp:40
wren::GraphBuilder::ctx_
std::shared_ptr< Context > ctx_
Definition
graph.hpp:60
wren::PassResources
Definition
render_pass.hpp:23
wren::RenderPass
Definition
render_pass.hpp:59
wren::RenderTarget
Definition
render_target.hpp:14
image.hpp
wren
Definition
editor_scene.hpp:5
wren::edge_t
std::pair< node_t, node_t > edge_t
Definition
graph.hpp:20
wren::node_t
std::shared_ptr< Node > node_t
Definition
graph.hpp:19
wren::expected
std::expected< T, Err > expected
Definition
result.hpp:43
render_pass.hpp
wren::Context
Definition
context.hpp:14
wren::Graph
Definition
graph.hpp:22
wren::Graph::edges
std::vector< edge_t > edges
Definition
graph.hpp:35
wren::Graph::node_by_name
auto node_by_name(const std::string &name) const -> node_t
Definition
graph.hpp:26
wren::Graph::nodes
std::vector< node_t > nodes
Definition
graph.hpp:34
wren::Graph::end
auto end()
Definition
graph.hpp:24
wren::Graph::begin
auto begin()
Definition
graph.hpp:23
wren::Node
Definition
graph.hpp:14
wren::Node::render_pass
std::shared_ptr< RenderPass > render_pass
Definition
graph.hpp:16
wren::Node::name
std::string name
Definition
graph.hpp:15
result.hpp
wren
include
wren
graph.hpp
Generated by
1.17.0