Skip to content
Supports hot reloading and asynchronous loading of assets (Replaced by
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


##New version is here:!##


By default the asset will automaticaly be watched and reloaded on the fly.

AssetManager::load( "cinder_logo_alpha.png", [this](DataSourceRef dataSource){
    mTexture = gl::Texture::create( loadImage( dataSource ) );
} );


By modifying the AssetManger::Options passed through the load function you can specify if you want asynchronous loading. In that case the loading will occur in a separated thread, and will not block the main thread. Be carefull what you do inside that thread.

AssetManager::load( "cinder_logo_alpha.png", [this](DataSourceRef dataSource){
    mSurface = Surface( loadImage( dataSource ) );
}, AssetManager::Options().asynchronous() );

Use the templated version if you want to pass an object from the loading thread to the main thread. Because we are providing the load function with two callbacks there's no need to specify Options().asynchronous() like we would do with only one callback.

// Load the image in a separated thread and returns the ImageSourceRef
auto asyncLoad = [](DataSourceRef dataSource){
    ImageSourceRef imageSource = loadImage( dataSource );
    return imageSource;
// The second callback is executed in the main thread so any OpenGL resources can be created here.
auto textureCreation = [this](ImageSourceRef imageSource){
    mTexture = gl::Texture::create( imageSource );

AssetManager::load<ImageSourceRef>( "cinder_logo_alpha.png", asyncLoad, textureCreation );

File Grouping:

AssetManager::load( "test.vert", "test.frag", [this]( DataSourceRef vert, DataSourceRef frag ) {
    // Load our shader and test if it is correctly compiled
    try {
        mShader = gl::GlslProg::create( vert, frag );
    catch( gl::GlslProgCompileExc exc ){
        console() << exc.what() << endl;
} );

Thanks to initializer lists and variadic templates we can group any number of assets and have the same callback function called for initialization. Works the same way as the non-variadic method with the only difference in the syntax that you can use {} to declare your list of asset paths to load.

The only downside right now is that lambdas with a capture list can't be implicitly cast to the variadic function pointer AssetManager is using, so the code looks a bit redundant, because you need to specify twice the method signature ( cast + lambda parameters ).

AssetManager::load( { "img01.png", "img02.png", "img03.png", "img04.png", "img05.png" }, 
      [this](DataSourceRef img01, DataSourceRef img02, DataSourceRef img03, DataSourceRef img04, DataSourceRef img05) {
    // Do something (Texture atlas?)
} );
You can’t perform that action at this time.