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 ShadersExample 6-2 Defining the VertexElement array and passing it to the shaderVertexElement elements[2];elements[0].components = 3;elements[0].offset = 0;elements[0].semantic = POSITION;elements[0].stream = 0;elements[0].type = GL_FLOAT;elements[1].components = 2;elements[1].offset = 3*sizeof(GLfloat);elements[1].semantic = TEXCOORD0;elements[1].stream = 0;elements[1].type = GL_FLOAT;Managed vertexDeclaration =context->createVertexDeclaration(elements, 2);context->setVertexDeclaration(vertexDeclaration);3. Example 6-3 shows the WORLD_VIEW_PROJECTION uniform in the vertex shader:Example 6-3 Using the VertexBuffer in the vertex shaderuniform mat4 WORLD_VIEW_PROJECTION;attribute vec4 POSITION;attribute vec2 TEXCOORD0;varying vec2 vTexCoord;void main(void){gl_Position = WORLD_VIEW_PROJECTION * POSITION;vTexCoord = TEXCOORD0;}4. The values for gl_Position and vTexCoord are calculated from the values in the vertexbuffer element that is being drawn.vTexCoord is passed to the fragment shader. The shader uses the texture coordinate togetherwith the fragment sampler uniform to calculate the color value for the pixel as shown inExample 6-4:Example 6-4 Using the texture sampler in the fragment shaderuniform sampler2D texture;varying vec2 vTexCoord;void main(void){gl_FragColor = texture2D(texture, vTexCoord);}6.3.2 Using asset filesThe Vector Buffer Object is appropriate for simple shapes, but applications often use complexshapes or shape data produced by a third-party tool.ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 6-8ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!