CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
RendererGraphicsPipeline.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Forward.hpp"
11
12#include "RendererShader.hpp"
13
15
18
20
21namespace CeresEngine {
22
26 };
27
31
32
36
39
42
45
46 public: // Reflection
49 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
50 CE_REFL_DATA(vertexDeclarations);
51 CE_REFL_DATA(primitiveTopology);
52 CE_REFL_DATA(shaderSpecialization);
54 }
55 };
56
60 class RendererGraphicsPipeline : public RefCounted<RendererGraphicsPipeline> {
61 private:
63
67
70
74
77
81
84
85 public:
97 const RendererShaderPtr& shader, const GPURenderPassPtr& renderPass, const GPUPipelineLayoutPtr& pipelineLayout = nullptr);
99
100 public:
104
116 const PrimitiveTopology primitiveTopology = PrimitiveTopology::Triangles, RendererShaderSpecialization shaderSpecialization = {}) const {
118 .primitiveTopology = primitiveTopology,
119 .shaderSpecialization = std::move(shaderSpecialization),
120 .state = state,
121 });
122 }
123
136 VertexDeclaration vertexDeclaration, const GPUGraphicsPipelineState& state,
137 const PrimitiveTopology primitiveTopology = PrimitiveTopology::Triangles, RendererShaderSpecialization shaderSpecialization = {}) const {
139 .vertexDeclarations = {std::move(vertexDeclaration)},
140 .primitiveTopology = primitiveTopology,
141 .shaderSpecialization = std::move(shaderSpecialization),
142 .state = state,
143 });
144 }
145
157 const RendererMesh& mesh, const GPUGraphicsPipelineState& state,
158 PrimitiveTopology primitiveTopology = PrimitiveTopology::Triangles, RendererShaderSpecialization shaderSpecialization = {}) const;
159
162 const PrimitiveTopology primitiveTopology = PrimitiveTopology::Triangles, RendererShaderSpecialization shaderSpecialization = {}) const {
163 return getPipeline(*mesh, state, primitiveTopology, std::move(shaderSpecialization));
164 }
165
166 public:
168 [[nodiscard]] const String& getName() const noexcept { return mName; }
169
172
175
178 };
179
183 private:
188
189 private:
191
194
198
199 public:
203
204 public:
217 const GPURenderPassPtr& renderPass, const GPUPipelineLayoutPtr& pipelineLayout = nullptr);
218
230 const GPUPipelineLayoutPtr& pipelineLayout = nullptr) {
231 return get(StringView(), shader, renderPass, pipelineLayout);
232 }
233
234 private:
235 friend class RendererGraphicsPipeline;
236
240 const GPURenderPassPtr& renderPass, const GPUPipelineLayoutPtr& pipelineLayout);
241
244 };
245
246} // namespace CeresEngine
247
#define CE_FLAGS_OPERATORS(Enum)
Defines global operators for a Flags<Enum, Storage> implementation.
Definition Flags.hpp:216
#define CE_REFLECT_HASH(T)
Definition Hash.hpp:89
#define CE_REFL_DATA(N)
Definition Macros.hpp:541
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
A simple reference counter base class.
Definition SmartPtr.hpp:438
A renderer graphics pipeline.
Definition RendererGraphicsPipeline.hpp:60
const GPURenderPassPtr & getRenderPass() const noexcept
Pointer to a RenderPass object. By default null.
Definition RendererGraphicsPipeline.hpp:171
const String & getName() const noexcept
A human-readable name to use on the pipeline.
Definition RendererGraphicsPipeline.hpp:168
const GPUPipelineLayoutPtr & getPipelineLayout() const noexcept
Pointer to an optional pipeline layout for the graphics pipeline.
Definition RendererGraphicsPipeline.hpp:174
GPUGraphicsPipelinePtr getPipeline(const RendererMesh &mesh, const GPUGraphicsPipelineState &state, PrimitiveTopology primitiveTopology=PrimitiveTopology::Triangles, RendererShaderSpecialization shaderSpecialization={}) const
Gets the compiled graphics pipeline program suitable for the given mesh.
RendererGraphicsPipelineManager & mManager
The renderer graphics pipeline manager that owns this graphics pipeline object.
Definition RendererGraphicsPipeline.hpp:66
GPUGraphicsPipelinePtr getPipeline(VertexDeclaration vertexDeclaration, const GPUGraphicsPipelineState &state, const PrimitiveTopology primitiveTopology=PrimitiveTopology::Triangles, RendererShaderSpecialization shaderSpecialization={}) const
Gets the compiled graphics pipeline program for the given parameters.
Definition RendererGraphicsPipeline.hpp:135
GPUPipelineLayoutPtr mPipelineLayout
Pointer to an optional pipeline layout for the graphics pipeline.
Definition RendererGraphicsPipeline.hpp:80
GPUGraphicsPipelinePtr getPipeline(const RendererGraphicsPipelineSpecialization &specialization) const
Gets the compiled graphics pipeline program for the given parameters.
GPURenderPassPtr mRenderPass
Pointer to a RenderPass object. By default null.
Definition RendererGraphicsPipeline.hpp:76
String mName
A human-readable name to use on the pipeline.
Definition RendererGraphicsPipeline.hpp:69
GPUGraphicsPipelinePtr getPipeline(const GPUGraphicsPipelineState &state, const PrimitiveTopology primitiveTopology=PrimitiveTopology::Triangles, RendererShaderSpecialization shaderSpecialization={}) const
Gets the compiled graphics pipeline program for the given parameters.
Definition RendererGraphicsPipeline.hpp:114
GPUGraphicsPipelinePtr getPipeline(const RendererMeshPtr &mesh, const GPUGraphicsPipelineState &state, const PrimitiveTopology primitiveTopology=PrimitiveTopology::Triangles, RendererShaderSpecialization shaderSpecialization={}) const
Definition RendererGraphicsPipeline.hpp:161
RendererShaderPtr mShader
The shader to be used when creating new GPU Graphics Pipeline instances.
Definition RendererGraphicsPipeline.hpp:73
HashMap< UInt64, GPUGraphicsPipelinePtr > mPipelines
The graphics pipeline programs, indexed by their parameters hash.
Definition RendererGraphicsPipeline.hpp:83
RendererGraphicsPipeline(RendererGraphicsPipelineManager &manager, StringView name, const RendererShaderPtr &shader, const GPURenderPassPtr &renderPass, const GPUPipelineLayoutPtr &pipelineLayout=nullptr)
Creates a new renderer graphics pipeline instance.
const RendererShaderPtr & getShader() const noexcept
The shader to be used when creating new GPU Graphics Pipeline instances.
Definition RendererGraphicsPipeline.hpp:177
The renderer graphics pipeline manager that is responsible for managing and re-using GPU graphics pip...
Definition RendererGraphicsPipeline.hpp:182
RendererGraphicsPipelinePtr getOrCreate(StringView name, const RendererShaderPtr &shader, const GPURenderPassPtr &renderPass, const GPUPipelineLayoutPtr &pipelineLayout)
Gets an existing or creates a new renderer graphics pipeline instance for the given base descriptor.
Renderer & mRenderer
The renderer that owns this manager instance.
Definition RendererGraphicsPipeline.hpp:193
RendererGraphicsPipelinePtr get(const RendererShaderPtr &shader, const GPURenderPassPtr &renderPass, const GPUPipelineLayoutPtr &pipelineLayout=nullptr)
Gets (or creates) a new RendererGraphicsPipeline from a graphics pipeline graphics pipeline program d...
Definition RendererGraphicsPipeline.hpp:229
HashMap< UInt64, GraphicsPipelineInfo > mGraphicsPipelines
A map that holds graphics pipeline information for each base graphics pipeline descriptor.
Definition RendererGraphicsPipeline.hpp:197
RendererGraphicsPipelineManager(Renderer &renderer)
Creates a new GraphicsPipeline Manager instance.
RendererGraphicsPipelinePtr get(StringView name, const RendererShaderPtr &shader, const GPURenderPassPtr &renderPass, const GPUPipelineLayoutPtr &pipelineLayout=nullptr)
Gets (or creates) a new RendererGraphicsPipeline from a graphics pipeline state descriptor.
void notifyDestroy(const RendererGraphicsPipeline *graphicsPipeline) noexcept
Notifies the manager that the renderer graphics pipeline is being destroyed.
The CeresEngine renderer.
Definition Renderer.hpp:35
A mesh that is usable by the renderer and the GPU.
Definition RendererMesh.hpp:95
Definition Application.hpp:19
BasicStringView< char > StringView
Narrow string view used for handling narrow encoded text in UTF-8.
Definition String.hpp:190
RendererGraphicsPipelineFlag
Flags that can be either set by the renderer or by the user to customize the behavior of the graphics...
Definition RendererGraphicsPipeline.hpp:25
std::unordered_map< Key, T, Hash, KeyEqual, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > HashMap
HashMap is an associative container that contains key-value pairs with unique keys.
Definition Map.hpp:33
struct CeresEngine::GLState state
Flags< RendererGraphicsPipelineFlag > RendererGraphicsPipelineFlags
Flags that can be either set by the renderer or by the user to customize the behavior of the graphics...
Definition Forward.hpp:39
sfl::small_vector< T, N, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > SmallVector
SmallVector is a sequence container similar to Vector.
Definition SmallVector.hpp:31
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Graphics pipeline state descriptor structure.
Definition GPUGraphicsPipeline.hpp:694
Primitive topology enumeration.
Definition PrimitiveTopology.hpp:21
@ Triangles
Triangle list, where each set of three vertices represent a single triangle primitive.
Definition PrimitiveTopology.hpp:50
RendererGraphicsPipeline * rendererGraphicsPipeline
An instance of the renderer graphics pipeline.
Definition RendererGraphicsPipeline.hpp:186
A structure that describes a RendererGraphicsPipeline specialization.
Definition RendererGraphicsPipeline.hpp:33
RendererShaderSpecialization shaderSpecialization
A description of the shader specialization to use.
Definition RendererGraphicsPipeline.hpp:41
GPUGraphicsPipelineState state
A description of the graphics pipeline state.
Definition RendererGraphicsPipeline.hpp:44
SmallVector< VertexDeclaration, 1 > vertexDeclarations
The vertex declarations that matches the rendered mesh.
Definition RendererGraphicsPipeline.hpp:35
PrimitiveTopology primitiveTopology
The primitive topology to be used when rendering.
Definition RendererGraphicsPipeline.hpp:38
static constexpr void reflect(Processor &&RTTI)
Executes the given processor for every field of the struct.
Definition RendererGraphicsPipeline.hpp:49
A structure that describes a RendererGraphicsPipeline specialization.
Definition RendererShader.hpp:31
Determines how vertices are laid-out on a vertex buffer or a mesh data.
Definition VertexDeclaration.hpp:205