ezEngine  Milestone 7
ezGALContextGL Class Reference

The GL implementation of the graphics context. More...

#include <ContextGL.h>

Inheritance diagram for ezGALContextGL:

Classes

struct  GLBufferBinding
 OpenGL buffer bindings. First elements are compatible with ezGALBufferType. More...
 
class  ScopedBufferBinding
 Buffer binding that will reset itself when leaving the scope. More...
 
class  ScopedTextureBinding
 Texture binding that will reset itself when leaving the scope. More...
 

Public Member Functions

ezResult SetGLState (ezUInt32 uiStateIdentifier, bool on)
 Enables or disables a given OpenGL state using glEnable/glDisable. More...
 
bool IsStateActive (ezUInt32 uiStateIdentifier)
 Returns if a given OpenGL state is active. More...
 
ezResult BindBuffer (GLBufferBinding::Enum binding, glBufferId buffer)
 Binds a gl buffer to the given binding point. More...
 
ezResult BindTexture (ezGALTextureType::Enum textureType, glTextureId textureHandle, ezInt32 iBindingSlot=-1)
 Binds a texture to a given slot. More...
 
- Public Member Functions inherited from ezGALContext
void Clear (const ezColor &ClearColor, ezUInt32 uiRenderTargetClearMask=0xFFFFFFFFu, bool bClearDepth=true, bool bClearStencil=true, float fDepthClear=1.0f, ezUInt8 uiStencilClear=0x0u)
 Clears active rendertargets. More...
 
void Draw (ezUInt32 uiVertexCount, ezUInt32 uiStartVertex)
 
void DrawIndexed (ezUInt32 uiIndexCount, ezUInt32 uiStartIndex)
 
void DrawIndexedInstanced (ezUInt32 uiIndexCountPerInstance, ezUInt32 uiInstanceCount, ezUInt32 uiStartIndex)
 
void DrawIndexedInstancedIndirect (ezGALBufferHandle hIndirectArgumentBuffer, ezUInt32 uiArgumentOffsetInBytes)
 
void DrawInstanced (ezUInt32 uiVertexCountPerInstance, ezUInt32 uiInstanceCount, ezUInt32 uiStartVertex)
 
void DrawInstancedIndirect (ezGALBufferHandle hIndirectArgumentBuffer, ezUInt32 uiArgumentOffsetInBytes)
 
void DrawAuto ()
 
void BeginStreamOut ()
 
void EndStreamOut ()
 
void Dispatch (ezUInt32 uiThreadGroupCountX, ezUInt32 uiThreadGroupCountY, ezUInt32 uiThreadGroupCountZ)
 
void DispatchIndirect (ezGALBufferHandle hIndirectArgumentBuffer, ezUInt32 uiArgumentOffsetInBytes)
 
void SetShader (ezGALShaderHandle hShader)
 
void SetIndexBuffer (ezGALBufferHandle hIndexBuffer)
 
void SetVertexBuffer (ezUInt32 uiSlot, ezGALBufferHandle hVertexBuffer)
 
void SetVertexDeclaration (ezGALVertexDeclarationHandle hVertexDeclaration)
 
void SetPrimitiveTopology (ezGALPrimitiveTopology::Enum Topology)
 
void SetConstantBuffer (ezUInt32 uiSlot, ezGALBufferHandle hBuffer)
 
void SetSamplerState (ezGALShaderStage::Enum Stage, ezUInt32 uiSlot, ezGALSamplerStateHandle hSamplerState)
 
void SetResourceView (ezGALShaderStage::Enum Stage, ezUInt32 uiSlot, ezGALResourceViewHandle hResourceView)
 
void SetRenderTargetSetup (const ezGALRenderTagetSetup &RenderTargetSetup)
 
void SetUnorderedAccessView (ezUInt32 uiSlot, ezGALResourceViewHandle hResourceView)
 
void SetBlendState (ezGALBlendStateHandle hBlendState, const ezColor &BlendFactor=ezColor::White, ezUInt32 uiSampleMask=0xFFFFFFFFu)
 
void SetDepthStencilState (ezGALDepthStencilStateHandle hDepthStencilState, ezUInt8 uiStencilRefValue=0xFFu)
 
