Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Divide::GL_API Class Referencefinal

OpenGL implementation of the RenderAPIWrapper. More...

#include <GLWrapper.h>

+ Inheritance diagram for Divide::GL_API:

Classes

struct  CachedSamplerEntry
 
struct  glHardwareQueryEntry
 
struct  TexBindEntry
 

Public Member Functions

 GL_API (GFXDevice &context)
 
- Public Member Functions inherited from Divide::RenderAPIWrapper
virtual ~RenderAPIWrapper ()=default
 

Static Public Member Functions

static GLStateTrackerGetStateTracker () noexcept
 
static GLUtil::GLMemory::GLMemoryType GetMemoryTypeForUsage (gl46core::GLenum usage) noexcept
 
static GLUtil::GLMemory::DeviceAllocatorGetMemoryAllocator (GLUtil::GLMemory::GLMemoryType memoryType) noexcept
 
static void QueueFlush () noexcept
 
static void AddDebugMessage (const char *message, U32 id=U32_MAX)
 
static void PushDebugMessage (const char *message, U32 id=U32_MAX)
 
static void PopDebugMessage ()
 
static bool DeleteShaderPrograms (gl46core::GLuint count, gl46core::GLuint *programs)
 
static bool DeleteSamplers (gl46core::GLuint count, gl46core::GLuint *samplers)
 
static bool DeleteBuffers (gl46core::GLuint count, gl46core::GLuint *buffers)
 
static bool DeleteFramebuffers (gl46core::GLuint count, gl46core::GLuint *framebuffers)
 
static gl46core::GLuint GetSamplerHandle (SamplerDescriptor sampler, size_t &samplerHashInOut)
 Return the OpenGL sampler object's handle for the given hash value.
 
static glHardwareQueryPoolGetHardwareQueryPool () noexcept
 
static gl46core::GLsync CreateFenceSync ()
 
static void DestroyFenceSync (gl46core::GLsync &sync)
 

Static Public Attributes

static constexpr U32 s_LockFrameLifetime = 3u
 

Static Protected Member Functions

static ShaderResult BindPipeline (GFXDevice &context, const Pipeline &pipeline)
 
static bool Draw (const GenericDrawCommand &cmd)
 

Private Types

enum class  GlobalQueryTypes : U8 {
  VERTICES_SUBMITTED = 0 , PRIMITIVES_GENERATED , TESSELLATION_PATCHES , TESSELLATION_EVAL_INVOCATIONS ,
  GPU_TIME , COUNT
}
 
using HardwareQueryContext = std::array< glHardwareQueryEntry, to_base(QueryType::COUNT)>
 
using SamplerObjectMap = eastl::fixed_vector< CachedSamplerEntry, InitialSamplerMapSize, true >
 

Private Member Functions

ErrorCode initRenderingAPI (I32 argc, char **argv, Configuration &config) override
 Try and create a valid OpenGL context taking in account the specified command line arguments.
 
void closeRenderingAPI () override
 Clear everything that was setup in initRenderingAPI()
 
bool drawToWindow (DisplayWindow &window) override
 Prepare the GPU for rendering a frame.
 
void onRenderThreadLoopStart () override
 
void onRenderThreadLoopEnd () override
 
void prepareFlushWindow (DisplayWindow &window) override
 
void flushWindow (DisplayWindow &window) override
 
bool frameStarted () override
 
bool frameEnded () override
 
void endPerformanceQueries ()
 
void idle (bool fast) override
 
void preFlushCommandBuffer (Handle< GFX::CommandBuffer > commandBuffer) override
 
void flushCommand (GFX::CommandBase *cmd) override
 
void postFlushCommandBuffer (Handle< GFX::CommandBuffer > commandBuffer) override
 
void onThreadCreated (const std::thread::id &threadID, bool isMainRenderThread) override
 
void clearStates (GLStateTracker &stateTracker) const
 Reset as much of the GL default state as possible within the limitations given.
 
