6.3.2. Using asset files

The Vector Buffer Object is appropriate for simple shapes, but applications often use complex shapes or shape data produced by a third-party tool.

Using files in Mali Binary Format improves efficiency and separates graphic creation from graphic display:

  1. To load asset files, create a Proxy object for the directory containing the assets. See Example 6.5:

    Example 6.5. Creating a proxy

    Managed<System> system = create_system_backend();
    Managed<FileSystem> filesystem = system->createFileSystem("data/");
    Proxy proxy(filesystem, context);
    

  2. Example 6.6 shows the code that loads the assets from the directory:

    Example 6.6. Loading assets from a proxy

    // load the scene from the asset file
    SceneAsset* scene = proxy.getSceneAsset("superpot.MBA");
    // load the shader programs
    Program* program = proxy.getProgramAsset("default.vert;default.frag")->getProgram();
    context->setProgram(program);
    // Access parts of the scene by name or id
    const char* exName = "Teapot01-mesh";
    GeometryAsset* mesh = (GeometryAsset*)scene->getAsset(Asset::TYPE_GEOMETRY, exName);
    

  3. The draw loop reads the geometry assets from the file and updates the context as shown in Example 6.7:

    Example 6.7. Redrawing geometries from the asset

    for(unsigned int i = 0; i < scene->getAssetCount(Asset::TYPE_GEOMETRY); i++)
    {
        // set the drawing options
        ...
        // calculate the camera position, world, view, and perspective projection
        ...
    
        // set the uniform values to pass to the shaders
        context->setUniformMatrix("WORLD", 4, 1, world);
        context->setUniformMatrix("VIEW", 4, 1, view);
        context->setUniformMatrix("PROJECTION", 4, 1, proj);
        context->setUniformMatrix("PROJ_VIEW", 4, 1, proj*view);
        
        // tell the scene asset to draw itself
        ((GeometryAsset*)scene->getAsset(Asset::TYPE_GEOMETRY, i))->draw();
    
        // update the context to switch the buffers and display the drawing
        context->update();
    }
    

For more information on the Mali Binary Format, see the Mali GPU Binary Asset Exporter User Guide.

Copyright © 2010 ARM. All rights reserved.ARM DUI 0527A‑02a
Non-Confidential - Draft - BetaID070710