2

I've just seen a texture example which contains the code:

GLubyte pixels[4 * 3] =
{
  255,  0,   0,  // Red
  0,  255,   0,  // Green
  0,    0, 255,  // Blue
255,  255,   0   // Yellow
};

// Use tightly packed data.
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

Wouldn't it be better to additionally store one padding component per pixel, and specify 4-byte alignment?

I'm asking out of interest in performance.

Many thanks

KomodoDave
  • 7,239
  • 10
  • 60
  • 92

1 Answers1

1

i was toying arround with it for a while, and came to (expected) conclusion. It is a little bit (about 10% faster) to have 4-byte aligned pixels if loading native pixel format (eg, RGB565 or RGB5_A1). It is only a little bit faster (like 1%) when loading other pixel formats (RGB8 or RGBA8).

This was the same with PC-class graphics cards, if one was loading native BGRA8 (NVIDIA), the alignment could make any difference, but in case the driver needed to swizzle the data or perform bit shifting, it wouldn't make so big difference.

I was testing loading 256x256 RGB texture with 3 or 4 byte align, 100 times. The textures were deleted between the tests. The tests contained glFlush() and glFinish() so there would not be pending out-of-order operations.

the swine
  • 10,713
  • 7
  • 58
  • 100
  • Nice! I'd forgotten I asked this, am glad you got back to me though as I've literally just written my first texture atlas for which it could be handy to know this :) Many thanks. – KomodoDave Jan 16 '12 at 12:21