Show / Hide Table of Contents

Class RenderContext

The render context contains all functions necessary to manipulate the underlying rendering hardware. Use this class' elements to render geometry to the RenderCanvas associated with this context. If you have worked with OpenGL or DirectX before you will find many similarities in this class' methods and properties.

Inheritance
System.Object
RenderContext
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Fusee.Engine.Core
Assembly: Fusee.Engine.Core.dll
Syntax
public class RenderContext

Constructors

RenderContext(IRenderContextImp)

Initializes a new instance of the RenderContext class.

Declaration
public RenderContext(IRenderContextImp rci)
Parameters
Type Name Description
IRenderContextImp rci

The IRenderContextImp.

Fields

DefaultEffect

The default Effect, that is used if a SceneNode has a mesh but no effect.

Declaration
public SurfaceEffectBase DefaultEffect
Field Value
Type Description
SurfaceEffectBase

ForwardLights

Global Uniform array of LightResults. Updated by a SceneRenderer.

Declaration
public LightResult[] ForwardLights
Field Value
Type Description
LightResult[]

Properties

ClearColor

The color to use when clearing the color buffer.

Declaration
public float4 ClearColor { get; set; }
Property Value
Type Description
float4

The color value is interpreted as a (Red, Green, Blue, Alpha) quadruple with component values ranging from 0.0f to 1.0f.

Remarks

This is the color that will be copied to all pixels in the output color buffer when Clear is called on the render context.

See Also
Clear(ClearFlags)

ClearDepth

The depth value to use when clearing the color buffer.

Declaration
public float ClearDepth { get; set; }
Property Value
Type Description
System.Single

Typically set to the highest possible depth value. Typically ranges between 0 and 1.

Remarks

This is the depth (z-) value that will be copied to all pixels in the depth (z-) buffer when Clear is called on the render context.

CurrentRenderState

Saves the current RenderState.

Declaration
public RenderStateSet CurrentRenderState { get; }
Property Value
Type Description
RenderStateSet

DefaultState

Contains the default state of the render context. can be used to reset this RenderContext to it's DefaultState.

Declaration
public RenderContextDefaultState DefaultState { get; }
Property Value
Type Description
RenderContextDefaultState

GetWindowHeight

Sets the window width.

Declaration
public Func<int> GetWindowHeight { get; }
Property Value
Type Description
System.Func<System.Int32>

GetWindowWidth

Gets the window width.

Declaration
public Func<int> GetWindowWidth { get; }
Property Value
Type Description
System.Func<System.Int32>

InvModel

Gets the inverted Model matrix.

Declaration
public float4x4 InvModel { get; }
Property Value
Type Description
float4x4

The inverted Model matrix.

Remarks

If the Model matrix is orthogonal (i.e. contains no scale component), its inverse matrix is equal to its transpose matrix.

See Also
Model
TransModel

InvModelView

The inverse of the ModelView matrix.

Declaration
public float4x4 InvModelView { get; }
Property Value
Type Description
float4x4

The 4x4 matrix resulting from the matrix inversion applied to the ModelView matrix.

Remarks

If the ModelView matrix is orthogonal (i.e. contains no scale component), its inverse matrix is equal to its transpose matrix.

See Also
ModelView
TransModelView

InvModelViewProjection

The inverse of the ModelViewProjection matrix.

Declaration
public float4x4 InvModelViewProjection { get; }
Property Value
Type Description
float4x4

The 4x4 matrix resulting from the matrix inversion applied to the ModelViewProjection matrix.

Remarks

If the ModelViewProjection matrix is orthogonal (i.e. contains no scale component), its inverse matrix is equal to its transpose matrix.

See Also
ModelViewProjection
TransModelViewProjection

InvProjection

The inverse of the Projection matrix.

Declaration
public float4x4 InvProjection { get; }
Property Value
Type Description
float4x4

