Graphics
public static abstract sealed class Graphics 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.
Properties
| Name | Type | Description |
|---|---|---|
IsActive static | Boolean | If true then we're currently rendering and you are safe to use the contents of this class |
LayerType static | SceneLayerType | 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. |
Viewport static | Rect | In pixel size, where are we rendering to? |
Attributes static | RenderAttributes | 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. |
CameraTransform static | Transform | The camera transform of the currently rendering view |
CameraPosition static | Vector3 | The camera position of the currently rendering view |
CameraRotation static | Rotation | The camera rotation of the currently rendering view |
FieldOfView static | Single | The field of view of the currently rendering camera view, in degrees. |
Frustum static | Frustum | The frustum of the currently rendering camera view. |
RenderTarget static | RenderTarget | Get or set the current render target. Setting this will bind the render target and change the viewport to match it. |
Methods
static Void SetupLighting(SceneObject obj, RenderAttributes targetAttributes = null) Setup the lighting attributes for this current object. Place them in the targetAttributes
static RenderTarget GrabFrameTexture(String targetName = FrameTexture, RenderAttributes renderAttributes = null, DownsampleMethod downsampleMethod = -1) Grabs the current viewport's color texture and stores it in targetName on renderAttributes.
static Void GrabFrameTexture(String targetName, RenderAttributes renderAttributes, Boolean withMips) static RenderTarget GrabDepthTexture(String targetName = DepthTexture, RenderAttributes renderAttributes = null) Grabs the current depth texture and stores it in targetName on renderAttributes.
static Void Clear(Color color, Boolean clearColor = True, Boolean clearDepth = True, Boolean 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. static Void Clear(Boolean clearColor = True, Boolean 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. static Boolean RenderToTexture(SceneCamera camera, Texture target) Render this camera to the specified texture target
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.
static Void CopyTexture(Texture srcTexture, Texture dstTexture, Int32 srcMipSlice = 0, Int32 srcArraySlice = 0, Int32 srcMipLevels = 1, Int32 dstMipSlice = 0, Int32 dstArraySlice = 0, Int32 dstMipLevels = 1) static Void CopyTexture(Texture srcTexture, Texture dstTexture, Int32 srcMipSlice = 0, Int32 srcArraySlice = 0, Int32 dstMipSlice = 0, Int32 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.
static Void FlushGPU() Forces the GPU to flush all pending commands and wait for completion. Useful when you need to ensure GPU work is finished before proceeding. Can be called outside of a render block.
static Void Draw(GpuBuffer<T> vertexBuffer, Material material, Int32 startVertex = 0, Int32 vertexCount = 0, RenderAttributes attributes = null, PrimitiveType primitiveType = 5) static Void Draw(GpuBuffer<T> vertexBuffer, GpuBuffer indexBuffer, Material material, Int32 startIndex = 0, Int32 indexCount = 0, RenderAttributes attributes = null, PrimitiveType primitiveType = 5) static Void Draw(Span<Vertex> vertices, Int32 vertCount, Material material, RenderAttributes attributes = null, PrimitiveType primitiveType = 5) static Void Draw(List<Vertex> vertices, Int32 vertCount, Material material, RenderAttributes attributes = null, PrimitiveType primitiveType = 5) static Void Draw(Span<Vertex> vertices, Int32 vertCount, Span<UInt16> indices, Int32 indexCount, Material material, RenderAttributes attributes = null, PrimitiveType primitiveType = 5) 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
static Void Render(SceneObject obj, Transform? transform = null, Color? color = null, Material material = null) static Void DrawQuad(Rect rect, Material material, Color color, RenderAttributes attributes = null) Draw a quad in screenspace
static Rect DrawText(Rect position, String text, Color color, String fontFamily = Roboto, Single fontSize = 20, Single fontWeight = 450, TextFlag flags = 132) Draws a text quad in screenspace using the Material.UI.Text material.
static Rect DrawText(Rect position, Scope scope, TextFlag flags = 132) Draws a text quad in screenspace using the Material.UI.Text material.
static Rect DrawText(Vector2 position, String text, Color color, String fontFamily = Roboto, Single fontSize = 20, Single fontWeight = 450) Draws a text quad in screenspace using the Material.UI.Text material.
static Rect MeasureText(Rect position, String text, String fontFamily = Roboto, Single fontSize = 20, Single fontWeight = 450, TextFlag flags = 132) Measure how big some text will be, without having to render it
static Rect MeasureText(Rect position, Scope scope, TextFlag flags = 132) Measure how big some text will be, without having to render it
static Rect DrawIcon(Rect rect, String iconName, Color color, Single fontSize = 20, TextFlag alignment = 132) Calls DrawText with "Material Icons" font. You can get a list of icons here https://fonts.google.com/icons?selected=Material+Icons
static Void DrawRoundedRectangle(Rect rect, Color color, Vector4 cornerRadius = null, Vector4 borderWidth = null, Color borderColor = null) Draw a rounded rectangle, with optional border, in Material.UI.Box
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 static Void DrawModelInstanced(Model model, Span<Transform> transforms, RenderAttributes attributes = null) static Void DrawModelInstancedIndirect(Model model, GpuBuffer buffer, Int32 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 static Void DrawModelInstanced(Model model, Int32 count, RenderAttributes attributes = null) Draws multiple instances of a model using GPU instancing. This is similar to RenderAttributes), 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 static Void GenerateMipMaps(Texture texture, DownsampleMethod downsampleMethod = 0, Int32 initialMip = 0, Int32 numMips = -1) Generate the mip maps for this texture. Obviously the texture needs to support mip maps.
static Void ResourceBarrierTransition(Texture texture, ResourceState state, Int32 mip = -1) 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. mip — The mip level to transition (-1 for all mips). static Void ResourceBarrierTransition(GpuBuffer<T> buffer, ResourceState state) 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. static Void ResourceBarrierTransition(GpuBuffer<T> buffer, ResourceState before, ResourceState after) 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. static Void UavBarrier(Texture texture) Issues a UAV barrier for the given texture, ensuring writes from prior shader invocations are visible to subsequent ones without changing the resource layout.
texture — The texture to barrier. static Void UavBarrier(GpuBuffer buffer) Issues a UAV barrier for the given GPU buffer, ensuring writes from prior shader invocations are visible to subsequent ones.
buffer — The buffer to barrier.