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.5 Assigning the shader programsThere are the following ways to assign the shader code to a shader:• In-line source code• External shader source code• Precompiled shader programs on page 6-15.6.5.1 In-line source codeExample 6-16 shows:• how to define shaders source code in text strings• using createShader() to compile the shader source code• using createProgram() to create a program from the object code• using setProgram() to assign the program to the context.Example 6-16 Specifying the attributes for the vertex source elements...const char* vertexsource ="attribute vec4 POSITION; \attribute vec4 COLOR;\varying vec4 col;\void main(void)\{\col = COLOR;\gl_Position = POSITION;\}";const char* fragmentsource ="precision mediump float; \varying vec4 col;\void main(void)\{\gl_FragColor = col;\}";Managed vertexshader =context->createShader(GL_VERTEX_SHADER, vertexsource);Managed fragmentshader =context->createShader(GL_FRAGMENT_SHADER, fragmentsource);Managed program = context->createProgram(vertexshader, fragmentshader);context->setProgram(program);...6.5.2 External shader source codeExample 6-17 shows loading the shader source code from two files:Example 6-17 Loading the hello_world shaders...Managed filesystem = system->createFileSystem(".");Proxy proxy(filesystem, context);Program *helloWorldProgram =ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 6-14ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!