The 4x4 matrix resulting from the matrix inversion applied to the Projection matrix.

Remarks

If the Projection matrix is orthogonal (i.e. contains no scale component), its inverse matrix is equal to its transpose matrix.

See Also
Projection
TransProjection

InvTransModel

The inverse transpose of the Model matrix.

Declaration
public float4x4 InvTransModel { get; }
Property Value
Type Description
float4x4

The 4x4 matrix resulting from the matrix inversion and transpose applied to the Model matrix.

Remarks

If the Model matrix is orthogonal (i.e. contains no scale component), its inverse transpose matrix is the same as the original Model matrix.

See Also
Model
InvModel
TransModel

InvTransModelView

The inverse transpose of the ModelView matrix.

Declaration
public float4x4 InvTransModelView { get; }
Property Value
Type Description
float4x4

The 4x4 matrix resulting from the matrix inversion and transpose applied to the ModelView matrix.

Remarks

If the ModelView matrix is orthogonal (i.e. contains no scale component), its inverse transpose matrix is the same as the original ModelView matrix.

See Also
ModelView
InvModelView
TransModelView

InvTransModelViewProjection

The inverse transpose of the ModelViewProjection matrix.

Declaration
public float4x4 InvTransModelViewProjection { get; }
Property Value
Type Description
float4x4

The 4x4 matrix resulting from the matrix inversion and transpose applied to the ModelViewProjection matrix.

Remarks

If the ModelViewProjection matrix is orthogonal (i.e. contains no scale component), its inverse transpose matrix is the same as the original ModelViewProjection matrix.

See Also
ModelViewProjection
InvModelViewProjection
TransModelViewProjection

InvTransProjection

The inverse transpose of the Projection matrix.

Declaration
public float4x4 InvTransProjection { get; }
Property Value
Type Description
float4x4

The 4x4 matrix resulting from the matrix inversion and transpose applied to the Projection matrix.

Remarks

If the Projection matrix is orthogonal (i.e. contains no scale component), its inverse transpose matrix is the same as the original Projection matrix.

See Also
Projection
InvProjection
TransProjection

InvTransView

The inverse transpose of the View matrix.

Declaration
public float4x4 InvTransView { get; }
Property Value
Type Description
float4x4

The 4x4 matrix resulting from the matrix inversion and transpose applied to the View matrix.

Remarks

If the View matrix is orthogonal (i.e. contains no scale component), its inverse transpose matrix is the same as the original View matrix.

See Also
View
InvView
TransView

InvView

Gets the inverted View matrix.

Declaration
public float4x4 InvView { get; }
Property Value
Type Description
float4x4

The inverted view matrix.

Remarks

If the View matrix is orthogonal (i.e. contains no scale component), its inverse matrix is equal to its transpose matrix.

See Also
View
TransView

LockedStates

If a state is forced it will remain the value currently set in CurrentRenderState.

Declaration
public Dictionary<RenderState, KeyValuePair<bool, uint>> LockedStates { get; }
Property Value
Type Description
System.Collections.Generic.Dictionary<RenderState, System.Collections.Generic.KeyValuePair<System.Boolean, System.UInt32>>

Model

The Model matrix used by the rendering pipeline.

Declaration
public float4x4 Model { get; set; }
Property Value
Type Description
float4x4

The model matrix.

Remarks

Model coordinates are the coordinates directly taken from the model (the mesh geometry - Mesh).

ModelView

The ModelView matrix used by the rendering pipeline.

Declaration
public float4x4 ModelView { get; }
Property Value
Type Description
float4x4

The 4x4 ModelView matrix defining the transformation applied to model coordinates yielding view coordinates.

Remarks

Model coordinates are the coordinates directly taken from the model (the mesh geometry - Mesh). The rendering pipeline transforms these coordinates into View coordinates. Further down the pipeline the coordinates will be transformed to screen coordinates to allow the geometry to be rendered to pixel positions on the screen. The ModelView matrix defines the transformations performed on the original model coordinates to yield view coordinates. In most cases the matrix is a composition of several translations, rotations, and scale operations.