void SetRasterizerState (ezGALRasterizerStateHandle hRasterizerState)
 
void SetViewport (float fX, float fY, float fWidth, float fHeight, float fMinDepth, float fMaxDepth)
 
void SetScissorRect (ezUInt32 uiX, ezUInt32 uiY, ezUInt32 uiWidth, ezUInt32 uiHeight)
 
void SetStreamOutBuffer (ezUInt32 uiSlot, ezGALBufferHandle hBuffer, ezUInt32 uiOffset)
 
void InsertFence (ezGALFenceHandle hFence)
 
bool IsFenceReached (ezGALFenceHandle hFence)
 
void WaitForFence (ezGALFenceHandle hFence)
 
void BeginQuery (ezGALQueryHandle hQuery)
 
void EndQuery (ezGALQueryHandle hQuery)
 
void CopyBuffer (ezGALBufferHandle hDest, ezGALBufferHandle hSource)
 
void CopyBufferRegion (ezGALBufferHandle hDest, ezUInt32 uiDestOffset, ezGALBufferHandle hSource, ezUInt32 uiSourceOffset, ezUInt32 uiByteCount)
 
void UpdateBuffer (ezGALBufferHandle hDest, ezUInt32 uiDestOffset, const void *pSourceData, ezUInt32 uiByteCount)
 
void CopyTexture (ezGALTextureHandle hDest, ezGALTextureHandle hSource)
 
void CopyTextureRegion (ezGALTextureHandle hDest, const ezGALTextureSubresource &DestinationSubResource, const ezVec3U32 &DestinationPoint, ezGALTextureHandle hSource, const ezGALTextureSubresource &SourceSubResource, const ezBoundingBoxu32 &Box)
 
void UpdateTexture (ezGALTextureHandle hDest, const ezGALTextureSubresource &DestinationSubResource, const ezBoundingBoxu32 &DestinationBox, const void *pSourceData, ezUInt32 uiSourceRowPitch, ezUInt32 uiSourceDepthPitch)
 
void ResolveTexture (ezGALTextureHandle hDest, const ezGALTextureSubresource &DestinationSubResource, ezGALTextureHandle hSource, const ezGALTextureSubresource &SourceSubResource)
 
void ReadbackTexture (ezGALTextureHandle hTexture)
 
void CopyTextureReadbackResult (ezGALTextureHandle hTexture, const ezArrayPtr< ezGALSystemMemoryDescription > *pData)
 
void PushMarker (const char *Marker)
 
void PopMarker ()
 
void InsertEventMarker (const char *Marker)
 
void ClearStatisticsCounters ()
 

Static Public Attributes

static const ezUInt32 s_GALTopologyToGL [ezGALPrimitiveTopology::ENUM_COUNT]
 Maps ezGALPrimitiveTopology to OpenGL types. More...
 
static const ezUInt32 s_GALIndexTypeToGL [ezGALIndexType::ENUM_COUNT]
 Maps ezGALIndexType to OpenGL types. More...
 
static const ezUInt32 s_GALBufferBindingToGL [GLBufferBinding::ENUM_COUNT]
 Maps GLBufferBindings to actual OpenGL binding points. More...
 
static const ezUInt32 s_GALTextureTypeToGL [ezGALTextureType::ENUM_COUNT]
 Maps ezGALTextureType to OpenGL texture types. More...
 

Protected Member Functions

 ezGALContextGL (ezGALDeviceGL *pDevice)
 
virtual void ClearPlatform (const ezColor &ClearColor, ezUInt32 uiRenderTargetClearMask, bool bClearDepth, bool bClearStencil, float fDepthClear, ezUInt8 uiStencilClear) override
 
virtual void DrawPlatform (ezUInt32 uiVertexCount, ezUInt32 uiStartVertex) override
 
virtual void DrawIndexedPlatform (ezUInt32 uiIndexCount, ezUInt32 uiStartIndex) override
 
virtual void DrawIndexedInstancedPlatform (ezUInt32 uiIndexCountPerInstance, ezUInt32 uiInstanceCount, ezUInt32 uiStartIndex) override
 
