pioneerspacesim/pioneer — pull request #2762 by Luomu (2014-02-16 15:37:55+00:00)
Title: New Vertex buffer class

Replaces the clunky Surface/StaticMesh classes with a simpler Vertex Buffer and Index Buffer. Should have done that from the start but I didn't know better :)
- more flexible with attribute combinations
- easier to render, less code
- less memory use (StaticMesh kept copy of data in client memory)

Usage summary:
```
//fill description and create
VertexBufferDesc vbd;
vbd.attrib[0].semantic = ATTRIB_POSITION;
vbd.attrib[0].format = ATTRIB_FORMAT_FLOAT3;
vbd.attrib[1].semantic = ATTRIB_UV0;
vbd.attrib[1].format = ATTRIB_FORMAT_FLOAT2;
vbd.numVertices = 512;
vbd.usage = BUFFER_USAGE_STATIC;

auto vb = renderer->CreateVertexBuffer(vbd);

//fill (style 1)
Uint8 *vtxPtr = vb->Map(BUFFER_MAP_WRITE);
const Uint32 posOffset = vbd.GetOffset(ATTRIB_POSITION);
const Uint32 stride = vbd.GetVertexSize();
//fill some vertices...
for (int i = 0; i < 512; i++)
*reinterpret_cast(vtxPtr + i * stride + posOffset) = vector3f(...)
vb->Unmap();

//fill (style 2)
SomeVertex *vtxPtr = vb->Map(BUFFER_MAP_WRITE);
for (int i = 0; i < 512; i++)
vtxPtr[i]->pos = vector3f(...);
vb->Unmap

//Render entire buffer
renderer->DrawBuffer(vb, renderState, material, TRIANGLES);

//render partial buffer
vb->SetVertexCount(50);
renderer->DrawBuffer(vb, renderState, material, TRIANGLES);
```

Index buffers are also available, with them you call renderer->DrawBufferIndexed().