bool bindShaderResources (const DescriptorSetEntries &descriptorSetEntries) override
 
bool makeTextureViewResident (gl46core::GLubyte bindingSlot, const ImageView &imageView, size_t imageViewHash, SamplerDescriptor sampler, size_t samplerHash) const
 
bool setViewportInternal (const Rect< I32 > &viewport) override
 
bool setScissorInternal (const Rect< I32 > &scissor) override
 
void flushTextureBindQueue ()
 
gl46core::GLuint getGLTextureView (ImageView srcView, size_t srcViewHash, U8 lifetimeInFrames) const
 
void initDescriptorSets () override
 
void flushPushConstantsLocks ()
 
RenderTarget_uptr newRT (const RenderTargetDescriptor &descriptor) const override
 
GenericVertexData_ptr newGVD (U32 ringBufferLength, const std::string_view name) const override
 
ShaderBuffer_uptr newSB (const ShaderBufferDescriptor &descriptor) const override
 

Private Attributes

GFXDevice_context
 
Time::ProfileTimer_swapBufferTimer
 
HardwareQueryContext _primitiveQueries
 
std::array< glHardwareQueryRing_uptr, to_base(GlobalQueryTypes::COUNT)> _performanceQueries
 Hardware query objects used for performance measurements.
 
eastl::stack< HardwareQueryContext_queryContext
 
bool _runQueries {false}
 
bool _uniformsNeedLock {false}
 
GFX::MemoryBarrierCommand _uniformsMemCommand {}
 
gl46core::GLuint _dummyVAO { GL_NULL_HANDLE }
 

Static Private Attributes

static eastl::fixed_vector< TexBindEntry, 32, false > s_TexBindQueue
 
static constexpr size_t InitialSamplerMapSize = 64u
 
static std::atomic_bool s_glFlushQueued {false}
 
static SharedMutex s_samplerMapLock
 
static SamplerObjectMap s_samplerMap {}
 
static GLStateTracker s_stateTracker
 
static std::array< GLUtil::GLMemory::DeviceAllocator, to_base(GLUtil::GLMemory::GLMemoryType::COUNT)> s_memoryAllocators
 
static std::array< size_t, to_base(GLUtil::GLMemory::GLMemoryType::COUNT)> s_memoryAllocatorSizes
 
static GLUtil::glTextureViewCache s_textureViewCache {}
 
static std::unique_ptr< glHardwareQueryPools_hardwareQueryPool = nullptr
 
static U32 s_fenceSyncCounter [s_LockFrameLifetime] {}
 

Friends

class glShader
 
class glTexture
 
class glFramebuffer
 
class glVertexArray
 
class glShaderProgram
 
class glSamplerObject
 
class glGenericVertexData
 
struct GLStateTracker
 

Additional Inherited Members

virtual bool drawToWindow (DisplayWindow &window)=0
 
virtual void onRenderThreadLoopStart ()=0
 
virtual void onRenderThreadLoopEnd ()=0
 
virtual void prepareFlushWindow (DisplayWindow &window)=0
 
virtual void flushWindow (DisplayWindow &window)=0
 
virtual bool frameStarted ()=0
 
virtual bool frameEnded ()=0
 
virtual void idle (bool fast)=0
 
virtual ErrorCode initRenderingAPI (I32 argc, char **argv, Configuration &config)=0
 
virtual void closeRenderingAPI ()=0
 
virtual void preFlushCommandBuffer (Handle< GFX::CommandBuffer > commandBuffer)=0
 
virtual void flushCommand (GFX::CommandBase *cmd)=0
 
virtual void postFlushCommandBuffer (Handle< GFX::CommandBuffer > commandBuffer)=0
 
virtual bool setViewportInternal (const Rect< I32 > &newViewport)=0
 
virtual bool setScissorInternal (const Rect< I32 > &newScissor)=0
 
virtual void onThreadCreated (const std::thread::id &threadID, bool isMainRenderThread)=0
 