virtual void DrawIndexedInstancedIndirectPlatform (ezGALBuffer *pIndirectArgumentBuffer, ezUInt32 uiArgumentOffsetInBytes) override
 
virtual void DrawInstancedPlatform (ezUInt32 uiVertexCountPerInstance, ezUInt32 uiInstanceCount, ezUInt32 uiStartVertex) override
 
virtual void DrawInstancedIndirectPlatform (ezGALBuffer *pIndirectArgumentBuffer, ezUInt32 uiArgumentOffsetInBytes) override
 
virtual void DrawAutoPlatform () override
 
virtual void BeginStreamOutPlatform () override
 
virtual void EndStreamOutPlatform () override
 
virtual void DispatchPlatform (ezUInt32 uiThreadGroupCountX, ezUInt32 uiThreadGroupCountY, ezUInt32 uiThreadGroupCountZ) override
 
virtual void DispatchIndirectPlatform (ezGALBuffer *pIndirectArgumentBuffer, ezUInt32 uiArgumentOffsetInBytes) override
 
virtual void SetShaderPlatform (ezGALShader *pShader) override
 
virtual void SetIndexBufferPlatform (ezGALBuffer *pIndexBuffer) override
 
virtual void SetVertexBufferPlatform (ezUInt32 uiSlot, ezGALBuffer *pVertexBuffer) override
 
virtual void SetVertexDeclarationPlatform (ezGALVertexDeclaration *pVertexDeclaration) override
 
virtual void SetPrimitiveTopologyPlatform (ezGALPrimitiveTopology::Enum Topology) override
 
virtual void SetConstantBufferPlatform (ezUInt32 uiSlot, ezGALBuffer *pBuffer) override
 
virtual void SetSamplerStatePlatform (ezGALShaderStage::Enum Stage, ezUInt32 uiSlot, ezGALSamplerState *pSamplerState) override
 
virtual void SetResourceViewPlatform (ezGALShaderStage::Enum Stage, ezUInt32 uiSlot, ezGALResourceView *pResourceView) override
 
virtual void SetRenderTargetConfigPlatform (ezGALRenderTargetConfig *pRenderTargetConfig) override
 
virtual void SetUnorderedAccessViewPlatform (ezUInt32 uiSlot, ezGALResourceView *pResourceView) override
 
virtual void SetBlendStatePlatform (ezGALBlendState *pBlendState, const ezColor &BlendFactor, ezUInt32 uiSampleMask) override
 
virtual void SetDepthStencilStatePlatform (ezGALDepthStencilState *pDepthStencilState, ezUInt8 uiStencilRefValue) override
 
virtual void SetRasterizerStatePlatform (ezGALRasterizerState *pRasterizerState) override
 
virtual void SetViewportPlatform (float fX, float fY, float fWidth, float fHeight, float fMinDepth, float fMaxDepth) override
 
virtual void SetScissorRectPlatform (ezUInt32 uiX, ezUInt32 uiY, ezUInt32 uiWidth, ezUInt32 uiHeight) override
 
virtual void SetStreamOutBufferPlatform (ezUInt32 uiSlot, ezGALBuffer *pBuffer, ezUInt32 uiOffset) override
 
virtual void InsertFencePlatform (ezGALFence *pFence) override
 
virtual bool IsFenceReachedPlatform (ezGALFence *pFence) override
 
virtual void BeginQueryPlatform (ezGALQuery *pQuery) override
 
virtual void EndQueryPlatform (ezGALQuery *pQuery) override
 
virtual void CopyBufferPlatform (ezGALBuffer *pDestination, ezGALBuffer *pSource) override
 
virtual void CopyBufferRegionPlatform (ezGALBuffer *pDestination, ezUInt32 uiDestOffset, ezGALBuffer *pSource, ezUInt32 uiSourceOffset, ezUInt32 uiByteCount) override
 
virtual void UpdateBufferPlatform (ezGALBuffer *pDestination, ezUInt32 uiDestOffset, const void *pSourceData, ezUInt32 uiByteCount) override
 
virtual void CopyTexturePlatform (ezGALTexture *pDestination, ezGALTexture *pSource) override
 
virtual void CopyTextureRegionPlatform (ezGALTexture *pDestination, const ezGALTextureSubresource &DestinationSubResource, const ezVec3U32 &DestinationPoint, ezGALTexture *pSource, const ezGALTextureSubresource &SourceSubResource, const ezBoundingBoxu32 &Box) override
 
virtual void UpdateTexturePlatform (ezGALTexture *pDestination, const ezGALTextureSubresource &DestinationSubResource, const ezBoundingBoxu32 &DestinationBox, const void *pSourceData, ezUInt32 uiSourceRowPitch, ezUInt32 uiSourceDepthPitch) override
 
virtual void ResolveTexturePlatform (ezGALTexture *pDestination, const ezGALTextureSubresource &DestinationSubResource, ezGALTexture *pSource, const ezGALTextureSubresource &SourceSubResource) override
 
virtual void ReadbackTexturePlatform (ezGALTexture *pTexture) override
 
virtual void CopyTextureReadbackResultPlatform (ezGALTexture *pTexture, const ezArrayPtr< ezGALSystemMemoryDescription > *pData) override
 
virtual void PushMarkerPlatform (const char *Marker) override
 
virtual void PopMarkerPlatform () override
 
virtual void InsertEventMarkerPlatform (const char *Marker) override
 
void FlushDeferredStateChanges ()
 
- Protected Member Functions inherited from ezGALContext
 ezGALContext (ezGALDevice *pDevice)
 
virtual void SetRenderTargetSetupPlatform (ezGALRenderTargetView **ppRenderTargetViews, ezUInt32 uiRenderTargetCount, ezGALRenderTargetView *pDepthStencilView)=0
 
void InvalidateState ()
 

Protected Attributes

friend ScopedBufferBinding
 
glSamplerId m_BoundSamplerStates [EZ_GAL_MAX_SHADER_RESOURCE_VIEW_COUNT]
 Already bound texture samplers, to be bound in a single glBindSamplers call.
 
glBufferId m_BoundVertexBuffers [EZ_GAL_MAX_VERTEX_BUFFER_COUNT]
 Already bound vertex buffers, to be bound in a single glBindVertexBuffers call .
 
ezInt32 m_VertexBufferStrides [EZ_GAL_MAX_VERTEX_BUFFER_COUNT]
 Vertex buffer strides to be set with next glBindVertexBuffers call.
 
const ezDynamicArray
< ezGALVertexDeclarationGL::VertexAttributeDesc > * 
m_pBoundVertexAttributes
 Preprocessed GL vertex attribute information.
 
ezBitflags
< ezGALGL::DeferredStateChanged > 
m_DeferredStateChanged
 Currently changed deferred states.
 
ezGALPrimitiveTopology::Enum m_PrimitiveTopology
 Primitive topology to use for upcoming draw-calls.
 
ezGALIndexType::Enum m_IndexType
 Index type to use for upcoming indexed draw-calls.
 
ezUInt32 m_uiNumColorTarget
 Number of currently bound render-targets.
 
ezUInt32 m_uiNumGLVertexAttributesBound
 Number of currently bound OpenGL vertex buffers.
 
ezHashTable< ezUInt32, bool > m_EnableStates
 
ezUInt32 m_DepthWriteMask
 Current depth write mask.
 
ezUInt32 m_StencilWriteMask
 Current depth write mask.
 
ezUInt32 m_StencilReadMask
 Current stencil read mask.
 
ezUInt32 m_StencilFunc
 Current stencil func.
 
ezUInt32 m_CullFaceState
 Current state of glCullFace.
 
ezUInt32 m_PolygonMode
 Current state of glPolygonMode.
 
ezUInt32 m_BufferBindings [GLBufferBinding::ENUM_COUNT]
 Currently bound buffers.
 
ezUInt32 m_uiActiveTextureUnit
 Currently active Texture unit - controlled with glActiveTexture.
 
ezInt32 m_iMaxNumTextureBindings
 Maximum of texture bindings.
 
ezArrayPtr< ezUInt32 > m_TextureBindings [ezGALTextureType::ENUM_COUNT]
 Currently bound textures.
 

Friends

class ezGALDeviceGL
 

Detailed Description

