GraphicsDevice.DrawIndexedPrimitives
– 그래픽카드에 vertex와 index 정보를 초기화하고, 그것을 호출하여 Draw하는 방식
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.graphicsdevice.drawindexedprimitives.aspx
void InitializePrimitive()
{
// 중간생략…
// Initialize our Vertex Declaration
vertexDeclaration = new VertexDeclaration(new VertexElement[]
{
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
}
);
// Initialize the vertex buffer, allocating memory for each vertex.
vertexBuffer = new VertexBuffer(graphics.GraphicsDevice,
vertexDeclaration, vertices.Count, BufferUsage.None);
// Set the vertex buffer data to the array of vertices.
vertexBuffer.SetData(vertices.ToArray());
// Create an index buffer, and copy our index data into it.
indexBuffer = new IndexBuffer(graphics.GraphicsDevice, typeof(ushort),
indices.Count, BufferUsage.None);
indexBuffer.SetData(indices.ToArray());
}
void DrawPrimitive()
{
// 중간생략…
// Set our vertex declaration, vertex buffer, and index buffer.
graphics.GraphicsDevice.SetVertexBuffer(vertexBuffer);
graphics.GraphicsDevice.Indices = indexBuffer;
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
int primitiveCount = indices.Count / 3;
graphics.GraphicsDevice.DrawIndexedPrimitives(
PrimitiveType.TriangleList, 0, 0, vertices.Count, 0, primitiveCount);
}
}
GraphicsDevice.DrawUserIndexedPrimitives
– 매 프레임마다 GPU로 vertex와 index 정보를 보내어 Draw 하는 방식
– vertex와 index 정보가 계속해서 바뀌는 경우에 사용 (그러나, DynamicVertexBuffer가 이것보다 좀 더 빠르다고 함)
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.graphicsdevice.drawuserindexedprimitives.aspx
{
// 중간생략…
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
int primitiveCount = indices.Count / 3;
graphics.GraphicsDevice.DrawUserIndexedPrimitives(
PrimitiveType.TriangleList, vertices.ToArray(), 0, vertices.Count,
indices.ToArray(), 0, primitiveCount);
}
}