Merge 'remotes/trunk'
[0ad.git] / source / renderer / VertexBufferManager.h
blob2ef7a81c1083bd69fd83c79e8a42f84fcc8913d4
1 /* Copyright (C) 2012 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
19 * Allocate and destroy CVertexBuffers
22 #ifndef INCLUDED_VERTEXBUFFERMANAGER
23 #define INCLUDED_VERTEXBUFFERMANAGER
25 #include "VertexBuffer.h"
27 ///////////////////////////////////////////////////////////////////////////////
28 // CVertexBufferManager: owner object for CVertexBuffer objects; acts as
29 // 'front end' for their allocation and destruction
30 class CVertexBufferManager
32 public:
34 /**
35 * Try to allocate a vertex buffer of the given size and type.
37 * @param vertexSize size of each vertex in the buffer
38 * @param numVertices number of vertices in the buffer
39 * @param usage GL_STATIC_DRAW, GL_DYNAMIC_DRAW, GL_STREAM_DRAW
40 * @param target typically GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER
41 * @param backingStore if usage is STATIC, this is NULL; else for DYNAMIC/STREAM,
42 * this must be a copy of the vertex data that remains valid for the
43 * lifetime of the VBChunk
44 * @return chunk, or NULL if no free chunks available
46 CVertexBuffer::VBChunk* Allocate(size_t vertexSize, size_t numVertices, GLenum usage, GLenum target, void* backingStore = NULL);
48 /// Returns the given @p chunk to its owning buffer
49 void Release(CVertexBuffer::VBChunk* chunk);
51 /// Returns a list of all buffers
52 const std::list<CVertexBuffer*>& GetBufferList() const { return m_Buffers; }
54 size_t GetBytesReserved();
55 size_t GetBytesAllocated();
57 /// Explicit shutdown of the vertex buffer subsystem; releases all currently-allocated buffers.
58 void Shutdown();
60 private:
61 /// List of all known vertex buffers
62 std::list<CVertexBuffer*> m_Buffers;
65 extern CVertexBufferManager g_VBMan;
67 #endif