Hymn to Beauty
C++ 3D Engine
Video::OpenGLRenderer Class Reference

Low-level renderer implementing OpenGL. More...

#include <OpenGLRenderer.hpp>

Inheritance diagram for Video::OpenGLRenderer:
Video::LowLevelRenderer

Public Member Functions

 OpenGLRenderer (Utility::Window *window)
 Create new OpenGL renderer. More...
 
 ~OpenGLRenderer () final
 Destructor. More...
 
CommandBufferCreateCommandBuffer () final
 Create a command buffer. More...
 
void BeginFrame () final
 Begin a new frame. More...
 
void Submit (CommandBuffer *commandBuffer) final
 Submit a command buffer for execution. More...
 
void Present () final
 Present the rendered image to the swap chain. More...
 
BufferCreateBuffer (Buffer::BufferUsage bufferUsage, uint32_t size, const void *data=nullptr) final
 
BufferCreateTemporaryBuffer (Buffer::BufferUsage bufferUsage, uint32_t size, const void *data=nullptr) final
 
VertexDescriptionCreateVertexDescription (unsigned int attributeCount, const VertexDescription::Attribute *attributes, bool indexBuffer=false) final
 Create a vertex description. More...
 
GeometryBindingCreateGeometryBinding (const VertexDescription *vertexDescription, Buffer *vertexBuffer, GeometryBinding::IndexType indexType=GeometryBinding::IndexType::NONE, const Buffer *indexBuffer=nullptr) final
 Create a geometry binding. More...
 
ShaderCreateShader (const ShaderSource &shaderSource, Shader::Type type) final
 Create a shader. More...
 
ShaderProgramCreateShaderProgram (std::initializer_list< const Shader * > shaders) final
 Create a shader program. More...
 
TextureCreateTexture (const glm::uvec2 size, Texture::Format format, int components, unsigned char *data) final
 Create a texture. More...
 
const SamplerGetSampler (Sampler::Filter filter, Sampler::Clamping clamping) const final
 Get a sampler. More...
 
TextureCreateRenderTarget (const glm::uvec2 &size, Texture::Format format) final
 Create a render target. More...
 
void FreeRenderTarget (Texture *renderTarget) final
 Free a render target. More...
 
GraphicsPipelineCreateGraphicsPipeline (const ShaderProgram *shaderProgram, const GraphicsPipeline::Configuration &configuration, const VertexDescription *vertexDescription=nullptr) final
 Create a graphics pipeline. More...
 
ComputePipelineCreateComputePipeline (const ShaderProgram *shaderProgram) final
 Create a compute pipeline. More...
 
void Wait () final
 Wait for all rendering to finish. More...
 
unsigned char * ReadImage (Texture *texture) final
 Read a render texture color image. More...
 
const std::vector< Profiling::Event > & GetTimeline () const final
 Get profiling timeline. More...
 
const OptionalFeaturesGetOptionalFeatures () const final
 Get which optional features are supported. More...
 
const OpenGLShaderProgramGetBlitShaderProgram () const
 Get the shader program used for blitting. More...
 
GLuint GetFreeQuery ()
 Get a free query. More...
 
- Public Member Functions inherited from Video::LowLevelRenderer
 LowLevelRenderer ()
 Create a new low-level renderer. More...
 
virtual ~LowLevelRenderer ()
 Destructor. More...
 
virtual BufferCreateBuffer (Buffer::BufferUsage bufferUsage, unsigned int size, const void *data=nullptr)=0
 Create a GPU buffer. More...
 
virtual BufferCreateTemporaryBuffer (Buffer::BufferUsage bufferUsage, unsigned int size, const void *data=nullptr)=0
 Create a temporary GPU buffer. More...
 
void SetProfiling (bool profiling)
 Set whether to profile. More...
 
bool IsProfiling () const
 Get whether profiling is active. More...
 

Detailed Description

Low-level renderer implementing OpenGL.

