Game Development Reference
In-Depth Information
identical shaders are not exactly the same when they run, in which case
there are two qualifiers—invariant and varying—to prevent or allow this.
Operators and expressions : All the common operators and expressions
you would expect from your typical programming language (see the
following sidebar for more details).
Many other powerful features : These include built-in angle, trigonometry,
exponential, matrix, and vector functions plus built-in variables and more.
NEED GLSL HELP?
There is so much to the GLSL language. The best source on GLSL is probably the OpenGL Software
Development Kit at https://www.opengl.org/sdk/docs/man4/index.php . Another great source on
the GLSL syntax is available from the Khronos Group at www.khronos.org/files/opengles_shading_
language.pdf .
These sites can help you learn more about GLSL features and syntax, so make sure to check them out.
Now let's take a look at how to implement a shader and use it in an Android program.
Anatomy of a Shader
The anatomy of a shader is defined by the following steps:
1.
Create a program : The first step is to create a shader program to be
run within your main program—a program within a program, if you will.
2.
Load the shader : Once you create the shader, you must load it from a
string variable or file.
3.
Attach : Next, you must attach the shader to the main program.
4.
Link : This step compiles the shader code and checks for syntax errors.
5.
Optional validation : It is always a good idea to validate the link status
and handle errors appropriately.
6.
Enable and use : Finally, you can enable it and use it against a set
of vertices.
Creating the Shader Program
To create a shader object or program, use the glCreateShader API call. It takes as a
parameter a shader type, either GL_VERTEX_SHADER or GL_FRAGMENT_SHADER for vertex
or fragment, respectively. glCreateShader returns a non-zero value by which it can be
 
Search WWH ::




Custom Search