Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://astro.uni-altai.ru/~aw/stellarium/api/classStelVertexBuffer.html
Дата изменения: Unknown Дата индексирования: Fri Feb 28 07:37:34 2014 Кодировка: Поисковые слова: comet tail |
![]() |
Stellarium 0.12.3
|
Vertex buffer interface. More...
#include <StelVertexBuffer.hpp>
Public Member Functions | |
~StelVertexBuffer () | |
Destroy the vertex buffer. StelVertexBuffer is deleted by the user, not StelRenderer. More... | |
void | addVertex (const V &vertex) |
Add a new vertex to the end of the buffer. More... | |
V | getVertex (const int index) const |
Return vertex at specified index in the buffer. More... | |
void | setVertex (const int index, const V &vertex) |
Set vertex at specified index in the buffer. More... | |
void | lock () |
Lock the buffer. Must be called before drawing. More... | |
void | unlock () |
Unlock the buffer. This is needed to modify the buffer after drawing. More... | |
bool | locked () const |
Is this buffer locked? More... | |
int | length () const |
Returns the number of vertices in the buffer. More... | |
PrimitiveType | primitiveType () const |
Return the type of graphics primitives drawn with this vertex buffer. More... | |
virtual void | clear () |
Clear the buffer, removing all vertices. More... | |
Vertex buffer interface.
Each StelRenderer backend might have a different vertex buffer buffer implementation. StelVertexBuffer, created by the StelRenderer's createVertexBuffer() function wraps this backend.
StelVertexBuffer supports basic operations such as adding, getting and modifying vertices. It can be locked to allow uploading the data to the GPU, and unlocked to modify the buffer.
For drawing (by a StelRenderer), the vertex buffer must be locked. To access/modify vertices, it must be unlocked. A newly created vertex buffer is always unlocked.
V | Vertex type. The addVertex(), getVertex() and setVertex() functions work with this type. This allows the API to be minimal and safe at the same time (no way to mess up vertex format). |
The vertex type is defined by the user. Some commonly used vertex types are in the file GenericVertexTypes.hpp.
Example vertex type:
Currently, vertices must be accessed individually through functions that might have considerable overhead (at least due to indirect call through the virtual function table).
If vertex processing turns out to be too slow, the solution is not to allow direct access to data through the pointer, as that ties us to a particular implementation (array in memory) and might be completely unusable with e.g. VBO based backends.
Rather, considerable speedup could be achieved by adding member functions to add, get and set ranges of vertices.
E.g.:
Note that end might be unnecessary in setVertexRange.
This is still not the same speedup as direct access (due to copying in get/set), but should allow for considerably faster implementations than accessing vertices individually, without forcing backends to store vertices in a particular way.
An alternative, possibly better (especially with C++11) option for modifying vertices would be to use a function pointer / function object to process each vertex.
VertexBuffer is currently separated into frontend (StelVertexBuffer), which allows type-safe vertex buffer construction thanks to templates, and backend, which doesn't know the vertex type and works on raw data described by metadata generated by the VERTEX_ATTRIBUTES macro in the vertex type.
This is because virtual methods can't be templated. There might be a workaround for this, but I'm not aware of any at the moment.
Definition at line 171 of file StelVertexBuffer.hpp.
|
inline |
Destroy the vertex buffer. StelVertexBuffer is deleted by the user, not StelRenderer.
Definition at line 179 of file StelVertexBuffer.hpp.
|
inline |
Add a new vertex to the end of the buffer.
The buffer must not be locked.
vertex | Vertex to add. |
Definition at line 189 of file StelVertexBuffer.hpp.
|
inlinevirtual |
Clear the buffer, removing all vertices.
The buffer must not be locked.
The backend implementation might reuse previously allocated storage after clearing, so calling clear() might be more efficient than destroying a buffer and then constructing a new one.
Definition at line 271 of file StelVertexBuffer.hpp.
|
inline |
Return vertex at specified index in the buffer.
The buffer must not be locked.
index | Index of the vertex to get. |
Definition at line 203 of file StelVertexBuffer.hpp.
|
inline |
Returns the number of vertices in the buffer.
Definition at line 253 of file StelVertexBuffer.hpp.
|
inline |
Lock the buffer. Must be called before drawing.
Definition at line 233 of file StelVertexBuffer.hpp.
|
inline |
Is this buffer locked?
Definition at line 247 of file StelVertexBuffer.hpp.
|
inline |
Return the type of graphics primitives drawn with this vertex buffer.
Definition at line 259 of file StelVertexBuffer.hpp.
|
inline |
Set vertex at specified index in the buffer.
The buffer must not be locked.
index | Index of the vertex to set. |
vertex | Value to set the vertex to. |
Definition at line 224 of file StelVertexBuffer.hpp.
|
inline |
Unlock the buffer. This is needed to modify the buffer after drawing.
Definition at line 240 of file StelVertexBuffer.hpp.