Game Development Reference
In-Depth Information
Note These classes are standard in the Android development library, and you can learn more about them on
the official Android web site at http://developer.android.com .
Once the shader has been successfully created, it is activated just before use by calling the
ActivateShader() function (see Listing 4-11). This is actually a wrapper function that just calls the
glUseProgram() function, which is a standard OpenGL 2.0 call. Again, note that the GLES20 prefix
denotes standard OpenGL 2.0 calls located in the standard Android library.
Listing 4-11. Activating the Shader
void ActivateShader()
{
GLES20.glUseProgram(m_ShaderProgram);
}
You can also call DeActivateShader() to deactivate a shader from functioning. This function calls
the glUseProgram() function with an input of 0 to indicate that no shader program should be used in
rendering an object. This will set the rendering pipeline to the fixed rendering pipeline of OpenGL
ES 1.0. (see Listing 4-12).
Listing 4-12. Deactivating the Shader
void DeActivateShader()
{
GLES20.glUseProgram(0);
}
The function GetShaderVertexAttributeVariableLocation() shown in Listing 4-13 is used to retrieve
the location of user-defined vertex shader variables, such as those used for the vertex position,
texture coordinates, and normals. These locations will be tied to the actual vertex data streams
through the glVertexAttribPointer() function. I will discuss this function that is used to draw 3D
meshes later. This function calls the standard OpenGL ES 2.0 function glGetAttribLocation() .
Listing 4-13. Get Vertex Attribute Variable Location
int GetShaderVertexAttributeVariableLocation(String variable)
{
return (GLES20.glGetAttribLocation(m_ShaderProgram, variable));
}
To set a uniform variable in a vertex or fragment shader, you can use the glUniformXXX series of
functions included in the standard GLES20 library. First, you would get the uniform variable location
index with the glGetUniformLocation() function, and then set it using the glUniformXXX() function
specific to the type of variable you want to set.
 
Search WWH ::




Custom Search