Gorgon
Show / Hide Table of Contents

Interface IGorgon2DFluent

A fluent interface for the Gorgon2D object.

Inherited Members
IDisposable.Dispose()
Namespace: Gorgon.Renderers
Assembly: Gorgon.Renderers.Gorgon2D.dll
Syntax
public interface IGorgon2DFluent : IDisposable

Properties

| 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
GorgonFont DefaultFont { get; }
Property Value
Type Description
GorgonFont
| Edit this page View Source

EmptyBlackTexture

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

Declaration
GorgonTexture2DView EmptyBlackTexture { get; }
Property Value
Type Description
GorgonTexture2DView
| Edit this page View Source

EmptyNormalMapTexture

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

Declaration
GorgonTexture2DView EmptyNormalMapTexture { get; }
Property Value
Type Description
GorgonTexture2DView
| Edit this page View Source

EmptyWhiteTexture

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

Declaration
GorgonTexture2DView EmptyWhiteTexture { get; }
Property Value
Type Description
GorgonTexture2DView
| Edit this page View Source

Log

Property to return the log used to log debug messages.

Declaration
IGorgonLog Log { get; }
Property Value
Type Description
IGorgonLog

Methods

| Edit this page View Source

Begin(Gorgon2DBatchState, GorgonCameraCommon)

Function to begin rendering a batch.

Declaration
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 the 2D interface.

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.

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

MeasureSprite(GorgonPolySprite, out RectangleF)

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

Declaration
IGorgon2DFluent MeasureSprite(GorgonPolySprite sprite, out RectangleF result)
Parameters
Type Name Description
GorgonPolySprite sprite

The sprite to retrieve the boundaries from.

RectangleF result

The measurement result.

Returns
Type Description
IGorgon2DFluent

The fluent interface for the 2D interface.

Remarks

This is the equivalent of an axis aligned bounding box.

| Edit this page View Source

MeasureSprite(GorgonSprite, out RectangleF)

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

Declaration
IGorgon2DFluent MeasureSprite(GorgonSprite sprite, out RectangleF result)
Parameters
Type Name Description
GorgonSprite sprite

The sprite to retrieve the boundaries from.

RectangleF result

The measurement result.

Returns
Type Description
IGorgon2DFluent

The fluent interface for the 2D interface.

Remarks

This is the equivalent of an axis aligned bounding box.

| Edit this page View Source

MeasureSprite(GorgonTextSprite, out RectangleF)

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

Declaration
IGorgon2DFluent MeasureSprite(GorgonTextSprite sprite, out RectangleF result)
Parameters
Type Name Description
GorgonTextSprite sprite

The sprite to retrieve the boundaries from.

RectangleF result

The measurement result.

Returns
Type Description
IGorgon2DFluent

The fluent interface for the 2D interface.

Remarks

This is the equivalent of an axis aligned bounding box.

| Edit this page View Source

Update(Action<GorgonGraphics>)

Function to perform an arbitrary update of any required logic prior to rendering.

Declaration
IGorgon2DFluent Update(Action<GorgonGraphics> updateMethod)
Parameters
Type Name Description
Action<GorgonGraphics> updateMethod

A method supplied by the user to perform some custom logic on objects that need to be rendered.

Returns
Type Description
IGorgon2DFluent

The fluent interface for the 2D interface.

Extension Methods

GorgonDebugExtensions.ValidateObject<T>(T, string)
GorgonNullExtensions.AsNullable<T>(object)
GorgonNullExtensions.IfNull<T>(object, T)
GorgonNullExtensions.IsNull(object)
  • 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