TINMAN 3D / REALTIME TERRAIN
Software Development Kit - User Manual

class DirectX11Context in Tinman.AddOns.DirectX11

An implementation of the IGraphicsContext interface for DirectX 11.

sealed class DirectX11Context extends DirectXContext

Remarks

You can use the DirectX11ContextFactory object to configure and create an instance of this class. Also you can use the ForDevice method to wrap an existing ID3D11Device* COM pointer.

The returned INativeHandle s can be interpreted as follows:

Public / Attributes

Cache

Returns the shared ResourceCache object for this graphics context.

public property Cache { get }
type ResourceCache
value [not-null] The shared resource cache.
inherited GraphicsContext.Cache

FrameTime

The GPU time that has been spent for the last frame.

public property FrameTime { get }
type float32
value [>=0] The spent time, in milliseconds.
inherited GraphicsContext.FrameTime

Remarks:

The last frame is defined as the sequence of render calls made between Begin and End. The frame time is measured for the most recent frame that has been finished by the GPU, i.e. measuring frame time will never stall the pipeline.

Graphics

Returns the shared Graphics object for this graphics context.

[OwnerReturn]
public property Graphics { get }
type Graphics
value [not-null] The shared graphics object.
inherited GraphicsContext.Graphics

IsNearAtZero

Is the near-clipping plane mapped to 0 in clip-space (true), or is it mapped to -1 (false)?

public property IsNearAtZero { get }
type bool
value The mapping behaviour for the near-clipping plane.
inherited GraphicsContext.IsNearAtZero

LifecycleState

Returns the lifecycle state of this object.

public override property LifecycleState { get }
type LifecycleState
value The lifecycle state.
inherited Initializable.LifecycleState

Name

Human readable name of this graphics context.

public property Name { get }
type string
value [not-empty] The graphics context name.
inherited GraphicsContext.Name

NativeHandle

Returns the raw handle value of the native resource that is contained in this object.

public override property NativeHandle { get }
type IntPtr
value The raw handle value.
implements GraphicsContext.NativeHandle

Remarks:

The documentation of the implementing class will contain information on how to interpret the raw handle value.

PrimitiveRenderer

Returns the IPrimitiveRenderer for this graphics context.

public override property PrimitiveRenderer { get }
type IPrimitiveRenderer
value [not-null] The IPrimitiveRenderer object.
implements GraphicsContext.PrimitiveRenderer

RenderTargetCount

The number of render targets that can be used simultaneously during rendering.

public property RenderTargetCount { get }
type int32
value [1..4] The number of render targets.
inherited GraphicsContext.RenderTargetCount

See also:

IGraphicsContext.SetRenderTarget

ShaderEffectNames

Returns the names of all shader effects.

public property ShaderEffectNames { get }
type string[]
value [not-null] The list of shader effect names.
inherited GraphicsContext.ShaderEffectNames

See also:

IGraphicsContext.ShaderEffect

Size

The pixel size of the render targets that have been specified by the most recent call to SetRenderTarget.

public property Size { get }
type Vec2I
value The render target size, in pixels.
inherited GraphicsContext.Size

Remarks:

If no render target is bound to index 0, Zero is returned.

TextureFactory

Returns the ITextureFactory for this graphics context.

public override property TextureFactory { get }
type ITextureFactory
value [not-null] The ITextureFactory object.
implements GraphicsContext.TextureFactory

Public / Constructors

ForDevice

Creates a new instance of DirectX11Context for the given native handle.

[OwnerReturn]
public static method ForDevice ([Owner] IntPtr deviceHandle, MultiSampleType multiSampling = default(MultiSampleType), bool verticalSync = true, int32 adapterOrdinal = 0)
type DirectX11Context
params deviceHandle The ID3D11Device* COM pointer to the device. Upon disposal, Release will be called on the COM pointer.
  multiSampling The multi-sampling setting that the DirectX11Context should use (see MultiSample). Defaults to None.
  verticalSync Enables or disables vertical synchronization when calling Present). Defaults to true.
  adapterOrdinal The ordinal number of the DXGI adapter that is used by the device. The adapter is only used once by this method to obtain the amount of video memory (see AvailableVideoMemory). Defaults to 0.
