Pyrogenesis  trunk
VertexBufferManager.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 
18 /*
19  * Allocate and destroy CVertexBuffers
20  */
21 
22 #ifndef INCLUDED_VERTEXBUFFERMANAGER
23 #define INCLUDED_VERTEXBUFFERMANAGER
24 
25 #include "VertexBuffer.h"
26 
27 ///////////////////////////////////////////////////////////////////////////////
28 // CVertexBufferManager: owner object for CVertexBuffer objects; acts as
29 // 'front end' for their allocation and destruction
31 {
32 public:
33 
34  /**
35  * Try to allocate a vertex buffer of the given size and type.
36  *
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
45  */
46  CVertexBuffer::VBChunk* Allocate(size_t vertexSize, size_t numVertices, GLenum usage, GLenum target, void* backingStore = NULL);
47 
48  /// Returns the given @p chunk to its owning buffer
49  void Release(CVertexBuffer::VBChunk* chunk);
50 
51  /// Returns a list of all buffers
52  const std::list<CVertexBuffer*>& GetBufferList() const { return m_Buffers; }
53 
54  size_t GetBytesReserved();
55  size_t GetBytesAllocated();
56 
57  /// Explicit shutdown of the vertex buffer subsystem; releases all currently-allocated buffers.
58  void Shutdown();
59 
60 private:
61  /// List of all known vertex buffers
62  std::list<CVertexBuffer*> m_Buffers;
63 };
64 
66 
67 #endif
Definition: VertexBufferManager.h:30
const std::list< CVertexBuffer * > & GetBufferList() const
Returns a list of all buffers.
Definition: VertexBufferManager.h:52
void Shutdown()
Explicit shutdown of the vertex buffer subsystem; releases all currently-allocated buffers...
Definition: VertexBufferManager.cpp:37
CVertexBufferManager g_VBMan
Definition: VertexBufferManager.cpp:31
VBChunk: describes a portion of this vertex buffer.
Definition: VertexBuffer.h:62
void Release(CVertexBuffer::VBChunk *chunk)
Returns the given chunk to its owning buffer.
Definition: VertexBufferManager.cpp:101
size_t GetBytesReserved()
Definition: VertexBufferManager.cpp:111
std::list< CVertexBuffer * > m_Buffers
List of all known vertex buffers.
Definition: VertexBufferManager.h:62
CVertexBuffer::VBChunk * Allocate(size_t vertexSize, size_t numVertices, GLenum usage, GLenum target, void *backingStore=NULL)
Try to allocate a vertex buffer of the given size and type.
Definition: VertexBufferManager.cpp:50
size_t GetBytesAllocated()
Definition: VertexBufferManager.cpp:122