Game Development Reference
In-Depth Information
After both shaders are created, they are linked using the GLES20.glLinkProgram(m_ShaderProgram)
statement (see Listing 4-7).
Listing 4-7. InitShaderProgram Function
void InitShaderProgram(int VSResourceId, int FSResourceId)
{
m_ShaderProgram = GLES20.glCreateProgram();
InitVertexShader(VSResourceId);
InitFragmentShader(FSResourceId);
GLES20.glLinkProgram(m_ShaderProgram);
String DebugInfo = GLES20.glGetProgramInfoLog(m_ShaderProgram);
Log.d("DEBUG - SHADER LINK INFO ", DebugInfo);
}
Finally, the log file for the link operation is retrieved and displayed by calling glGetProgramInfoLog()
to get the log information and then displaying it to the Android Log window through the Log()
statement.
Note The GLES20 prefix indicates that the function is from the standard implementation of the OpenGL
ES 2.0 specification for Android.
The InitVertexShader() function is called from the InitShaderProgram() function in Listing 4-7.
The vertex shader source code is read into a temporary string buffer called tempBuffer .
An empty vertex shader is then created using the glCreateShader() function.
Next, the tempBuffer that holds the source code is associated with the vertex shader using the
glShaderSource() function.
Then, the vertex shader itself is compiled using the glCompileShader() function.
Next, the compile error status is checked by calling the glGetShaderiv() function. If there is no error,
the vertex shader is attached to the main shader program (see Listing 4-8).
Listing 4-8. InitVertexShader() Function
void InitVertexShader(int ResourceId)
{
StringBuffer tempBuffer = ReadInShader(ResourceId);
m_VertexShader= GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
GLES20.glShaderSource(m_VertexShader,tempBuffer.toString());
GLES20.glCompileShader(m_VertexShader);
 
 
Search WWH ::




Custom Search