returns The graphics context of null if deviceHandle is zero.

Public / Methods

AcquireTry

Acquires a strong reference to this disposable object.

[OwnerReturn, ThreadSafe]
public method AcquireTry ()
type IDisposable
returns this if a new strong reference has been acquired, null if this object is already being disposed.
inherited Disposable.AcquireTry

Remarks:

The object will not be actually disposed by calls to Dispose when there is at least one strong reference left. Code that calls the AcquireTry method is responsible for calling the Dispose method accordingly.

This method is not intended to be used in performance-critical code. It should only be used to high-level resource management.

Begin

Begins an access to this object.

public override method Begin ()
overrides GraphicsContext.Begin

Remarks:

See the documentation of the class which implements this interface for details on the operations that must be wrapped in Begin and End calls.

See also:

BeginEnd

Clear

Clears pixels to the given values on the render targets that have been specified by the most recent call to SetRenderTarget.

[BeginEnd]
public override method Clear (RenderTargetClearFlags flags, int64 color = 0, float32 depth = 1, int32 stencil = 0)
params flags Flags that depict the buffers to clear.
  color The color (see Colors) to clear to.
  depth The depth value to clear to.
  stencil The stencil value to clear to.
implements GraphicsContext.Clear

Remarks:

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 Clear method should only be called after SetRenderTarget and before SetViewport.

Passing Depth and/or Stencil with the flags parameter when there is no depth/stencil buffer (see D24_S8) can make the Clear method fail silently.

CreateGeometryBuffer

Creates a buffer for drawing geometry.

[OwnerReturn]
public override method CreateGeometryBuffer ([Owner] IVertexBuffer vertices, [Owner] IIndexBuffer indices = null, [Owner] IVertexBuffer instances = null)
type IGeometryBuffer
params vertices [not-null] The vertex buffer that holds geometry data.
  indices The index buffer or null. Defaults to null.
  instances The vertex buffer that holds instance data or null. Defaults to null.
returns [not-null] The instance buffer.
implements GraphicsContext.CreateGeometryBuffer

See also:

IGraphicsContext.SetGeometryBuffer

CreateIndexBuffer

Creates a dynamic IIndexBuffer object (i.e. CanSetIndices returns true).

[OwnerReturn]
public override method CreateIndexBuffer (int32 capacity)
type IIndexBuffer
params capacity [>0] The capacity of the index buffer, in vertex indices.
returns [not-null] The IIndexBuffer object.
implements GraphicsContext.CreateIndexBuffer

Creates a static IIndexBuffer object (i.e. CanSetIndices returns false).

[OwnerReturn]
public override method CreateIndexBuffer (int32[] indices, int32 offset = 0, int32 count = 0)
type IIndexBuffer
params indices [not-null] The index buffer content.
  offset [>=0] Offset to first vertex index in indices. Defaults to 0.
  count [>=0] Total number of vertex indices. If 0, all remaining vertex indices will be used. Defaults to 0.
returns [not-null] The IIndexBuffer object.
implements GraphicsContext.CreateIndexBuffer

CreateRenderTarget

Creates a new off-screen render target.

[OwnerReturn]
public override method CreateRenderTarget (int32 width, int32 height, RenderTargetFormat format)
type IRenderTarget
params width [>0] Width of render target, in pixels.
  height [>0] Height of render target, in pixels.
  format The render target format.
returns [not-null] The render target.
implements GraphicsContext.CreateRenderTarget

See also:

IGraphicsContext.ValidateRenderTargetFormat
IGraphicsContext.SetRenderTarget

CreateSwapChain

Creates a swap chain render target for the given window.

[OwnerReturn]
public override method CreateSwapChain (IApplicationWindow window)
type ISwapChain
params window [not-null] The target window.
returns [not-null] The render target for the created swap chain.
implements GraphicsContext.CreateSwapChain

