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

Implementation of the Diligent::IDeviceContextGL interface. More...

Inheritance diagram for Diligent::DeviceContextGLImpl:
Diligent::DeviceContextBase< IDeviceContextGL > Diligent::ObjectBase< IDeviceContextGL > Diligent::RefCountedObject< IDeviceContextGL > Diligent::IDeviceContextGL Diligent::IDeviceContext

Public Member Functions

virtual void QueryInterface (const Diligent::INTERFACE_ID &IID, IObject **ppInterface) override final
 Queries the specific interface, see IObject::QueryInterface() for details.
 
virtual void SetPipelineState (IPipelineState *pPipelineState) override final
 Base implementation of IDeviceContext::SetPipelineState(); caches references to the pipeline state object.
 
virtual void TransitionShaderResources (IPipelineState *pPipelineState, IShaderResourceBinding *pShaderResourceBinding) override final
 Transitions shader resources to the require states. More...
 
virtual void CommitShaderResources (IShaderResourceBinding *pShaderResourceBinding, Uint32 Flags) override final
 Commits shader resources to the device context. More...
 
virtual void SetStencilRef (Uint32 StencilRef) override final
 Sets the stencil reference value. More...
 
virtual void SetBlendFactors (const float *pBlendFactors=nullptr) override final
 
virtual void SetVertexBuffers (Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer **ppBuffers, Uint32 *pStrides, Uint32 *pOffsets, Uint32 Flags) override final
 Base implementation of IDeviceContext::SetVertexBuffers(); validates parameters and caches references to the buffers.
 
virtual void InvalidateState () override final
 Invalidates the cached context state. More...
 
virtual void SetIndexBuffer (IBuffer *pIndexBuffer, Uint32 ByteOffset) override final
 Base implementation of IDeviceContext::SetIndexBuffer(); caches the strong reference to the index buffer.
 
virtual void SetViewports (Uint32 NumViewports, const Viewport *pViewports, Uint32 RTWidth, Uint32 RTHeight) override final
 Sets an array of viewports. More...
 
virtual void SetScissorRects (Uint32 NumRects, const Rect *pRects, Uint32 RTWidth, Uint32 RTHeight) override final
 Sets active scissor rects. More...
 
virtual void SetRenderTargets (Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil) override final
 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) override final
 Executes a draw command. More...
 
virtual void DispatchCompute (const DispatchComputeAttribs &DispatchAttrs) override final
 Executes a dispatch compute command. More...
 
virtual void ClearDepthStencil (ITextureView *pView, Uint32 ClearFlags, float fDepth, Uint8 Stencil) override final
 Clears a depth-stencil view. More...
 
virtual void ClearRenderTarget (ITextureView *pView, const float *RGBA) override final
 Clears a render target view. More...
 
virtual void Flush () override final
 Flushes the command buffer.
 
virtual void FinishCommandList (class ICommandList **ppCommandList) override final
 Finishes recording commands and generates a command list. More...
 
virtual void ExecuteCommandList (class ICommandList *pCommandList) override final
 Executes recorded commands in a command list. More...
 
virtual bool UpdateCurrentGLContext () override final
 Attaches to the active GL context in the thread. More...
 
- Public Member Functions inherited from Diligent::DeviceContextBase< IDeviceContextGL >
 DeviceContextBase (IReferenceCounters *pRefCounters, IRenderDevice *pRenderDevice, bool bIsDeferred)
 
bool CommitShaderResources (IShaderResourceBinding *pShaderResourceBinding, Uint32 Flags, int)
 Base implementation of IDeviceContext::CommitShaderResources(); validates parameters.
 
void SetViewports (Uint32 NumViewports, const Viewport *pViewports, Uint32 &RTWidth, Uint32 &RTHeight)
 Caches the viewports.
 
void SetScissorRects (Uint32 NumRects, const Rect *pRects, Uint32 &RTWidth, Uint32 &RTHeight)
 Caches the scissor rects.
 
bool SetRenderTargets (Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil, Uint32 Dummy=0)
 Caches the render target and depth stencil views. Returns true if any view is different from the cached value and false otherwise.
 
virtual void SetSwapChain (ISwapChain *pSwapChain) override final
 Sets the strong pointer to the swap chain.
 
ISwapChainGetSwapChain ()
 Returns the swap chain.
 
bool IsDefaultFBBound ()
 Returns true if currently bound frame buffer is the default frame buffer.
 
void GetPipelineState (IPipelineState **ppPSO, float *BlendFactors, Uint32 &StencilRef)
 Returns currently bound pipeline state and blend factors.
 
void GetRenderTargets (Uint32 &NumRenderTargets, ITextureView **ppRTVs, ITextureView **ppDSV)
 Returns currently bound render targets.
 
void GetViewports (Uint32 &NumViewports, Viewport *pViewports)
 Returns currently set viewports.
 
IRenderDeviceGetDevice ()
 Returns the render device.
 

Additional Inherited Members

- Protected Member Functions inherited from Diligent::DeviceContextBase< IDeviceContextGL >
void GetRenderTargetSize (Uint32 &RTWidth, Uint32 &RTHeight)
 Returns the size of the currently bound render target.
 
void ClearStateCache ()
 Clears all cached resources.
 
- Protected Attributes inherited from Diligent::DeviceContextBase< IDeviceContextGL >
RefCntAutoPtr< IRenderDevicem_pDevice
 Strong reference to the device.
 
RefCntAutoPtr< ISwapChainm_pSwapChain
 Strong reference to the swap chain. Swap chain holds weak reference to the immediate context.
 
