How important is alignment in opengl vertex data in iOS

♀尐吖头ヾ 提交于 2019-12-08 16:51:38

问题


The OpenGL ES Programming guide discusses that you should avoid misaligned vertex data and gives an example of aligning the data to 4 byte blocks.

OpenGL ES Programming Guide

However in most demo material and tutorials I've found online I don't see anyone doing this. Example below is from a demo project on 71 Squared:

static const SSTexturedVertexData3D EnemyFighterVertexData[] = {
    {/*v:*/{1.987003, -0.692074, -1.720503}, /*n:*/{0.946379, -0.165685, -0.277261}, /*t:*/{0.972816, 0.024320}},

And how would you do it anyway? Add a dummy 0.0 to the v and n and 2 of them to the t?

My guess is that if you're only loading the vertex data once per app it wouldn't matter much but if your binding and rebinding to different arrays on each rendered frame it would matter. My plan is to combine all my arrays into one anyway, but I'm curious.


回答1:


General a vertex is made up of floats which are going to be aligned, so you don't need to get too concerned with that. In fact a lot of books use ordinary structs to hold vertex data, which are not guaranteed to be contiguous due to the padding issue, but if all you have are floats, that's fine since you aren't likely to have padding. Of course, some people (myself included) prefer to use the STL vector from C++ but if you are on iOS, while you can use C++ you are probably using Objective-C thus contiguity in a non-struct way would involve normal C arrays which are not so fun to work with.

If you create custom structures to hold vertex data as well as other data for your drawable object, and you use shorts or other types, you might find padding to become an issue. But if you stick with only floats you will be fine, and you will be in good company since most educational sources on OpenGL do this.



来源:https://stackoverflow.com/questions/12819188/how-important-is-alignment-in-opengl-vertex-data-in-ios

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