Remarks:

When the swap chain render target is created, the following format flags are used:

See also:

IGraphicsContext.SetRenderTarget

Creates a swap chain render target for the given window.

[OwnerReturn]
public override method CreateSwapChain (IntPtr windowHandle, Vec2I clientSize)
type ISwapChain
params windowHandle The HWND window handle.
  clientSize The swap chain size, in pixels.
returns [not-null] The render target for the created swap chain.
implements DirectXContext.CreateSwapChain

Remarks:

When the swap chain render target is created, the following format flags are used:

CreateTextureCube

Creates a dynamic ITextureCube object (i.e. CanSetTexels returns true).

[OwnerReturn]
public override method CreateTextureCube (int32 size, TextureFormat format, int32 mipmaps = 1, bool srgb = true)
type ITextureCube
params size [>0] The texture size, in texels.
  format [not-null] The texture format (will be returned by Format).
  mipmaps [>=0] The number of mipmap levels (including the full-resolution level). If 0 the number of levels will be inferred from size. Defaults to 1.
  srgb The sRGB behaviour of the created texture (see IsSrgb). Defaults to true.
returns [not-null] The ITexture2D object.
implements GraphicsContext.CreateTextureCube

See also:

ITextureFactory.ValidateTextureFormat

Exceptions:

CreateVertexBuffer

Creates a static IVertexBuffer object (i.e. CanLockBuffer returns false).

[OwnerReturn]
public override method CreateVertexBuffer (VertexElements format, ByteBuffer content)
type IVertexBuffer
params format [not-null] The vertex buffer format.
  content [not-null] The vertex buffer contents.
implements GraphicsContext.CreateVertexBuffer

Remarks:

The capacity (see Capacity) of the returned vertex buffer is equal to floor(BS/VS), where BS is the buffer size (see Remaining) and VS is the vertex size (see Size).


Creates a dynamic IVertexBuffer object (i.e. CanLockBuffer returns true).

[OwnerReturn]
public override method CreateVertexBuffer (int32 capacity, VertexElements format)
type IVertexBuffer
params capacity [>0] The capacity of the vertex buffer, in vertices.
  format [not-null] The vertex format.
returns [not-null] The IVertexBuffer object.
implements GraphicsContext.CreateVertexBuffer

Dispose

Releases all resources held by this object if there are no more strong references to it, decrements the reference counter by one otherwise.

[Dispose, OwnerThis, ThreadSafe]
public method Dispose ()
inherited Disposable.Dispose

Remarks:

The Dispose method silently returns if the object has already been disposed.

End

Ends the current access to this object.

public override method End ()
overrides GraphicsContext.End

Remarks:

See the documentation of the class which implements this interface for details on the operations that must be wrapped in Begin and End calls.

See also:

BeginEnd

Initialize

Initializes the object, if necessary

public method Initialize ()
inherited Initializable.Initialize

Remarks:

The Initialize method returns silently if the object is already in the state Initialized.

ReadPixels

Obtains a snapshot of the given render target.

public override method ReadPixels (int32 renderTargetIndex = 0)
type ColorBuffer
params renderTargetIndex [0..RenderTargetCount-1] The render target index.
returns The snapshot pixels or null if no render target is bound to the given index.
implements GraphicsContext.ReadPixels

RegisterShaderEffects

Scans the given directory for shader effect files and registers them in this graphics context.

public override sealed method RegisterShaderEffects (Path source, Path binary)
params source [not-null] The directory that holds shader effect source code files.
  binary [not-null] The directory that holds shader effect binary files.
inherited DirectXContext.RegisterShaderEffects

Remarks:

Only the given directories are scanned for shader effect files. Subdirectories are not scanned.

Please refer to the documentation of the implementing class for details on which files are used to represent shader effect files.

The source and binary parameters may point to the same directory.

See also:

IGraphicsContext.ShaderEffect

SetClip

Sets the clip rectangle on the current render target.

[BeginEnd]
public override method SetClip (Box2I value)
params value The clip rectangle.
implements GraphicsContext.SetClip