VertexStreamInfo m_VertexStreams [MaxBufferSlots]
 Vertex streams. Every stream holds strong reference to the buffer.
 
Uint32 m_NumVertexStreams
 Number of bound vertex streams.
 
RefCntAutoPtr< IPipelineStatem_pPipelineState
 Strong reference to the bound pipeline state object.
 
RefCntAutoPtr< IBufferm_pIndexBuffer
 Strong reference to the bound index buffer.
 
Uint32 m_IndexDataStartOffset
 Offset from the beginning of the index buffer to the start of the index data, in bytes.
 
Uint32 m_StencilRef
 Current stencil reference value.
 
Float32 m_BlendFactors [4]
 Curent blend factors.
 
Viewport m_Viewports [MaxRenderTargets]
 Current viewports.
 
Uint32 m_NumViewports
 Number of current viewports.
 
Rect m_ScissorRects [MaxRenderTargets]
 Current scissor rects.
 
Uint32 m_NumScissorRects
 Number of current scissor rects.
 
RefCntAutoPtr< ITextureViewm_pBoundRenderTargets [MaxRenderTargets]
 Vector of strong references to the bound render targets.
 
Uint32 m_NumBoundRenderTargets
 Number of bound render targets.
 
bool m_IsDefaultFramebufferBound
 Flag indicating if default render target & depth-stencil buffer are currently bound.
 
RefCntAutoPtr< ITextureViewm_pBoundDepthStencil
 Strong references to the bound depth stencil view.
 

Detailed Description

Implementation of the Diligent::IDeviceContextGL interface.

Member Function Documentation

◆ ClearDepthStencil()

void Diligent::DeviceContextGLImpl::ClearDepthStencil ( ITextureView pView,
Uint32  ClearFlags,
float  fDepth,
Uint8  Stencil 
)
finaloverridevirtual

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.

Implements Diligent::IDeviceContext.

◆ ClearRenderTarget()

void Diligent::DeviceContextGLImpl::ClearRenderTarget ( ITextureView pView,
const float *  RGBA 
)
finaloverridevirtual

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.

Implements Diligent::IDeviceContext.

◆ CommitShaderResources()

void Diligent::DeviceContextGLImpl::CommitShaderResources ( IShaderResourceBinding pShaderResourceBinding,
Uint32  Flags 
)
finaloverridevirtual

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()

Implements Diligent::IDeviceContext.

◆ DispatchCompute()

void Diligent::DeviceContextGLImpl::DispatchCompute ( const DispatchComputeAttribs DispatchAttrs)
finaloverridevirtual

Executes a dispatch compute command.

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

Implements Diligent::IDeviceContext.

◆ Draw()

void Diligent::DeviceContextGLImpl::Draw ( DrawAttribs DrawAttribs)
finaloverridevirtual

Executes a draw command.

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

Implements Diligent::IDeviceContext.

◆ ExecuteCommandList()

void Diligent::DeviceContextGLImpl::ExecuteCommandList ( class ICommandList pCommandList)
finaloverridevirtual

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.

Implements Diligent::IDeviceContext.

◆ FinishCommandList()

void Diligent::DeviceContextGLImpl::FinishCommandList ( class ICommandList **  ppCommandList)
finaloverridevirtual

Finishes recording commands and generates a command list.

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

Implements Diligent::IDeviceContext.

◆ InvalidateState()

void Diligent::DeviceContextGLImpl::InvalidateState ( )
finaloverridevirtual

Invalidates the cached context state.

This method should be called by say Unity plugin before (or after) issuing draw commands to invalidate cached states

Implements Diligent::DeviceContextBase< IDeviceContextGL >.

◆ SetBlendFactors()

void Diligent::DeviceContextGLImpl::SetBlendFactors ( const float *  pBlendFactors = nullptr)
finaloverridevirtual
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.

Implements Diligent::IDeviceContext.

◆ SetRenderTargets()

void Diligent::DeviceContextGLImpl::SetRenderTargets ( Uint32  NumRenderTargets,
ITextureView ppRenderTargets[],
ITextureView pDepthStencil 
)
finaloverridevirtual

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); 

Implements Diligent::IDeviceContext.

◆ SetScissorRects()

void Diligent::DeviceContextGLImpl::SetScissorRects ( Uint32  NumRects,
const Rect pRects,
Uint32  RTWidth,
Uint32  RTHeight 
)
finaloverridevirtual

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.

Implements Diligent::IDeviceContext.

◆ SetStencilRef()

void Diligent::DeviceContextGLImpl::SetStencilRef ( Uint32  StencilRef)
finaloverridevirtual

Sets the stencil reference value.

Parameters
[in]StencilRef- Stencil reference value.

Implements Diligent::IDeviceContext.

◆ SetViewports()

void Diligent::DeviceContextGLImpl::SetViewports ( Uint32  NumViewports,
const Viewport pViewports,
Uint32  RTWidth,
Uint32  RTHeight 
)
finaloverridevirtual

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); 

Implements Diligent::IDeviceContext.

◆ TransitionShaderResources()

void Diligent::DeviceContextGLImpl::TransitionShaderResources ( IPipelineState pPipelineState,
IShaderResourceBinding pShaderResourceBinding 
)
finaloverridevirtual

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()

Implements Diligent::IDeviceContext.

◆ UpdateCurrentGLContext()

bool Diligent::DeviceContextGLImpl::UpdateCurrentGLContext ( )
finaloverridevirtual

Attaches to the active GL context in the thread.

If an application uses multiple GL contexts, this method must be called before any other command to let the engine update active context every time when control flow is passed over from the main application

Returns
false if there is no active GL context, and true otherwise

Implements Diligent::IDeviceContextGL.