Kohi Game Engine
rendergraph.h
Go to the documentation of this file.
1 #ifndef _RENDERGRAPH_H_
2 #define _RENDERGRAPH_H_
3 
4 #include "defines.h"
6 
7 #define RG_CHECK(expr) \
8  if (!expr) { \
9  KERROR("Failed to execute: '%s'.", #expr); \
10  return false; \
11  }
12 
13 struct rendergraph_system_state;
14 
25 
30 typedef struct rendergraph_source {
31  char* name;
37  union {
40 
43  } value;
45 
50 typedef struct rendergraph_sink {
51  const char* name;
58 
59 struct rendergraph;
60 
67 typedef struct rendergraph_node {
70  const char* name;
71 
72  // The graph owning this node.
73  struct rendergraph* graph;
74 
77 
80 
82 
83  b8 (*initialize)(struct rendergraph_node* self);
85  b8 (*execute)(struct rendergraph_node* self, struct frame_data* p_frame_data);
86  void (*destroy)(struct rendergraph_node* self);
88 
89 // Opaque type representing internal dependency graph.
90 struct rg_dep_graph;
91 
92 typedef struct rendergraph {
93  char* name;
94 
95  // A pointer to the global colourbuffer framebuffer.
97  // A pointer to the global depthbuffer framebuffer.
99 
101  // Array of nodes in this graph.
103 
106 
108 
109  struct rg_dep_graph* dep_graph;
111 
116  const char* name;
117  const char* type;
118  const char* source_name;
120 
124 typedef struct rendergraph_node_config {
126  const char* name;
128  const char* type;
129 
134 
136  const char* config_str;
138 
139 typedef struct rendergraph_node_factory {
140  const char* type;
141  b8 (*create)(rendergraph* graph, rendergraph_node* node, const struct rendergraph_node_config* config);
143 
144 KAPI b8 rendergraph_create(const char* config_str, ktexture global_colourbuffer, ktexture global_depthbuffer, rendergraph* out_graph);
146 
148 
151 
153 
155 
164 b8 rendergraph_system_initialize(u64* memory_requirement, struct rendergraph_system_state* state);
165 
171 void rendergraph_system_shutdown(struct rendergraph_system_state* state);
172 
181 KAPI b8 rendergraph_system_node_factory_register(struct rendergraph_system_state* state, const rendergraph_node_factory* new_factory);
182 
183 #endif
This file contains global type definitions which are used throughout the entire engine and applicatio...
#define KAPI
Import/export qualifier.
Definition: defines.h:205
unsigned int u32
Unsigned 32-bit integer.
Definition: defines.h:25
_Bool b8
8-bit boolean type
Definition: defines.h:58
unsigned long long u64
Unsigned 64-bit integer.
Definition: defines.h:28
u16 ktexture
Represents a texture to be used for rendering purposes, stored on the GPU (VRAM)
Definition: kresource_types.h:45
struct rendergraph_source rendergraph_source
Represents some source of data/resource, to be plugged into a sink.
b8 rendergraph_system_initialize(u64 *memory_requirement, struct rendergraph_system_state *state)
struct rendergraph_node_factory rendergraph_node_factory
KAPI b8 rendergraph_system_node_factory_register(struct rendergraph_system_state *state, const rendergraph_node_factory *new_factory)
Registers the provided factory with the rendergraph system. Note that passing a factory with a duplic...
struct rendergraph rendergraph
KAPI b8 rendergraph_initialize(rendergraph *graph)
struct rendergraph_sink rendergraph_sink
Represents a sortof "socket" which accepts data of a specfic type (i.e. a texture or number),...
KAPI b8 rendergraph_finalize(rendergraph *graph)
KAPI b8 rendergraph_execute_frame(rendergraph *graph, struct frame_data *p_frame_data)
KAPI rendergraph_resource_type string_to_resource_type(const char *str)
void rendergraph_system_shutdown(struct rendergraph_system_state *state)
Shuts this system down.
struct rendergraph_node rendergraph_node
Represents a single node in a rendergraph. A node is responsible for acquiring and maintaining its re...
KAPI b8 rendergraph_load_resources(rendergraph *graph)
KAPI void rendergraph_destroy(rendergraph *graph)
struct rendergraph_node_sink_config rendergraph_node_sink_config
KAPI b8 rendergraph_create(const char *config_str, ktexture global_colourbuffer, ktexture global_depthbuffer, rendergraph *out_graph)
rendergraph_resource_type
Represents a resource type to be used with rendergraph sources and sinks.
Definition: rendergraph.h:19
@ RENDERGRAPH_RESOURCE_TYPE_TEXTURE
Definition: rendergraph.h:21
@ RENDERGRAPH_RESOURCE_TYPE_MAX
Definition: rendergraph.h:23
@ RENDERGRAPH_RESOURCE_TYPE_NUMBER
Definition: rendergraph.h:22
@ RENDERGRAPH_RESOURCE_TYPE_UNDEFINED
Definition: rendergraph.h:20
struct rendergraph_node_config rendergraph_node_config
The configuration for a rendergraph node.
Engine-level current frame-specific data.
Definition: frame_data.h:11
The configuration for a rendergraph node.
Definition: rendergraph.h:124
u32 sink_count
The number of sinks in this node.
Definition: rendergraph.h:131
const char * config_str
Additional node-specific config in string format. The node should know how to parse this....
Definition: rendergraph.h:136
const char * type
The type of the node.
Definition: rendergraph.h:128
rendergraph_node_sink_config * sinks
A collection of sink configs. Must be a config for each sink in the node. Names must match.
Definition: rendergraph.h:133
const char * name
The name of the node.
Definition: rendergraph.h:126
Definition: rendergraph.h:139
b8(* create)(rendergraph *graph, rendergraph_node *node, const struct rendergraph_node_config *config)
Definition: rendergraph.h:141
const char * type
Definition: rendergraph.h:140
Definition: rendergraph.h:115
const char * type
Definition: rendergraph.h:117
const char * name
Definition: rendergraph.h:116
const char * source_name
Definition: rendergraph.h:118
Represents a single node in a rendergraph. A node is responsible for acquiring and maintaining its re...
Definition: rendergraph.h:67
u32 sink_count
Definition: rendergraph.h:78
struct rendergraph * graph
Definition: rendergraph.h:73
u32 source_count
Definition: rendergraph.h:75
b8(* execute)(struct rendergraph_node *self, struct frame_data *p_frame_data)
Definition: rendergraph.h:85
b8(* load_resources)(struct rendergraph_node *self)
Definition: rendergraph.h:84
rendergraph_source * sources
Definition: rendergraph.h:76
const char * name
The name of the node.
Definition: rendergraph.h:70
void * internal_data
Definition: rendergraph.h:81
b8(* initialize)(struct rendergraph_node *self)
Definition: rendergraph.h:83
rendergraph_sink * sinks
Definition: rendergraph.h:79
void(* destroy)(struct rendergraph_node *self)
Definition: rendergraph.h:86
u32 index
Definition: rendergraph.h:68
Represents a sortof "socket" which accepts data of a specfic type (i.e. a texture or number),...
Definition: rendergraph.h:50
rendergraph_resource_type type
The type of data expected in this sink. Bound source type must match.
Definition: rendergraph.h:54
const char * configured_source_name
Definition: rendergraph.h:52
const char * name
Definition: rendergraph.h:51
rendergraph_source * bound_source
A pointer to the bound source.
Definition: rendergraph.h:56
Represents some source of data/resource, to be plugged into a sink.
Definition: rendergraph.h:30
ktexture t
A pointer to the underlying texture resource.
Definition: rendergraph.h:39
char * name
Definition: rendergraph.h:31
rendergraph_resource_type type
The type of resource held in this source.
Definition: rendergraph.h:35
u64 u64
A copy of the underlying unsigned int resource.
Definition: rendergraph.h:42
b8 is_bound
Indicates if this source has been bound.
Definition: rendergraph.h:33
union rendergraph_source::@71 value
The resource value.
Definition: rendergraph.h:92
rendergraph_node * nodes
Definition: rendergraph.h:102
rendergraph_node * begin_node
Definition: rendergraph.h:104
struct rg_dep_graph * dep_graph
Definition: rendergraph.h:109
char * name
Definition: rendergraph.h:93
u32 node_count
Definition: rendergraph.h:100
u32 * execution_list
Definition: rendergraph.h:107
ktexture global_depthbuffer
Definition: rendergraph.h:98
rendergraph_node * end_node
Definition: rendergraph.h:105
ktexture global_colourbuffer
Definition: rendergraph.h:96