Defined in:Returns a pointer to a resource object.
static type *GetResource(const char *name, uint32 flags = 0, ResourceCatalog *catalog = nullptr, ResourceLocation *location = nullptr);
||The name of the resource, including any containing folder names separated by forward slashes.|
||The resource load flags. See below for possible values.|
||The resource catalog from which the resource should be loaded.|
||If not |
GetResourcefunction returns a pointer to a resource object of the type corresponding to the template parameter of the
Resourceclass. If the resource object already exists, then its reference count is incremented and a pointer to the existing object is returned. Otherwise, a new resource object is created and the resource data is loaded into memory (unless the
kResourceDeferLoadflag is specified). If the resource data does not exist on disk, then the return value is
Each successful call to the
GetResourcefunction should be balanced by a matching call to the
flagsparameter can be a combination (through logical OR) of the following constants.
||The resource data is not loaded when the resource object is constructed.|
||Do not load a default resource if the requested resource does not exist.|
||This flag is specified to force a new copy of a resource to be loaded from the disk without sharing any copy of the resource that might already be loaded and without going through the resource cache. Pack files are also ignored, so the resource will fail to load if it is not in a separate file.|
kResourceDeferLoadflag is specified, then the resource data is not loaded, but a resource object is created and returned. Note that in this case, the return value is never
nullptr, so it's not possible to determine whether the resource data exists based on the return value. The resource data can subsequently be loaded outside of the resource object using the functions of the
ResourceLoaderobject returned by the
Resource::OpenLoaderfunction. The resource data can also be loaded (in its entirety) into the
Resourceobject by calling the
nullptr, then the resource is loaded from the virtual catalog.
When a resource is loaded from the virtual catalog and the
locationparameter is not
nullptr, then the path stored in the
ResourceLocationobject is set to the path to the folder containing the resource file. If the resource was loaded from a pack file, then the path is set to that of the pack file without the extension. The resource location is not set if the
kResourceDeferLoadflag is specified in the
GetResourcefunction is normally not called directly using the
Resourceclass template. Higher-level classes normally make calls to the
GetResourcefunction as part of a larger initialization procedure. The following list names some of those functions and the type of resources that they create.