How to use different indices for tex coords array and vertex array using glDrawElements

删除回忆录丶 提交于 2021-01-27 07:10:00

问题


I've been trying to use glDrawElements in my tile-based 2D OpenGL game. However when I draw the tiles, the tex coords may be different for different faces at the same vertex: For example, here the texcoords will be different for the 2 quads at the common vertex:

___|
___|___
   |___
   |___

The problem is that glDrawElements takes only one index array and so it appears that I can only use one tex coord per vertex. Is there any way to overcome this limitation?


回答1:


Short answer: You don't. You instead break your vertices down into unique vertices, so that you can have a single index list for every attribute. If you have multiple index lists, you need to walk that list of indices, replicating attribute data (positions, texture coordinates, etc) for any set of indices that is not repeated.

Long answer: You shouldn't.

With modern hardware capabilities techniques (buffer textures in OpenGL 3.x and/or shader image load/store in 4.x), you can subvert the attribute pipeline entirely and load data arbitrarily from buffer objects. However, you should not expect this to be nearly as fast as just doing things the right way.

Unless you have some well-defined need to do it this way (and I don't just mean your model format provides data like this), you're better off doing things properly. Remember: this is something every graphics application that uses arrays in rendering has done for the last decade and a half. You won't be missing out on any special hardware features or anything.



来源:https://stackoverflow.com/questions/6964648/how-to-use-different-indices-for-tex-coords-array-and-vertex-array-using-gldrawe

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