ModelViewProjection

The combination of the ModelView and Projection matrices.

Declaration
public float4x4 ModelViewProjection { get; }
Property Value
Type Description
float4x4

The 4x4 matrix resulting from the matrix multiplication of the ModelView and the Projection matrix.

Remarks

ModelView and Projection.

Projection

The projection matrix used by the rendering pipeline

Declaration
public float4x4 Projection { get; set; }
Property Value
Type Description
float4x4

The 4x4 projection matrix applied to view coordinates yielding clip space coordinates.

Remarks

View coordinates are the result of the ModelView matrix multiplied to the geometry (ModelView). The coordinate system of the view space has its origin in the camera center with the z axis aligned to the viewing direction, and the x- and y axes aligned to the viewing plane. Still, no projection from 3d space to the viewing plane has been performed. This is done by multiplying view coordinate geometry with the projection matrix. Typically, the projection matrix either performs a parallel projection or a perspective projection.

RenderFrustum

The world space frustum planes, derived from the current view-projection matrix.

Declaration
public FrustumF RenderFrustum { get; }
Property Value
Type Description
FrustumF

TransModel

The transpose of the Model matrix.

Declaration
public float4x4 TransModel { get; }
Property Value
Type Description
float4x4

The 4x4 matrix resulting from the matrix transpose applied to the Model matrix.

Remarks

If the Model matrix is orthogonal (i.e. contains no scale component), its transpose matrix is equal to its inverse matrix.

See Also
Model
InvModel

TransModelView

The transpose of the ModelView matrix.

Declaration
public float4x4 TransModelView { get; }
Property Value
Type Description
float4x4

The 4x4 matrix resulting from the matrix transpose applied to the ModelView matrix.

Remarks

If the ModelView matrix is orthogonal (i.e. contains no scale component), its transpose matrix is equal to its inverse matrix.

See Also
ModelView
InvModelView

TransModelViewProjection

The transpose of the ModelViewProjection matrix.

Declaration
public float4x4 TransModelViewProjection { get; }
Property Value
Type Description
float4x4

The 4x4 matrix resulting from the matrix transpose applied to the ModelViewProjection matrix.

Remarks

If the ModelViewProjection matrix is orthogonal (i.e. contains no scale component), its transpose matrix is equal to its inverse matrix.

See Also
ModelViewProjection
InvModelViewProjection

TransProjection

The transpose of the Projection matrix.

Declaration
public float4x4 TransProjection { get; }
Property Value
Type Description
float4x4

The 4x4 matrix resulting from the matrix transpose applied to the Projection matrix.

Remarks

If the Projection matrix is orthogonal (i.e. contains no scale component), its transpose matrix is equal to its inverse matrix.

See Also
Projection
InvProjection

TransView

The transpose of the View matrix.

Declaration
public float4x4 TransView { get; }
Property Value
Type Description
float4x4

The 4x4 matrix resulting from the matrix transpose applied to the View matrix.

Remarks

If the View matrix is orthogonal (i.e. contains no scale component), its transpose matrix is equal to its inverse matrix.

See Also
View
InvView

View

The View matrix used by the rendering pipeline.

Declaration
public float4x4 View { get; set; }
Property Value
Type Description
float4x4

The view matrix.

Remarks

This matrix is also referred often as the camera transformation(not the projection). It describes the orientation of the view that is used to render a scene. You can use LookAt(float3, float3, float3) to create a valid view matrix and analyze how it is build up.

ViewportHeight

Gets and sets the viewport height.

Declaration
public int ViewportHeight { get; }
Property Value
Type Description
System.Int32

ViewportWidth

Gets and sets the viewport width.

Declaration
public int ViewportWidth { get; }
Property Value
Type Description
System.Int32