virtual bool bindShaderResources (const DescriptorSetEntries &descriptorSetEntries)=0
 
virtual void initDescriptorSets ()=0
 
virtual RenderTarget_uptr newRT (const RenderTargetDescriptor &descriptor) const =0
 
virtual GenericVertexData_ptr newGVD (U32 ringBufferLength, std::string_view name) const =0
 
virtual ShaderBuffer_uptr newSB (const ShaderBufferDescriptor &descriptor) const =0
 

Detailed Description

OpenGL implementation of the RenderAPIWrapper.

Definition at line 65 of file GLWrapper.h.

Member Typedef Documentation

◆ HardwareQueryContext

Definition at line 186 of file GLWrapper.h.

◆ SamplerObjectMap

using Divide::GL_API::SamplerObjectMap = eastl::fixed_vector<CachedSamplerEntry, InitialSamplerMapSize, true>
private

Definition at line 194 of file GLWrapper.h.

Member Enumeration Documentation

◆ GlobalQueryTypes

enum class Divide::GL_API::GlobalQueryTypes : U8
strongprivate
Enumerator
VERTICES_SUBMITTED 
PRIMITIVES_GENERATED 
TESSELLATION_PATCHES 
TESSELLATION_EVAL_INVOCATIONS 
GPU_TIME 
COUNT 

Definition at line 161 of file GLWrapper.h.

Constructor & Destructor Documentation

◆ GL_API()

Divide::GL_API::GL_API ( GFXDevice context)

Definition at line 115 of file GLWrapper.cpp.

Member Function Documentation

◆ AddDebugMessage()

void Divide::GL_API::AddDebugMessage ( const char *  message,
U32  id = U32_MAX 
)
static

Definition at line 1795 of file GLWrapper.cpp.

◆ BindPipeline()

ShaderResult Divide::GL_API::BindPipeline ( GFXDevice context,
const Pipeline pipeline 
)
staticprotected

Definition at line 1674 of file GLWrapper.cpp.

◆ bindShaderResources()

bool Divide::GL_API::bindShaderResources ( const DescriptorSetEntries descriptorSetEntries)
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 1508 of file GLWrapper.cpp.

◆ clearStates()

void Divide::GL_API::clearStates ( GLStateTracker stateTracker) const
private

Reset as much of the GL default state as possible within the limitations given.

Definition at line 1462 of file GLWrapper.cpp.

◆ closeRenderingAPI()

void Divide::GL_API::closeRenderingAPI ( )
overrideprivatevirtual

Clear everything that was setup in initRenderingAPI()

Implements Divide::RenderAPIWrapper.

Definition at line 494 of file GLWrapper.cpp.

◆ CreateFenceSync()

gl46core::GLsync Divide::GL_API::CreateFenceSync ( )
static

Definition at line 1988 of file GLWrapper.cpp.

◆ DeleteBuffers()

bool Divide::GL_API::DeleteBuffers ( gl46core::GLuint  count,
gl46core::GLuint *  buffers 
)
static

Definition at line 1879 of file GLWrapper.cpp.

◆ DeleteFramebuffers()

bool Divide::GL_API::DeleteFramebuffers ( gl46core::GLuint  count,
gl46core::GLuint *  framebuffers 
)
static

Definition at line 1908 of file GLWrapper.cpp.

◆ DeleteSamplers()

bool Divide::GL_API::DeleteSamplers ( gl46core::GLuint  count,
gl46core::GLuint *  samplers 
)
static

Definition at line 1851 of file GLWrapper.cpp.

◆ DeleteShaderPrograms()

bool Divide::GL_API::DeleteShaderPrograms ( gl46core::GLuint  count,
gl46core::GLuint *  programs 
)
static

Definition at line 1829 of file GLWrapper.cpp.

◆ DestroyFenceSync()

void Divide::GL_API::DestroyFenceSync ( gl46core::GLsync &  sync)
static

Definition at line 1998 of file GLWrapper.cpp.

◆ Draw()

