cubos::engine::RenderMeshPool class

Used to allocate render meshes, which can then be rendered using a single draw call.

Internally, creates a single large vertex buffer, which is divided into buckets. Allocated meshes must fit within a single bucket. If they don't, they should be split among multiple buckets.

Public types

struct BucketId
Identifies a bucket in the pool.

Constructors, destructors, conversion operators

RenderMeshPool(core::gl::RenderDevice& renderDevice, std::size_t bucketCount, std::size_t bucketSize)
Constructs.
RenderMeshPool(const RenderMeshPool&) deleted
Forbid copy constructor.

Public functions

auto operator=(const RenderMeshPool&) -> RenderMeshPool& deleted
Forbid copy assignment.
auto bucketCount() const -> std::size_t
Gets the bucket count.
auto bucketSize() const -> std::size_t
Gets the bucket size in vertices.
auto freeBucketCount() const -> std::size_t
Gets the number of free buckets.
auto vertexBuffer() const -> core::gl::VertexBuffer
Gets the vertex buffer of the pool.
auto allocate(const RenderMeshVertex* vertices, std::size_t count) -> BucketId
Creates a new bucket, and copies the given vertices into it.
void deallocate(BucketId bucketId)
Frees the bucket at the given index, and any other buckets linked to it.
auto vertexCount(BucketId bucketId) const -> std::size_t
Gets the number of vertices in the given bucket.
auto next(BucketId bucketId) const -> BucketId
Gets the bucket linked to the given bucket.

Function documentation

cubos::engine::RenderMeshPool::RenderMeshPool(core::gl::RenderDevice& renderDevice, std::size_t bucketCount, std::size_t bucketSize)

Constructs.

Parameters
renderDevice Render device.
bucketCount Bucket count.
bucketSize Bucket size (in vertices).

std::size_t cubos::engine::RenderMeshPool::bucketCount() const

Gets the bucket count.

Returns Bucket count.

std::size_t cubos::engine::RenderMeshPool::bucketSize() const

Gets the bucket size in vertices.

Returns Bucket size in vertices.

std::size_t cubos::engine::RenderMeshPool::freeBucketCount() const

Gets the number of free buckets.

Returns Number of free buckets.

BucketId cubos::engine::RenderMeshPool::allocate(const RenderMeshVertex* vertices, std::size_t count)

Creates a new bucket, and copies the given vertices into it.

Parameters
vertices Pointer to the vertices.
count Number of vertices.
Returns Bucket identifier, or BucketId::Invalid on failure.

If the mesh does not fit within a single bucket, then buckets are created and linked as needed.

void cubos::engine::RenderMeshPool::deallocate(BucketId bucketId)

Frees the bucket at the given index, and any other buckets linked to it.

Parameters
bucketId Bucket identifier.

std::size_t cubos::engine::RenderMeshPool::vertexCount(BucketId bucketId) const

Gets the number of vertices in the given bucket.

Parameters
bucketId Bucket identifier.
Returns Bucket size.

BucketId cubos::engine::RenderMeshPool::next(BucketId bucketId) const

Gets the bucket linked to the given bucket.

Parameters
bucketId Bucket identifier.
Returns Bucket identifier, or BucketId::Invalid if there's none.