Gorgon
Show / Hide Table of Contents

Class Gorgon2D

Provides 2D rendering functionality.

Inheritance
object
Gorgon2D
Implements
IGorgon2DFluent
IDisposable
IGorgon2DDrawingFluent
IGorgonGraphicsObject
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
Namespace: Gorgon.Renderers
Assembly: Gorgon.Renderers.Gorgon2D.dll
Syntax
public sealed class Gorgon2D : IGorgon2DFluent, IDisposable, IGorgon2DDrawingFluent, IGorgonGraphicsObject
Remarks

The 2D renderer allows applications to render sprites, text and primitives (lines, rectangles, ellipses, etc...) using a simplified interface.

This is a batching renderer, which means that items that need to be drawn are done as a group of items sharing a common global state during rendering (this includes pixel and vertex shaders). Which global states/shaders are applied can be defined by the user via the Gorgon2DBatchState object which is passed to the Begin(Gorgon2DBatchState, GorgonCameraCommon) method.

Because this is a batching renderer, applications must inform the renderer when to start rendering items via the Begin(Gorgon2DBatchState, GorgonCameraCommon) method, and when to end rendering using the End() method.

important

While all drawing must be done between these calls. Changing the current render target, viewport and/or depth/stencil on the GorgonGraphics interface while rendering is not allowed and will generate an exception if an attempt to change those items is made. This means that applications must perform target changes, viewport changes, and/or depth/stencil changes prior to calling Begin(Gorgon2DBatchState, GorgonCameraCommon), or after End().

To render, an application must start the process by calling the Begin(Gorgon2DBatchState, GorgonCameraCommon) method, draw the desired items, and then call the End() method. This render block segregates drawing by global states. So, for example, if the user wishes to change the blending mode, a call to Begin(Gorgon2DBatchState, GorgonCameraCommon) with the Gorgon2DBatchState set up for the appropriate blending mode is made. When finished, the user will call the End() method. These blocks batch all rendering commands until the End() method is called, and this allows for high performance 2D rendering.

Because this renderer uses batching to achieve its performance, it is worth noting that calls to draw items will share the same global state via the GorgonBlendState, GorgonDepthStencilState and GorgonRasterState state objects. This includes pixel shaders and vertex shaders, and their associated resources. And users can send custom states and shaders to the Begin(Gorgon2DBatchState, GorgonCameraCommon) method. However, when a new item is drawn with a different GorgonTexture2DView, or GorgonSamplerState, a state change will be performaned on behalf of the user (for sake of convenience). This means that too many texture/sampler changes between sprites may cause a performance issue.

Constructors

| Edit this page View Source

Gorgon2D(GorgonGraphics, GorgonCameraCommon)

Initializes a new instance of the Gorgon2D class.

Declaration
public Gorgon2D(GorgonGraphics graphics, GorgonCameraCommon defaultCamera = null)
Parameters
Type Name Description
GorgonGraphics graphics

The graphics interface to use for rendering.

GorgonCameraCommon defaultCamera

[Optional] A camera to use as the default camera when rendering.

Remarks

The defaultCamera parameter allows a developer to assign a custom camera as a default camera to fall back on when no camera is passed to the Begin(Gorgon2DBatchState, GorgonCameraCommon) method. As such, this allows developers to maintain control over the default camera view, including its transformation (e.g. offset, rotation, etc...)

If the defaultCamera parameter is null, then an internal default camera will be used.

Exceptions
Type Condition
ArgumentNullException

Thrown when the graphics parameter is null.

See Also
GorgonGraphics
Gorgon2DBatchState

Fields

| Edit this page View Source

Gorgon2DShaderIncludeName

The name of the shaders used by the 2D renderer when including in external shaders.

Declaration
public const string Gorgon2DShaderIncludeName = "Gorgon2DShaders"
Field Value
Type Description
string
See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

GorgonBloomShaderIncludeName

The name of the shaders used by the Gorgon2DBloomEffect.

Declaration
public const string GorgonBloomShaderIncludeName = "Gorgon2DHdrBloomShader"
Field Value
Type Description
string
See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

GorgonChromaticAberrationShaderIncludeName

The name of the shaders used by the Gorgon2DChromaticAberrationEffect.

Declaration
public const string GorgonChromaticAberrationShaderIncludeName = "Gorgon2DChromaticAberrationShader"
Field Value
Type Description
string
See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

