Game Development Reference
In-Depth Information
IntBuffer CompileErrorStatus = IntBuffer.allocate(1);
GLES20.glGetShaderiv(m_VertexShader,
GLES20.GL_COMPILE_STATUS,
CompileErrorStatus);
if (CompileErrorStatus.get(0) == 0)
{
Log.e("ERROR - VERTEX SHADER ",
"Could not compile Vertex shader!! " +
String.valueOf(ResourceId));
Log.e("ERROR - VERTEX SHADER ",
GLES20.glGetShaderInfoLog(m_VertexShader));
GLES20.glDeleteShader(m_VertexShader);
m_VertexShader = 0;
}
else
{
GLES20.glAttachShader(m_ShaderProgram,m_VertexShader);
Log.d("DEBUG - VERTEX SHADER ATTACHED ", "In InitVertexShader()");
}
}
The InitFragmentShader() function is called from the InitShaderProgram() , shown in Listing 4-7.
First the fragment shader source code is read in and stored in the tempBuffer string buffer.
Then, an empty fragment shader is created. The source code in the tempBuffer variable is then
linked to the fragment shader that was just created. Next, the shader is compiled then attached to
the main shader program, if there are no errors (see Listing 4-9).
Listing 4-9. InitFragmentShader() Function
void InitFragmentShader(int ResourceId)
{
StringBuffer tempBuffer = ReadInShader(ResourceId);
m_FragmentShader= GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
GLES20.glShaderSource(m_FragmentShader,tempBuffer.toString());
GLES20.glCompileShader(m_FragmentShader);
IntBuffer CompileErrorStatus = IntBuffer.allocate(1);
GLES20.glGetShaderiv(m_FragmentShader,
GLES20.GL_COMPILE_STATUS,
CompileErrorStatus);
if (CompileErrorStatus.get(0) == 0)
{
Log.e("ERROR - FRAGMENT SHADER ",
"Could not compile Fragment shader file = " +
String.valueOf(ResourceId));
Log.e("ERROR - FRAGMENT SHADER ",
GLES20.glGetShaderInfoLog(m_FragmentShader));
GLES20.glDeleteShader(m_FragmentShader);
m_FragmentShader = 0;
}
 
Search WWH ::




Custom Search