WebGL Initial Knowledge 2

Source: Internet
Author: User

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.

    1. Attributes property (data obtained from the buffer)
    2. Uniforms global variable (maintains a consistent value for all vertices in one draw)
    3. 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

    1. Uniforms Global variables (values that stay the same for every pixel of a single draw call)
    2. Textures texture (data from pixels/texels)
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.