GorgonGBufferShaderIncludeName

The name of the shaders used by the Gorgon2DGBuffer when including in external shaders.

Declaration
public const string GorgonGBufferShaderIncludeName = "Gorgon2DGBufferShaders"
Field Value
Type Description
string
See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

GorgonLightingShaderIncludeName

The name of the shaders used by the Gorgon2DLightingEffect.

Declaration
public const string GorgonLightingShaderIncludeName = "Gorgon2DLightingShader"
Field Value
Type Description
string
See Also
GorgonGraphics
Gorgon2DBatchState

Properties

| Edit this page View Source

CurrentCamera

Property to return the currently active camera.

Declaration
public GorgonCameraCommon CurrentCamera { get; }
Property Value
Type Description
GorgonCameraCommon
See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

DefaultFont

Property to return the default font used for text rendering if the user did not specify a font with text drawing routines.

Declaration
public GorgonFont DefaultFont { get; }
Property Value
Type Description
GorgonFont
See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

EmptyBlackTexture

Property to return a black texture to pass to shaders when no texture is specified.

Declaration
public GorgonTexture2DView EmptyBlackTexture { get; }
Property Value
Type Description
GorgonTexture2DView
See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

EmptyNormalMapTexture

Property to return an empty normal map texture to pass to shaders when no texture is specified.

Declaration
public GorgonTexture2DView EmptyNormalMapTexture { get; }
Property Value
Type Description
GorgonTexture2DView
See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

EmptyWhiteTexture

Property to return an empty white texture to pass to shaders when no texture is specified.

Declaration
public GorgonTexture2DView EmptyWhiteTexture { get; }
Property Value
Type Description
GorgonTexture2DView
See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

Graphics

Property to return the GorgonGraphics interface that owns this renderer.

Declaration
public GorgonGraphics Graphics { get; }
Property Value
Type Description
GorgonGraphics
See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

IsRendering

Property to return whether the renderer is currently rendering.

Declaration
public bool IsRendering { get; }
Property Value
Type Description
bool
Remarks

This value will return true if Begin(Gorgon2DBatchState, GorgonCameraCommon) was previously called, and false when End() is called.

See Also
Begin(Gorgon2DBatchState, GorgonCameraCommon)
End()
| Edit this page View Source

Log

Property to return the log used to log debug messages.

Declaration
public IGorgonLog Log { get; }
Property Value
Type Description
IGorgonLog
See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

PrimitiveAlphaTestRange

Property to set or return the alpha testing range for primitive functions.

Declaration
public GorgonRangeF? PrimitiveAlphaTestRange { get; set; }
Property Value
Type Description
GorgonRangeF?
Remarks

Setting this value with a GorgonRangeF will exclude any alpha values within the range when rendering, this will improve performance. If this value is null, then alpha testing is disabled and all pixel values will be rendered.

Currently, the default is set to a minimum of 0 and a maximum of 0. This means that alpha values with a value of 0 will not be rendered.

This applies to methods like DrawFilledRectangle(RectangleF, GorgonColor, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float), DrawRectangle(RectangleF, GorgonColor, float, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float), etc... DrawSprite(GorgonSprite) and DrawTextSprite(GorgonTextSprite) have their own alpha test ranges and are not affected by this property.

See Also
DrawLine(float, float, float, float, GorgonColor, float, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float, float)
DrawRectangle(RectangleF, GorgonColor, float, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float)
DrawEllipse(RectangleF, GorgonColor, float, float, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float)
DrawArc(RectangleF, GorgonColor, float, float, float, float, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float)
DrawTriangle(in GorgonTriangleVertex, in GorgonTriangleVertex, in GorgonTriangleVertex, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float)
DrawFilledRectangle(RectangleF, GorgonColor, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float)
DrawFilledEllipse(RectangleF, GorgonColor, float, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float)
DrawFilledArc(RectangleF, GorgonColor, float, float, float, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float)

Methods

| Edit this page View Source

Begin(Gorgon2DBatchState, GorgonCameraCommon)

Function to begin rendering a batch.

Declaration
public IGorgon2DDrawingFluent Begin(Gorgon2DBatchState batchState = null, GorgonCameraCommon camera = null)
Parameters
Type Name Description
Gorgon2DBatchState batchState