Constructor & Destructor Documentation

◆ OpenGLRenderer()

Video::OpenGLRenderer::OpenGLRenderer ( Utility::Window window)
explicit

Create new OpenGL renderer.

Parameters
windowThe window to render to.
Todo:
Disable GPU profiling if not supported.

◆ ~OpenGLRenderer()

Video::OpenGLRenderer::~OpenGLRenderer ( )
final

Destructor.

Member Function Documentation

◆ BeginFrame()

void Video::OpenGLRenderer::BeginFrame ( )
finalvirtual

Begin a new frame.

Implements Video::LowLevelRenderer.

◆ CreateBuffer()

Buffer * Video::OpenGLRenderer::CreateBuffer ( Buffer::BufferUsage  bufferUsage,
uint32_t  size,
const void *  data = nullptr 
)
final

◆ CreateCommandBuffer()

CommandBuffer * Video::OpenGLRenderer::CreateCommandBuffer ( )
finalvirtual

Create a command buffer.

Returns
The created command buffer.

Implements Video::LowLevelRenderer.

◆ CreateComputePipeline()

ComputePipeline * Video::OpenGLRenderer::CreateComputePipeline ( const ShaderProgram shaderProgram)
finalvirtual

Create a compute pipeline.

Parameters
shaderProgramThe shader program to use.
Returns
The created compute pipeline.

Implements Video::LowLevelRenderer.

◆ CreateGeometryBinding()

GeometryBinding * Video::OpenGLRenderer::CreateGeometryBinding ( const VertexDescription vertexDescription,
Buffer vertexBuffer,
GeometryBinding::IndexType  indexType = GeometryBinding::IndexType::NONE,
const Buffer indexBuffer = nullptr 
)
finalvirtual

Create a geometry binding.

Parameters
vertexDescriptionDescription of the attributes in the vertex buffer.
vertexBufferBuffer containing the vertex data.
indexTypeThe type of values in the index buffer.
indexBufferIndex buffer.
Returns
The created geometry binding.

Implements Video::LowLevelRenderer.

◆ CreateGraphicsPipeline()

GraphicsPipeline * Video::OpenGLRenderer::CreateGraphicsPipeline ( const ShaderProgram shaderProgram,
const GraphicsPipeline::Configuration configuration,
const VertexDescription vertexDescription = nullptr 
)
finalvirtual

Create a graphics pipeline.

Parameters
shaderProgramThe shader program to use.
configurationThe configuration of the pipeline.
vertexDescriptionThe description of the vertex input to the pipeline.
Returns
The created graphics pipeline.

Implements Video::LowLevelRenderer.

◆ CreateRenderTarget()

Texture * Video::OpenGLRenderer::CreateRenderTarget ( const glm::uvec2 &  size,
Texture::Format  format 
)
finalvirtual

Create a render target.

Parameters
sizeThe size of the texture, in pixels.
formatThe format of the texture.
Returns
The created texture.

Implements Video::LowLevelRenderer.

◆ CreateShader()

Shader * Video::OpenGLRenderer::CreateShader ( const ShaderSource &  shaderSource,
Shader::Type  type 
)
finalvirtual

Create a shader.

Parameters
shaderSourceThe source of the shader, generated by the shader processor.
typeThe type of shader to create.
Returns
The created shader.

Implements Video::LowLevelRenderer.

◆ CreateShaderProgram()

ShaderProgram * Video::OpenGLRenderer::CreateShaderProgram ( std::initializer_list< const Shader * >  shaders)
finalvirtual

Create a shader program.

Link together shaders into a shader program that can be run on the GPU.

Sample:

Shader* vertexShader = lowLevelRenderer->CreateShader(vertexSource, Shader::Type::VERTEX_SHADER);
Shader* fragmentShader = lowLevelRenderer->CreateShader(fragmentSource, Shader::Type::FRAGMENT_SHADER);
ShaderProgram* shaderProgram = lowLevelRenderer->CreateShaderProgram({ vertexShader, fragmentShader });
@ VERTEX_SHADER
Vertex shader.
@ FRAGMENT_SHADER
Fragment shader.
Parameters
shadersList of shaders to link together.
Returns
The created shader program.