The GL implementation of the graphics context.

Member Function Documentation

ezResult ezGALContextGL::BindBuffer ( GLBufferBinding::Enum  binding,
glBufferId  buffer 
)

Binds a gl buffer to the given binding point.

Will avoid redundant bindings.

ezResult ezGALContextGL::BindTexture ( ezGALTextureType::Enum  textureType,
glTextureId  textureHandle,
ezInt32  iBindingSlot = -1 
)

Binds a texture to a given slot.

Will avoid unnecessary state changes.

Parameters
textureTypeBinding type.
textureHandleOpenGL texture handle.
iBindingSlotBinding slot used for glActiveTexture. Negative values will ignore the binding slot. This is useful for allocation operations.
void ezGALContextGL::CopyTextureReadbackResultPlatform ( ezGALTexture pTexture,
const ezArrayPtr< ezGALSystemMemoryDescription > *  pData 
)
overrideprotectedvirtual
Todo:
add parameters for mip level & count selection?

Implements ezGALContext.

void ezGALContextGL::FlushDeferredStateChanges ( )
protected
Todo:
GL4 Together with glVertexAttribPointer
bool ezGALContextGL::IsStateActive ( ezUInt32  uiStateIdentifier)

Returns if a given OpenGL state is active.

Will ready state from an intern hash-table. If not yet known glIsEnable will be called once and then stored into the intern hash-table.

See Also
SetGLState
void ezGALContextGL::SetDepthStencilStatePlatform ( ezGALDepthStencilState pDepthStencilState,
ezUInt8  uiStencilRefValue 
)
overrideprotectedvirtual
Todo:
Stencil func needs to be implemented

Implements ezGALContext.

ezResult ezGALContextGL::SetGLState ( ezUInt32  uiStateIdentifier,
bool  on 
)

Enables or disables a given OpenGL state using glEnable/glDisable.

Will check if statechange is necessary.

See Also
IsStateActive
void ezGALContextGL::SetRasterizerStatePlatform ( ezGALRasterizerState pRasterizerState)
overrideprotectedvirtual
Todo:

Implements ezGALContext.

void ezGALContextGL::SetResourceViewPlatform ( ezGALShaderStage::Enum  Stage,
ezUInt32  uiSlot,
ezGALResourceView pResourceView 
)
overrideprotectedvirtual
Todo:
GL4 TextureViews

Implements ezGALContext.

void ezGALContextGL::UpdateBufferPlatform ( ezGALBuffer pDestination,
ezUInt32  uiDestOffset,
const void *  pSourceData,
ezUInt32  uiByteCount 
)
overrideprotectedvirtual
Todo:
All those glGetIntegerv should be avoided! Need to store gl state somewhere

Implements ezGALContext.

Member Data Documentation

ezHashTable<ezUInt32, bool> ezGALContextGL::m_EnableStates
protected

Maps OpenGL glEnable/glDisable options to their current state.

See Also
SetGLState, IsStateActive
const ezUInt32 ezGALContextGL::s_GALBufferBindingToGL
static
Initial value:
=
{
GL_SHADER_STORAGE_BUFFER,
GL_ARRAY_BUFFER,
GL_ELEMENT_ARRAY_BUFFER,
GL_UNIFORM_BUFFER,
GL_TRANSFORM_FEEDBACK_BUFFER,
GL_DRAW_INDIRECT_BUFFER
}

Maps GLBufferBindings to actual OpenGL binding points.

const ezUInt32 ezGALContextGL::s_GALIndexTypeToGL
static
Initial value:
=
{
GL_UNSIGNED_SHORT,
GL_UNSIGNED_INT
}

Maps ezGALIndexType to OpenGL types.

const ezUInt32 ezGALContextGL::s_GALTextureTypeToGL
static
Initial value:
=
{
GL_TEXTURE_2D,
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
GL_TEXTURE_3D
}

Maps ezGALTextureType to OpenGL texture types.

const ezUInt32 ezGALContextGL::s_GALTopologyToGL
static
Initial value:
=
{
GL_TRIANGLES
}

Maps ezGALPrimitiveTopology to OpenGL types.


The documentation for this class was generated from the following files: