nCine::RenderResources class

Creates and holds the OpenGL rendering resources shared by the whole application.

Owns the global singletons of the render pipeline (binary shader cache, buffers manager, VAO pool, render command pool, batcher), the built-in default shader programs and the default camera. Lifetime is driven by Application; it cannot be instantiated.

Public types

struct VertexFormatPos2
Vertex format for vertices with positions only.
struct VertexFormatPos2Tex2
Vertex format for vertices with positions and texture coordinates.
struct VertexFormatPos2Index
Vertex format for vertices with positions and draw indices.
struct VertexFormatPos2Tex2Index
Vertex format for vertices with positions, texture coordinates and draw indices.
struct CameraUniformData
Per-shader camera uniform data and the frames its matrices were last updated.

Public static variables

static std::uint32_t VerticesPerQuad constexpr
Number of distinct corners a quad contributes to an indexed mesh.
static std::uint32_t IndicesPerQuad constexpr
Number of indices that draw one quad as two triangles.

Public static functions

static auto GetBinaryShaderCache() -> BinaryShaderCache&
static auto GetBuffersManager() -> RenderBuffersManager&
static auto GetVaoPool() -> RenderVaoPool&
static auto GetRenderCommandPool() -> RenderCommandPool&
static auto GetRenderBatcher() -> RenderBatcher&
static auto GetMaxQuadsPerDraw(std::uint32_t floatsPerVertex) -> std::uint32_t
Returns how many quads one indexed draw can describe, for a mesh of floatsPerVertex floats per vertex.
static auto GetQuadIndices() -> const std::uint16_t*
Returns the host-side index array that draws quads as two triangles each.
static auto GetShaderProgram(Material::ShaderProgramType shaderProgramType) -> RHI::ShaderProgram*
static auto GetBatchedShader(const RHI::ShaderProgram* shader) -> RHI::ShaderProgram*
static auto RegisterBatchedShader(const RHI::ShaderProgram* shader, RHI::ShaderProgram* batchedShader) -> bool
static auto UnregisterBatchedShader(const RHI::ShaderProgram* shader) -> bool
static auto GetCameraUniformsBuffer() -> std::uint8_t*
static auto FindCameraUniformData(RHI::ShaderProgram* shaderProgram) -> CameraUniformData*
static void InsertCameraUniformData(RHI::ShaderProgram* shaderProgram, CameraUniformData&& cameraUniformData)
static auto RemoveCameraUniformData(RHI::ShaderProgram* shaderProgram) -> bool
static auto GetCurrentCamera() -> const Camera*
static auto GetCurrentViewport() -> const Viewport*
static void SetDefaultAttributesParameters(RHI::ShaderProgram& shaderProgram)

Constructors, destructors, conversion operators

RenderResources() deleted
~RenderResources() deleted

Function documentation

static std::uint32_t nCine::RenderResources::GetMaxQuadsPerDraw(std::uint32_t floatsPerVertex)

Returns how many quads one indexed draw can describe, for a mesh of floatsPerVertex floats per vertex.

A quad occupies four interleaved vertices in the shared array buffer and six 16-bit indices in the shared element one, so the smaller of those two limits - and of what a 16-bit index can address at all - is how far a single draw reaches. A quad mesh larger than that has to be split into several commands on whole-quad boundaries.

static const std::uint16_t* nCine::RenderResources::GetQuadIndices()

Returns the host-side index array that draws quads as two triangles each.

The pattern is the same for every quad mesh - 0, 1, 2, 0, 2, 3 per quad, counted from the first vertex of the command - so one array backs all of them instead of every renderer building its own. A quad mesh writes only its four distinct corners and points its geometry here, which is a third less vertex data to copy and a third fewer vertex shader invocations than the six-vertex stream the same triangles need without indices.

The array is allocated once, long enough for the longest draw GetMaxQuadsPerDraw() can report, so the returned pointer stays valid as long as the rendering resources do - a render queue may hold it until its draw phase without another mesh moving it in between.