Cogs.Core
RenderPipelineManager.h
1#pragma once
2
3#include "Tasks/RenderTask.h"
4
5#include "RenderSettings.h"
6#include "SubContext.h"
7#include "Resources/ResourceHandle.h"
8#include "Serialization/RenderPipelineReader.h"
9
10#include "Utilities/Expressions.h"
11
12#include "Foundation/ComponentModel/Component.h"
13
14#include <list>
15
16namespace Cogs
17{
18 namespace Core
19 {
20 class Context;
21 class Renderer;
22
24 {
26 RenderPipeline(const RenderPipeline&) = delete;
27 RenderPipeline& operator=(const RenderPipeline&) = delete;
28
29 RenderTaskList tasks;
30
31 RenderTaskResources resources;
32 std::vector<ResourceHandleBase> resourceHandles;
33
34 RenderTaskResources updateResources;
35
36 ExpressionContext expressionContext;
37
38 std::list<std::unique_ptr<SubContext>> subContexts;
39 std::list<std::string> dependsVariables;
40 size_t hash = 0;
41 };
42
44 {
45 std::string name;
46 RenderPipeline pipeline;
47 PipelineOptions options;
48
49 int priority = 0;
50 uint32_t touched = 0;
51 size_t definitionKey = 0;
52 size_t dataHash = 0;
53 const void* sanityCheck = nullptr;
55 };
56
57 class COGSCORE_DLL_API RenderPipelineManager
58 {
59 public:
60 RenderPipelineManager() = default;
62 RenderPipelineManager& operator=(const RenderPipelineManager&) = delete;
63
64 void initialize(RenderTaskContext* renderContext);
65 void cleanup(RenderTaskContext * renderContext);
66
67 void setupPipeline(RenderTaskContext * renderContext);
68
69 void initializeFrame(RenderTaskContext * renderContext);
70 void applyPipeline(RenderTaskContext * renderContext);
71 void cleanupFrame(RenderTaskContext * renderContext);
72
73 std::pair<PipelineInstance*, bool> instanceByKey(Context* context, size_t key);
74
75 ExpressionContext* getExpressionContextRoot() { return &expressionContextRoot; }
76
77 struct RenderList * getRenderList() { return renderList; }
78
79 RenderPipelineDefinition& definitionByKey(Context * /*context*/, size_t key) { return *(definitions[key].get()); }
80
81 const std::unordered_map<size_t, std::unique_ptr<PipelineInstance>> & getPipelineInstances() const { return pipelineInstances; }
82 const struct RenderList * getMainRenderList() const { return renderList; }
83 const RenderTask * getGenerateListTask() const { return generateListTask; }
84
85 RenderPipelineDefinition& definitionByPath(Context * context, const StringView & path);
86
87 public:
88 std::unordered_map<std::string, size_t> nameMap;
89
90 // Hook to insert globally visible resources, will be added to all renderlists.
91 RenderTaskResources globalResources;
92 bool dirty = true;
93
94 private:
95 struct RenderList * renderList = nullptr;
96 RenderTask * generateListTask = nullptr;
97
98 std::unordered_map<size_t, std::unique_ptr<RenderPipelineDefinition>> definitions;
99
100 std::unordered_map<size_t, std::unique_ptr<PipelineInstance>> pipelineInstances;
101
102 ExpressionContext expressionContextRoot;
103
104 RenderTaskList currentPipeline;
105 };
106 }
107}
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
Provides a context for evaluation of expressions.
Definition: Expressions.h:54
uint32_t touched
Last time this pipeline was looked up; look up pipeline once a frame to keep alive.
std::string name
Friendly name used for debugging.
RenderTexture * renderTarget
Render-target that this pipeline outputs to, nullptr for default rendertarget.