IGraphicsContext
Description
- Derived from
- Extended by
-
GraphicsContext abstract
Base interface for classes that provide a graphics context.
Rendering with a graphics context is performed as follows:
-
Call Validate:
-
true
: The graphics context is valid, continue with 3. -
false
: The graphics context has become invalid, continue with 2.
-
-
Reset the graphics context:
-
Dispose all resources:
IGpuBuffer, IGeometryBuffer, IGraphicsFence, IGraphicsTimer, IRenderEffect, IRenderTarget, ITexture -
Call Validate. The method will return
true
if the graphics context is valid again. -
Recreate all resources.
-
-
Call IBeginEnd.Begin:
The GPU may still be busy with processing commands of the previous frame. To wait for the GPU to finish (for example when using GpuUpdateFlag.NoOverwrite), use a IGraphicsFence. -
Use SetRenderTarget to perform rendering for each IRenderTarget resp. ISwapChain.
-
Call IBeginEnd.End
-
Call ISwapChain.Present for each swap chain.
There are several types of GPU resources that can be created with a graphics context:
-
Resources with IResource.AccessPattern = ResourceAccessPattern.Static, created by:
ITextureFactory.CreateTexture2DStatic
IBufferFactory.CreateIndexBufferStatic
IBufferFactory.CreateStructuredBufferStatic
IBufferFactory.CreateVertexBufferStatic -
Resources with IResource.AccessPattern = ResourceAccessPattern.Dynamic, created by:
ITextureFactory.CreateTexture2D
CreateTextureCube
IBufferFactory.CreateIndexBuffer
IBufferFactory.CreateStructuredBuffer
IBufferFactory.CreateVertexBuffer -
Resources with IResource.AccessPattern = ResourceAccessPattern.Mappable, created by:
ITextureFactory.CreateTexture2D
IBufferFactory.CreateIndexBuffer
IBufferFactory.CreateStructuredBuffer
IBufferFactory.CreateVertexBuffer
Public / Methods
CanCreateRenderEffect
Checks if this IGraphicsContext is capable of creating an instance of IRenderEffectBase for the given render effect parameters.
CanCreateSwapChain
Checks if this IGraphicsContext is capable of creating an instance of ISwapChain for the given native window.
ClearCache
Requests to clear the graphics resource cache.
The graphics resource cache will be cleared upon the next call to IBeginEnd.End when there are no pending resource loading jobs (see ResourceLoader.IsLoading). Before clearing the cache, the method waits for the GPU to finish all pending work.
- See also
ClearRenderTarget
Clears pixels to the given values on the render targets that have been specified by the most recent call to SetRenderTarget.
An implementation can choose to either clear all pixels (e.g. Direct3D 10/11), or to clear only those that are inside of the current viewport rectangle (e.g. Direct3D 9). This behaviour is not exposed, so the ClearRenderTarget method should only be called after SetRenderTarget and before SetViewport.
CreateFence
Creates a new graphics fence object.
- RenderException
-
If a graphics subsystem error has occurred.
CreateGeometryBuffer
Creates a buffer for drawing geometry.
Geometry buffers should be created infrequently and then re-used over many frames. Creating new geometry buffers frequently can have significant impact on performance.
- RenderException
-
If a graphics subsystem error has occurred.
- See also
CreateRenderEffect
Creates an instance of IRenderEffectBase for the given render effect parameters.
The documentation of the concrete implementation class of parameters in depicts the render effect interface that will be implemented by the returned object.
- RenderException
-
If a graphics subsystem error has occurred.
CreateRenderTarget
Creates a new off-screen render target.
A render target may have a color buffer (see IRenderTarget.HasColor), a depth buffer (see IRenderTarget.HasDepth) or both. The content of a newly created render target is undefined. The color opt, depth opt and stencil opt parameters give a hint regarding the default values that will be used for clearing the render target with ClearRenderTarget. Some graphics APIs provide high-performance clears when the default values are used.
- RenderException
-
If a graphics subsystem error has occurred.
CreateSwapChain
Creates a swap chain render target for the given window.
When the swap chain render target is created, the following format flags are used:
The content of a newly created swap chain is undefined, its default clear color is transparent black and its depth/stencil value is zero.
- RenderException
-
If a graphics subsystem error has occurred.
- See also
CreateTextureCube
Creates a ITextureCube with ResourceAccessPattern.Dynamic access.
- RenderException
-
If a graphics subsystem error has occurred.
CreateTimer
Creates a new graphics timer object.
- RenderException
-
If a graphics subsystem error has occurred.
GetRenderTarget
Returns the current set of render targets.
The returned RenderTargets value represents the most recent value that has been passed to SetRenderTarget and will not capture the render targets that have been specified by external code.
IsCompatibleWith
Checks if the implementation class of this IGraphicsContext object is compatible with the given factory in.
ReadPixels
Obtains a snapshot of the given render target.
- RenderException
-
If a graphics subsystem error has occurred.
RegisterRenderEffectFactory
Registers the given render effect factory.
- RenderException
-
If a graphics subsystem error has occurred.
SetGeometryBuffer
Sets the geometry buffers to use for drawing geometry.
This method should be called with default arguments to clear the geometry buffer bindings, after the rendering work has been submitted. Not doing so can potentially lead to incompatible combinations of active render effect pass (see IRenderEffectBase.Pass) and current geometry buffer. Although this is not an error, it might produce warning log messages for some APIs.
If IGeometryBuffer.Instances is not null
, the cartesian product of the vertices and instances in geometryBuffer opt is used to draw instanced geometry: Each vertex in IGeometryBuffer.Vertices that is referenced by subsequent calls to IPrimitiveRenderer is duplicated instanceCount opt times; instance data from IGeometryBuffer.Instances is appended to the vertex data, which is then consumed by GPU shaders.
The firstInstance opt and instanceCount opt parameters choose the range of instances that will be used by subsequent calls to IPrimitiveRenderer. If IGeometryBuffer.Instances is null
, these parameters are ignored.
SetRenderTarget
Sets the render targets for subsequent draw calls.
Setting the render targets will also reset the viewport (see SetViewport) and clip rectangle (see SetClip) to the bounds of the render target set (see RenderTargets.Size). The screen bounds of the shared Graphics object will also be set, by calling Graphics.Fullscreen.
The calling code is responsible for handling the required calls the IRenderTarget.Finish method for each used render target.
SetRenderTargetBackup
Backs up the current render target set (see GetRenderTarget), the current viewport (see Viewport), the current clip rectangle (see Clip) and the bounds of the shared Graphics object (see Graphics.Bounds).
Calls to SetRenderTargetBackup and SetRenderTargetRestore must be balanced and may be nested.
SetRenderTargetRestore
Restores the backed-up render target set, viewport, clip rectangle and graphics bounds.
Calls to SetRenderTargetBackup and SetRenderTargetRestore must be balanced and may be nested.
Validate
Checks if this graphics context is still valid.
Once a graphics context has become invalid, it must be detached from the application and all graphics resources have to be re-created (e.g. via IApplication.GraphicsContextDetach and IApplication.GraphicsContextAttach).
ValidateRenderTargetFormat
Checks if the given render target format is supported by this graphics context.
Implementations usually need to perform render API calls in order to determine render target format support, which may include creation of dummy resources. However, implementations will cache validation results for each format in value, to avoid unnecessary work at runtime.
- See also
Wait
Waits up to 250 ms for the GPU to finish its work.
This method is not intended to be used for synchronizing with the GPU during real-time rendering, for which IGraphicsFence objects should be used. Instead, this method is a helper for trivial cases, for example waiting for the GPU to finish before taking a screenshot.
Public / Attributes
Clip
The pixel bounds of the current clip rectangle that has been specified by the most recent call to SetClip.
Graphics
Returns the shared Graphics object for this graphics context.
The returned Graphics may only be used between calls to IBeginEnd.Begin and IBeginEnd.End of IGraphicsContext, which surround the separate calls to IBeginEnd.Begin and IBeginEnd.End of Graphics.
The bounds of the shared Graphics object are set automatically to the bounds of the current render target. If the graphics context is not active or if no render target has been set, the bounds of the Graphics object will be empty, i.e. the screen size will be zero (see Graphics.ScreenSize).
- See also
IsNearAtZero
Is the near-clipping plane mapped to 0
in clip-space (true
), or is it mapped to -1
(false
)?
MeshDispatcher
Returns the IMeshDispatcher for this graphics context.
The methods of IMeshDispatcher may only be used within calls to IBeginEnd.Begin and IBeginEnd.End.
PrimitiveRenderer
Returns the IPrimitiveRenderer for this graphics context.
The methods of IPrimitiveRenderer may only be used within calls to IBeginEnd.Begin and IBeginEnd.End.
RenderTargetCount
The number of color render targets that can be used simultaneously during rendering.
The optional depth/stencil render target may always be used during rendering and is not included in this count.
Size
The pixel size of the render targets that have been specified by the most recent call to SetRenderTarget.
If no render target is bound to index 0
, Vec2I.Zero is returned.
Viewport
The pixel bounds of the current viewport rectangle that has been specified by the most recent call to SetViewport.
WorkDispatcher
Returns the IWorkDispatcher for this graphics context.
The methods of IWorkDispatcher may only be used within calls to IBeginEnd.Begin and IBeginEnd.End.
Extensions
CreateRenderTarget
Creates a new off-screen render target.
A render target may have a color buffer (see IRenderTarget.HasColor), a depth buffer (see IRenderTarget.HasDepth) or both.
- RenderException
-
If a graphics subsystem error has occurred.
LoadTextureCube
Loads a ITextureCube resource.
- RenderException
-
If a graphics subsystem error has occurred.
- IOException
-
If an I/O error has occurred.
- ValidatingException
-
If the image reader has reported an error, for example because of an unsupported file format feature.
SetGeometryBuffer
Sets the geometry buffers to use for drawing geometry.
This method should be called with default arguments to clear the geometry buffer bindings, after the rendering work has been submitted. Not doing so can potentially lead to incompatible combinations of active render effect pass (see IRenderEffectBase.Pass) and current geometry buffer. Although this is not an error, it might produce warning log messages for some APIs.
If IGeometryBuffer.Instances is not null
, the cartesian product of the vertices and instances in geometryBuffer in is used to draw instanced geometry: Each vertex in IGeometryBuffer.Vertices that is referenced by subsequent calls to IPrimitiveRenderer is duplicated RangeI.Length times; instance data from IGeometryBuffer.Instances is appended to the vertex data, which is then consumed by GPU shaders.
The instances in parameter chooses the range of instances that will be used by subsequent calls to IPrimitiveRenderer. If IGeometryBuffer.Instances is null
, this parameter is ignored.
SetRenderTarget
Sets the render target for subsequent draw calls.
Setting the render target will also reset the viewport (see IGraphicsContext.SetViewport) and clip rectangle (see IGraphicsContext.SetClip) to the size of the given render target (see IRenderTarget.Size). The screen size of the shared Graphics object will be set accordingly, too.
The color and/or depth buffer of the given render target will be used.