[Optional] Defines common state to use when rendering a batch of objects.

GorgonCameraCommon camera

[Optional] A camera to use when rendering.

Returns
Type Description
IGorgon2DDrawingFluent

The fluent interface for drawing in 2D.

Remarks

The 2D renderer uses batching for performance. This means that drawing items with common states (e.g. blending) can all be sent to the GPU at the same time. To faciliate this, applications must call this method prior to drawing.

When batching occurs, all drawing that shares the same state and texture will be drawn in one deferred draw call to the GPU. However, if too many items are drawn (~10,000 sprites), or the item being drawn has a different texture than the previous item, then the batch is broken up and the previous items will be drawn to the GPU first. So, best practice is to ensure that everything that is drawn shares the same texture. This is typically achieved by using a sprite sheet where multiple sprite images are pack into a single texture.

information

One exception to this is the GorgonPolySprite object, which is drawn immediately.

Once rendering is done, the user must call End() to finalize the rendering. Otherwise, items drawn in the batch will not appear.

This method takes an optional Gorgon2DBatchState object which allows an application to override the blend state, depth/stencil state (if applicable), rasterization state, and pixel/vertex shaders and their associated resources. This means that if an application wants to, for example, change blending modes, then a separate call to this method is required after drawing items with the previous blend state.

If a custom pixel or vertex shader is passed to the batchState, then developers should note which resource slots, and constant buffer slots are used by the 2D renderer itself. Gorgon will allow overriding of these slots, but in those cases, some information may no longer available and things may not work as expected. The following slots are use by the 2D renderer:

Shader TypeResource typeSlot #Purpose
PixelTexture/Sampler0Primary sprite texture/sampler.
PixelTexture1Additional texture for effects.
PixelConstants0Data for alpha testing.
Pixel and VertexConstants12Timing data.
Pixel and VertexConstants13Miscellaneous data (e.g. target width and height, current slot 0 texture size, etc...)
VertexConstants0View/Projection matrix for the CurrentCamera (or the default camera if null).
VertexConstants1Data for a polygon sprite.
Following this list, a developer can use any texture slot from 2 and up, and any constant buffer slots between 2 (or 1 for pixel shaders) and 11 for their own data.

The other optional parameter, camera, allows an application to change the view in which the items are drawn for a batch. This takes a GorgonCameraCommon object that defines the projection and view of the scene being rendered. It is possible with this object to change the coordinate system, and to allow perspective rendering for a batch.

important

There are a few things to be aware of when rendering:

  • Batches cannot be nested. Attempting to do so will cause an exception.
  • Applications must call this method prior to drawing anything. Failure to do so will result in an exception.
  • Calls to SetRenderTarget(GorgonRenderTargetView, GorgonDepthStencil2DView), SetRenderTargets(ReadOnlySpan<GorgonRenderTargetView>, GorgonDepthStencil2DView), SetDepthStencil(GorgonDepthStencil2DView), SetViewport(ViewportF), or SetViewports(ReadOnlySpan<ViewportF>) while a batch is in progress is not allowed and will result in an exception if attempted.
Exceptions
Type Condition
GorgonException

Thrown if Begin(Gorgon2DBatchState, GorgonCameraCommon) is called more than once without calling End().

See Also
Gorgon2DBatchState
GorgonCameraCommon
GorgonPolySprite
GorgonGraphics
| Edit this page View Source

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public void Dispose()
See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

DrawArc(RectangleF, GorgonColor, float, float, float, float, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float)

Function to draw an ellipse.

Declaration
public IGorgon2DDrawingFluent DrawArc(RectangleF region, GorgonColor color, float startAngle, float endAngle, float smoothness = 1, float thickness = 1, GorgonTexture2DView texture = null, RectangleF? textureRegion = null, int textureArrayIndex = 0, GorgonSamplerState textureSampler = null, float depth = 0)
Parameters
Type Name Description
RectangleF region

The region that will contain the ellipse.

GorgonColor color

The color of the ellipse.

float startAngle

The starting angle of the arc, in degrees.

float endAngle

The ending angle of the arc, in degrees.

float smoothness

[Optional] The smoothness of the ellipse.

float thickness

[Optional] The ellipse line thickness.

GorgonTexture2DView texture

[Optional] The texture to render on the ellipse.

RectangleF? textureRegion

