1. Create a shader container
Gles20.glcreateshader (Shadertype);
The function prototypes are:
int glcreateshader (int type)
Method Parameters:
Gles20.gl_vertex_shader (vertex SHADER)
Gles20.gl_fragment_shader (Element SHADER)
return value:
The function returns a positive integer that is shaped as the ID of the shader container.
2. Load the shader source code
Gles20.glshadersource (shader, source);
To add the shader source code to the created shader container. The source code should be represented as an array of strings. Of course, you can also use just one string to contain all the source code.
The prototype of the function:
void Glshadersource (int shader, string string)
Method Parameters:
Shader is the ID representing the shader container (the number of shapes returned by Glcreateshader);
Strings is an array of strings containing the source program;
3. Compiling shader
Gles20.glcompileshader (shader);
Use the Glcompileshader function to compile the source code in the shader container.
The prototype of the function is as follows:
void Glcompileshader (int shader)
Parameter meaning:
Shader is the ID representing the shader container
4. Commissioning
4.1 Compile phase using GLGETSHADERIV to get the compilation situation
Function prototype:void Glgetshaderiv (int offset) parameter meaning: shader is a shader id;pname use gl_compile_status; theparams is the return value, Returns Gl_false if everything returns to the gl_true generation normally.
4.2 Compile phase using Glgetshaderinfolog to get compilation errors
Function prototype: String glgetshaderinfolog (int shader) parameter meaning: shader is the ID of a vertex shader or slice shader.
4.3 using GLGETPROGRAMIV in the connection phase to get the connection condition
Function prototype:void glgetprogramiv (int offset) parameter meaning: program is a shader programs Id;pname is Gl_link_status;param is the return value, if everything returns normally Gl_ True generation, otherwise returns GL_FALSE.
4.4 Using Glgetprograminfolog to get connection errors during the connection phase
Function prototype: The String glgetprograminfolog (int program) parameter means: The programs is the ID of a shader application.
5. Cleaning shader
When you no longer need a shader or a program, you need to clean it up to free up resources.
Function Prototypes:
void Gldeleteshader (int shader)
Parameter meaning:
Shader is the ID of the vertex shader or slice shader to be excluded
6. Creating a Program Object
int program = Gles20.glcreateprogram ();
Function prototype:int Glcreateprogram () if the function call succeeds, it returns a positive integer as the ID of the shader program.
7.Shader Connection Program Object
// Adding a vertex shader to your program Gles20.glattachshader (program, vertexshader); // Adding a slice shader to your program Gles20.glattachshader (program, pixelshader);
Function prototype:void Glattachshader (int shader) parameter meaning: program is the id;shader of the shader programs container is the ID of the vertex or slice shader container to add.
8. Linking programs
Function prototype:the void Gllinkprogram (int program) parameter means: Programs is the ID of the shader application container.
9. Use a linked program
If program is set to 0, a fixed-function pipeline is used.
Function prototype: thevoid Gluseprogram (int program) parameter means: Programs is the ID of the shader application to be used.
Reference:
Http://www.tuicool.com/articles/VZVJra
http://fengmm521.blog.163.com/blog/static/2509135820133254936364/
OpenGL ES 2.0 Shader development