Diligent Engine API Reference
Public Member Functions | List of all members
Diligent::IDeviceContext Class Referenceabstract

Device context interface. More...

Inheritance diagram for Diligent::IDeviceContext:
Diligent::IObject Diligent::IDeviceContextD3D11 Diligent::IDeviceContextGL Diligent::RefCountedObject< IDeviceContext, IMemoryAllocator > Diligent::RefCountedObject< IDeviceContextD3D11, IMemoryAllocator > Diligent::RefCountedObject< IDeviceContextGL, IMemoryAllocator > Diligent::ObjectBase< IDeviceContext, IMemoryAllocator > Diligent::ObjectBase< IDeviceContextD3D11, IMemoryAllocator > Diligent::ObjectBase< IDeviceContextGL, IMemoryAllocator > Diligent::DeviceContextBase< IDeviceContext > Diligent::DeviceContextBase< IDeviceContextD3D11 > Diligent::DeviceContextBase< IDeviceContextGL > Diligent::DeviceContextD3D12Impl Diligent::DeviceContextD3D11Impl Diligent::DeviceContextGLImpl

Public Member Functions

virtual void QueryInterface (const Diligent::INTERFACE_ID &IID, IObject **ppInterface)=0
 Queries the specific interface, see IObject::QueryInterface() for details.
 
virtual void SetPipelineState (IPipelineState *pPipelineState)=0
 Sets the pipeline state. More...
 
virtual void TransitionShaderResources (IPipelineState *pPipelineState, IShaderResourceBinding *pShaderResourceBinding)=0
 Transitions shader resources to the require states. More...
 
virtual void CommitShaderResources (IShaderResourceBinding *pShaderResourceBinding, Uint32 Flags)=0
 Commits shader resources to the device context. More...
 
virtual void SetStencilRef (Uint32 StencilRef)=0
 Sets the stencil reference value. More...
 
virtual void SetBlendFactors (const float *pBlendFactors=nullptr)=0
 
virtual void SetVertexBuffers (Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer **ppBuffers, Uint32 *pStrides, Uint32 *pOffsets, Uint32 Flags)=0
 Binds vertex buffers to the pipeline. More...
 
virtual void ClearState ()=0
 Clears the context state.
 
virtual void SetIndexBuffer (IBuffer *pIndexBuffer, Uint32 ByteOffset)=0
 Binds an index buffer to the pipeline. More...
 
virtual void SetViewports (Uint32 NumViewports, const Viewport *pViewports, Uint32 RTWidth, Uint32 RTHeight)=0
 Sets an array of viewports. More...
 
virtual void SetScissorRects (Uint32 NumRects, const Rect *pRects, Uint32 RTWidth, Uint32 RTHeight)=0
 Sets active scissor rects. More...
 
virtual void SetRenderTargets (Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil)=0
 Binds one or more render targets and the depth-stencil buffer to the pipeline. It also sets the viewport to match the first non-null render target or depth-stencil buffer. More...
 
virtual void Draw (DrawAttribs &DrawAttribs)=0
 Executes a draw command. More...
 
virtual void DispatchCompute (const DispatchComputeAttribs &DispatchAttrs)=0
 Executes a dispatch compute command. More...
 
virtual void ClearDepthStencil (ITextureView *pView, Uint32 ClearFlags=CLEAR_DEPTH_FLAG, float fDepth=1.f, Uint8 Stencil=0)=0
 Clears a depth-stencil view. More...
 
virtual void ClearRenderTarget (ITextureView *pView, const float *RGBA=nullptr)=0
 Clears a render target view. More...
 
virtual void FinishCommandList (class ICommandList **ppCommandList)=0
 Finishes recording commands and generates a command list. More...
 
virtual void ExecuteCommandList (class ICommandList *pCommandList)=0
 Executes recorded commands in a command list. More...
 
virtual void Flush ()=0
 Flushes the command buffer.
 
- Public Member Functions inherited from Diligent::IObject
virtual Atomics::Long AddRef ()=0
 Increments the number of strong references by 1. More...
 
virtual Atomics::Long Release ()=0
 Decrements the number of strong references by 1 and destroys the object when the counter reaches zero. More...
 
virtual IReferenceCountersGetReferenceCounters () const =0
 Returns the pointer to IReferenceCounters interface of the associated reference counters object. The metod does NOT increment the number of strong references to the returned object.
 

Detailed Description

Device context interface.

