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.2 Data resources used by the shadersShader processors can use the following resources to create the graphic:ProgramsTexturesThe vertex and fragment shader processors in the <strong>GPU</strong> execute programs that aredownloaded from the application running on the CPU. The shader code can beeither OpenGL ES Shading Language (ESSL) source code or pre-compiledbinary objects. Different shader code can be used for different shapes, but thecode does not change within the primitive drawing stage.The fragment shaders in the <strong>GPU</strong> can use a texture, typically from a bitmap, tofill a primitive shape. Multiple textures can be defined and used for differentshape primitives.Global variablesThe vertex and fragment shader in the <strong>GPU</strong> can read global variables associatedwith the graphics context. Some globals are specific to the vertex shader orfragment shader or can only be written to by one of the shaders. The mostcommonly used globals are:• gl_Position is only visible to the vertex shader. The shader sets it to thecalculated vertex position..• gl_FragColor is only visible to the fragment shader. The shader can set it tothe fragment color or execute the discard statement to discard the fragment.If set, the fragment color is used in the framebuffer.Global constants and built-in functionsThe library provides global constants and functions that can be used by theshaders such as gl_MaxVertexAttribs or sin().Uniform constantsThe uniform constants are global values that apply to the primitive shape. Theyare read-only, and are either standard OpenGL ES variables orapplication-defined variables.Attribute constantsAttribute variables are values passed to the vertex shader on a per-vertex basis.They are read-only, and are either standard OpenGL ES variables orapplication-defined variables.Varying variablesVarying variables are values passed to the fragment shader from the vertex shader.They are read-only in the fragment shader. If an vertex shader attribute variablemust be used by the fragment shader, the vertex shader must copy the attributeinto a new varying variable that is shared between the processors.For points on the face that are not vertices, the <strong>GPU</strong> calculates the varying valuebased on the distance of the point from the vertices and the values at the vertices.Local variables and functionsEach shader can define local variables and functions to hold intermediate valuesand simplify calculations.Preprocessor directivesThe shader code can contain directives such as #ifdef statements to instruct thecompiler to use specified declarations for the actual environment. The sourcecode can also contain // or /* */ to identify comment text.ARM DUI 0527A-02a Copyright © 2010 ARM. All rights reserved. 6-5ID070710Non-Confidential - Draft - Beta

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

Saved successfully!

Ooh no, something went wrong!