Opengles and the organization format of vertex attributes in WebGL-a joke that's not funny

Source: Internet
Author: User

Opengles and the organization format of vertex attributes in WebGL-a joke that's not funny

The beautiful Life of the Sun Vulcan (http://blog.csdn.net/opengl_es)

This article follows "Attribution-non-commercial use-consistent" authoring public agreement

Reprint Please keep this sentence: Sun Vulcan's Beautiful Life-this blog focuses on Agile development and mobile and IoT device research: IOS, Android, HTML5, Arduino, Pcduino , Otherwise, the article from this blog refused to reprint or re-reproduced, thank you for your cooperation.


An array of cube vertex coordinates in WebGL:

    vertices = [        //Front face        -3.0, -3.0, 3.0,        3.0, -3.0, 3.0,        3.0, 3.0, 3.0,        -3.0, 3.0, 3.0,        //back Face        -3.0, -3.0, -3.0,        -3.0, 3.0, -3.0,        3.0, 3.0, -3.0,        3.0, -3.0, -3.0,        //Top face        -3.0, 3.0 , -3.0,        -3.0, 3.0, 3.0,        3.0, 3.0, 3.0,        3.0, 3.0, -3.0,        //Bottom face        -3.0, -3.0, -3.0,        3.0 , -3.0, -3.0,        3.0, -3.0, 3.0,        -3.0, -3.0, 3.0,        //Right face        3.0, -3.0, -3.0,        3.0, 3.0, -3.0,
   3.0, 3.0, 3.0,        3.0, -3.0, 3.0,        //left face        -3.0, -3.0, -3.0,        -3.0, -3.0, 3.0,        -3.0, 3.0, 3.0,< c30/>-3.0, 3.0, -3.0,    ];

the cube polygon Vertex coordinate index array in WebGL:

    var cubevertexindices = [        0, 1, 2, 0, 2, 3,    //Front face        4, 5, 6, 4, 6, 7,    //back face        8, 9, 10, 8, Ten, one,  //Top face,        20,        21, 2, (+), +,//Bottom face, +, +,. 2, Max, Max  //left face    ];

The difference between IOS and above:

The first is that there is a repeating triangle vertex combination in the vertex coordinate array;

The second is only the vertex coordinates in the polygon vertex coordinate array, does not provide the coordinates of the texture pixel of the point, nor provides the normal coordinates of the light reflection calculation when the light is illuminated to the top; however, WebGL provides two arrays corresponding to the vertex coordinate arrays, respectively. The texture coordinates and the normal coordinates of each vertex coordinate pair in the vertex coordinate array are respectively corresponding.


After a while, put down, pick up, from a little outside to see this problem,

First, for the use of vertex-indexed drawing, the actual drawing is from the Polygon Vertex index cache to find the drawing order, and the vertex coordinate cache is just a container, does not determine the order;

Second, the purpose of using Vertex index cache is to avoid the vertex coordinates of the repetition in the cache, and substituting the index of coordinates to reduce the footprint of GPU memory greatly;

Finally, this is actually a test code of someone else, the vertex coordinate array is stored that way, one is used when drawing without using index, is this called multiplexing? Haha, see how you understand, convenient Bai, at least the original author is very clear of the operating mechanism, so dare to write, to simplify the purpose of its testing, which also gave me a problem, but also because of this problem, let me in-depth understanding of some things. Second, I seem to see that it uses four points to represent a polygon that has not been drawn using an indexed method? Have you got any wood? I have not done OpenGL four-sided, not very well, experts may see it, at least not opengles, this in my understanding of the scope of people, I am sure! But, you do not forget, I understand the scope, I do not know more or less, so you do not be sure, or to consult the outdoor expert.


The joke is finished, actually really not good laugh, but I just understand when Hou, indeed the atmosphere is not out, stingy constantly hum a few sound, unexpectedly to is, Yuan Fang, how do you think? There's Wood there!





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.