PDA

View Full Version : VertexArray in graphics memory



Steffen
02-10-2009, 07:42 AM
How is it possible to create some vertex arrays in graphics memory and then draw them periodical with different matrices?

Direct3D pseudo-code:

// create vertex buffer in graphics memory
VertexBuffer vb = new VertexBuffer(
typeof(CustomVertex.PositionColored),
numVerts,
D3Ddevice,
Usage.None,
CustomVertex.PositionColored.Format,
Pool.Default);

// write array to graphics memory
GraphicsStream stm = vb.Lock(0, 0, LockFlags.None);
stm.Write(array);
vb.Unlock();

// draw vertices directly from graphics memory
D3Ddevice.Transform.World = GetTransformMatrix();
D3Ddevice.SetStreamSource(0, vb, 0);
D3Ddevice.DrawPrimitives(PrimitiveType.LineStrip, 0, numVerts - 1);

zeoverlord
02-10-2009, 09:02 AM
it's pretty simple, just use vertex buffer objects, just read this document http://www.opengl.org/registry/specs/ARB/vertex_buffer_object.txt
There are some samples at the end of the document.

_NK47
02-11-2009, 04:38 AM
OpenGL equivalents -
new VertexBuffer - glGenBuffers
Lock - glMapBuffer
Unlock - glUnmapBuffer
SetStreamSource - tough one. glBindBuffer then iterate through vertex elements and call the correct function (glVertexPointer, glColorPointer, glTexCoordPointer, ...)

glPointer calls are deprecated in 3.0.