cubos::core::gl::RenderDevice class

Interface used to wrap low-level rendering APIs such as OpenGL.

Using this interface, the engine never directly interacts with OpenGL or any other low-level rendering API. This allows use to use different rendering APIs without having to change the engine code, which is useful for porting the engine to different platforms.

Public functions

auto createFramebuffer(const FramebufferDesc& desc) -> Framebuffer pure virtual
Creates a new framebuffer.
void setFramebuffer(Framebuffer fb) pure virtual
Sets the current framebuffer.
auto createRasterState(const RasterStateDesc& desc) -> RasterState pure virtual
Creates a new rasterizer state.
void setRasterState(RasterState rs) pure virtual
Sets the current rasterizer state.
auto createDepthStencilState(const DepthStencilStateDesc& desc) -> DepthStencilState pure virtual
Creates a new depth stencil state.
void setDepthStencilState(DepthStencilState dss) pure virtual
Sets the current depth stencil state.
auto createBlendState(const BlendStateDesc& desc) -> BlendState pure virtual
Creates a new blend state.
void setBlendState(BlendState bs) pure virtual
Sets the current blend state.
auto createPixelPackBuffer(std::size_t size) -> PixelPackBuffer pure virtual
Creates a new pixel pack buffer.
auto createSampler(const SamplerDesc& desc) -> Sampler pure virtual
Creates a new texture sampler.
auto createTexture1D(const Texture1DDesc& desc) -> Texture1D pure virtual
Creates a new 1D texture.
auto createTexture2D(const Texture2DDesc& desc) -> Texture2D pure virtual
Creates a new 2D texture.
auto createTexture2DArray(const Texture2DArrayDesc& desc) -> Texture2DArray pure virtual
Creates a new 2D texture array.
auto createTexture3D(const Texture3DDesc& desc) -> Texture3D pure virtual
Creates a new 3D texture.
auto createCubeMap(const CubeMapDesc& desc) -> CubeMap pure virtual
Creates a new cube map.
auto createCubeMapArray(const CubeMapArrayDesc& desc) -> CubeMapArray pure virtual
Creates a new cube map array.
auto createConstantBuffer(std::size_t size, const void* data, Usage usage) -> ConstantBuffer pure virtual
Creates a new constant buffer.
auto createIndexBuffer(std::size_t size, const void* data, IndexFormat format, Usage usage) -> IndexBuffer pure virtual
Creates a new index buffer.
void setIndexBuffer(IndexBuffer ib) pure virtual
Sets the current index buffer.
auto createVertexBuffer(std::size_t size, const void* data, Usage usage) -> VertexBuffer pure virtual
Creates a new vertex buffer.
auto createVertexArray(const VertexArrayDesc& desc) -> VertexArray pure virtual
Creates a new vertex array.
void setVertexArray(VertexArray va) pure virtual
Sets the current vertex array.
auto createShaderStage(Stage stage, const char* src) -> ShaderStage pure virtual
Creates a new shader stage from GLSL source code.
auto createShaderPipeline(ShaderStage vs, ShaderStage ps) -> ShaderPipeline pure virtual
Creates a new shader pipeline from vertex and pixel shaders.
auto createShaderPipeline(ShaderStage vs, ShaderStage gs, ShaderStage ps) -> ShaderPipeline pure virtual
Creates a new shader pipeline from vertex, pixel and geometry shaders.
auto createShaderPipeline(ShaderStage cs) -> ShaderPipeline pure virtual
Creates a new shader pipeline from a compute shader. Unsupported on some platforms.
void setShaderPipeline(ShaderPipeline pipeline) pure virtual
Sets the current shader pipeline used for rendering.
auto createTimer() -> Timer pure virtual
Creates a new timer.
auto createPipelinedTimer() -> PipelinedTimer
Creates a new pipelined timer.
void clearColor(float r, float g, float b, float a) pure virtual
Clears the color buffer bit on the current framebuffer to a specific color.
void clearTargetColor(std::size_t target, float r, float g, float b, float a) pure virtual
Clears the color buffer of a specific target on the current framebuffer to a specific color.
void clearTargetColor(std::size_t target, int r, int g, int b, int a) pure virtual
Clear the color buffer of a specific target on the current framebuffer to a specific color using integer values.
void clearDepth(float depth) pure virtual
Clears the depth buffer bit on the current framebuffer to a specific value.
void clearStencil(int stencil) pure virtual
Clears the stencil buffer bit on the current framebuffer to a specific value.
void drawLines(std::size_t offset, std::size_t count) pure virtual
Draws lines.
void drawTriangles(std::size_t offset, std::size_t count) pure virtual
Draws tringles.
void drawTrianglesIndexed(std::size_t offset, std::size_t count) pure virtual
Draws tringles with an index buffer.
void drawTrianglesInstanced(std::size_t offset, std::size_t count, std::size_t instanceCount) pure virtual
Draws tringles multiple times.
void drawTrianglesIndexedInstanced(std::size_t offset, std::size_t count, std::size_t instanceCount) pure virtual
Draws tringles multiple times with an index buffer.
void dispatchCompute(std::size_t x, std::size_t y, std::size_t z) pure virtual
Dispatches a compute pipeline.
void memoryBarrier(MemoryBarriers barriers) pure virtual
Defines a barrier ordering memory transactions. Unsupported on some platforms.
void setViewport(int x, int y, int w, int h) pure virtual
Sets the current viewport.
void setScissor(int x, int y, int w, int h) pure virtual
Sets the current scissor rectangle.
auto getProperty(Property prop) -> int pure virtual
Gets a runtime property of the render device.

