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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Tutorial on Drawing 3D Shapes4.7 Advanced MBA scene renderingThis tutorial combines:• a complex geometry asset• multiple varying light sources• a timer• automated movement of the camera.Open the 10-Advanced MBA Scene Rendering example:1. Example 4-52 shows the node traversal function:Example 4-52 Traversal function...#include #define TIME_INCREMENT 0.03f#define FIXED_FRAMERATE 1using namespace MDE;// the function takes as parameters: a node in the asset, the drawing context, a projection_view matrix,// a world matrix, and the current timevoid traverse(Tree* node, Context* context, mat4 prjViw, mat4 world, float time){if (!node) return; // no node to draw// find the sibling node and recursively traverse ittraverse(node->getNextSibling(), context, prjViw, world, time);if (node->data) // skip if the node does not have any data{world *= node->data->sampleLocalTransform(time);mat4 inv_world;world.invert(inv_world); // create the inverse of the world matrix and invert itmat3 tiv3 = inv_world.transposed().toMat3();// pass the calculated uniforms to the shaderscontext->setUniformMatrix("TRA_INV_WRL", tiv3);context->setUniformMatrix("WORLD", world);context->setUniformMatrix("PRJ_VIW_WRL", prjViw*world);node->data->setAbsoluteTransform(world);for (unsigned int i = 0; i < node->data->getBatchCount(); i++){Batch b = node->data->getBatch(i);if (b.material) // calculate how the material responds to the light sources{// Check for diffuse textureTextureAsset* diffuse = b.material->getMap("diffuse");if (diffuse){context->setUniformSampler("TEXTURE_DIFFUSE", diffuse->getTexture());}// Check for spec level textureTextureAsset* spec_level = b.material->getMap("spec_level");if(spec_level){context->setUniformSampler("TEXTURE_SPEC_LEVEL", spec_level->getTexture());}ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 4-41ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!