class Graphics

in global :: Sandbox

Used to render to the screen using your Graphics Card, or whatever you kids are using in your crazy future computers. Whatever it is I'm sure it isn't fungible and everyone has free money and no-one has to ever work.


public static bool IsActive { get; }

If true then we're currently rendering and you are safe to use the contents of this class

public static SceneLayerType LayerType { get; }

The current layer type. This is useful to tell whether you're meant to be drawing opaque, transparent or shadow. You mainly don't need to think about this, but when you do, it's here.

public static Rect Viewport { get; set; }

In pixel size, where are we rendering to?

public static RenderAttributes Attributes { get; }

Access to the current render context's attributes. These will be used to set attributes in materials/shaders. This is cleared at the end of the render block.

public static Vector3 CameraPosition { get; }

The camera position of the currently rendering view

public static void SetupLighting( SceneObject obj, RenderAttributes targetAttributes = null )

Setup the lighting attributes for this current object. Place them in the targetAttributes

public static RenderTarget GrabFrameTexture( string targetName = FrameTexture, RenderAttributes renderAttributes = null, bool withMips = False )

Grabs the current viewport's color texture and stores it in targetName on renderAttributes.

public static RenderTarget GrabDepthTexture( string targetName = DepthTexture, RenderAttributes renderAttributes = null, bool withMips = False )

Grabs the current depth texture and stores it in targetName on renderAttributes.

public static RenderTarget RenderTarget { get; set; }

Get or set the current render target. Setting this will bind the render target and change the viewport to match it.

public static void Clear( Color color, bool clearColor = True, bool clearDepth = True, bool clearStencil = True )

Clear the current drawing context to given color.

  • color Color to clear to.
  • clearColor Whether to clear the color buffer at all.
  • clearDepth Whether to clear the depth buffer.
  • clearStencil Whether to clear the stencil buffer.

public static void Clear( bool clearColor = True, bool clearDepth = True )

Clear the current drawing context to given color.

  • clearColor Whether to clear the color buffer to transparent color.
  • clearDepth Whether to clear the depth buffer.

public static bool RenderToTexture( SceneCamera camera, Texture target )

Render this camera to the specified texture target

public static void CopyTexture( Texture srcTexture, Texture dstTexture )

Copies pixel data from one texture to another on the GPU. This does not automatically resize or scale the texture, format and size should be equal.

public static void CopyTexture( Texture srcTexture, Texture dstTexture, int srcMipSlice = 0, int srcArraySlice = 0, int dstMipSlice = 0, int dstArraySlice = 0 )

Copies pixel data from one texture to another on the GPU. This does not automatically resize or scale the texture, format and size should be equal. This one lets you copy to/from arrays / specific mips.

public static void Blit( Material material, RenderAttributes attributes = null )

Draw a screen space quad using the passed material. Your material should be using a screenspace shader so it will actually render to the screen and not in worldspace at 0,0,0

public static void DrawQuad( ref Rect rect, ref Material material, ref Color color, RenderAttributes attributes = null )

Draw a quad in screenspace

public static Rect DrawText( ref Rect position, string text, Color color, string fontFamily = Roboto, float fontSize = 20, float fontWeight = 450, TextFlag flags = Center )

Draws a text quad in screenspace using the Material.UI.Text material.

public static Rect DrawText( ref Rect position, ref TextRendering.Scope scope, TextFlag flags = Center )

Draws a text quad in screenspace using the Material.UI.Text material.

public static Rect DrawText( ref Vector2 position, string text, Color color, string fontFamily = Roboto, float fontSize = 20, float fontWeight = 450 )

Draws a text quad in screenspace using the Material.UI.Text material.

public static Rect MeasureText( ref Rect position, string text, string fontFamily = Roboto, float fontSize = 20, float fontWeight = 450, TextFlag flags = Center )

Measure how big some text will be, without having to render it

public static Rect MeasureText( ref Rect position, ref TextRendering.Scope scope, TextFlag flags = Center )

Measure how big some text will be, without having to render it

public static Rect DrawIcon( Rect rect, string iconName, Color color, float fontSize = 20, TextFlag alignment = Center )

Calls DrawText with "Material Icons" font. You can get a list of icons here https://fonts.google.com/icons?selected=Material+Icons

public static void DrawRoundedRectangle( ref Rect rect, ref Color color, ref Vector4 cornerRadius = null, ref Vector4 borderWidth = null, ref Color borderColor = null )

