|
Cogs.Core
|
Texture manager responsible for loading, processing, activation and lifetime of Texture resources. More...
#include <TextureManager.h>
Classes | |
| struct | FetchedItem |
Public Member Functions | |
| TextureManager (Context *context) | |
| Constructs a TextureManager in the given context. | |
| ~TextureManager () | |
| Destructs the texture manager. | |
| void | initialize () override |
| Initialize the texture manager. Creates the default texture resource. | |
| void | clear () override |
| TextureHandle | loadTexture (const void *imageData, ResourceDimensions target, int width, int height, int depth, int layers, TextureFormat format, int stride, const ResourceId resourceId, TextureLoadFlags flags) |
| Load a texture with the given data. | |
| void | cancelTextureLoad (TextureHandle handle) |
| Notify that the texture isn't needed anymore and the texture load can be cancelled if posible. | |
| TextureHandle | loadTexture (const void *imageData, ResourceDimensions target, int width, int height, int depth, int layers, TextureFormat format, int stride, const TextureHandle &resourceHandle, TextureLoadFlags flags) |
| Load an existing texture with the given data. | |
| template<typename RESOURCE > | |
| TextureHandle | loadTexture2D (const void *imageData, int width, int height, TextureFormat format, int stride, RESOURCE resource, TextureLoadFlags flags) |
| TextureHandle | loadExternalTexture (intptr_t externalHandle, ResourceDimensions target, int width, int height, int depth, int layers, TextureFormat format, const ResourceId resourceId, TextureLoadFlags flags) |
| Loads a texture resource wrapping the external texture data so it may be used in the Engine like an internal texture resource. | |
| TextureHandle | loadTexture (const StringView &resourceName, const ResourceId resourceId, TextureLoadFlags flags) |
| Loads a texture resource from the named resource given. | |
| TextureHandle | loadTextureFromMemory (const void *dataPtr, const size_t dataSize, const StringView &resourcePath, const ResourceId resourceId, TextureLoadFlags flags) |
| Loads an encoded texture from data in memory. | |
| TextureHandle | loadTexture (TextureLoadInfo *loadInfo) |
| Loads a texture resource using the given loadInfo. | |
| TextureHandle | getTexture (const StringView &path, bool isQuery=false) |
| Gets the texture with the given path. | |
| void | handleLoad (TextureLoadInfo *loadInfo) override |
| void | handleReload (ResourceHandleBase handle) override |
| void | loadFromData (TextureLoadInfo *loadInfo) |
| ActivationResult | handleActivation (TextureHandle handle, Texture *texture) override |
| Overridden to handle texture activation, updating the texture resource in the renderer. | |
| void | handleDeletion (Texture *texture) override |
| Overridden to handle texture deletion, removing the texture resource from the renderer. | |
Public Member Functions inherited from Cogs::Core::ResourceManager< Texture, TextureLoadInfo > | |
| ResourceManager (Context *context, Collections::ElementOffset capacity=1024) | |
| Constructs a resource manager with the given context. | |
| ~ResourceManager () override | |
| Destructs a resource manager, provided for destruction via base pointer. | |
| void | clear () override |
| Clear the resource manager, cleaning up resources held by member handles. | |
| void | clearSwapping () override |
| Clear the swap queue, ensuring indirect resource references are released. | |
| ResourceHandle | create () |
| Create a new resource. | |
| ResourceHandle | release (ResourceId resourceId) |
| ResourceHandle | loadResource (TextureLoadInfo *loadInfo) |
| ResourceProxy | createLocked () |
| Creates a new resource, but returns a ResourceProxy for thread safe editing instead of a handle to the actual resource. | |
| ResourceProxy | lock (const ResourceHandle &handle) |
| Takes the handle given and returns a resource proxy to edit the contents of the held resource safely on other threads than the main thread. | |
| void | unlockProxy (const ResourceHandle &handle, const ResourceHandle &proxy) |
| Unlock the given resource proxy. | |
| ResourceHandle | generateHandle (ResourceBase *resource) |
| Generate a handle to the given resource. | |
| virtual void | handleLoad (TextureLoadInfo *) |
| Handler for resource loading. | |
| virtual void | handleFailedLoad (const TextureLoadInfo *) |
| Handler for failed resource loads using the given loadInfo. | |
| virtual ActivationResult | handleActivation (ResourceHandle, Texture *) |
| Handler for activation of resources. | |
| virtual void | handleDeletion (Texture *) |
| Handler for deletion of resources. | |
| Texture * | get (const ResourceHandleBase &handle) |
| Resolve the given handle to a resource. | |
| void | processSwapping () override |
| Process queued swap operations, exchanging resource contents of the destination resources by those indicated in the operation data. | |
| ResourceHandle | getHandle (const ResourceId id) const |
| Get a resource handle to the resource with the given id. | |
| void | registerLoader (IResourceLoader< Texture, TextureLoadInfo > *loader) |
| Register a resource loader capable of handling resources of the template type. | |
| void | destroyLoadInfoInternal (ResourceLoadInfoBase *loadInfo) override |
| TextureLoadInfo * | createLoadInfo () |
Public Member Functions inherited from Cogs::Core::ResourceManagerBase | |
| ResourceManagerBase (Context *context) | |
| void | initialize () override |
| void | clear () override |
| void | reportLeaks (std::string_view typeName) |
| std::string | getReport () |
| Return a string with current resource usage. | |
| bool | checkPreloaded (ResourceLoadInfoBase *loadInfo) |
| ResourceHandleBase | releaseInternal (ResourceId resourceId) |
| Releases a resourceId -> ResourceHandle mapping. | |
| ResourceHandleBase | loadResourceInternal (ResourceLoadInfoBase *loadInfo) |
| Load a resource using the given loadInfo. | |
| void | processLoading () final |
| Process loading resources. | |
| void | setProcessed (ResourceLoadInfoBase *loadInfo, bool swapping=false) |
| Signal the resource being loaded as done loading and ready for activation etc. | |
| void | activateResources () final |
| virtual void | processDeletion () override |
| Process resources pending deallocation. | |
| void | fillDeletionQueue (std::vector< ResourceBase * > &deletion) |
| void | destroyLocked (ResourceBase *resource) |
| void | safeDestroy (ResourceBase *resource) |
| ResourceId | getNextResourceId () override |
| Get the next unique resource id. | |
| void | resourceChanged (ResourceBase *resource) override |
| void | resourceDeleted (ResourceBase *resource) override |
| void | setResourceId (ResourceBase *resource, ResourceId id) override |
| Assign the given id to a previously created resource. | |
| void | queueResource (ResourceLoadInfoBase *loadInfo) |
| Re-queue the given loadInfo to defer loading to the next time the processLoading() phase is performed. | |
| virtual void | handleLoadInternal (ResourceLoadInfoBase *loadInfo)=0 |
| virtual ActivationResult | handleActivationInternal (ResourceHandleBase r, ResourceBase *resource)=0 |
| virtual void | handleDeletionInternal (ResourceBase *resource)=0 |
| virtual void | handleFailedLoadInternal (ResourceLoadInfoBase *loadInfo)=0 |
| virtual void | destroyLoadInfoInternal (ResourceLoadInfoBase *loadInfo)=0 |
| virtual bool | shouldAutoReload () const |
| virtual bool | shouldMergeBySource () const |
| virtual void | handleReload (ResourceHandleBase) |
| std::vector< ResourceBase * > | getAllocatedResources () const |
| ResourceHandleBase | getOrCreate (ResourceId id) |
| ResourceHandleBase | getByName (std::string_view name) const |
| ResourceHandleBase | getBySource (std::string_view source) const |
| ResourceHandleBase | createResource () |
| virtual ResourceBase * | createInternal ()=0 |
| virtual void | destroyInternal (ResourceBase *resource)=0 |
| virtual void | destroyInternalLocked (ResourceBase *resource)=0 |
| ResourceHandleBase | generateHandle (ResourceBase *resource) |
| void | clearUpdated () |
| virtual int | getUpdateQuota () const |
| size_t | updatedResourceCount () |
| size_t | orphanedResourceCount () |
| size_t | allocatedResourceCount () |
| virtual void | initialize ()=0 |
| virtual void | clear ()=0 |
| virtual void | clearSwapping ()=0 |
| virtual void | processLoading ()=0 |
| virtual void | processSwapping ()=0 |
| virtual void | activateResources ()=0 |
| virtual void | processDeletion ()=0 |
| virtual void | resourceChanged (ResourceBase *resource)=0 |
| virtual void | resourceDeleted (ResourceBase *resource)=0 |
| virtual ResourceId | getNextResourceId ()=0 |
| virtual void | setResourceId (ResourceBase *resource, ResourceId id)=0 |
Public Attributes | |
| TextureHandle | white = TextureHandle::NoHandle |
| TextureHandle | whiteCube = TextureHandle::NoHandle |
| Cogs::Mutex | lock |
| std::map< size_t, DataFetcherManager::FetchId > | map |
Protected Member Functions | |
| void | postProcessLoading () override final |
| Hook for resource managers to run code at the tail of processLoading. | |
Protected Member Functions inherited from Cogs::Core::ResourceManager< Texture, TextureLoadInfo > | |
| Texture * | createInternal () override |
| void | destroyInternal (ResourceBase *resource) override |
| void | handleLoadInternal (ResourceLoadInfoBase *loadInfo) override |
| ActivationResult | handleActivationInternal (ResourceHandleBase r, ResourceBase *resource) override |
| void | handleDeletionInternal (ResourceBase *resource) override |
| void | handleFailedLoadInternal (ResourceLoadInfoBase *loadInfo) override |
| IResourceLoader< Texture, TextureLoadInfo > * | findLoader (const TextureLoadInfo *loadInfo) |
| Find a loader capable of loading the resource given by loadInfo. | |
Protected Member Functions inherited from Cogs::Core::ResourceManagerBase | |
| ResourceHandleBase | getResourceHandle (ResourceId id) const |
| Get existing resource handle. | |
| bool | isValidResource (ResourceId id) const |
| Check if resource handle points to. | |
| virtual void | postProcessLoading () |
| Hook for resource managers to run code at the tail of processLoading. | |
Private Member Functions | |
| bool | invokeLoader (ITextureLoader *loader, TextureLoadInfo *loadInfo) |
| bool | invokeLoader (ILoadedTextureLoader *loadedLoader, TextureLoadInfo *loadInfo) |
| bool | processFetchedItem (ILoadedTextureLoader *loadedLoader, TextureLoadInfo *loadInfo, std::unique_ptr< FileContents > data) |
| void | loadFromPath (TextureLoadInfo *loadInfo) |
Private Attributes | |
| std::thread::id | main |
| std::queue< FetchedItem > | fetchedItems |
| struct { | |
| Cogs::Mutex lock | |
| std::map< size_t, DataFetcherManager::FetchId > map | |
| } | fetchIds |
Additional Inherited Members | |
Public Types inherited from Cogs::Core::ResourceManager< Texture, TextureLoadInfo > | |
| using | ResourceHandle = ResourceHandle_t< Texture > |
| Type of handle used to hold resources. | |
| using | ResourceProxy = ResourceProxy< Texture, ResourceManager > |
| Type of resource proxy objects, specialized on the type of resource. | |
Protected Attributes inherited from Cogs::Core::ResourceManager< Texture, TextureLoadInfo > | |
| Mutex | swapMutex |
| Collections::Pool< Texture > | resources |
| std::vector< IResourceLoader< Texture, TextureLoadInfo > * > | loaders |
| std::deque< SwapOperation > | swapQueue |
| ResourceHandle | defaultResource |
Protected Attributes inherited from Cogs::Core::ResourceManagerBase | |
| std::unique_ptr< ResourceManagerBaseStorage > | storage |
| Context * | context = nullptr |
| ResourceTypes | resourceType = ResourceTypes::Unknown |
Texture manager responsible for loading, processing, activation and lifetime of Texture resources.
Texture resources can either be created and modified manually by using the create() method, or automatically using one of the load*() methods. Using the load methods will create a texture resource and populate it using the load information given.
Definition at line 26 of file TextureManager.h.
|
inline |
Constructs a TextureManager in the given context.
Definition at line 30 of file TextureManager.h.
| Cogs::Core::TextureManager::~TextureManager | ( | ) |
Destructs the texture manager.
Definition at line 122 of file TextureManager.cpp.
| void Cogs::Core::TextureManager::cancelTextureLoad | ( | TextureHandle | handle | ) |
Notify that the texture isn't needed anymore and the texture load can be cancelled if posible.
Definition at line 213 of file TextureManager.cpp.
|
overridevirtual |
Reimplemented from Cogs::Core::ResourceManagerBase.
Definition at line 206 of file TextureManager.cpp.
| Cogs::Core::TextureHandle Cogs::Core::TextureManager::getTexture | ( | const StringView & | path, |
| bool | isQuery = false |
||
| ) |
Gets the texture with the given path.
Definition at line 335 of file TextureManager.cpp.
References Cogs::Core::HandleIsValid(), Cogs::StringView::hash(), Cogs::hash(), Cogs::Core::LinearColorSpace, Cogs::Core::ResourceHandle_t< Texture >::NoHandle, Cogs::Core::NoMipMaps, Cogs::Core::None, and Cogs::StringView::NoPosition.
|
overridevirtual |
Overridden to handle texture activation, updating the texture resource in the renderer.
Reimplemented from Cogs::Core::ResourceManager< Texture, TextureLoadInfo >.
Definition at line 548 of file TextureManager.cpp.
|
overridevirtual |
Overridden to handle texture deletion, removing the texture resource from the renderer.
Reimplemented from Cogs::Core::ResourceManager< Texture, TextureLoadInfo >.
Definition at line 553 of file TextureManager.cpp.
|
overridevirtual |
Overridden to handle loading of textures. Loading might be handed off to loaders implementing the ITextureLoader interface.
Reimplemented from Cogs::Core::ResourceManager< Texture, TextureLoadInfo >.
Definition at line 474 of file TextureManager.cpp.
References Cogs::Core::ResourceLoadInfoBase::resourcePath, and Cogs::Core::TaskManager::ResourceQueue.
|
overridevirtual |
Reimplemented from Cogs::Core::ResourceManagerBase.
Definition at line 503 of file TextureManager.cpp.
|
overridevirtual |
Initialize the texture manager. Creates the default texture resource.
Reimplemented from Cogs::Core::ResourceManagerBase.
Definition at line 127 of file TextureManager.cpp.
References Cogs::TextureFlags::CubeMap, Cogs::Core::ForceSynchronous, Cogs::Core::HandleIsValid(), Cogs::Core::Texture::setData(), Cogs::Core::ResourceBase::setName(), and Cogs::TextureFlags::Texture.
|
private |
Definition at line 616 of file TextureManager.cpp.
|
private |
Definition at line 604 of file TextureManager.cpp.
| Cogs::Core::TextureHandle Cogs::Core::TextureManager::loadExternalTexture | ( | intptr_t | externalHandle, |
| ResourceDimensions | target, | ||
| int | width, | ||
| int | height, | ||
| int | depth, | ||
| int | layers, | ||
| TextureFormat | format, | ||
| const ResourceId | resourceId, | ||
| TextureLoadFlags | flags | ||
| ) |
Loads a texture resource wrapping the external texture data so it may be used in the Engine like an internal texture resource.
| imageData | Handle to an external texture resource (platform dependent). |
| width | Width of the image in pixels. |
| height | Height of the image in pixels. |
| format | Format of the image data. |
| resourceId | Resource identifier to assign to the Texture. If a texture resource with the same id already exists, the existing Texture contents are replaced with the new data. |
| flags | Loading flags describing how to load the texture resource. |
Definition at line 516 of file TextureManager.cpp.
References Cogs::FormatInfo::elements, Cogs::TextureFlags::GenerateMipMaps, Cogs::Core::NoDelete, Cogs::TextureFlags::NoDelete, Cogs::Core::NoMipMaps, and Cogs::Core::None.
| void Cogs::Core::TextureManager::loadFromData | ( | TextureLoadInfo * | loadInfo | ) |
Definition at line 723 of file TextureManager.cpp.
|
private |
Definition at line 628 of file TextureManager.cpp.
| Cogs::Core::TextureHandle Cogs::Core::TextureManager::loadTexture | ( | const StringView & | resourceName, |
| const ResourceId | resourceId, | ||
| TextureLoadFlags | flags | ||
| ) |
Loads a texture resource from the named resource given.
The \resourceName might point to a resource on disk or in the ResourceStore.
| resourceId | Resource identifier to assign to the Texture. If a texture resource with the same id already exists, the existing Texture contents are replaced with the new data. |
| flags | Loading flags describing how to load the texture resource. |
Definition at line 288 of file TextureManager.cpp.
References Cogs::Core::DoNotStoreSource, Cogs::Core::Flip, Cogs::Core::LinearColorSpace, Cogs::Core::ResourceLoadInfoBase::loadFlags, Cogs::Core::ResourceLoadInfoBase::resourceId, Cogs::Core::ResourceLoadInfoBase::resourcePath, and Cogs::StringView::to_string().
| Cogs::Core::TextureHandle Cogs::Core::TextureManager::loadTexture | ( | const void * | imageData, |
| ResourceDimensions | target, | ||
| int | width, | ||
| int | height, | ||
| int | depth, | ||
| int | layers, | ||
| TextureFormat | format, | ||
| int | stride, | ||
| const ResourceId | resourceId, | ||
| TextureLoadFlags | flags | ||
| ) |
Load a texture with the given data.
A Texture resource is created and the given data queued to be loaded at an suitable time.
| imageData | Pointer to image data buffer of size at least width (or stride) * height * bpp of the format. |
| width | Width of the image in pixels. |
| height | Height of the image in pixels. |
| format | Format of the image data. |
| stride | Row width stride in bytes. If set to zero, defaults to the size of one row of pixels. |
| resourceId | Resource identifier to assign to the Texture. If a texture resource with the same id already exists, the existing Texture contents are replaced with the new data. |
| flags | Loading flags describing how to load the texture resource. |
Definition at line 233 of file TextureManager.cpp.
References Cogs::Core::ResourceHandle_t< Texture >::NoHandle, Cogs::Core::ResourceLoadInfoBase::resourceData, and Cogs::Core::ResourceLoadInfoBase::resourceId.
| Cogs::Core::TextureHandle Cogs::Core::TextureManager::loadTexture | ( | const void * | imageData, |
| ResourceDimensions | target, | ||
| int | width, | ||
| int | height, | ||
| int | depth, | ||
| int | layers, | ||
| TextureFormat | format, | ||
| int | stride, | ||
| const TextureHandle & | resourceHandle, | ||
| TextureLoadFlags | flags | ||
| ) |
Load an existing texture with the given data.
| imageData | Pointer to image data buffer of size at least width (or stride) * height * bpp of the format. |
| width | Width of the image in pixels. |
| height | Height of the image in pixels. |
| format | Format of the image data. |
| stride | Row width stride in bytes. If set to zero, defaults to the size of one row of pixels. |
| resourceHandle | Resource handle whose Texture contents are to be replaced with the new data. |
| flags | Loading flags describing how to load the texture resource. |
Definition at line 261 of file TextureManager.cpp.
References Cogs::Core::ResourceLoadInfoBase::handle, Cogs::Core::ResourceHandle_t< Texture >::NoHandle, and Cogs::Core::ResourceLoadInfoBase::resourceData.
| Cogs::Core::TextureHandle Cogs::Core::TextureManager::loadTexture | ( | TextureLoadInfo * | loadInfo | ) |
Loads a texture resource using the given loadInfo.
| loadInfo | Contains information on how to load the texture. Takes ownership of object. |
Definition at line 330 of file TextureManager.cpp.
|
inline |
Definition at line 80 of file TextureManager.h.
| TextureHandle Cogs::Core::TextureManager::loadTextureFromMemory | ( | const void * | dataPtr, |
| const size_t | dataSize, | ||
| const StringView & | resourcePath, | ||
| const ResourceId | resourceId, | ||
| TextureLoadFlags | flags | ||
| ) |
Loads an encoded texture from data in memory.
| dataPtr | Pointer to the memory block with encoded data, the data is copied. |
| dataSize | Sizeo fo the memory block with encoded data, the data is copied. |
| resourcePath | Suffix of file path is used to determine loader, can be a dummy file path. |
| resourceId | Resource identifier to assign to the Texture. If a texture resource with the same id already exists, the existing Texture contents are replaced with the new data. |
| flags | Loading flags describing how to load the texture resource. |
Definition at line 307 of file TextureManager.cpp.
References Cogs::Core::ColorSpaceFromLoadInfo, Cogs::Core::DoNotStoreSource, Cogs::Core::Flip, Cogs::Core::ForceUnique, Cogs::Core::LinearColorSpace, Cogs::Core::ResourceLoadInfoBase::loadFlags, Cogs::Core::NoMipMaps, Cogs::Core::ResourceLoadInfoBase::resourceData, Cogs::Core::ResourceLoadInfoBase::resourceId, Cogs::Core::ResourceLoadInfoBase::resourcePath, and Cogs::StringView::to_string().
|
finaloverrideprotectedvirtual |
Hook for resource managers to run code at the tail of processLoading.
Reimplemented from Cogs::Core::ResourceManagerBase.
Definition at line 432 of file TextureManager.cpp.
References Cogs::Core::ResourceLoadInfoBase::resourceData.
|
private |
Definition at line 558 of file TextureManager.cpp.
|
private |
Definition at line 178 of file TextureManager.h.
| Cogs::Mutex Cogs::Core::TextureManager::lock |
Definition at line 181 of file TextureManager.h.
|
private |
Definition at line 162 of file TextureManager.h.
| std::map<size_t, DataFetcherManager::FetchId> Cogs::Core::TextureManager::map |
Definition at line 182 of file TextureManager.h.
| TextureHandle Cogs::Core::TextureManager::white = TextureHandle::NoHandle |
Definition at line 155 of file TextureManager.h.
| TextureHandle Cogs::Core::TextureManager::whiteCube = TextureHandle::NoHandle |
Definition at line 156 of file TextureManager.h.