|
void | parseAtlas (const std::shared_ptr< JsonValue > &json, const std::shared_ptr< Texture > &texture) |
|
SDL_Surface * | preload (const std::string source) |
|
void | materialize (const std::string key, SDL_Surface *surface, LoaderCallback callback) |
|
void | materialize (const std::shared_ptr< JsonValue > &json, SDL_Surface *surface, LoaderCallback callback) |
|
virtual bool | read (const std::string key, const std::string source, LoaderCallback callback, bool async) override |
|
virtual bool | read (const std::shared_ptr< JsonValue > &json, LoaderCallback callback, bool async) override |
|
virtual bool | purgeJson (const std::shared_ptr< JsonValue > &json) override |
|
virtual bool | read (const std::string key, const std::string source, LoaderCallback callback, bool async) |
|
virtual bool | read (const std::shared_ptr< JsonValue > &json, LoaderCallback callback, bool async) |
|
virtual bool | purgeKey (const std::string key) |
|
virtual bool | purgeJson (const std::shared_ptr< JsonValue > &json) |
|
virtual bool | verify (const std::string key) const |
|
This class is a specific implementation of Loader<Texture>
This asset loader allows us to allocate texture objects from the associated image files. A texture asset is identified by both its source file and its texture parameters. Hence you may wish to load a texture asset multiple times, though this is potentially wasteful regarding memory. However, changing the parameters for a texture asset will change the asset parameters in this loader as well.
Note that this implementation uses a two phase loading system. First, it loads as much of the asset as possible without using OpenGL. This allows us to load the texture in a separate thread. It then finishes off the remainder of asset loading using Application#schedule
. This is a good template for asset loaders in general.
As with all of our loaders, this loader is designed to be attached to an asset manager. Use the method getHook()
to get the appropriate pointer for attaching the loader.
void cugl::graphics::TextureLoader::dispose |
( |
| ) |
|
|
inlineoverridevirtual |
Disposes all resources and assets of this loader
Any assets loaded by this object will be immediately released by the loader. However, a texture may still be available if it is referenced by another smart pointer. OpenGL will only release a texture asset once all smart pointer attached to the asset are null.
Once the loader is disposed, any attempts to load a new asset will fail. You must reinitialize the loader to begin loading assets again.
Reimplemented from cugl::BaseLoader.
void cugl::graphics::TextureLoader::materialize |
( |
const std::shared_ptr< JsonValue > & |
json, |
|
|
SDL_Surface * |
surface, |
|
|
LoaderCallback |
callback |
|
) |
| |
|
protected |
Creates an OpenGL texture from the SDL_Surface accoring to the directory entry.
This method finishes the asset loading started in preload
. This step is not safe to be done in a separate thread. Instead, it takes place in the main CUGL thread via Application#schedule
.
This version of read provides support for JSON directories. A texture directory entry has the following values
"file": The path to the asset
"mipmaps": Whether to generate mipmaps (bool)
"minfilter": The name of the min filter ("nearest", "linear";
with mipmaps, "nearest-nearest", "linear-nearest",
"nearest-linear", or "linear-linear")
"magfilter": The name of the min filter ("nearest" or "linear")
"wrapS": The s-coord wrap rule ("clamp", "repeat", or "mirrored")
"wrapT": The t-coord wrap rule ("clamp", "repeat", or "mirrored")
The asset key is the key for the JSON directory entry
This method supports an optional callback function which reports whether the asset was successfully materialized.
- Parameters
-
json | The asset directory entry |
surface | The SDL_Surface to convert |
callback | An optional callback for asynchronous loading |
void cugl::graphics::TextureLoader::materialize |
( |
const std::string |
key, |
|
|
SDL_Surface * |
surface, |
|
|
LoaderCallback |
callback |
|
) |
| |
|
protected |
Creates an OpenGL texture from the SDL_Surface, and assigns it the given key.
This method finishes the asset loading started in preload
. This step is not safe to be done in a separate thread. Instead, it takes place in the main CUGL thread via Application#schedule
.
The loaded texture will have default parameters for scaling and wrap. It will only have a mipmap if that is the default.
This method supports an optional callback function which reports whether the asset was successfully materialized.
- Parameters
-
key | The key to access the asset after loading |
surface | The SDL_Surface to convert |
callback | An optional callback for asynchronous loading |
void cugl::graphics::TextureLoader::parseAtlas |
( |
const std::shared_ptr< JsonValue > & |
json, |
|
|
const std::shared_ptr< Texture > & |
texture |
|
) |
| |
|
protected |
Extracts any subtextures specified in an atlas
An atlas is specified as a list of named, four-element integer arrays. Each integer array specifies the left, top, right, and bottom pixels of the subtexture, respectively. Each subtexture will have the key of the main texture as the prefix (together with an underscore _) of its key.
- Parameters
-
json | The asset directory entry |
texture | The texture loaded for this asset |
virtual bool cugl::graphics::TextureLoader::purgeJson |
( |
const std::shared_ptr< JsonValue > & |
json | ) |
|
|
overrideprotectedvirtual |
Unloads the asset for the given directory entry
An asset may still be available if it is referenced by a smart pointer. See the description of the specific implementation for how assets are released.
This version of the method not only unloads the given Texture
, but also any texture atlases attached to it.
- Parameters
-
json | The directory entry for the asset |
- Returns
- true if the asset was successfully unloaded
Reimplemented from cugl::BaseLoader.
virtual bool cugl::graphics::TextureLoader::read |
( |
const std::shared_ptr< JsonValue > & |
json, |
|
|
LoaderCallback |
callback, |
|
|
bool |
async |
|
) |
| |
|
overrideprotectedvirtual |
Internal method to support asset loading.
This method supports either synchronous or asynchronous loading, as specified by the given parameter. If the loading is asynchronous, the user may specify an optional callback function.
This method will split the loading across the preload
and materialize
methods. This ensures that asynchronous loading is safe.
This version of read provides support for JSON directories. A texture directory entry has the following values
"file": The path to the asset
"mipmaps": Whether to generate mipmaps (bool)
"minfilter": The name of the min filter ("nearest", "linear";
with mipmaps, "nearest-nearest", "linear-nearest",
"nearest-linear", or "linear-linear")
"magfilter": The name of the min filter ("nearest" or "linear")
"wrapS": The s-coord wrap rule ("clamp", "repeat", or "mirrored")
"wrapT": The t-coord wrap rule ("clamp", "repeat", or "mirrored")
- Parameters
-
json | The directory entry for the asset |
callback | An optional callback for asynchronous loading |
async | Whether the asset was loaded asynchronously |
- Returns
- true if the asset was successfully loaded
Reimplemented from cugl::BaseLoader.
virtual bool cugl::graphics::TextureLoader::read |
( |
const std::string |
key, |
|
|
const std::string |
source, |
|
|
LoaderCallback |
callback, |
|
|
bool |
async |
|
) |
| |
|
overrideprotectedvirtual |
Internal method to support asset loading.
This method supports either synchronous or asynchronous loading, as specified by the given parameter. If the loading is asynchronous, the user may specify an optional callback function.
This method will split the loading across the preload
and materialize
methods. This ensures that asynchronous loading is safe.
- Parameters
-
key | The key to access the asset after loading |
source | The pathname to the asset |
callback | An optional callback for asynchronous loading |
async | Whether the asset was loaded asynchronously |
- Returns
- true if the asset was successfully loaded
Reimplemented from cugl::BaseLoader.