Description
The DrawIndexed
method is used to render indexed geometry using the specified vertex and index buffers, material, and rendering attributes. This method is part of the CommandList
class within the Sandbox.Rendering
namespace. It allows for efficient rendering of complex models by reusing vertices through indices.
Usage
To use the DrawIndexed
method, you need to provide the following parameters:
vertexBuffer
: A GpuBuffer<T>
containing the vertex data.
indexBuffer
: A GpuBuffer
containing the indices that define the order of vertices.
material
: A Material
object that defines the appearance of the rendered geometry.
startIndex
: An Int32
specifying the starting index in the index buffer.
indexCount
: An Int32
specifying the number of indices to be used for rendering.
attributes
: A RenderAttributes
object that contains additional rendering settings.
primitiveType
: A Graphics.PrimitiveType
enum value that specifies the type of primitives to render (e.g., triangles, lines).
Ensure that the vertex and index buffers are properly populated and that the material is correctly configured before calling this method.
Example
// Example usage of DrawIndexed method
// Assume vertexBuffer and indexBuffer are already created and populated
GpuBuffer<Vertex> vertexBuffer = new GpuBuffer<Vertex>(...);
GpuBuffer indexBuffer = new GpuBuffer(...);
Material material = new Material(...);
RenderAttributes attributes = new RenderAttributes();
// Create a CommandList instance
CommandList commandList = new CommandList();
// Set the primitive type to triangles
Graphics.PrimitiveType primitiveType = Graphics.PrimitiveType.TriangleList;
// Draw the indexed geometry
commandList.DrawIndexed(
vertexBuffer,
indexBuffer,
material,
startIndex: 0,
indexCount: indexBuffer.Count,
attributes: attributes,
primitiveType: primitiveType
);