Table of Contents

Class RenderContext

Namespace
Icy.MonoGame.Rendering
Assembly
IcyUI.MonoGame.dll

Represents MonoGame implementation of the IRenderContext interface.

public sealed class RenderContext : IRenderContext, IDisposable
Inheritance
RenderContext
Implements
Inherited Members
Extension Methods

Constructors

RenderContext(GraphicsDevice)

Initializes a new instance of the RenderContext class.

public RenderContext(GraphicsDevice device)

Parameters

device GraphicsDevice

An instance of the graphics device used in game.

Properties

DisplayScale

Gets the operating system display scale of the surface this context renders into.

public float DisplayScale { get; }

Property Value

float

Remarks

1.0 means 96 DPI (100 %), 2.0 means 192 DPI (200 %). A host process that isn't DPI-aware always reports 1.0, because the OS scales its window itself. The default implementation returns 1.0.

Options

Gets the current rendering options.

public IRenderOptions Options { get; }

Property Value

IRenderOptions

Transform

Gets or sets the transform used for rendering.

public Transform2D Transform { get; set; }

Property Value

Transform2D

ViewportSize

Gets the actual size of the viewport to render into.

public Size ViewportSize { get; }

Property Value

Size

Remarks

Typically, the viewport size represent the actual size of the graphics device back buffer.

WhiteTexture

Gets an instance of the shared white ITexture for auxiliary drawing.

public ITexture WhiteTexture { get; }

Property Value

ITexture

Methods

ApplyEffect(IEffect)

Applies an effect to the next draw calls.

public void ApplyEffect(IEffect effect)

Parameters

effect IEffect

Effect instance to apply.

AttachDisplayScaleTracker(DisplayScaleTracker)

Attaches the tracker that reports this context's display scale, and forwards its changes to DisplayScaleChanged.

public void AttachDisplayScaleTracker(DisplayScaleTracker tracker)

Parameters

tracker DisplayScaleTracker

The tracker for the window this context renders into.

Begin()

Begins rendering process.

public void Begin()

ClearEffects()

Remove applied effect instance by setting default effect instance.

public void ClearEffects()

CreateTexture<TColor>(int, int, TColor[])

Creates an instance of the texture with specified size and colors data.

public ITexture CreateTexture<TColor>(int width, int height, TColor[] data) where TColor : unmanaged

Parameters

width int

Width of the texture to create.

height int

Height of the texture to create.

data TColor[]

Colors data to set to the texture.

Returns

ITexture

An instance of the created texture with colors data set.

Type Parameters

TColor

Format of the pixel colors to set data to the texture.

Dispose()

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

public void Dispose()

Draw(ITexture, in TextureRenderingOptions)

Draws a texture into the rendering surface.

public void Draw(ITexture texture, in TextureRenderingOptions options)

Parameters

texture ITexture

A texture to render.

options TextureRenderingOptions

Options to draw the brush with.

End()

Ends rendering process.

public void End()

Flush()

Clears rendering queue with making context ready for new render.

public void Flush()

GetBuiltInEffect(EffectCode)

Gets the built-in effect instance by its EffectCode.

public IEffect GetBuiltInEffect(EffectCode code)

Parameters

code EffectCode

The code to identify built-in effect.

Returns

IEffect

An instance of the IEffect for the specified effect code.

PollDisplayScale()

Re-reads the display scale. Called once per update by the engine integration.

public void PollDisplayScale()

Events

DisplayScaleChanged

Occurs when DisplayScale changes, e.g. when the window moves to a monitor with a different DPI.

public event EventHandler? DisplayScaleChanged

Event Type

EventHandler

Remarks

Provided for application code. Canvas doesn't subscribe to it; it re-reads DisplayScale on every Render() call instead. The default implementation never raises the event.

ViewportResize

Occurs when size of the viewport changes.

public event EventHandler? ViewportResize

Event Type

EventHandler