带有交错缓冲区的openGL glDrawElements [英] openGL glDrawElements with interleaved buffers

查看:117
本文介绍了带有交错缓冲区的openGL glDrawElements的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我只使用了glDrawArrays,想继续使用索引缓冲区和索引三角形.我正在绘制带有纹理坐标,法线和顶点坐标的有点复杂的对象.所有这些数据都收集到一个交错的顶点缓冲区中,并使用类似于(假定所有serup正确完成的)调用进行绘制:

Thus far i have only used glDrawArrays and would like to move over to using an index buffer and indexed triangles. I am drawing a somewhat complicated object with texture coords, normals and vertex coords. All this data is gathered into a single interleaved vertex buffer and drawn using calls similar to ( Assuming all the serup is done correctly ):

glVertexPointer( 3, GL_FLOAT, 22, (char*)m_vertexData );
glNormalPointer( GL_SHORT, 22, (char*)m_vertexData+(12) );
glTexCoordPointer( 2, GL_SHORT, 22, (char*)m_vertexData+(18) );
glDrawElements(GL_TRIANGLES, m_numTriangles, GL_UNSIGNED_SHORT, m_indexData );

这是否允许m_indexData也与我的法线和纹理坐标的索引以及标准位置索引数组交错?还是假设单个线性线性清单适用于整个顶点格式(POS,NOR,TEX)?如果后者为真,那么如何用不同的纹理坐标或法线来渲染相同的顶点?

Does this allow for m_indexData to also be interleaved with the indices of my normals and texture coords as well as the standard position index array? Or does it assume a single linear list of inidices that apply to the entire vertex format ( POS, NOR, TEX )? If the latter is true, how is it possible to render the same vertex with different texture coords or normals?

我想这个问题也可以表述为:如果我有3个单独的索引列表(POS,NOR,TEX),其中后两个不能重新排列以与第一个共享相同的索引列表,那么最好的方法是渲染出来.

I guess this question could also be rephrased into: if i had 3 seperate indexed lists ( POS, NOR, TEX ) where the latter 2 cannot be rearranged to share the same index list as the first, what is the best way to render that.

推荐答案

对于不同的列表,您不能具有不同的索引.当您指定glArrayElement(3)时,OpenGL将采用每个列表的第三个元素.
您可以做的就是使用您指定的指针,因为实际上在列表中最终可以访问的位置是指针从列表开头的偏移量加上指定的索引.如果列表之间的偏移量恒定,这将很有用.如果列表只是一个随机排列,那么每个顶点的这种播放就和使用普通的glVertex3fv()glNormal3fv()glTexCoord3fv()

You cannot have different indexes for the different lists. When you specify glArrayElement(3) then OpenGL is going to take the 3rd element of every list.
What you can do is play with the pointer you specify since essentially the place in the list which is eventually accessed is the pointer offset from the start of the list plus the index you specify. This is useful if you have a constant offset between the lists. if the lists are just a random permutation then this kind of play for every vertex is probably going to be as costy as just using plain old glVertex3fv(), glNormal3fv() and glTexCoord3fv()

这篇关于带有交错缓冲区的openGL glDrawElements的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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