IRenderContextΒΆ

interface IRenderContext

An interface which provides the current context in which rendering is being performed. This is passed to all Render methods by the engine.

You should avoid performing calls to MonoGame’s rendering APIs unless you have an accessible instance of T:Protogame.IRenderContext. Without having an instance of T:Protogame.IRenderContext, it’s possible that the code you are writing will be invoked outside of the standard rendering loop.

readonly BoundingFrustum BoundingFrustum

Gets the bounding frustum for the current view and projection matrixes.

Value:The bounding frustum for the current view and projection matrixes.
readonly GraphicsDevice GraphicsDevice

Gets the associated graphics device.

Value:The graphics device.
bool IsRendering

Gets a value indicating whether the game is currently rendering in either the render pipeline or the backbuffer. This value will always be true within any method call that occurs below M:Microsoft.Xna.Framework.Game.Draw(Microsoft.Xna.Framework.GameTime) in the call stack. When you are rendering, certain operations can not be performed, in particular, operations which reset the graphics device like resizing the game window.

Vector3 CameraPosition

Gets or sets the last known camera position. The value of this property is set internally by cameras so that the camera position is known when lighting effects are applied. Setting this property from user code will not actually update the camera position or modify projection parameters; it will only impact the way lights are rendered.

Vector3 CameraLookAt

Gets or sets the last known camera look at vector. The value of this property is set internally by cameras so that the camera look at vector is known when lighting effects are applied. Setting this property from user code will not actually update the camera look at vector or modify projection parameters; it will only impact the way lights are rendered.

Matrix Projection

Gets or sets the projection matrix for 3D rendering.

Value:The projection matrix for 3D rendering.
readonly Texture2D SingleWhitePixel

Gets a texture representing a single white pixel.

Value:The single white pixel.
readonly SpriteBatch SpriteBatch

Gets a sprite batch associated with the current device, upon which 2D rendering is performed.

Value:The sprite batch.
Matrix View

Gets or sets the view matrix for 3D rendering.

Value:The view matrix for 3D rendering.
Matrix World

Gets or sets the world matrix for 3D rendering.

Value:The world matrix for 3D rendering.
readonly IRenderPass CurrentRenderPass

Gets the current render pass that is being used.

Value:The current render pass that is being used.
void PopRenderTarget()

Pops the current render target from the current rendering context. If there are no more render targets in the stack after this call, then the rendering will default back to rendering to the back buffer.

void PushRenderTarget(RenderTargetBinding renderTarget)

Push a render target onto the current rendering context, making it the active target for rendering. By using the PushRenderTarget / PopRenderTarget methods, this allows you to safely chain render target switches, without risk of losing the previous render target. An example of where this can be used is if you want to capture the next frame, you can simply start with a PushRenderTarget and as long as all other render target switching uses these methods or respects the previous render target, then everything will be captured as intended.

Parameters:
  • renderTarget (Microsoft.Xna.Framework.Graphics.RenderTargetBinding) – The render target instance to make active.
void PushRenderTarget(Microsoft.Xna.Framework.Graphics.RenderTargetBinding[] renderTargets)

Push an array of render targets onto the current rendering context, making them the active target for rendering. By using the PushRenderTarget / PopRenderTarget methods, this allows you to safely chain render target switches, without risk of losing the previous render target.

Parameters:
  • renderTargets (Microsoft.Xna.Framework.Graphics.RenderTargetBinding[]) – The render targets to make active.
void Render(IGameContext context)

Called by the world manager to set up the render context at the beginning of a render.

Parameters:
  • context (Protogame.IGameContext) – The current game context.
IRenderPass AddFixedRenderPass(IRenderPass renderPass)

Adds the specified render pass to the render pipeline permanently. This render pass will take effect after the start of the next frame.

Parameters:
  • renderPass (Protogame.IRenderPass) – The render pass to add.
Returns:

The render pass that was given to this function. This return value is for convenience only, so that you may construct and add a render pass in a single statement, while obtaining a reference to it if you need to modify it’s values or call M:Protogame.IRenderContext.RemoveFixedRenderPass(Protogame.IRenderPass) later. The render pass is not modified by this function.

void RemoveFixedRenderPass(IRenderPass renderPass)

Removes the specified render pass from the render pipeline.

Parameters:
  • renderPass (Protogame.IRenderPass) – The render pass to remove.
IRenderPass AppendTransientRenderPass(IRenderPass renderPass)

Append the specified render pass to the render pipeline for this frame only. This is method that allows you to temporarily add additional render passes to a frame.

If all standard (non-post-processing) render passes have finished post-processing has begun and this method is given a standard render pass, it will have no effect.

Render passes that were appended can not be removed with M:Protogame.IRenderContext.RemoveFixedRenderPass(Protogame.IRenderPass).

Parameters:
  • renderPass (Protogame.IRenderPass) – The render pass to add.
Returns:

The render pass that was given to this function. This return value is for convenience only, so that you may construct and add a render pass in a single statement, while obtaining a reference to it if you need to modify it’s value. The render pass is not modified by this function.

bool IsCurrentRenderPass<T>()

Returns whether or not the current render pass is of the specified type.

Type Parameters:
 
  • T – The type to check the render pass against.
Returns:

Whether or not the current render pass is of the specified type.

bool IsCurrentRenderPass<T>(ref Protogame.T currentRenderPass)
Type Parameters:
 
  • T
Parameters:
  • (ref) currentRenderPass (Protogame.T) –
Protogame.T GetCurrentRenderPass<T>()

Returns the current render pass as the type T.

Type Parameters:
 
  • T – The type of render pass to return.
Returns:

The current render pass as the type T.

bool IsFirstRenderPass()

Returns whether this is the first render pass being performed. You can use this method to isolate render logic that should only occur once per frame (such as appending transient render passes).

Returns:Whether this is the first render pass being performed.