Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 typically GL_STATIC_DRAW or GL_DYNAMIC_DRAW
40  * @param target typically GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER
41  * @return chunk, or NULL if no free chunks available
42  */
43  CVertexBuffer::VBChunk* Allocate(size_t vertexSize, size_t numVertices, GLenum usage, GLenum target);
44 
45  /// Returns the given @p chunk to its owning buffer
46  void Release(CVertexBuffer::VBChunk* chunk);
47 
48  /// Returns a list of all buffers
49  const std::list<CVertexBuffer*>& GetBufferList() const { return m_Buffers; }
50 
51  size_t GetBytesReserved();
52  size_t GetBytesAllocated();
53 
54  /// Returns the maximum possible size of a single vertex buffer
55  size_t GetMaxBufferSize() const { return MAX_VB_SIZE_BYTES; }
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
const std::list< CVertexBuffer * > & GetBufferList() const
Returns a list of all buffers.
void Shutdown()
Explicit shutdown of the vertex buffer subsystem; releases all currently-allocated buffers...
CVertexBufferManager g_VBMan
VBChunk: describes a portion of this vertex buffer.
Definition: VertexBuffer.h:47
CVertexBuffer::VBChunk * Allocate(size_t vertexSize, size_t numVertices, GLenum usage, GLenum target)
Try to allocate a vertex buffer of the given size and type.
void Release(CVertexBuffer::VBChunk *chunk)
Returns the given chunk to its owning buffer.
std::list< CVertexBuffer * > m_Buffers
List of all known vertex buffers.
#define MAX_VB_SIZE_BYTES
Definition: VertexBuffer.h:34
size_t GetMaxBufferSize() const
Returns the maximum possible size of a single vertex buffer.