ViewportXStart

Gets and sets the x coordinate of viewport's lower left (starting) point.

Declaration
public int ViewportXStart { get; }
Property Value
Type Description
System.Int32

ViewportYStart

Gets and sets the y coordinate of viewport's lower left (starting) point.

Declaration
public int ViewportYStart { get; }
Property Value
Type Description
System.Int32

Methods

BlitMultisample2DTextureToTexture(WritableMultisampleTexture, WritableTexture)

Takes a WritableMultisampleTexture and blits the result of all samples into an existing WritableTexture for further use (e. g. bind and use as Albedo texture)

Declaration
public void BlitMultisample2DTextureToTexture(WritableMultisampleTexture input, WritableTexture output)
Parameters
Type Name Description
WritableMultisampleTexture input

WritableMultisampleTexture

WritableTexture output

WritableTexture

Clear(ClearFlags)

Erases the contents of the specified rendering buffers.

Declaration
public void Clear(ClearFlags flags)
Parameters
Type Name Description
ClearFlags flags

A combination of flags specifying the rendering buffers to clear.

Remarks

Calling this method erases all contents of the rendering buffers. A typical use case for this method is to erase the contents of the color buffer and the depth buffer (z-buffer) before rendering starts at the beginning of a rendering loop. Thus, rendering the current frame starts with an empty color and z-buffer. ClearFlags for a list of possible buffers to clear. Make sure to use the bitwise or-operator (|) to combine several buffers to clear.

CreateGBufferTarget(TexRes)

Creates a IRenderTarget with the purpose of being used as CPU GBuffer representation.

Declaration
public IRenderTarget CreateGBufferTarget(TexRes res)
Parameters
Type Name Description
TexRes res

The texture resolution.

Returns
Type Description
IRenderTarget

CreateGpuMesh(PrimitiveType, float3[], UInt32[], float3[], UInt32[], UInt32[], UInt32[], float2[], float4[], float3[], float4[], float4[], UInt32[])

Creates a GpuMesh, registers it in the Fusee.Engine.Core.MeshManager and uploads the data to the gpu.

Declaration
public GpuMesh CreateGpuMesh(PrimitiveType primitiveType, float3[] vertices, uint[] triangles = null, float3[] normals = null, uint[] colors = null, uint[] colors1 = null, uint[] colors2 = null, float2[] uvs = null, float4[] tangents = null, float3[] bitangents = null, float4[] boneIndices = null, float4[] boneWeights = null, uint[] flags = null)
Parameters
Type Name Description
PrimitiveType primitiveType
float3[] vertices

The vertex data of the mesh.

System.UInt32[] triangles

The triangle indices of the mesh.

float3[] normals

The normal vectors of the mesh.

System.UInt32[] colors

The first color set of the mesh.

System.UInt32[] colors1

The second color set of the mesh.

System.UInt32[] colors2

The third color set of the mesh.

float2[] uvs

The uv coordinates of the mesh.

float4[] tangents

The tangent vectors of the mesh.

float3[] bitangents

The bitangent vectors of the mesh.

float4[] boneIndices

The bone indices of the mesh.

float4[] boneWeights

The bone weights of the mesh.

System.UInt32[] flags
Returns
Type Description
GpuMesh

CreateMeshImp()

Creates a platform specific IMeshImp.

Declaration
public IMeshImp CreateMeshImp()
Returns
Type Description
IMeshImp

DisableDepthClamp()

Disables depths clamping. EnableDepthClamp()

Declaration
public void DisableDepthClamp()

DispatchCompute(Int32, Int32, Int32, Int32)

Launch the bound Compute Shader Program.

Declaration
public void DispatchCompute(int kernelIndex, int threadGroupsX, int threadGroupsY, int threadGroupsZ)
Parameters
Type Name Description
System.Int32 kernelIndex
System.Int32 threadGroupsX

The number of work groups to be launched in the X dimension.