Implements Video::LowLevelRenderer.

◆ CreateTemporaryBuffer()

Buffer * Video::OpenGLRenderer::CreateTemporaryBuffer ( Buffer::BufferUsage  bufferUsage,
uint32_t  size,
const void *  data = nullptr 
)
final

◆ CreateTexture()

Texture * Video::OpenGLRenderer::CreateTexture ( const glm::uvec2  size,
Texture::Format  format,
int  components,
unsigned char *  data 
)
finalvirtual

Create a texture.

Parameters
sizeThe size of the texture, in pixels.
formatThe format of the texture.
componentsThe number of components in the texture, 0 if no texture data is supplied.
dataThe texture data to upload, or nullptr.
Returns
The created texture.

Implements Video::LowLevelRenderer.

◆ CreateVertexDescription()

VertexDescription * Video::OpenGLRenderer::CreateVertexDescription ( unsigned int  attributeCount,
const VertexDescription::Attribute attributes,
bool  indexBuffer = false 
)
finalvirtual

Create a vertex description.

Parameters
attributeCountThe number of vertex attributes.
attributesThe array of attributes.
indexBufferWhether to use an index buffer.
Returns
The created vertex description.

Implements Video::LowLevelRenderer.

◆ FreeRenderTarget()

void Video::OpenGLRenderer::FreeRenderTarget ( Texture renderTarget)
finalvirtual

Free a render target.

Parameters
renderTargetThe render target to free.

Implements Video::LowLevelRenderer.

◆ GetBlitShaderProgram()

const OpenGLShaderProgram * Video::OpenGLRenderer::GetBlitShaderProgram ( ) const

Get the shader program used for blitting.

Returns
The blit shader program.

◆ GetFreeQuery()

GLuint Video::OpenGLRenderer::GetFreeQuery ( )

Get a free query.

Returns
The query object.

◆ GetOptionalFeatures()

const OpenGLRenderer::OptionalFeatures & Video::OpenGLRenderer::GetOptionalFeatures ( ) const
finalvirtual

Get which optional features are supported.

Returns
Which optional features are supported.

Implements Video::LowLevelRenderer.

◆ GetSampler()

const Sampler * Video::OpenGLRenderer::GetSampler ( Sampler::Filter  filter,
Sampler::Clamping  clamping 
) const
finalvirtual

Get a sampler.

Parameters
filterThe interpolation to apply.
clampingHow to handle sampling outside the texture dimensions.
Returns
The requested sampler.

Implements Video::LowLevelRenderer.

◆ GetTimeline()

const std::vector< Profiling::Event > & Video::OpenGLRenderer::GetTimeline ( ) const
finalvirtual

Get profiling timeline.

Returns
A list of events that have occurred since the last time fetching the timeline.

Implements Video::LowLevelRenderer.

◆ Present()

void Video::OpenGLRenderer::Present ( )
finalvirtual

Present the rendered image to the swap chain.

Implements Video::LowLevelRenderer.

◆ ReadImage()

unsigned char * Video::OpenGLRenderer::ReadImage ( Texture texture)
finalvirtual

Read a render texture color image.

Parameters
textureThe texture to read.
Returns
The color image as a char-array.

Implements Video::LowLevelRenderer.

◆ Submit()

void Video::OpenGLRenderer::Submit ( CommandBuffer commandBuffer)
finalvirtual

Submit a command buffer for execution.

Parameters
commandBufferThe command buffer to submit.

Implements Video::LowLevelRenderer.

◆ Wait()

void Video::OpenGLRenderer::Wait ( )
finalvirtual

Wait for all rendering to finish.

Implements Video::LowLevelRenderer.


The documentation for this class was generated from the following files: