C4 Engine
C4 Engine API Documentation


Defined in:  C4Textures.h
Returns a reference to a texture object.

static Texture *GetTexture(const char *name);

static Texture *GetTexture(const TextureHeader *header, const void *image = nullptr);

name The name of the texture resource.
header A pointer to a TextureHeader structure describing the texture.
image A pointer to the pixel image for the texture. If this is nullptr, then the texture image should immediately follow the texture header in memory.
The GetTexture function returns a reference to a texture map object. A texture map may be stored in a resource or created in memory, and the location determines which version of the GetTexture function should be called. If the texture is stored in a resource, then the version of the GetTexture function taking the name of the resource in the name parameter should be called. If the texture image exists in memory, then the version of the GetTexture function taking a TextureHeader structure should be called.

If a texture object already exists for the parameters passed to the GetTexture function, then its reference count is incremented, and a pointer to the existing object is returned. Otherwise, a new texture object is created with a reference count of 1, and a pointer to the new object is returned. If an attempt is made to create a texture object for a resource that does not exist, then the return value is a pointer to a special "missing" texture map.

When the header and image parameters are used to create a texture map from data stored in memory, the header and image data must continue to exist in memory for the lifetime of the texture object returned by the GetTexture function.

For each successful call to the GetTexture function, there should be a balancing call to the Shared::Release function that releases the texture object.
See Also