English 中文(简体)
What data type should I use for my texture coordinates in OpenGL ES?
原标题:

I notice that the default data type for texture coordinates in the OpenGL docs is GLfloat, but much of the sample code I see written by experienced iphone developers uses GLshort or GLbyte. Is this an optimization?

GLfloat vertices[] = {    
  // Upper left
  x1, y2,
  // Lower left
  x1, y1,
  // Lower right
  x2, y1,
  // Upper right
  x2, y2,
};
glTexCoordPointer(2, GL_FLOAT, 0, iconSTs);

vs.

GLbyte vertices[] = {    
  // Upper left
  x1, y2,
  // Lower left
  x1, y1,
  // Lower right
  x2, y1,
  // Upper right
  x2, y2,
};
glTexCoordPointer(2, GL_BYTE, 0, iconSTs);
最佳回答

I don t recommend using byte/short cordinates on iPhone, especially if you re a beginner. Just use floats. They take more space, but it doesn t matter until you need to render thousands of vertices at maximum speed. Also, you ll have to change texture matrix to represent fractional values with integer texture coords, otherwise they ll only point to texture corners (0, 1). This adds complexity to your code.

I believe they are NOT faster by themselves, at least on iPhone. They can be somewhat faster because of smaller memory bandwidth necessary to read thousands of them in a single call. This optimization isn t worth doing if you writing your first engine. Unless you are a very experienced engine coder and going to push the hardware to its limits, this will never be the main bottleneck in your code, bringing negligible performance benefits.

Situation can probably be different for some other OGL-ES devices, since OpenGL pipline is partially implemented in software and some devices lack FPU and therefore unable to process floats quickly. That s why some Android games try to avoid float type altogether (in 2009).

问题回答

GLFloat vs. GLByte is a matter a size taken by your vertices.
In OpenGL, you can specify which is the underlying datatype of your geometry.
I did not program on iphone, but I m pretty sure they do it to save space (and maybe computation time).
Float is 4 bytes, short is 2 bytes, byte is... 1 byte :)
Of course you loose precision with less bits.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签