Class RenderContext
Represents the Stride implementation of the IRenderContext interface.
public sealed class RenderContext : IRenderContext, IDisposable
- Inheritance
-
RenderContext
- Implements
- Inherited Members
- Extension Methods
Remarks
Unlike MonoGame's SpriteBatch.Begin, Stride's requires a GraphicsContext
(frame-scoped command-submission state), not just a GraphicsDevice. Since this render context
is constructed once but the render stage that drives it (see the Configuration namespace) only receives a
valid GraphicsContext while it is actually being drawn (through
SceneRendererBase.DrawCore(RenderDrawContext)), GraphicsContext here is a settable
property the render stage refreshes every frame before calling into the UI tree, rather than a constructor
parameter captured once.
Constructors
RenderContext(GraphicsDevice)
Initializes a new instance of the RenderContext class.
public RenderContext(GraphicsDevice device)
Parameters
deviceGraphicsDeviceAn 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
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.
GraphicsContext
Gets or sets the frame-scoped Stride GraphicsContext to render with.
public GraphicsContext GraphicsContext { get; set; }
Property Value
Remarks
The render stage that owns this context must set this once per frame, before any drawing happens through it - see the remarks on RenderContext itself.
Options
Gets the current rendering options.
public IRenderOptions Options { get; }
Property Value
Transform
Gets or sets the transform used for rendering.
public Transform2D Transform { get; set; }
Property Value
ViewportSize
Gets the actual size of the viewport to render into.
public Size ViewportSize { get; }
Property Value
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
Methods
ApplyEffect(IEffect)
Applies an effect to the next draw calls.
public void ApplyEffect(IEffect effect)
Parameters
effectIEffectEffect 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
trackerDisplayScaleTrackerThe 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
widthintWidth of the texture to create.
heightintHeight of the texture to create.
dataTColor[]Colors data to set to the texture.
Returns
- ITexture
An instance of the created texture with colors data set.
Type Parameters
TColorFormat 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
textureITextureA texture to render.
optionsTextureRenderingOptionsOptions 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
codeEffectCodeThe code to identify built-in effect.
Returns
NotifyViewportResize()
Raises ViewportResize - call this from the owning render stage when the back buffer
(window/presenter) size changes, since Stride has no per-GraphicsDevice resize event to
subscribe to the way MonoGame's GraphicsDevice.DeviceReset provides.
public void NotifyViewportResize()
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
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