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 )

robot_2Generated
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 part of the rendering pipeline and is used to draw graphics using a specified material and render attributes. It allows for the rendering of a specified range of vertices from a vertex buffer, using a particular primitive type.

Usage

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

  • vertexBuffer: A GpuBuffer<T> containing the vertices to be drawn. This buffer should be populated with vertex data before calling this method.
  • material: A Material object that defines the appearance of the drawn vertices. This includes shaders and textures.
  • startVertex: An Int32 indicating the starting index in the vertex buffer from which to begin drawing.
  • vertexCount: An Int32 specifying the number of vertices to draw from the vertex buffer.
  • 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.

This method does not return a value and is typically called within a rendering loop or a rendering context where the graphics pipeline is set up.

Example

// Example usage of the Draw method

// Assume vertexBuffer is a GpuBuffer<T> that has been populated with vertex data
GpuBuffer<Vertex> vertexBuffer = new GpuBuffer<Vertex>(...);

// Create a material for rendering
Material material = new Material("path/to/shader");

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

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

// Draw the vertices
Graphics.Draw(vertexBuffer, material, 0, vertexBuffer.Count, attributes, primitiveType);