views:

284

answers:

2

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);
A: 

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.

slurdge
+2  A: 

I don't recommend using byte/short cordinates on iPhone, especially if you're 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). 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. Unless you're very experienced engine coder, it'll never be the main bottleneck in your code.

Situation can probably be different for some other OGL-ES devices, since OpenGL pipline is partiolly 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.

noop