bool Divide::GL_API::Draw ( const GenericDrawCommand cmd)
staticprotected

Definition at line 682 of file GLWrapper.cpp.

◆ drawToWindow()

bool Divide::GL_API::drawToWindow ( DisplayWindow window)
overrideprivatevirtual

Prepare the GPU for rendering a frame.

Implements Divide::RenderAPIWrapper.

Definition at line 545 of file GLWrapper.cpp.

◆ endPerformanceQueries()

void Divide::GL_API::endPerformanceQueries ( )
private

Definition at line 530 of file GLWrapper.cpp.

◆ flushCommand()

void Divide::GL_API::flushCommand ( GFX::CommandBase cmd)
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 889 of file GLWrapper.cpp.

◆ flushPushConstantsLocks()

void Divide::GL_API::flushPushConstantsLocks ( )
private

Definition at line 873 of file GLWrapper.cpp.

◆ flushTextureBindQueue()

void Divide::GL_API::flushTextureBindQueue ( )
private

Definition at line 735 of file GLWrapper.cpp.

◆ flushWindow()

void Divide::GL_API::flushWindow ( DisplayWindow window)
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 566 of file GLWrapper.cpp.

◆ frameEnded()

bool Divide::GL_API::frameEnded ( )
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 622 of file GLWrapper.cpp.

◆ frameStarted()

bool Divide::GL_API::frameStarted ( )
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 587 of file GLWrapper.cpp.

◆ getGLTextureView()

gl46core::GLuint Divide::GL_API::getGLTextureView ( ImageView  srcView,
size_t  srcViewHash,
U8  lifetimeInFrames 
) const
private

Definition at line 836 of file GLWrapper.cpp.

◆ GetHardwareQueryPool()

glHardwareQueryPool * Divide::GL_API::GetHardwareQueryPool ( )
staticnoexcept

Definition at line 1983 of file GLWrapper.cpp.

◆ GetMemoryAllocator()

GLUtil::GLMemory::DeviceAllocator & Divide::GL_API::GetMemoryAllocator ( GLUtil::GLMemory::GLMemoryType  memoryType)
staticnoexcept

Definition at line 1778 of file GLWrapper.cpp.

◆ GetMemoryTypeForUsage()

GLUtil::GLMemory::GLMemoryType Divide::GL_API::GetMemoryTypeForUsage ( gl46core::GLenum  usage)
staticnoexcept

Definition at line 1754 of file GLWrapper.cpp.

◆ GetSamplerHandle()

gl46core::GLuint Divide::GL_API::GetSamplerHandle ( SamplerDescriptor  sampler,
size_t &  samplerHashInOut 
)
static

Return the OpenGL sampler object's handle for the given hash value.

Definition at line 1931 of file GLWrapper.cpp.

◆ GetStateTracker()

GLStateTracker & Divide::GL_API::GetStateTracker ( )
staticnoexcept

Definition at line 1749 of file GLWrapper.cpp.

◆ idle()

void Divide::GL_API::idle ( bool  fast)
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 677 of file GLWrapper.cpp.

◆ initDescriptorSets()

void Divide::GL_API::initDescriptorSets ( )
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 1418 of file GLWrapper.cpp.

◆ initRenderingAPI()

ErrorCode Divide::GL_API::initRenderingAPI ( I32  argc,
char **  argv,
Configuration config 
)
overrideprivatevirtual

Try and create a valid OpenGL context taking in account the specified command line arguments.

Try and create a valid OpenGL context taking in account the specified resolution and command line arguments.

Implements Divide::RenderAPIWrapper.

Definition at line 123 of file GLWrapper.cpp.

◆ makeTextureViewResident()

bool Divide::GL_API::makeTextureViewResident ( gl46core::GLubyte  bindingSlot,
const ImageView imageView,
size_t  imageViewHash,
SamplerDescriptor  sampler,
size_t  samplerHash 
) const
private

Definition at line 1614 of file GLWrapper.cpp.

