13.07.2015 Views

Mali GPU User Interface Engine Application Development Guide

Mali GPU User Interface Engine Application Development Guide

Mali GPU User Interface Engine Application Development Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Tutorial on Constructing Custom ShadersUsing files in <strong>Mali</strong> Binary Format improves efficiency and separates graphic creation fromgraphic display:1. To load asset files, create a Proxy object for the directory containing the assets. SeeExample 6-5:Example 6-5 Creating a proxyManaged system = create_system_backend();Managed 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 fileSceneAsset* scene = proxy.getSceneAsset("superpot.MBA");// load the shader programsProgram* program = proxy.getProgramAsset("default.vert;default.frag")->getProgram();context->setProgram(program);// Access parts of the scene by name or idconst 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 shownin Example 6-7:Example 6-7 Redrawing geometries from the assetfor(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 shaderscontext->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 drawingcontext->update();For more information on the <strong>Mali</strong> Binary Format, see the <strong>Mali</strong> <strong>GPU</strong> Binary Asset Exporter <strong>User</strong><strong>Guide</strong>.ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 6-9ID070710Non-Confidential - Draft - Beta

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!