15 #ifndef FPLBASE_ASSET_MANAGER_H
16 #define FPLBASE_ASSET_MANAGER_H
21 #include "fplbase/config.h"
24 #include "fplbase/fpl_common.h"
38 virtual bool Finalize();
39 virtual bool IsValid();
84 const char *alias =
nullptr);
103 const std::vector<std::string> &defines,
104 bool async =
false,
const char *alias =
nullptr);
221 Mesh *
LoadMesh(
const char *filename,
bool async =
false);
308 const std::vector<std::string> &defines_to_add,
309 const std::vector<std::string> &defines_to_omit);
313 const std::function<
void(
Shader *)> &func);
316 Shader *LoadShaderHelper(
const char *basename,
317 const std::vector<std::string> &local_defines,
318 const char *alias,
bool async);
325 template <
typename T>
326 T *LoadOrQueue(T *asset, std::map<std::string, T *> &asset_map,
bool async,
328 asset_map[alias !=
nullptr ? alias : asset->filename()] = asset;
332 bool ok = asset->LoadNow();
342 std::map<std::string, Shader *> shader_map_;
343 std::map<std::string, Texture *> texture_map_;
344 std::map<std::string, TextureAtlas *> texture_atlas_map_;
345 std::map<std::string, Material *> material_map_;
346 std::map<std::string, Mesh *> mesh_map_;
347 std::map<std::string, FileAsset *> file_map_;
349 mathfu::vec2 texture_scale_;
351 std::vector<std::string> defines_to_add_;
352 std::vector<std::string> defines_to_omit_;
358 #endif // FPLBASE_ASSET_MANAGER_H
Material * LoadMaterial(const char *filename, bool async_resources=false)
Loads and returns a material object.
Texture * LoadTexture(const char *filename, TextureFormat format=kFormatAuto, TextureFlags flags=kTextureFlagsUseMipMaps|kTextureFlagsLoadAsync)
Queue loading a texture if it hasn't been loaded already.
void UnloadMesh(const char *filename)
Deletes the previously loaded mesh.
void ResetGlobalShaderDefines(const std::vector< std::string > &defines_to_add, const std::vector< std::string > &defines_to_omit)
Reset global defines and set dirty flags of all shaders.
Shader * LoadShader(const char *basename, bool async=false, const char *alias=nullptr)
Loads and returns a shader object.
~AssetManager()
AssetManager destructor that purges all assets.
Definition: asset_manager.h:61
Load texture asynchronously.
Definition: texture.h:62
void Stop()
Shuts down the loader after completing all pending loads.
Shader * LoadShaderDef(const char *filename)
Load a shader built by shader_pipeline.
void UnloadTexture(const char *filename)
Deletes the previously loaded texture.
Abstraction for a set of indices, used for rendering.
Definition: mesh.h:56
Represents a shader consisting of a vertex and pixel shader.
Definition: shader.h:42
const Renderer & renderer() const
Handy accessor for the renderer.
Definition: asset_manager.h:288
void StartLoadingTextures()
Start loading all previously queued textures.
Abstraction for a texture object loaded on the GPU.
Definition: texture.h:104
Central place to own game assets loaded from disk.
Definition: asset_manager.h:53
FileAsset * FindFileAsset(const char *filename)
Look up a previously loaded file asset.
Shader * FindShader(const char *basename)
Returns a previously loaded shader object.
Collections of textures used for rendering multi-texture models.
Definition: material.h:37
bool TryFinalize()
Check for the status of async loading resources.
FileAsset * LoadFileAsset(const char *filename)
Loads a file asset.
AssetManager(Renderer &renderer)
AssetManager constructor.
Material * FindMaterial(const char *filename)
Returns a previously loaded material.
TextureFormat
Definition: texture.h:36
void StopLoadingTextures()
Stop loading previously queued textures.
Mesh * LoadMesh(const char *filename, bool async=false)
Loads and returns a mesh object.
void UnloadFileAsset(const char *filename)
Delete a file asset and remove it from the asset manager.
void UnloadTextureAtlas(const char *filename)
Delete a texture atlas and remove it from the asset manager.
TextureFlags
Flags affecting loading and sampler modes for a texture.
Definition: texture.h:52
Renderer & renderer()
Handy accessor for the renderer.
Definition: asset_manager.h:283
A generic asset whose contents the AssetManager doesn't care about.
Definition: asset_manager.h:36
Uses (or generates) mipmaps.
Definition: texture.h:58
void ClearAllAssets()
Removes and destructs all assets held by the AssetManager.
void UnloadMaterial(const char *filename)
Deletes the previously loaded material.
Texture * FindTexture(const char *filename)
Returns a previously created texture.
void UnloadShader(const char *filename)
Deletes the previously loaded shader.
TextureAtlas * LoadTextureAtlas(const char *filename, TextureFormat format=kFormatAuto, TextureFlags flags=kTextureFlagsUseMipMaps|kTextureFlagsLoadAsync)
Loads a texture atlas.
void QueueJob(AsyncAsset *res)
Queues AsyncResources to be loaded by StartLoading.
void SetTextureScale(const mathfu::vec2 &scale)
Set a scaling factor to apply when loading texture materials.
Definition: asset_manager.h:301
Texture coordinate dictionary.
Definition: texture_atlas.h:43
The default, picks based on loaded data.
Definition: texture.h:37
TextureAtlas * FindTextureAtlas(const char *filename)
Look up a previously loaded texture atlas.
Renderer is the main API class for rendering commands.
Definition: renderer.h:310
Definition: async_loader.h:48
Mesh * FindMesh(const char *filename)
Returns a previously loaded mesh.
void ForEachShaderWithDefine(const char *define, const std::function< void(Shader *)> &func)
Foreach shader with a specific define.