static void Draw( GpuBuffer<T> vertexBuffer, Material material, int startVertex, int vertexCount, RenderAttributes attributes, Sandbox.Graphics/PrimitiveType primitiveType )
static void Draw( GpuBuffer<T> vertexBuffer, GpuBuffer indexBuffer, Material material, int startIndex, int indexCount, RenderAttributes attributes, Sandbox.Graphics/PrimitiveType primitiveType )
static void Draw( System.Span<Vertex> vertices, int vertCount, Material material, RenderAttributes attributes, Sandbox.Graphics/PrimitiveType primitiveType )
static void Draw( List<Vertex> vertices, int vertCount, Material material, RenderAttributes attributes, Sandbox.Graphics/PrimitiveType primitiveType )
static void Draw( System.Span<Vertex> vertices, int vertCount, System.Span<System.UInt16> indices, int indexCount, Material material, RenderAttributes attributes, Sandbox.Graphics/PrimitiveType primitiveType )

book_4_sparkGenerated
code_blocksInput

Description

The Draw method in the Sandbox.Graphics class is a static method used to render a set of vertices to the screen. This method is designed to work with a vertex buffer, a material, and various rendering attributes to draw a specified number of vertices starting from a given index. The method also allows specifying the type of primitive to render, such as triangles or lines.

Usage

To use the Draw method, you need to provide the following parameters:

  • vertexBuffer: A GpuBuffer<T> containing the vertices to be rendered. This buffer should be properly initialized and filled with vertex data.
  • material: A Material object that defines the appearance of the rendered vertices. This includes shaders and textures.
  • startVertex: An int specifying the index of the first vertex to start rendering from within the vertex buffer.
  • vertexCount: An int indicating the number of vertices to render.
  • attributes: A RenderAttributes object that provides additional rendering settings and parameters.
  • primitiveType: A Graphics.PrimitiveType enum value that specifies the type of primitive to render, such as triangles, lines, or points.

Example

// Example usage of the Draw method

// Assume vertexBuffer is a GpuBuffer<Vertex> that has been initialized and filled with data
GpuBuffer<Vertex> vertexBuffer = new GpuBuffer<Vertex>(...);

// Assume material is a Material object that has been set up with shaders and textures
Material material = new Material(...);

// Define the start vertex and the number of vertices to draw
int startVertex = 0;
int vertexCount = 100;

// Create render attributes
RenderAttributes attributes = new RenderAttributes();

// Specify the primitive type
Graphics.PrimitiveType primitiveType = Graphics.PrimitiveType.TriangleList;

// Draw the vertices
Graphics.Draw(vertexBuffer, material, startVertex, vertexCount, attributes, primitiveType);