Function documentation

Framebuffer cubos::core::gl::RenderDevice::createFramebuffer(const FramebufferDesc& desc) pure virtual

Creates a new framebuffer.

Parameters
desc Framebuffer description.
Returns Framebuffer handle, or nullptr on failure.

void cubos::core::gl::RenderDevice::setFramebuffer(Framebuffer fb) pure virtual

Sets the current framebuffer.

Parameters
fb Framebuffer handle.

RasterState cubos::core::gl::RenderDevice::createRasterState(const RasterStateDesc& desc) pure virtual

Creates a new rasterizer state.

Parameters
desc Rasterizer state description.
Returns Rasterizer state handle, or nullptr on failure.

void cubos::core::gl::RenderDevice::setRasterState(RasterState rs) pure virtual

Sets the current rasterizer state.

Parameters
rs Rasterizer state handle.

DepthStencilState cubos::core::gl::RenderDevice::createDepthStencilState(const DepthStencilStateDesc& desc) pure virtual

Creates a new depth stencil state.

Parameters
desc Depth stencil state description.
Returns Depth stencil state handle, or nullptr on failure.

void cubos::core::gl::RenderDevice::setDepthStencilState(DepthStencilState dss) pure virtual

Sets the current depth stencil state.

Parameters
dss Depth stencil state handle.

BlendState cubos::core::gl::RenderDevice::createBlendState(const BlendStateDesc& desc) pure virtual

Creates a new blend state.

Parameters
desc Blend state description.
Returns Blend state handle, or nullptr on failure.

void cubos::core::gl::RenderDevice::setBlendState(BlendState bs) pure virtual

Sets the current blend state.

Parameters
bs Blend state handle.

PixelPackBuffer cubos::core::gl::RenderDevice::createPixelPackBuffer(std::size_t size) pure virtual

Creates a new pixel pack buffer.

Parameters
size Buffer size in bytes.
Returns Pixel pack buffer handle, or nullptr on failure.

Sampler cubos::core::gl::RenderDevice::createSampler(const SamplerDesc& desc) pure virtual

Creates a new texture sampler.

Parameters
desc Sampler description.
Returns Sampler handle, or nullptr on failure.

Texture1D cubos::core::gl::RenderDevice::createTexture1D(const Texture1DDesc& desc) pure virtual

Creates a new 1D texture.

Parameters
desc 1D texture description.
Returns Texture handle, or nullptr on failure.

Texture2D cubos::core::gl::RenderDevice::createTexture2D(const Texture2DDesc& desc) pure virtual

Creates a new 2D texture.

Parameters
desc 2D texture description.
Returns Texture handle, or nullptr on failure.