[Optional] The texture coordinates to map to the rectangle.

int textureArrayIndex

[Optional] The array index for a texture array to use.

GorgonSamplerState textureSampler

[Optional] The texture sampler to apply to the texture.

float depth

[Optional] The depth value for the ellipse.

Returns
Type Description
IGorgon2DDrawingFluent

The fluent drawing interface.

Exceptions
Type Condition
InvalidOperationException

Thrown if this method was called without having called Begin(Gorgon2DBatchState, GorgonCameraCommon) first.

See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

DrawEllipse(RectangleF, GorgonColor, float, float, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float)

Function to draw an ellipse.

Declaration
public IGorgon2DDrawingFluent DrawEllipse(RectangleF region, GorgonColor color, float smoothness = 1, float thickness = 1, GorgonTexture2DView texture = null, RectangleF? textureRegion = null, int textureArrayIndex = 0, GorgonSamplerState textureSampler = null, float depth = 0)
Parameters
Type Name Description
RectangleF region

The region that will contain the ellipse.

GorgonColor color

The color of the ellipse.

float smoothness

[Optional] The smoothness of the ellipse.

float thickness

[Optional] The ellipse line thickness.

GorgonTexture2DView texture

[Optional] The texture to render on the ellipse.

RectangleF? textureRegion

[Optional] The texture coordinates to map to the rectangle.

int textureArrayIndex

[Optional] The array index for a texture array to use.

GorgonSamplerState textureSampler

[Optional] The texture sampler to apply to the texture.

float depth

[Optional] The depth value for the ellipse.

Returns
Type Description
IGorgon2DDrawingFluent

The fluent drawing interface.

Exceptions
Type Condition
InvalidOperationException

Thrown if this method was called without having called Begin(Gorgon2DBatchState, GorgonCameraCommon) first.

See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

DrawFilledArc(RectangleF, GorgonColor, float, float, float, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float)

Function to draw an ellipse.

Declaration
public IGorgon2DDrawingFluent DrawFilledArc(RectangleF region, GorgonColor color, float startAngle, float endAngle, float smoothness = 1, GorgonTexture2DView texture = null, RectangleF? textureRegion = null, int textureArrayIndex = 0, GorgonSamplerState textureSampler = null, float depth = 0)
Parameters
Type Name Description
RectangleF region

The region that will contain the ellipse.

GorgonColor color

The color of the ellipse.

float startAngle

The starting angle of the arc, in degrees.

float endAngle

The ending angle of the arc, in degrees.

float smoothness

[Optional] The smoothness of the ellipse.

GorgonTexture2DView texture

[Optional] The texture to render on the ellipse.

RectangleF? textureRegion

[Optional] The texture coordinates to map to the rectangle.

int textureArrayIndex

[Optional] The array index for a texture array to use.

GorgonSamplerState textureSampler

[Optional] The texture sampler to apply to the texture.

float depth

[Optional] The depth value for the ellipse.

Returns
Type Description
IGorgon2DDrawingFluent

The fluent drawing interface.

Exceptions
Type Condition
InvalidOperationException

Thrown if this method was called without having called Begin(Gorgon2DBatchState, GorgonCameraCommon) first.

See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

DrawFilledEllipse(RectangleF, GorgonColor, float, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float)

Function to draw an ellipse.

Declaration
public IGorgon2DDrawingFluent DrawFilledEllipse(RectangleF region, GorgonColor color, float smoothness = 1, GorgonTexture2DView texture = null, RectangleF? textureRegion = null, int textureArrayIndex = 0, GorgonSamplerState textureSampler = null, float depth = 0)
Parameters
Type Name Description
RectangleF region

The region that will contain the ellipse.

GorgonColor color

The color of the ellipse.

float smoothness

[Optional] The smoothness of the ellipse.

GorgonTexture2DView texture

[Optional] The texture to render on the ellipse.

RectangleF? textureRegion

[Optional] The texture coordinates to map to the rectangle.

int textureArrayIndex

[Optional] The array index for a texture array to use.

GorgonSamplerState textureSampler

[Optional] The texture sampler to apply to the texture.

float depth

[Optional] The depth value for the ellipse.

Returns
Type Description
IGorgon2DDrawingFluent
Exceptions
Type Condition
InvalidOperationException

Thrown if this method was called without having called Begin(Gorgon2DBatchState, GorgonCameraCommon) first.