Remarks
Device context keeps strong references to all objects currently bound to the pipeline: buffers, states, samplers, shaders, etc. The context also keeps strong reference to the device and the swap chain.

Member Function Documentation

virtual void Diligent::IDeviceContext::ClearDepthStencil ( ITextureView pView,
Uint32  ClearFlags = CLEAR_DEPTH_FLAG,
float  fDepth = 1.f,
Uint8  Stencil = 0 
)
pure virtual

Clears a depth-stencil view.

Parameters
[in]pView- Pointer to ITextureView interface to clear. The view type must be Diligent::TEXTURE_VIEW_DEPTH_STENCIL.
[in]ClearFlags- Idicates which parts of the buffer to clear, see Diligent::CLEAR_DEPTH_STENCIL_FLAGS.
[in]fDepth- Value to clear depth part of the view with.
[in]Stencil- Value to clear stencil part of the view with.
Remarks
The full extent of the view is always cleared. Viewport and scissor settings are not applied.
Note
The depth-stencil view must be bound to the pipeline for clear operation to be performed.

Implemented in Diligent::DeviceContextD3D12Impl, Diligent::DeviceContextD3D11Impl, and Diligent::DeviceContextGLImpl.

virtual void Diligent::IDeviceContext::ClearRenderTarget ( ITextureView pView,
const float *  RGBA = nullptr 
)
pure virtual

Clears a render target view.

Parameters
[in]pView- Pointer to ITextureView interface to clear. The view type must be Diligent::TEXTURE_VIEW_RENDER_TARGET.
[in]RGBA- A 4-component array that represents the color to fill the render target with. If nullptr is provided, the default array {0,0,0,0} will be used.
Remarks
The full extent of the view is always cleared. Viewport and scissor settings are not applied.
Note
The render target view must be bound to the pipeline for clear operation to be performed.

Implemented in Diligent::DeviceContextD3D12Impl, Diligent::DeviceContextD3D11Impl, and Diligent::DeviceContextGLImpl.

virtual void Diligent::IDeviceContext::CommitShaderResources ( IShaderResourceBinding pShaderResourceBinding,
Uint32  Flags 
)
pure virtual

Commits shader resources to the device context.

Parameters
[in]pShaderResourceBinding- Shader resource binding whose resources will be committed. If pipeline state contains no shader resources, this parameter can be null.
[in]Flags- Additional flags for the operation. See Diligent::COMMIT_SHADER_RESOURCES_FLAG for a list of allowed values.
Remarks
Pipeline state object that was used to create the shader resource binding must be bound to the pipeline when CommitShaderResources() is called. If no pipeline state object is bound or the pipeline state object does not match shader resource binding, the method will fail.
If Diligent::COMMIT_SHADER_RESOURCES_FLAG_TRANSITION_RESOURCES flag is specified, the engine will also transition all shader resources to the correct state. If the flag is not specified, it is assumed that all resources are already in correct states.
Resources can be explicitly transitioned to the required states by calling IDeviceContext::TransitionShaderResources()

Implemented in Diligent::DeviceContextD3D12Impl, Diligent::DeviceContextD3D11Impl, and Diligent::DeviceContextGLImpl.

virtual void Diligent::IDeviceContext::DispatchCompute ( const DispatchComputeAttribs DispatchAttrs)
pure virtual

Executes a dispatch compute command.

Parameters
[in]DispatchAttrs- Structure describing dispatch command attributes, see DispatchComputeAttribs for details.

Implemented in Diligent::DeviceContextD3D12Impl, Diligent::DeviceContextD3D11Impl, and Diligent::DeviceContextGLImpl.

virtual void Diligent::IDeviceContext::Draw ( DrawAttribs DrawAttribs)
pure virtual

Executes a draw command.

Parameters
[in]DrawAttribs- Structure describing draw command attributes, see DrawAttribs for details.

Implemented in Diligent::DeviceContextD3D12Impl, Diligent::DeviceContextD3D11Impl, and Diligent::DeviceContextGLImpl.

virtual void Diligent::IDeviceContext::ExecuteCommandList ( class ICommandList pCommandList)
pure virtual

Executes recorded commands in a command list.

Parameters
[in]pCommandList- Pointer to the command list to executre.
Remarks
After command list is executed, it is no longer valid and should be released.

Implemented in Diligent::DeviceContextD3D12Impl, Diligent::DeviceContextD3D11Impl, and Diligent::DeviceContextGLImpl.