Texture2DArray cubos::core::gl::RenderDevice::createTexture2DArray(const Texture2DArrayDesc& desc) pure virtual

Creates a new 2D texture array.

Parameters
desc 2D texture array description.
Returns Texture array handle, or nullptr on failure.

Texture3D cubos::core::gl::RenderDevice::createTexture3D(const Texture3DDesc& desc) pure virtual

Creates a new 3D texture.

Parameters
desc 3D texture description.
Returns Texture handle, or nullptr on failure.

CubeMap cubos::core::gl::RenderDevice::createCubeMap(const CubeMapDesc& desc) pure virtual

Creates a new cube map.

Parameters
desc Cube map description.
Returns Cube map handle, or nullptr on failure.

CubeMapArray cubos::core::gl::RenderDevice::createCubeMapArray(const CubeMapArrayDesc& desc) pure virtual

Creates a new cube map array.

Parameters
desc Cube map array description.
Returns Cube map array handle, or nullptr on failure.

ConstantBuffer cubos::core::gl::RenderDevice::createConstantBuffer(std::size_t size, const void* data, Usage usage) pure virtual

Creates a new constant buffer.

Parameters
size Size in bytes.
data Initial data, can be nullptr.
usage Usage which the buffer will have.
Returns Constant buffer handle, or nullptr on failure.

IndexBuffer cubos::core::gl::RenderDevice::createIndexBuffer(std::size_t size, const void* data, IndexFormat format, Usage usage) pure virtual

Creates a new index buffer.

Parameters
size Size in bytes.
data Initial data, can be nullptr.
format Index format.
usage Usage which the buffer will have.
Returns Index buffer handle, or nullptr on failure.

void cubos::core::gl::RenderDevice::setIndexBuffer(IndexBuffer ib) pure virtual

Sets the current index buffer.

Parameters
ib Index buffer handle.

VertexBuffer cubos::core::gl::RenderDevice::createVertexBuffer(std::size_t size, const void* data, Usage usage) pure virtual

Creates a new vertex buffer.

Parameters
size Size in bytes.
data Initial data, can be nullptr.
usage Usage which the buffer will have.
Returns Vertex buffer handle, or nullptr on failure.

VertexArray cubos::core::gl::RenderDevice::createVertexArray(const VertexArrayDesc& desc) pure virtual

Creates a new vertex array.

Parameters
desc Vertex array description.
Returns Vertex array handle, or nullptr on failure.

void cubos::core::gl::RenderDevice::setVertexArray(VertexArray va) pure virtual

Sets the current vertex array.

Parameters
va Vertex array handle.

ShaderStage cubos::core::gl::RenderDevice::createShaderStage(Stage stage, const char* src) pure virtual

Creates a new shader stage from GLSL source code.

Parameters
stage Shader stage.
src GLSL source code.
Returns Shader stage handle, or nullptr on failure.

ShaderPipeline cubos::core::gl::RenderDevice::createShaderPipeline(ShaderStage vs, ShaderStage ps) pure virtual

Creates a new shader pipeline from vertex and pixel shaders.

Parameters
vs Vertex shader stage.
ps Pixel shader stage.
Returns Shader pipeline handle, or nullptr on failure.

ShaderPipeline cubos::core::gl::RenderDevice::createShaderPipeline(ShaderStage vs, ShaderStage gs, ShaderStage ps) pure virtual

Creates a new shader pipeline from vertex, pixel and geometry shaders.

Parameters
vs Vertex shader stage.
gs Geometry shader stage.
ps Pixel shader stage.
Returns Shader pipeline handle, or nullptr on failure.

ShaderPipeline cubos::core::gl::RenderDevice::createShaderPipeline(ShaderStage cs) pure virtual

Creates a new shader pipeline from a compute shader. Unsupported on some platforms.

Parameters
cs Compute shader stage.
Returns Shader pipeline handle, or nullptr on failure.

void cubos::core::gl::RenderDevice::setShaderPipeline(ShaderPipeline pipeline) pure virtual

Sets the current shader pipeline used for rendering.

Parameters
pipeline Shader pipeline handle.

Timer cubos::core::gl::RenderDevice::createTimer() pure virtual