System.Int32 threadGroupsY

The number of work groups to be launched in the Y dimension.

System.Int32 threadGroupsZ

he number of work groups to be launched in the Z dimension.

EnableDepthClamp()

The clipping behavior against the Z position of a vertex can be turned off by activating depth clamping. This is done with glEnable(GL_DEPTH_CLAMP). This will cause the clip-space Z to remain unclipped by the front and rear viewing volume. See: https://www.khronos.org/opengl/wiki/Vertex_Post-Processing#Depth_clamping

Declaration
public void EnableDepthClamp()

GetHardwareCapabilities(HardwareCapability)

Returns the hardware capabilities.

Declaration
public uint GetHardwareCapabilities(HardwareCapability capability)
Parameters
Type Name Description
HardwareCapability capability
Returns
Type Description
System.UInt32

GetHardwareDescription()

Returns a human readable description of the underlying graphics hardware

Declaration
public string GetHardwareDescription()
Returns
Type Description
System.String

GetRenderState(RenderState)

Returns a current render state.

Declaration
public uint GetRenderState(RenderState renderState)
Parameters
Type Name Description
RenderState renderState
Returns
Type Description
System.UInt32

MemoryBarrier()

Defines a barrier ordering memory transactions. At the moment it will insert all supported barriers.

Declaration
public void MemoryBarrier()

RegisterTexture(ExposedTexture)

This method enables an external Texture to be registered to the current RenderContext without the need to be rendered first. This procedure is needed for image rendering with ImGui

Declaration
public void RegisterTexture(ExposedTexture tex)
Parameters
Type Name Description
ExposedTexture tex

Texture to register

Render(GpuMesh, Boolean)

Renders the specified mesh.

Declaration
public void Render(GpuMesh mesh, bool doRenderForward = true)
Parameters
Type Name Description
GpuMesh mesh

The mesh that should be rendered.

System.Boolean doRenderForward

Is a forward or deferred renderer used? Will fetch the proper shader for the render method.

Remarks

Passes geometry to be pushed through the rendering pipeline. Mesh for a description how geometry is made up. The geometry is transformed and rendered by the currently active shader program.

Render(Mesh, InstanceData, Boolean)

Renders the specified mesh.

Declaration
public void Render(Mesh mesh, InstanceData instanceData = null, bool doRenderForward = true)
Parameters
Type Name Description
Mesh mesh

The mesh that should be rendered.

InstanceData instanceData

Optional parameter in case gpu instancing is used to render the given mesh. See InstanceData.

System.Boolean doRenderForward

Is a forward or deferred renderer used? Will fetch the proper shader for the render method.

Remarks

Passes geometry to be pushed through the rendering pipeline. Mesh for a description how geometry is made up. The geometry is transformed and rendered by the currently active shader program.

SetEffect(Effect, Boolean)

Activates the passed shader effect as the current shader for geometry rendering. Will compile a shader by calling CreateShaderProgram(String, String, String) if it hasn't been compiled yet.

Declaration
public void SetEffect(Effect ef, bool renderForward = true)
Parameters
Type Name Description
Effect ef

The effect.

System.Boolean renderForward
Remarks

A Effect must be attached to a context before you can render geometry with it. The main task performed in this method is compiling the provided shader source code and uploading the shaders to the gpu.

SetLineWidth(Single)

Specifies the rasterized width of both aliased and antialiased lines.

Declaration
public void SetLineWidth(float width)
Parameters
Type Name Description
System.Single width

The width in pixel.

SetRenderState(RenderState, UInt32, Boolean)

Apply a single render state to the render context. All subsequent rendering will be performed using the currently set state unless it is changed to a different value.

Declaration
public void SetRenderState(RenderState renderState, uint value, bool doLockState = false)
Parameters
Type Name Description
RenderState renderState

One of the RenderState enumeration values.

System.UInt32 value

