Hymn to Beauty
C++ 3D Engine
LowLevelRenderer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Buffer.hpp"
5#include "GeometryBinding.hpp"
6#include "RenderPass.hpp"
7#include "Shader.hpp"
8#include "Texture.hpp"
9#include "Sampler.hpp"
10#include "GraphicsPipeline.hpp"
11
12#include <glm/glm.hpp>
13#include <initializer_list>
14#include <vector>
16
17struct ShaderSource;
18
19namespace Video {
20
21class CommandBuffer;
22class ShaderProgram;
23class Texture;
24class ComputePipeline;
25
28 public:
33
36
39
42
45
49 };
50
53
55 virtual ~LowLevelRenderer() {}
56
58
62
64 virtual void BeginFrame() = 0;
65
67
70 virtual void Submit(CommandBuffer* commandBuffer) = 0;
71
73 virtual void Present() = 0;
74
76
83 virtual Buffer* CreateBuffer(Buffer::BufferUsage bufferUsage, unsigned int size, const void* data = nullptr) = 0;
84
86
95 virtual Buffer* CreateTemporaryBuffer(Buffer::BufferUsage bufferUsage, unsigned int size, const void* data = nullptr) = 0;
96
98
105 virtual VertexDescription* CreateVertexDescription(unsigned int attributeCount, const VertexDescription::Attribute* attributes, bool indexBuffer = false) = 0;
106
108
116 virtual GeometryBinding* CreateGeometryBinding(const VertexDescription* vertexDescription, Buffer* vertexBuffer, GeometryBinding::IndexType indexType = GeometryBinding::IndexType::NONE, const Buffer* indexBuffer = nullptr) = 0;
117
119
125 virtual Shader* CreateShader(const ShaderSource& shaderSource, Shader::Type type) = 0;
126
128
142 virtual ShaderProgram* CreateShaderProgram(std::initializer_list<const Shader*> shaders) = 0;
143
145
153 virtual Texture* CreateTexture(const glm::uvec2 size, Texture::Format format, int components, unsigned char* data) = 0;
154
156
162 virtual const Sampler* GetSampler(Sampler::Filter filter, Sampler::Clamping clamping) const = 0;
163
165
171 virtual Texture* CreateRenderTarget(const glm::uvec2& size, Texture::Format format) = 0;
172
174
177 virtual void FreeRenderTarget(Texture* renderTarget) = 0;
178
180
187 virtual GraphicsPipeline* CreateGraphicsPipeline(const ShaderProgram* shaderProgram, const GraphicsPipeline::Configuration& configuration, const VertexDescription* vertexDescription = nullptr) = 0;
188
190
195 virtual ComputePipeline* CreateComputePipeline(const ShaderProgram* shaderProgram) = 0;
196
198 virtual void Wait() = 0;
199
201
206 virtual unsigned char* ReadImage(Texture* texture) = 0;
207
209
212 void SetProfiling(bool profiling) {
213 this->profiling = profiling;
214 }
215
217
220 bool IsProfiling() const {
221 return profiling;
222 }
223
225
228 virtual const std::vector<Profiling::Event>& GetTimeline() const = 0;
229
231
234 virtual const OptionalFeatures& GetOptionalFeatures() const = 0;
235
236 private:
237 LowLevelRenderer(const LowLevelRenderer& other) = delete;
238
239 bool profiling = false;
240};
241
242} // namespace Video
A buffer containing GPU accessible data.
Definition: Buffer.hpp:8
BufferUsage
How the buffer is going to be used.
Definition: Buffer.hpp:11
A buffer into which rendering commands are recorded.
Definition: CommandBuffer.hpp:24
A compute pipeline.
Definition: ComputePipeline.hpp:11
Binds together a vertex description with buffers.
Definition: GeometryBinding.hpp:8
IndexType
The type of values in the index buffer.
Definition: GeometryBinding.hpp:11
A graphics pipeline.
Definition: GraphicsPipeline.hpp:11
Low level renderer abstracting the underlaying graphics API (OpenGL or Vulkan).
Definition: LowLevelRenderer.hpp:27
virtual ShaderProgram * CreateShaderProgram(std::initializer_list< const Shader * > shaders)=0
Create a shader program.
virtual CommandBuffer * CreateCommandBuffer()=0
Create a command buffer.
virtual const Sampler * GetSampler(Sampler::Filter filter, Sampler::Clamping clamping) const =0
Get a sampler.
virtual Texture * CreateTexture(const glm::uvec2 size, Texture::Format format, int components, unsigned char *data)=0
Create a texture.
bool IsProfiling() const
Get whether profiling is active.
Definition: LowLevelRenderer.hpp:220
virtual Buffer * CreateTemporaryBuffer(Buffer::BufferUsage bufferUsage, unsigned int size, const void *data=nullptr)=0
Create a temporary GPU buffer.
virtual ComputePipeline * CreateComputePipeline(const ShaderProgram *shaderProgram)=0
Create a compute pipeline.
virtual void Present()=0
Present the rendered image to the swap chain.
virtual void FreeRenderTarget(Texture *renderTarget)=0
Free a render target.
virtual Shader * CreateShader(const ShaderSource &shaderSource, Shader::Type type)=0
Create a shader.
virtual GraphicsPipeline * CreateGraphicsPipeline(const ShaderProgram *shaderProgram, const GraphicsPipeline::Configuration &configuration, const VertexDescription *vertexDescription=nullptr)=0
Create a graphics pipeline.
virtual ~LowLevelRenderer()
Destructor.
Definition: LowLevelRenderer.hpp:55
virtual const OptionalFeatures & GetOptionalFeatures() const =0
Get which optional features are supported.
virtual VertexDescription * CreateVertexDescription(unsigned int attributeCount, const VertexDescription::Attribute *attributes, bool indexBuffer=false)=0
Create a vertex description.
virtual void Submit(CommandBuffer *commandBuffer)=0
Submit a command buffer for execution.
virtual Buffer * CreateBuffer(Buffer::BufferUsage bufferUsage, unsigned int size, const void *data=nullptr)=0
Create a GPU buffer.
LowLevelRenderer()
Create a new low-level renderer.
Definition: LowLevelRenderer.hpp:52
virtual GeometryBinding * CreateGeometryBinding(const VertexDescription *vertexDescription, Buffer *vertexBuffer, GeometryBinding::IndexType indexType=GeometryBinding::IndexType::NONE, const Buffer *indexBuffer=nullptr)=0
Create a geometry binding.
virtual Texture * CreateRenderTarget(const glm::uvec2 &size, Texture::Format format)=0
Create a render target.
void SetProfiling(bool profiling)
Set whether to profile.
Definition: LowLevelRenderer.hpp:212
virtual unsigned char * ReadImage(Texture *texture)=0
Read a render texture color image.
virtual const std::vector< Profiling::Event > & GetTimeline() const =0
Get profiling timeline.
virtual void BeginFrame()=0
Begin a new frame.
virtual void Wait()=0
Wait for all rendering to finish.
Determines how a texture should be sampled.
Definition: Sampler.hpp:6
Filter
The interpolation to apply.
Definition: Sampler.hpp:9
Clamping
How to handle sampling outside the texture dimensions.
Definition: Sampler.hpp:16
Compiles and handles a shader. Shaders should be linked together into a ShaderProgram.
Definition: Shader.hpp:8
Type
The type of shader.
Definition: Shader.hpp:11
A shader program.
Definition: ShaderProgram.hpp:11
A texture.
Definition: Texture.hpp:8
Format
The format of the texture.
Definition: Texture.hpp:18
Describes how a vertex buffer is accessed by a shader.
Definition: VertexDescription.hpp:8
Definition: Editor.hpp:18
The configuration of the graphics pipeline.
Definition: GraphicsPipeline.hpp:14
Optional features.
Definition: LowLevelRenderer.hpp:30
bool wideLines
Whether wide lines are supported.
Definition: LowLevelRenderer.hpp:35
bool timestamps
Whether timestamps are supported.
Definition: LowLevelRenderer.hpp:38
bool fillModeNonSolid
Whether non-solid fill modes (point and line) are supported.
Definition: LowLevelRenderer.hpp:32
bool shaderAtomics
Definition: LowLevelRenderer.hpp:48
uint32_t attachmentlessMsaaSamples
Bitmask of the number of MSAA samples supported for attachmentless rendering.
Definition: LowLevelRenderer.hpp:44
bool conservativeRasterization
Whether conservative rasterization is supported.
Definition: LowLevelRenderer.hpp:41
Describes an attribute used in a vertex shader.
Definition: VertexDescription.hpp:18