Workspace 6.21.5
Classes | Public Types | Public Member Functions | List of all members
WSGLBufferObjectCache Class Reference

The WSGLBufferObjectCache is a cache which manages the allocation and storage of WSGLBufferObjectCacheItem (cache items). More...

#include <Rendering/OpenGL/wsglbufferobjectcache.h>

Inheritance diagram for WSGLBufferObjectCache:
[legend]

Classes

struct  CacheItemDiagnosticInfo
 

Public Types

using ContentDiagnostics = QMap< QString, CacheItemDiagnosticInfo >
 

Public Member Functions

 WSGLBufferObjectCache ()
 
 WSGLBufferObjectCache (const WSGLBufferObjectCache &)=delete
 
 WSGLBufferObjectCache (size_t capacity)
 
 ~WSGLBufferObjectCache () override
 
void discardUnused ()
 
size_t getBytesInUse ()
 
WSGLBufferObjectCacheItemPtr getCacheItem (const QString &id, QOpenGLBuffer::Type type)
 
size_t getCapacity ()
 
ContentDiagnostics getContentDiagnostics () const
 
size_t getSize ()
 
bool hasCacheItem (const QString &id) const
 
WSGLBufferObjectCacheoperator= (const WSGLBufferObjectCache &)=delete
 
void setCapacity (size_t capacity)
 

Detailed Description

The cache keeps track of each cache item, making sure that unused items are placed onto an expiry queue, ready for deletion. Items that are still in use will never be placed on the queue.

The only way that WSGLBufferObjectCacheItems should be created is via the getCacheItem function. This will return a reference-counted pointer (WSGLBufferObjectCacheItemPtr) to the cache item.

See also
WSGLBufferObjectCacheItem
WSGLBufferObjectCacheItemPtr

Member Typedef Documentation

◆ ContentDiagnostics

Constructor & Destructor Documentation

◆ WSGLBufferObjectCache() [1/3]

Create a cache with no size limit.

◆ WSGLBufferObjectCache() [2/3]

WSGLBufferObjectCache ( size_t  capacity)

Create a cache with the specified size limit.

◆ ~WSGLBufferObjectCache()

~WSGLBufferObjectCache ( )
override

Must ensure the cache is emptied before deleting it. We must not hold onto any OpenGL buffer objects.

◆ WSGLBufferObjectCache() [3/3]

Member Function Documentation

◆ discardUnused()

void discardUnused ( )

Purges any expired items in the cache. The items themselves will manage their own deletion.

◆ getBytesInUse()

size_t getBytesInUse ( )

Returns the number of bytes that are currently in use (i.e. not on the expiry queue). This can be used to determine whether or not pointers are being held between frames for debug purposes.

Returns
size of the number of items currently held by pointers, in bytes.

◆ getCacheItem()

WSGLBufferObjectCacheItemPtr getCacheItem ( const QString &  id,
QOpenGLBuffer::Type  type 
)

Publically accessible function to get an item from the cache. If one does not exist, a new item will be created and added to the cache. In certain situations, the cache item may fail to be created (usually due to an invalid GL context, or no buffer support). If this occurs, an invalid (empty) WSGLBufferObjectCacheItemPtr will be returned.

Parameters
idThe unique identifier of the item to retrieve / create.
typeThe GL buffer type of the item. Not used if retrieving an item. Only used when creating.
Returns
pointer object to the Cache Item which will automatically manage the ref counting

◆ getCapacity()

size_t getCapacity ( )

Returns the capacity of the cache in bytes, AKA its size limit. If the cache is of unlimited capacity, it will return 0.

Returns
the capacity of the cache, in bytes (or 0 of capacity is unlimited)

◆ getContentDiagnostics()

WSGLBufferObjectCache::ContentDiagnostics getContentDiagnostics ( ) const
Returns
A collection of diagnostics; one for each item in the cache.

◆ getSize()

size_t getSize ( )

Returns the current size of the cache in bytes, i.e. the total size of all the items that have been added to the cache.

Returns
size of the cache in bytes.

◆ hasCacheItem()

bool hasCacheItem ( const QString &  id) const

Function to check whether or not an item with the specified ID is in the cache.

Parameters
id
Returns
true if an item with the specified id exists in the cache, false otherwise.

◆ operator=()

WSGLBufferObjectCache & operator= ( const WSGLBufferObjectCache )
delete

◆ setCapacity()

void setCapacity ( size_t  capacity)
Parameters
capacityThe desired capacity of the buffer object cache.

Sets the capacity of the WSGLBufferObjectCache. Note that if the specified capacity is lower than the existing capacity, unused items in the cache will be discarded up-until the size is less than or equal to the new capacity.