VBO - Indexation without indexation

天大地大妈咪最大 提交于 2019-12-02 04:05:47

Let me clarify the following for you

A triangle have 3 Text coords. I have N vertexs, and M Triangles, so i have 3M Text Coord, and not 3N TextCoord.

A triangle has 3 vertices. A vertex is a vector consisting of several attributes; it's a common misconception that a vertex was just the position! A vertex is in fact the whole combination of all the attributes it consists of. And if two vertices differ in only one of their attributes, they're different vertices.

In your case the attributes are

  • position
  • texture coordinate

So when you say you have M triangles, then this implies that you have 3N vertices – except for the corner case that some of the triangles share vertices, which means that they share all their attributes.

Or in other words: You always have exactly as many texture coordinates as you have vertices, because the texture coordinate is part of the vertex.

Update

Some mesh formats separate the vertex attributes into independtly indexed lists of attributes, like position, normal, texture coordinate. Usually those lists are then indexed from faces. If you want to draw the contents of such a mesh data structure you first have to expand it into a single indexed list of vertices. The usual way in doing so is iterating over all faces of the mesh and use the tuple of indices as a key into a list of new substitution indices. Then for each key encountered the attributes are collected from the various attribute lists into a single vertex indexed by the substitution index.

So i can't use glTexCoordPointer because he's expecting that a vertex have a only one text coord...

...per texture unit. Activate two more TUs and call glTexCoordPointer() for each:

glVertexPointer( ... );
glNormalPointer( ... );

glActiveTexture( GL_TEXTURE0 + 0 );
glClientActiveTexture( GL_TEXTURE0 + 0 );
glBindTexture( ..., texture1 );
glTexCoordPointer( ..., FIRST_OFFSET );

glActiveTexture( GL_TEXTURE0 + 1 );
glClientActiveTexture( GL_TEXTURE0 + 1 );
glBindTexture( ..., texture2 );
glTexCoordPointer( ..., SECOND_OFFSET );

glActiveTexture( GL_TEXTURE0 + 2 );
glClientActiveTexture( GL_TEXTURE0 + 2 );
glBindTexture( ..., texture3 );
glTexCoordPointer( ..., THIRD_OFFSET );

glDrawElements( ... );

EDIT: Though for maximum flexibility and forward compatibility just use generic vertex attributes for both the vertex position and the three texture coordinates.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!