Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/renderer/VertexBufferManager.h
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2022 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | public: | ||||
* | * | ||||
* @param vertexSize size of each vertex in the buffer | * @param vertexSize size of each vertex in the buffer | ||||
* @param numVertices number of vertices in the buffer | * @param numVertices number of vertices in the buffer | ||||
* @param usage GL_STATIC_DRAW, GL_DYNAMIC_DRAW, GL_STREAM_DRAW | * @param usage GL_STATIC_DRAW, GL_DYNAMIC_DRAW, GL_STREAM_DRAW | ||||
* @param target typically GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER | * @param target typically GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER | ||||
* @param backingStore if usage is STATIC, this is NULL; else for DYNAMIC/STREAM, | * @param backingStore if usage is STATIC, this is NULL; else for DYNAMIC/STREAM, | ||||
* this must be a copy of the vertex data that remains valid for the | * this must be a copy of the vertex data that remains valid for the | ||||
* lifetime of the VBChunk | * lifetime of the VBChunk | ||||
* @return chunk, or NULL if no free chunks available | * @return chunk, or empty handle if no free chunks available | ||||
*/ | */ | ||||
CVertexBuffer::VBChunk* Allocate(size_t vertexSize, size_t numVertices, GLenum usage, GLenum target, void* backingStore = nullptr); | Handle AllocateChunk(size_t vertexSize, size_t numVertices, GLenum usage, GLenum target, void* backingStore = nullptr, Group group = Group::DEFAULT); | ||||
/// Returns the given @p chunk to its owning buffer | /// Returns the given @p chunk to its owning buffer | ||||
void Release(CVertexBuffer::VBChunk* chunk); | void Release(CVertexBuffer::VBChunk* chunk); | ||||
// Same as the Allocate function but returns Handle. Should be used instead | |||||
// of the Allocate. | |||||
Handle AllocateChunk(size_t vertexSize, size_t numVertices, GLenum usage, GLenum target, void* backingStore = nullptr, Group group = Group::DEFAULT); | |||||
size_t GetBytesReserved() const; | size_t GetBytesReserved() const; | ||||
size_t GetBytesAllocated() const; | size_t GetBytesAllocated() const; | ||||
/// Explicit shutdown of the vertex buffer subsystem; releases all currently-allocated buffers. | /// Explicit shutdown of the vertex buffer subsystem; releases all currently-allocated buffers. | ||||
void Shutdown(); | void Shutdown(); | ||||
private: | private: | ||||
CVertexBuffer::VBChunk* AllocateImpl(size_t vertexSize, size_t numVertices, GLenum usage, GLenum target, void* backingStore = nullptr, Group group = Group::DEFAULT); | |||||
/// List of all known vertex buffers | /// List of all known vertex buffers | ||||
std::vector<std::unique_ptr<CVertexBuffer>> m_Buffers[static_cast<std::size_t>(Group::COUNT)]; | std::vector<std::unique_ptr<CVertexBuffer>> m_Buffers[static_cast<std::size_t>(Group::COUNT)]; | ||||
}; | }; | ||||
extern CVertexBufferManager g_VBMan; | extern CVertexBufferManager g_VBMan; | ||||
#endif | #endif |
Wildfire Games · Phabricator