The previous article describes WebGL.
Further streamlined here.
The whole content of WEBGL is to create different shaders,
Provides data to the shader and then calls gl.drawArrays
or gl.drawElements
Lets WebGL invoke the current vertex shader to process each vertex, calling the current fragment shader to render each pixel.
Since shaders require data, shaders are divided into two parts, vertex and fragment shaders
The data that is required by the vertex shader can be obtained in the following three ways.
- Attributes property (data obtained from the buffer)
- Uniforms global variable (maintains a consistent value for all vertices in one draw)
- Textures texture (data obtained from a pixel or texture element)
The data required by the fragment shader can be obtained in the following three ways
- Uniforms Global variables (values that stay the same for every pixel of a single draw call)
- Textures texture (data from pixels/texels)
- Varyings variable amount (data passed from the vertex shader and interpolated)
Property Write
- var buf = gl.
- gl. Bindbuffer (gl. Array_buffer, Buf);
- gl. (gl. Array_buffer, somedata, gl< Span class= "pun". static_draw
Property Read
- GL. Getattriblocation(positionloc);(can be initiated)
- GL. Enablevertexattribarray(positionloc);
- Gl.bindbuffer (gl. Array_buffer, buf);
- GL. Vertexattribpointer(positionloc, numcomponents, type, false, Stride, offset);
< Span class= "PLN" >< Span class= "pun" > variable read and write (when used, it's OK to bind the value directly to a variable.) )
- var offsetloc = gl. Getuniformlocation(progress, XX);
- GL. Uniform(XXXXXX); //Offset half screen width to the right
Texture Write
- var txt = gl.createtexture ();
- GL. Bindtexture(gl. texture_2d, Tex);
- GL. Teximage2d(gl. texture_2d, level, GL. RGBA, width, height, 0, GL. RGBA, gl. Unsigned_byte, img);
Texture Read
- GL. Getuniformlocation(positionloc);(can be initialized)
- GL. Activetexture(gl. TEXTURE0 + unit);
- GL. Bindtexture(gl. texture_2d, Tex);
- GL. Uniform1i(somesamplerloc, unit);
Variables available
Vertex shader passed directly to fragment shader
WebGL Initial Knowledge 2