See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

DrawFilledRectangle(RectangleF, GorgonColor, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float)

Function to draw a filled rectangle.

Declaration
public IGorgon2DDrawingFluent DrawFilledRectangle(RectangleF region, GorgonColor color, GorgonTexture2DView texture = null, RectangleF? textureRegion = null, int textureArrayIndex = 0, GorgonSamplerState textureSampler = null, float depth = 0)
Parameters
Type Name Description
RectangleF region

The region for the rectangle.

GorgonColor color

The color of the rectangle.

GorgonTexture2DView texture

[Optional] The texture for the rectangle.

RectangleF? textureRegion

[Optional] The texture coordinates to map to the rectangle.

int textureArrayIndex

[Optional] The array index for a texture array to use.

GorgonSamplerState textureSampler

[Optional] The texture sampler to apply to the texture.

float depth

[Optional] The depth value for the rectangle.

Returns
Type Description
IGorgon2DDrawingFluent

The fluent drawing interface.

Exceptions
Type Condition
InvalidOperationException

Thrown if this method was called without having called Begin(Gorgon2DBatchState, GorgonCameraCommon) first.

See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

DrawLine(float, float, float, float, GorgonColor, float, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float, float)

Function to draw a line.

Declaration
public IGorgon2DDrawingFluent DrawLine(float x1, float y1, float x2, float y2, GorgonColor color, float thickness = 1, GorgonTexture2DView texture = null, RectangleF? textureRegion = null, int textureArrayIndex = 0, GorgonSamplerState textureSampler = null, float startDepth = 0, float endDepth = 0)
Parameters
Type Name Description
float x1

The starting horizontal position.

float y1

The starting vertical position.

float x2

The ending horizontal position.

float y2

The ending vertical position.

GorgonColor color

The color of the line.

float thickness

[Optional] The line thickness.

GorgonTexture2DView texture

[Optional] The texture to render on the line.

RectangleF? textureRegion

[Optional] The texture coordinates to map to the rectangle.

int textureArrayIndex

[Optional] The array index for a texture array to use.

GorgonSamplerState textureSampler

[Optional] The texture sampler to apply to the texture.

float startDepth

[Optional] The depth value for the starting point of the line.

float endDepth

[Optional] The depth value for the ending point of the line.

Returns
Type Description
IGorgon2DDrawingFluent

The fluent drawing interface.

Exceptions
Type Condition
InvalidOperationException

Thrown if this method was called without having called Begin(Gorgon2DBatchState, GorgonCameraCommon) first.

See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

DrawPolygonSprite(GorgonPolySprite)

Function to draw a polygonal sprite.

Declaration
public IGorgon2DDrawingFluent DrawPolygonSprite(GorgonPolySprite sprite)
Parameters
Type Name Description
GorgonPolySprite sprite

The polygon sprite to draw.

Returns
Type Description
IGorgon2DDrawingFluent

The fluent drawing interface.

Remarks

This method draws a sprite using a polygon as its surface. This is different from other sprite rendering in that:

  • The surface is not rectangular.
  • It is not batched with other drawing types, and is drawn immediately. This may be a performance hit.
  • Unlike a GorgonSprite, which uses a rectangle, this type of sprite produces an irregular shape that can be used to match the texture being drawn.

The method takes a GorgonPolySprite object which contains GorgonPolySpriteVertex objects to define the outer shape (hull) of the polygon. Gorgon will triangulate the hull into a mesh that can be rendered.

GorgonPolySprite objects cannot be created directly, but can be built using the GorgonPolySpriteBuilder object. Please note that these objects implement IDisposable, so users should call the Dispose method when they are done with the objects.

caution

For performance reasons, any exceptions thrown from this method will only be thrown when Gorgon is compiled as DEBUG.

Exceptions
Type Condition
ArgumentNullException

Thrown when the sprite parameter is null.

InvalidOperationException

Thrown if this method was called without having called Begin(Gorgon2DBatchState, GorgonCameraCommon) first.

See Also
GorgonPolySpriteBuilder
GorgonPolySprite
GorgonPolySpriteVertex
GorgonSprite
| Edit this page View Source

DrawRectangle(RectangleF, GorgonColor, float, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float)

Function to draw a filled rectangle.