Creates a new timer.

Returns Timer handle, or nullptr on failure.

PipelinedTimer cubos::core::gl::RenderDevice::createPipelinedTimer()

Creates a new pipelined timer.

Returns Pipelined timer handle, or nullptr on failure.

void cubos::core::gl::RenderDevice::clearColor(float r, float g, float b, float a) pure virtual

Clears the color buffer bit on the current framebuffer to a specific color.

Parameters
r Red component.
g Green component.
b Blue component.
a Alpha component.

void cubos::core::gl::RenderDevice::clearTargetColor(std::size_t target, float r, float g, float b, float a) pure virtual

Clears the color buffer of a specific target on the current framebuffer to a specific color.

Parameters
target Target index.
r Red component.
g Green component.
b Blue component.
a Alpha component.

void cubos::core::gl::RenderDevice::clearTargetColor(std::size_t target, int r, int g, int b, int a) pure virtual

Clear the color buffer of a specific target on the current framebuffer to a specific color using integer values.

Parameters
target Target index.
r Red component.
g Green component.
b Blue component.
a Alpha component.

void cubos::core::gl::RenderDevice::clearDepth(float depth) pure virtual

Clears the depth buffer bit on the current framebuffer to a specific value.

Parameters
depth Depth value.

void cubos::core::gl::RenderDevice::clearStencil(int stencil) pure virtual

Clears the stencil buffer bit on the current framebuffer to a specific value.

Parameters
stencil Stencil value.

void cubos::core::gl::RenderDevice::drawLines(std::size_t offset, std::size_t count) pure virtual

Draws lines.

Parameters
offset Index of the first vertex to be drawn.
count Number of vertices that will be drawn.

void cubos::core::gl::RenderDevice::drawTriangles(std::size_t offset, std::size_t count) pure virtual

Draws tringles.

Parameters
offset Index of the first vertex to be drawn.
count Number of vertices that will be drawn.

void cubos::core::gl::RenderDevice::drawTrianglesIndexed(std::size_t offset, std::size_t count) pure virtual

Draws tringles with an index buffer.

Parameters
offset Index of the first indice to be drawn.
count Number of indices that will be drawn.

void cubos::core::gl::RenderDevice::drawTrianglesInstanced(std::size_t offset, std::size_t count, std::size_t instanceCount) pure virtual

Draws tringles multiple times.

Parameters
offset Index of the first vertex to be drawn.
count Number of vertices that will be drawn.
instanceCount Number of instances drawn.

void cubos::core::gl::RenderDevice::drawTrianglesIndexedInstanced(std::size_t offset, std::size_t count, std::size_t instanceCount) pure virtual

Draws tringles multiple times with an index buffer.

Parameters
offset Index of the first indice to be drawn.
count Number of indices that will be drawn.
instanceCount Number of instances drawn.

void cubos::core::gl::RenderDevice::dispatchCompute(std::size_t x, std::size_t y, std::size_t z) pure virtual

Dispatches a compute pipeline.

Parameters
x X dimension of the work group.
y Y dimension of the work group.
z Z dimension of the work group.

void cubos::core::gl::RenderDevice::memoryBarrier(MemoryBarriers barriers) pure virtual

Defines a barrier ordering memory transactions. Unsupported on some platforms.

Parameters
barriers Barriers to apply.

This ensure that all memory transactions before the barrier are completed before the barrier is executed.

void cubos::core::gl::RenderDevice::setViewport(int x, int y, int w, int h) pure virtual

Sets the current viewport.

Parameters
x Bottom left viewport corner X coordinate.
y Bottom left viewport corner Y coordinate.
w Viewport width.
h Viewport height.

void cubos::core::gl::RenderDevice::setScissor(int x, int y, int w, int h) pure virtual

Sets the current scissor rectangle.

Parameters
x Bottom left scissor rectangle corner X coordinate.
y Bottom left scissor rectangle corner Y coordinate.
w Scissor rectangle width.
h Scissor rectangle height.

int cubos::core::gl::RenderDevice::getProperty(Property prop) pure virtual

Gets a runtime property of the render device.

Parameters
prop Property name.