VBO - 没有索引的索引 [英] VBO - Indexation without indexation

查看:320
本文介绍了VBO - 没有索引的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将VBO与Element Array Buffer一起用于我的三角形,如下所示:

I'm trying to use the VBO with a Element Array Buffer for my triangle, like this :

 glBindBuffer(GL_ARRAY_BUFFER, g_Buffer[0]);    
 glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
 glNormalPointer(GL_FLOAT, 0, BUFFER_OFFSET(Model->GetNbVertex()*3*sizeof(float)));

 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_Buffer[1]);
 glDrawElements(GL_TRIANGLES, Model->GetNbTriangle()*3, GL_UNSIGNED_INT, BUFFER_OFFSET(0));

但我想使用一些纹理坐标,但我的TextCoord 不是心甘情愿
已编入索引

But I wanna use some Texture Coord, but my TextCoord isn't willingly "indexed"

三角形有3个文本坐标。
我有N个顶点和M个三角形,所以我有3M文本坐标, 3N TextCoord。所以我不能使用glTexCoordPointer,因为他期望一个顶点只有一个文本坐标,而不是我的情况。

A triangle have 3 Text coords. I have N vertexs, and M Triangles, so i have 3M Text Coord, and not 3N TextCoord. So i can't use glTexCoordPointer because he's expecting that a vertex have a only one text coord, and it's not my case.

我想保持我的顶点的索引到不要爆炸我的GPU内存。

I wanna keep the indexation of my vertex to don't explode my GPU memory.

有一种方法可以使用三角形索引来处理像顶点这样的元素而不是其他元素,比如我的文本坐标? (我正在使用GLSL)

There is a way to use Triangle Indexation for some element like vertex and not for other, like my text coord ? (I'm using GLSL)

推荐答案


所以我不能使用glTexCoordPointer,因为他期待那样一个顶点只有一个文本坐标...

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

... 每个纹理单位。激活另外两个TU,并为每个TMC调用 glTexCoordPointer()

...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.

这篇关于VBO - 没有索引的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