Declaration
public IGorgon2DDrawingFluent DrawRectangle(RectangleF region, GorgonColor color, float thickness = 1, GorgonTexture2DView texture = null, RectangleF? textureRegion = null, int textureArrayIndex = 0, GorgonSamplerState textureSampler = null, float depth = 0)
Parameters
Type Name Description
RectangleF region

The region for the rectangle.

GorgonColor color

The color of the rectangle.

float thickness

[Optional] The line thickness.

GorgonTexture2DView texture

[Optional] The texture for the rectangle.

RectangleF? textureRegion

[Optional] The texture coordinates to map to the rectangle.

int textureArrayIndex

[Optional] The array index for a texture array to use.

GorgonSamplerState textureSampler

[Optional] The texture sampler to apply to the texture.

float depth

[Optional] The depth value for the rectangle.

Returns
Type Description
IGorgon2DDrawingFluent

The fluent drawing interface.

Exceptions
Type Condition
InvalidOperationException

Thrown if this method was called without having called Begin(Gorgon2DBatchState, GorgonCameraCommon) first.

See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

DrawSprite(GorgonSprite)

Function to draw a sprite.

Declaration
public IGorgon2DDrawingFluent DrawSprite(GorgonSprite sprite)
Parameters
Type Name Description
GorgonSprite sprite

The sprite object to draw.

Returns
Type Description
IGorgon2DDrawingFluent

The fluent drawing interface.

Remarks

This method draws a regular rectangular GorgonSprite object.

A GorgonSprite is a data object that provides a means to rotate, scale and translate a texture region when rendering.

Exceptions
Type Condition
ArgumentNullException

Thrown when the sprite parameter is null.

InvalidOperationException

Thrown if this method was called without having called Begin(Gorgon2DBatchState, GorgonCameraCommon) first.

See Also
GorgonSprite
| Edit this page View Source

DrawString(string, Vector2, GorgonFont, GorgonColor?)

Function to draw text.

Declaration
public IGorgon2DDrawingFluent DrawString(string text, Vector2 position, GorgonFont font = null, GorgonColor? color = null)
Parameters
Type Name Description
string text

The text to render.

Vector2 position

The position of the text.

GorgonFont font

[Optional] The font to use.

GorgonColor? color

[Optional] The color of the text.

Returns
Type Description
IGorgon2DDrawingFluent

The fluent drawing interface.

Remarks

This is a convenience method that allows an application to draw text directly to the currently assigned render target.

If the font parameter is not specified, then the DefaultFont is used to render the text.

If the color parameter is not specified, then the White color is used.

Exceptions
Type Condition
InvalidOperationException

Thrown if this method was called without having called Begin(Gorgon2DBatchState, GorgonCameraCommon) first.

See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

DrawTextSprite(GorgonTextSprite)

Function to draw text.

Declaration
public IGorgon2DDrawingFluent DrawTextSprite(GorgonTextSprite sprite)
Parameters
Type Name Description
GorgonTextSprite sprite

The text sprite to render.

Returns
Type Description
IGorgon2DDrawingFluent

The fluent drawing interface.

Remarks

This method is used to draw a GorgonTextSprite to the current render target. A GorgonTextSprite is similar to a GorgonSprite in that it allows an application to take a block of text and translate, scale, and rotate the block of text.

Unlike the DrawString(string, Vector2, GorgonFont, GorgonColor?) method, which just renders whatever text is sent to it, a GorgonTextSprite can also be used to align text to a boundary (e.g. center, left align, etc...).

Exceptions
Type Condition
ArgumentNullException

Thrown when the sprite parameter is null.

InvalidOperationException

Thrown if this method was called without having called Begin(Gorgon2DBatchState, GorgonCameraCommon) first.

See Also
GorgonTextSprite
GorgonSprite
| Edit this page View Source

DrawTriangle(in GorgonTriangleVertex, in GorgonTriangleVertex, in GorgonTriangleVertex, GorgonTexture2DView, RectangleF?, int, GorgonSamplerState, float)

Function to draw a simple triangle.

Declaration
public IGorgon2DDrawingFluent DrawTriangle(in GorgonTriangleVertex point1, in GorgonTriangleVertex point2, in GorgonTriangleVertex point3, GorgonTexture2DView texture = null, RectangleF? textureRegion = null, int textureArrayIndex = 0, GorgonSamplerState textureSampler = null, float depth = 0)
Parameters
Type Name Description
GorgonTriangleVertex point1

