Game Development Reference
In-Depth Information
Shader Program
Vertex Shader
Pixel Shader
Figure 4-14. Shader program overview
The Shader class holds a handle to the fragment shader in m_FragmentShader . The handle to the
vertex shader is in m_VertexShader . The handle to the main shader program that the vertex shader
and fragment or pixel shader is attached to is m_ShaderProgram . Finally, the m_Context holds a
reference to the activity that this shader object belongs to (see Listing 4-5). These variables are
all private and cannot be accessed outside the class. Only class member functions may access
these variables.
Listing 4-5. Shader Class Data
private Context m_Context;
private int m_FragmentShader;
private int m_VertexShader;
private int m_ShaderProgram;
The Shader class's constructor initializes the vertex, fragment, and main shader program handles to
0. It also takes as input the vertex and fragment shader resource ids that represent the actual shader
source text files. It then calls the InitShaderProgram() function with these shader resource ids
(see Listing 4-6).
Listing 4-6. Shader Class Constructor
public Shader(Context context, int VSResourceId, int FSResourceId)
{
// Shader Variables
m_FragmentShader = 0;
m_VertexShader = 0;
m_ShaderProgram = 0;
m_Context = context;
InitShaderProgram(VSResourceId, FSResourceId);
}
The InitShaderProgram() function receives the vertex and fragment shader resource ids and creates
the actual main shader program.
First, the main shader program is created through the GLES20.glCreateProgram() function.
Next, InitVertexShader() is called to create the vertex shader, and InitFragmentShader() is called
to create the fragment shader.
 
Search WWH ::




Custom Search