◆ newGVD()

GenericVertexData_ptr Divide::GL_API::newGVD ( U32  ringBufferLength,
const std::string_view  name 
) const
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 2014 of file GLWrapper.cpp.

◆ newRT()

RenderTarget_uptr Divide::GL_API::newRT ( const RenderTargetDescriptor descriptor) const
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 2009 of file GLWrapper.cpp.

◆ newSB()

ShaderBuffer_uptr Divide::GL_API::newSB ( const ShaderBufferDescriptor descriptor) const
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 2019 of file GLWrapper.cpp.

◆ onRenderThreadLoopEnd()

void Divide::GL_API::onRenderThreadLoopEnd ( )
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 557 of file GLWrapper.cpp.

◆ onRenderThreadLoopStart()

void Divide::GL_API::onRenderThreadLoopStart ( )
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 552 of file GLWrapper.cpp.

◆ onThreadCreated()

void Divide::GL_API::onThreadCreated ( const std::thread::id &  threadID,
bool  isMainRenderThread 
)
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 1423 of file GLWrapper.cpp.

◆ PopDebugMessage()

void Divide::GL_API::PopDebugMessage ( )
static

Definition at line 1818 of file GLWrapper.cpp.

◆ postFlushCommandBuffer()

void Divide::GL_API::postFlushCommandBuffer ( Handle< GFX::CommandBuffer commandBuffer)
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 1402 of file GLWrapper.cpp.

◆ preFlushCommandBuffer()

void Divide::GL_API::preFlushCommandBuffer ( Handle< GFX::CommandBuffer commandBuffer)
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 883 of file GLWrapper.cpp.

◆ prepareFlushWindow()

void Divide::GL_API::prepareFlushWindow ( DisplayWindow window)
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 561 of file GLWrapper.cpp.

◆ PushDebugMessage()

void Divide::GL_API::PushDebugMessage ( const char *  message,
U32  id = U32_MAX 
)
static

Definition at line 1806 of file GLWrapper.cpp.

◆ QueueFlush()

void Divide::GL_API::QueueFlush ( )
staticnoexcept

Definition at line 1783 of file GLWrapper.cpp.

◆ setScissorInternal()

bool Divide::GL_API::setScissorInternal ( const Rect< I32 > &  scissor)
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 1669 of file GLWrapper.cpp.

◆ setViewportInternal()

bool Divide::GL_API::setViewportInternal ( const Rect< I32 > &  viewport)
overrideprivatevirtual

Implements Divide::RenderAPIWrapper.

Definition at line 1664 of file GLWrapper.cpp.

Friends And Related Function Documentation

◆ glFramebuffer

friend class glFramebuffer
friend

Definition at line 68 of file GLWrapper.h.

◆ glGenericVertexData

friend class glGenericVertexData
friend

Definition at line 72 of file GLWrapper.h.

◆ glSamplerObject

friend class glSamplerObject
friend

Definition at line 71 of file GLWrapper.h.

◆ glShader

friend class glShader
friend

Definition at line 66 of file GLWrapper.h.

◆ glShaderProgram

friend class glShaderProgram
friend

Definition at line 70 of file GLWrapper.h.

◆ GLStateTracker

friend struct GLStateTracker
friend

Definition at line 74 of file GLWrapper.h.

◆ glTexture

friend class glTexture
friend

Definition at line 67 of file GLWrapper.h.

◆ glVertexArray

friend class glVertexArray
friend

Definition at line 69 of file GLWrapper.h.

Member Data Documentation

◆ _context

GFXDevice& Divide::GL_API::_context
private

Definition at line 197 of file GLWrapper.h.

◆ _dummyVAO

gl46core::GLuint Divide::GL_API::_dummyVAO { GL_NULL_HANDLE }
private

Definition at line 210 of file GLWrapper.h.

◆ _performanceQueries

std::array<glHardwareQueryRing_uptr, to_base(GlobalQueryTypes::COUNT)> Divide::GL_API::_performanceQueries
private