An unsigned integer value representing the value the state should be set to. Depending on the renderState, this value can be interpreted as an integer value, a float value, a boolean value, or even a color.

System.Boolean doLockState

Forces this state to have the given value and locks the state. Unlock it by calling UnlockRenderState(RenderState, Boolean)

Remarks

This method is close to the underlying implementation layer and might be awkward to use due to the ambiguity of the value parameter type. If you want type-safe state values and also want to set a couple of states at the same time, try the more elaborate SetRenderStateSet(RenderStateSet, Boolean) method.

SetRenderStateSet(RenderStateSet, Boolean)

Apply a number of render states to this render context. All subsequent rendering will be performed using the currently set state set unless one of its values it is changed. Use this method to change more than one render state at once.

Declaration
public void SetRenderStateSet(RenderStateSet renderStateSet, bool doLockState = false)
Parameters
Type Name Description
RenderStateSet renderStateSet

A set of render states with their respective values to be set.

System.Boolean doLockState

Forces all states that are set in this RenderStateSet to have the given value and locks them. Unlock them by calling UnlockRenderState(RenderState, Boolean)

SetRenderTarget(IRenderTarget)

Sets the RenderTarget, if texture is null render target is the main screen, otherwise the picture will be rendered onto given texture

Declaration
public void SetRenderTarget(IRenderTarget renderTarget = null)
Parameters
Type Name Description
IRenderTarget renderTarget

The render target.

SetRenderTarget(IWritableArrayTexture, Int32)

Renders into the given texture.

Declaration
public void SetRenderTarget(IWritableArrayTexture tex, int layer)
Parameters
Type Name Description
IWritableArrayTexture tex

The render texture.

System.Int32 layer

The layer of the array texture that is set as render target.

SetRenderTarget(IWritableCubeMap)

Renders into the given texture.

Declaration
public void SetRenderTarget(IWritableCubeMap tex)
Parameters
Type Name Description
IWritableCubeMap tex

The render texture.

SetRenderTarget(IWritableTexture)

Renders into the given texture.

Declaration
public void SetRenderTarget(IWritableTexture tex)
Parameters
Type Name Description
IWritableTexture tex

The render texture.

SetRenderTarget(WritableMultisampleTexture)

Renders into the given texture.

Declaration
public void SetRenderTarget(WritableMultisampleTexture tex)
Parameters
Type Name Description
WritableMultisampleTexture tex

The render texture.

SetRenderTarget(WritableTexture)

Renders into the given texture.

Declaration
public void SetRenderTarget(WritableTexture tex)
Parameters
Type Name Description
WritableTexture tex

The render texture.

UnlockAllRenderStates(Boolean)

Unlocks all previously locked RenderStates.

True by default. Defines if the states get reset to their pre-locked value.
Declaration
public void UnlockAllRenderStates(bool resetValue = true)
Parameters
Type Name Description
System.Boolean resetValue

UnlockRenderState(RenderState, Boolean)

Unlocks the given RenderState. And sets it to the value it had before it was locked. After this call the state can be set to a new value again.

Declaration
public void UnlockRenderState(RenderState state, bool resetValue = true)
Parameters
Type Name Description
RenderState state

The state to unlock.

System.Boolean resetValue

True by default. Defines if the state gets reset to its pre-locked value.

Viewport(Int32, Int32, Int32, Int32)

Sets the rectangular output region within the output buffer(s).

Declaration
public void Viewport(int x, int y, int width, int height)
Parameters
Type Name Description
System.Int32 x

leftmost pixel of the rectangular output region within the output buffer.

System.Int32 y

topmost pixel of the rectangular output region within the output buffer.

System.Int32 width

horizontal size (in pixels) of the output region.

System.Int32 height

vertical size (in pixels) of the output region.

Remarks

Setting the Viewport limits the rendering output to the specified rectangular region.

Generated by DocFX
GitHub Repo
Back to top