The vertex for the first point in the triangle.

GorgonTriangleVertex point2

The vertex for the second point in the triangle.

GorgonTriangleVertex point3

The vertex for the third point in the triangle.

GorgonTexture2DView texture

[Optional] The texture for the rectangle.

RectangleF? textureRegion

[Optional] The texture coordinates to map to the rectangle.

int textureArrayIndex

[Optional] The array index for a texture array to use.

GorgonSamplerState textureSampler

[Optional] The texture sampler to apply to the texture.

float depth

[Optional] The depth value for the rectangle.

Returns
Type Description
IGorgon2DDrawingFluent

The fluent drawing interface.

Exceptions
Type Condition
InvalidOperationException

Thrown if this method was called without having called Begin(Gorgon2DBatchState, GorgonCameraCommon) first.

See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

End()

Function to end rendering.

Declaration
public IGorgon2DFluent End()
Returns
Type Description
IGorgon2DFluent

The IGorgon2DFluent interface to allow continuation of rendering.

Remarks

This finalizes rendering and flushes the current batch data to the GPU. Effectively, this is the method that performs the actual rendering for anything the user has drawn.

The 2D renderer uses batching to achieve its performance. Because of this, we define a batch with a call to Begin(Gorgon2DBatchState, GorgonCameraCommon) and End. So, for optimal performance, it is best to draw as much drawing as possible within the Begin/End batch body.

This method must be paired with a call to Begin(Gorgon2DBatchState, GorgonCameraCommon), if it is not, it will do nothing. If this method is not called after a call to Begin(Gorgon2DBatchState, GorgonCameraCommon), then nothing (in most cases) will be drawn. If a previous call to Begin(Gorgon2DBatchState, GorgonCameraCommon) is made, and this method is not called, and another call to Begin(Gorgon2DBatchState, GorgonCameraCommon) is made, an exception is thrown.

See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

GetVertices(GorgonSprite)

Function to retrieve the read only vertex values for a sprite.

Declaration
public ref readonly Gorgon2DVertex[] GetVertices(GorgonSprite sprite)
Parameters
Type Name Description
GorgonSprite sprite

The sprite to evaluate.

Returns
Type Description
Gorgon2DVertex[]

A read only list of vertices from the sprite.

Exceptions
Type Condition
ArgumentNullException

Thrown when the sprite parameter is null.

See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

MeasureSprite(GorgonPolySprite)

Property to return the bounds of the sprite, with transformation applied.

Declaration
public RectangleF MeasureSprite(GorgonPolySprite sprite)
Parameters
Type Name Description
GorgonPolySprite sprite

The sprite to retrieve the boundaries from.

Returns
Type Description
RectangleF

The bounds with transformation applied.

Remarks

This is the equivalent of an axis aligned bounding box.

See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

MeasureSprite(GorgonSprite)

Property to return the bounds of the sprite, with transformation applied.

Declaration
public RectangleF MeasureSprite(GorgonSprite sprite)
Parameters
Type Name Description
GorgonSprite sprite

The sprite to retrieve the boundaries from.

Returns
Type Description
RectangleF

The bounds with transformation applied.

Remarks

This is the equivalent of an axis aligned bounding box.

See Also
GorgonGraphics
Gorgon2DBatchState
| Edit this page View Source

MeasureSprite(GorgonTextSprite)

Property to return the bounds of the sprite, with transformation applied.

Declaration
public RectangleF MeasureSprite(GorgonTextSprite sprite)
Parameters
Type Name Description
GorgonTextSprite sprite

The sprite to retrieve the boundaries from.

Returns
Type Description
RectangleF

The bounds with transformation applied.

Remarks

This is the equivalent of an axis aligned bounding box.

See Also
GorgonGraphics
Gorgon2DBatchState

Implements

IGorgon2DFluent
IDisposable
IGorgon2DDrawingFluent
IGorgonGraphicsObject

Extension Methods

GorgonDebugExtensions.ValidateObject<T>(T, string)
GorgonNullExtensions.AsNullable<T>(object)
GorgonNullExtensions.IfNull<T>(object, T)
GorgonNullExtensions.IsNull(object)

See Also

GorgonGraphics
Gorgon2DBatchState
  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author