SetGeometryBuffer

Sets the geometry buffers to use for drawing geometry.

[BeginEnd]
public override method SetGeometryBuffer (IGeometryBuffer geometryBuffer = null, int32 firstInstance = 0, int32 instanceCount = -1)
params geometryBuffer The geometry buffer to use or null to clear all buffer bindings. Defaults to null.
  firstInstance [>=0] Index of first instance to draw. Will be ignored if geometry is not instanced. Defaults to 0.
  instanceCount [>=-1] Total number of instances to draw. Set to -1 to draw all instances in geometryBuffer. Will be ignored if geometry is not instanced. Defaults to -1.
implements GraphicsContext.SetGeometryBuffer

Remarks:

If Instances is not null, the cartesian product of the vertices and instances in geometryBuffer is used to draw instanced geometry: Each vertex in Vertices that is referenced by subsequent calls to IPrimitiveRenderer is duplicated instanceCount times; instance data from Instances is appended to the vertex data, which is then consumed by GPU shaders.

The firstInstance and instanceCount parameters choose the range of instances that will be used by subsequent calls to IPrimitiveRenderer. If Instances is null, these parameters are ignored.

SetRenderTarget

Sets the render target to use for subsequent draw calls.

[BeginEnd]
public override method SetRenderTarget (IRenderTarget renderTarget0 = null, IRenderTarget renderTarget1 = null, IRenderTarget renderTarget2 = null, IRenderTarget renderTarget3 = null, bool keepDepthStencil = false)
params renderTarget0 The render target to use at color index 0. Defaults to null.
  renderTarget1 The render target to use at color index 1. Defaults to null.
  renderTarget2 The render target to use at color index 2. Defaults to null.
  renderTarget3 The render target to use at color index 3. Defaults to null.
  keepDepthStencil Keep current depth/stencil buffer, in case that none of the given render targets has a depth/stencil buffer? Defaults to false.
overrides GraphicsContext.SetRenderTarget

Remarks:

Setting the render target will also reset the viewport (see SetViewport) and clip rectangle (see SetClip) to the render target size (see Size).

Setting all render targets to null will restore the previous render targets, i.e. the ones that have been set in the current Begin/End cycle by the before last call to SetRenderTarget with at least one non-null renderTarget* parameter.

Render target arguments with color indices greater than or equal to RenderTargetCount will be skipped silently.

The render targets are probed for a depth/stencil buffer, from color index 0 to 3. The first non-null buffer will be used. If none of the render targets has a buffer, depth/stencil buffer will be disabled, unless keepDepthStencil is true.

See also:

IGraphicsContext.CreateRenderTarget
IGraphicsContext.CreateSwapChain
IGraphicsContext.RenderTargetCount

SetViewport

Sets the viewport rectangle on the current render target.

[BeginEnd]
public override method SetViewport (Box2I value)
params value The viewport rectangle.
implements GraphicsContext.SetViewport

ShaderEffect

Returns a shader effect by its name.

public method ShaderEffect (string name)
type IShaderEffect
params name [not-empty] The shader effect name.
returns [not-null] The shader effect object.
inherited GraphicsContext.ShaderEffect

Remarks:

The lookup scheme for shader source code or shader binaries is up to the implementing class.

See also:

IGraphicsContext.ShaderEffectNames

Validate

Checks if this graphics context is still valid.

public override method Validate ()
type bool
returns true if the graphics context is valid, false if it has become invalid.
implements GraphicsContext.Validate

Remarks:

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 GraphicsContextDetach and GraphicsContextAttach).

ValidateRenderTargetFormat

Checks if the given render target format is supported by this graphics context.

public override method ValidateRenderTargetFormat (RenderTargetFormat format)
type bool
params format The render target format.
returns true if CreateRenderTarget will succeed, false if it will fail.
implements GraphicsContext.ValidateRenderTargetFormat

See also:

IGraphicsContext.CreateRenderTarget

Logging

Logger

The logger object of this class.

public static readonly field Logger
type ILogger