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 Shaders6.6 Filling a shape with a bitmap textureThe examples in Minimal shader programs on page 6-12 use fixed or interpolated colors for thefragment color. To map a bitmap onto the shape:1. Example 6-18 shows the code to load the bitmap and create a texture:Example 6-18 Creating a texture from a bitmap fileManaged filesystem = system->createFileSystem(".");Proxy proxy(filesystem, context);...Program *texturingProgram =proxy.getProgram("shaders/texturing.vert;shaders/texturing.frag");Texture2D *texture = proxy.getTexture2D("data/rock_t.png");texture->setFilterMode(GL_NEAREST, GL_NEAREST);...2. The semantic entry in the VertexElement array must specify TEXTCOORD0 as shown inExample 6-19:Example 6-19 Modifying the VertexElement array to use a texture...Managed vertexBuffer =context->createBuffer(GL_ARRAY_BUFFER, sizeof(vertexData), sizeof(GLfloat)*5);vertexBuffer->setData(0, sizeof(vertexData), vertexData);context->setVertexBuffer(0, vertexBuffer);VertexElement 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-20 shows the use of setProgram() to connect the texturing program fromExample 6-18 to the context:Example 6-20 Create a texture program and a uniform sampler to use the bitmap...context->setProgram(texturingProgram);context->setUniformSampler("texture", static_cast(texture));...ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 6-16ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!