virtual void Diligent::IDeviceContext::FinishCommandList ( class ICommandList **  ppCommandList)
pure virtual

Finishes recording commands and generates a command list.

Parameters
[out]ppCommandList- Memory location where pointer to the recorded command list will be written.

Implemented in Diligent::DeviceContextD3D12Impl, Diligent::DeviceContextD3D11Impl, and Diligent::DeviceContextGLImpl.

virtual void Diligent::IDeviceContext::SetBlendFactors ( const float *  pBlendFactors = nullptr)
pure virtual
Parameters
[in]pBlendFactors- Array of four blend factors, one for each RGBA component. Theses factors are used if the blend state uses one of the Diligent::BLEND_FACTOR_BLEND_FACTOR or Diligent::BLEND_FACTOR_INV_BLEND_FACTOR blend factors. If nullptr is provided, default blend factors array {1,1,1,1} will be used.

Implemented in Diligent::DeviceContextD3D12Impl, Diligent::DeviceContextD3D11Impl, and Diligent::DeviceContextGLImpl.

virtual void Diligent::IDeviceContext::SetIndexBuffer ( IBuffer pIndexBuffer,
Uint32  ByteOffset 
)
pure virtual

Binds an index buffer to the pipeline.

Parameters
[in]pIndexBuffer- Pointer to the index buffer. The buffer must have been created with the Diligent::BIND_INDEX_BUFFER flag.
[in]ByteOffset- Offset from the beginning of the buffer to the start of index data.
Remarks
The device context keeps strong reference to the index buffer. Thus an index buffer object cannot be released until it is unbound from the context.

Implemented in Diligent::DeviceContextBase< IDeviceContextGL >, Diligent::DeviceContextBase< IDeviceContext >, Diligent::DeviceContextBase< IDeviceContextD3D11 >, Diligent::DeviceContextD3D12Impl, Diligent::DeviceContextD3D11Impl, and Diligent::DeviceContextGLImpl.

virtual void Diligent::IDeviceContext::SetPipelineState ( IPipelineState pPipelineState)
pure virtual
virtual void Diligent::IDeviceContext::SetRenderTargets ( Uint32  NumRenderTargets,
ITextureView ppRenderTargets[],
ITextureView pDepthStencil 
)
pure virtual

Binds one or more render targets and the depth-stencil buffer to the pipeline. It also sets the viewport to match the first non-null render target or depth-stencil buffer.

Parameters
[in]NumRenderTargets- Number of render targets to bind.
[in]ppRenderTargets- Array of pointers to ITextureView that represent the render targets to bind to the device. The type of each view in the array must be Diligent::TEXTURE_VIEW_RENDER_TARGET.
[in]pDepthStencil- Pointer to the ITextureView that represents the depth stencil to bind to the device. The view type must be Diligent::TEXTURE_VIEW_DEPTH_STENCIL.
Remarks
The device context will keep strong references to all bound render target and depth-stencil views. Thus these views (and consequently referenced textures) cannot be released until they are unbound from the context.
Any render targets not defined by this call are set to nullptr.

You can set the default render target and depth stencil using the following call:
pContext->SetRenderTargets(0, nullptr, nullptr); 

Implemented in Diligent::DeviceContextD3D12Impl, Diligent::DeviceContextD3D11Impl, and Diligent::DeviceContextGLImpl.

virtual void Diligent::IDeviceContext::SetScissorRects ( Uint32  NumRects,
const Rect pRects,
Uint32  RTWidth,
Uint32  RTHeight 
)
pure virtual

Sets active scissor rects.

Parameters
[in]NumRects- Number of scissor rectangles to set.
[in]pRects- An array of Rect structures describing the scissor rectangles to bind.
[in]RTWidth- Render target width. If 0 is provided, width of the currently bound render target will be used.
[in]RTHeight- Render target height. If 0 is provided, height of the currently bound render target will be used.
Remarks
DirectX and OpenGL use different window coordinate systems. In DirectX, the coordinate system origin is in the left top corner of the screen with Y axis pointing down. In OpenGL, the origin is in the left bottom corener of the screen with Y axis pointing up. Render target size is required to convert viewport from DirectX to OpenGL coordinate system if OpenGL device is used.

All scissor rects must be set atomically as one operation. Any rects not defined by the call are disabled.

Implemented in Diligent::DeviceContextD3D12Impl, Diligent::DeviceContextD3D11Impl, and Diligent::DeviceContextGLImpl.