Draw a rounded rectangle, with optional border, in Material.UI.Box

public static void DrawModel( Model model, Transform transform, RenderAttributes attributes = null )

Draws a single model at the given Transform immediately.

  • model The model to draw
  • transform Transform to draw the model at
  • attributes Optional attributes to apply only for this draw call

public static void DrawModelInstancedIndirect( Model model, GpuBuffer buffer, int bufferOffset = 0, RenderAttributes attributes = null )

Draws multiple instances of a model using GPU instancing with the number of instances being provided by indirect draw arguments. Use `SV_InstanceID` semantic in shaders to access the rendered instance.

  • model The model to draw
  • buffer The GPU buffer containing the DrawIndirectArguments
  • bufferOffset Optional offset in the GPU buffer
  • attributes Optional attributes to apply only for this draw call

public static void DrawModelInstanced( Model model, int count, RenderAttributes attributes = null )

Draws multiple instances of a model using GPU instancing. This is similar to , except the count is provided from the CPU rather than via a GPU buffer. Use `SV_InstanceID` semantic in shaders to access the rendered instance.

  • model The model to draw
  • count The number of instances to draw
  • attributes Optional attributes to apply only for this draw call

public static void GenerateMipMaps( Texture texture, Graphics.DownsampleMethod downsampleMethod = Box, int initialMip = 0, int numMips = -1 )

Generate the mip maps for this texture. Obviously the texture needs to support mip maps.

public static void ResourceBarrierTransition( Texture texture, ResourceState state )

Executes a barrier transition for the given GPU Texture Resource. Transitions the texture resource to a new pipeline stage and access state.

  • texture The texture to transition.
  • state The new resource state for the texture.

public static void ResourceBarrierTransition( GpuBuffer buffer, ResourceState state )

Executes a barrier transition for the given GPU Buffer Resource. Transitions the buffer resource to a new pipeline stage and access state.

  • buffer The GPU buffer to transition.
  • state The new resource state for the buffer.

public static void ResourceBarrierTransition( GpuBuffer buffer, ResourceState before, ResourceState after )

Executes a barrier transition for the given GPU Buffer Resource. Transitions the buffer resource from a known source state to a specified destination state.

  • buffer The GPU buffer to transition.
  • before The current resource state of the buffer.
  • after The desired resource state of the buffer after the transition.

public static void ResourceBarrierTransition( GpuBuffer<T> buffer, ResourceState state )

😔 No documentation found.

public static void ResourceBarrierTransition( GpuBuffer<T> buffer, ResourceState before, ResourceState after )

😔 No documentation found.

public Type GetType( )

😔 No documentation found.

public string ToString( )

😔 No documentation found.

public int GetHashCode( )

😔 No documentation found.

public bool Equals( object obj )

😔 No documentation found.

public static void Draw( Span<Vertex> vertices, int vertCount, Span<ushort> indices, int indexCount, Material material, RenderAttributes attributes = null, Graphics.PrimitiveType primitiveType = Triangles )

😔 No documentation found.

public static void Draw( List<Vertex> vertices, int vertCount, Material material, RenderAttributes attributes = null, Graphics.PrimitiveType primitiveType = Triangles )

😔 No documentation found.

public static void Draw( Span<Vertex> vertices, int vertCount, Material material, RenderAttributes attributes = null, Graphics.PrimitiveType primitiveType = Triangles )

😔 No documentation found.

public static void Draw( GpuBuffer<T> vertexBuffer, GpuBuffer indexBuffer, Material material, int startIndex = 0, int indexCount = 0, RenderAttributes attributes = null, Graphics.PrimitiveType primitiveType = Triangles )

😔 No documentation found.

public static void Draw( GpuBuffer<T> vertexBuffer, Material material, int startVertex = 0, int vertexCount = 0, RenderAttributes attributes = null, Graphics.PrimitiveType primitiveType = Triangles )

😔 No documentation found.

public static void CopyTexture( Texture srcTexture, Texture dstTexture, int srcMipSlice = 0, int srcArraySlice = 0, int srcMipLevels = 1, int dstMipSlice = 0, int dstArraySlice = 0, int dstMipLevels = 1 )

😔 No documentation found.

public static void DrawModelInstanced( Model model, Span<Transform> transforms, RenderAttributes attributes = null )

😔 No documentation found.

public static void Render( SceneObject obj, Nullable<Transform> transform = null, Nullable<Color> color = null, Material material = null )

😔 No documentation found.