Hardware query objects used for performance measurements.

Definition at line 202 of file GLWrapper.h.

◆ _primitiveQueries

HardwareQueryContext Divide::GL_API::_primitiveQueries
private

Definition at line 200 of file GLWrapper.h.

◆ _queryContext

eastl::stack<HardwareQueryContext> Divide::GL_API::_queryContext
private

Definition at line 204 of file GLWrapper.h.

◆ _runQueries

bool Divide::GL_API::_runQueries {false}
private

Definition at line 205 of file GLWrapper.h.

◆ _swapBufferTimer

Time::ProfileTimer& Divide::GL_API::_swapBufferTimer
private

Definition at line 198 of file GLWrapper.h.

◆ _uniformsMemCommand

GFX::MemoryBarrierCommand Divide::GL_API::_uniformsMemCommand {}
private

Definition at line 208 of file GLWrapper.h.

◆ _uniformsNeedLock

bool Divide::GL_API::_uniformsNeedLock {false}
private

Definition at line 207 of file GLWrapper.h.

◆ InitialSamplerMapSize

constexpr size_t Divide::GL_API::InitialSamplerMapSize = 64u
staticconstexprprivate

Definition at line 187 of file GLWrapper.h.

◆ s_fenceSyncCounter

U32 Divide::GL_API::s_fenceSyncCounter {}
staticprivate

Definition at line 227 of file GLWrapper.h.

◆ s_glFlushQueued

std::atomic_bool Divide::GL_API::s_glFlushQueued {false}
staticprivate

Definition at line 214 of file GLWrapper.h.

◆ s_hardwareQueryPool

std::unique_ptr< glHardwareQueryPool > Divide::GL_API::s_hardwareQueryPool = nullptr
staticprivate

Definition at line 225 of file GLWrapper.h.

◆ s_LockFrameLifetime

constexpr U32 Divide::GL_API::s_LockFrameLifetime = 3u
staticconstexpr

Definition at line 78 of file GLWrapper.h.

◆ s_memoryAllocators

NO_DESTROY std::array< GLUtil::GLMemory::DeviceAllocator, to_base(GLUtil::GLMemory::GLMemoryType::COUNT)> Divide::GL_API::s_memoryAllocators
staticprivate

◆ s_memoryAllocatorSizes

NO_DESTROY std::array< size_t, to_base(GLUtil::GLMemory::GLMemoryType::COUNT)> Divide::GL_API::s_memoryAllocatorSizes
staticprivate
Initial value:
{
TO_MEGABYTES( 1 << 10 ),
TO_MEGABYTES( 1 << 8 ),
TO_MEGABYTES( 1 << 9 ),
TO_MEGABYTES( 1 << 7 ),
TO_MEGABYTES( 1 << 7 )
}
#define TO_MEGABYTES(X)
Definition: MathHelper.h:47

Definition at line 221 of file GLWrapper.h.

◆ s_samplerMap

NO_DESTROY GL_API::SamplerObjectMap Divide::GL_API::s_samplerMap {}
staticprivate

Definition at line 217 of file GLWrapper.h.

◆ s_samplerMapLock

SharedMutex Divide::GL_API::s_samplerMapLock
staticprivate

Definition at line 216 of file GLWrapper.h.

◆ s_stateTracker

NO_DESTROY GLStateTracker Divide::GL_API::s_stateTracker
staticprivate

Definition at line 218 of file GLWrapper.h.

◆ s_TexBindQueue

NO_DESTROY eastl::fixed_vector< GL_API::TexBindEntry, GLStateTracker::MAX_BOUND_TEXTURE_UNITS, false > Divide::GL_API::s_TexBindQueue
staticprivate

Definition at line 184 of file GLWrapper.h.

◆ s_textureViewCache

NO_DESTROY GLUtil::glTextureViewCache Divide::GL_API::s_textureViewCache {}
staticprivate

Definition at line 223 of file GLWrapper.h.


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