virtual void Diligent::IDeviceContext::SetStencilRef ( Uint32  StencilRef)
pure virtual

Sets the stencil reference value.

Parameters
[in]StencilRef- Stencil reference value.

Implemented in Diligent::DeviceContextD3D12Impl, Diligent::DeviceContextD3D11Impl, and Diligent::DeviceContextGLImpl.

virtual void Diligent::IDeviceContext::SetVertexBuffers ( Uint32  StartSlot,
Uint32  NumBuffersSet,
IBuffer **  ppBuffers,
Uint32 pStrides,
Uint32 pOffsets,
Uint32  Flags 
)
pure virtual

Binds vertex buffers to the pipeline.

Parameters
[in]StartSlot- The first input slot for binding. The first vertex buffer is explicitly bound to the start slot; each additional vertex buffer in the array is implicitly bound to each subsequent input slot.
[in]NumBuffersSet- The number of vertex buffers in the array.
[in]ppBuffers- A pointer to an array of vertex buffers.
[in]pStrides- Pointer to an array of stride values; one stride value for each buffer in the vertex-buffer array. Each stride is the size (in bytes) of the elements that are to be used from that vertex buffer. If this parameter is nullptr, tight strides from the input layout will be used for each buffer. See IPipelineState::GetTightStrides().
[in]pOffsets- Pointer to an array of offset values; one offset value for each buffer in the vertex-buffer array. Each offset is the number of bytes between the first element of a vertex buffer and the first element that will be used. If this parameter is nullptr, zero offsets for all buffers will be used.
[in]Flags- Additional flags for the operation. See Diligent::SET_VERTEX_BUFFERS_FLAGS for a list of allowed values.
Remarks
The device context keeps strong references to all bound vertex buffers. Thus a buffer cannot be released until it is unbound from the context.
It is suggested to specify Diligent::SET_VERTEX_BUFFERS_FLAG_RESET flag whenever possible. This will assure that no buffers from previous draw calls are are bound to the pipeline.

Implemented in Diligent::DeviceContextBase< IDeviceContextGL >, Diligent::DeviceContextBase< IDeviceContext >, Diligent::DeviceContextBase< IDeviceContextD3D11 >, Diligent::DeviceContextD3D12Impl, Diligent::DeviceContextD3D11Impl, and Diligent::DeviceContextGLImpl.

virtual void Diligent::IDeviceContext::SetViewports ( Uint32  NumViewports,
const Viewport pViewports,
Uint32  RTWidth,
Uint32  RTHeight 
)
pure virtual

Sets an array of viewports.

Parameters
[in]NumViewports- Number of viewports to set.
[in]pViewports- An array of Viewport structures describing the viewports to bind.
[in]RTWidth- Render target width. If 0 is provided, width of the currently bound render target will be used.
[in]RTHeight-Render target height. If 0 is provided, height of the currently bound render target will be used.
Remarks
DirectX and OpenGL use different window coordinate systems. In DirectX, the coordinate system origin is in the left top corner of the screen with Y axis pointing down. In OpenGL, the origin is in the left bottom corener of the screen with Y axis pointing up. Render target size is required to convert viewport from DirectX to OpenGL coordinate system if OpenGL device is used.

All viewports must be set atomically as one operation. Any viewports not defined by the call are disabled.

You can set the viewport size to match the currently bound render target using the following call:
pContext->SetViewports(1, nullptr, 0, 0); 

Implemented in Diligent::DeviceContextD3D12Impl, Diligent::DeviceContextD3D11Impl, and Diligent::DeviceContextGLImpl.

virtual void Diligent::IDeviceContext::TransitionShaderResources ( IPipelineState pPipelineState,
IShaderResourceBinding pShaderResourceBinding 
)
pure virtual

Transitions shader resources to the require states.

Parameters
[in]pPipelineState- Pipeline state object that was used to create the shader resource binding.
[in]pShaderResourceBinding- Shader resource binding whose resources will be transitioned.
Remarks
This method explicitly transitiones all resources to the correct states. If this method was called, there is no need to specify Diligent::COMMIT_SHADER_RESOURCES_FLAG_TRANSITION_RESOURCES when calling IDeviceContext::CommitShaderResources()

Implemented in Diligent::DeviceContextD3D12Impl, Diligent::DeviceContextD3D11Impl, and Diligent::DeviceContextGLImpl.