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 Constructing Custom Shaders6.3 Passing data as uniformsThe application defines matrices and vectors, that represent the required transformations and thedata for the graphics objects, and pass these values to the shader for further modification andrendering.Read-only parameters that are passed to shaders are called uniforms and are passed by memberfunctions of the context class.6.3.1 Vertex buffer objectsIt is efficient to use Vertex Buffer Objects (VBO) to pass data for simple shapes to the shaders:1. The data values, typically the vertices of primitive shapes, is defined in the VertexBufferarray as shown in Example 6-1:Example 6-1 Defining the VertexData array and passing it to the shader// Set up the geometry of the cubeGLfloat vertexData[] = {// FRONT-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, //x,y,z location and u,v texture location0.5f, -0.5f, 0.5f, 1.0f, 0.0f,-0.5f, 0.5f, 0.5f, 0.0f, 1.0f,0.5f, 0.5f, 0.5f, 1.0f, 1.0f,// BACK-0.5f, -0.5f, -0.5f, 0.0f, 0.0f,-0.5f, 0.5f, -0.5f, 1.0f, 0.0f,0.5f, -0.5f, -0.5f, 0.0f, 1.0f,0.5f, 0.5f, -0.5f, 1.0f, 1.0f,// LEFT-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,-0.5f, 0.5f, 0.5f, 1.0f, 0.0f,-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,-0.5f, 0.5f, -0.5f, 1.0f, 1.0f,// RIGHT0.5f, -0.5f, -0.5f, 0.0f, 0.0f,0.5f, 0.5f, -0.5f, 1.0f, 0.0f,0.5f, -0.5f, 0.5f, 0.0f, 1.0f,0.5f, 0.5f, 0.5f, 1.0f, 1.0f,// TOP-0.5f, 0.5f, 0.5f, 0.0f, 0.0f,0.5f, 0.5f, 0.5f, 1.0f, 0.0f,-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,0.5f, 0.5f, -0.5f, 1.0f, 1.0f,// BOTTOM-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,-0.5f, -0.5f, -0.5f, 1.0f, 0.0f,0.5f, -0.5f, 0.5f, 0.0f, 1.0f,0.5f, -0.5f, -0.5f, 1.0f, 1.0f,}Managed vertexBuffer =context->createBuffer(GL_ARRAY_BUFFER, sizeof(vertexData),sizeof(GLfloat)*5);vertexBuffer->setData(0, sizeof(vertexData), vertexData);context->setVertexBuffer(0, vertexBuffer);2. The type of data that is passed is defined in the VertexElement array as shown inExample 6-2 on page 6-8:ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 6-7ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!