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
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 256×256 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.