For the vast majority of images that you see, you do not need GL_ROW_LENGTH . Setting this value to a non-zero value can greatly degrade download performance; use it only when you absolutely need it.
For most images, the step will be just ( width * bpp ) aligned with some border. For example, if bpp is 3 (bytes per pixel) and the width is 9, you get 27. This is not a very good line number for many computers, so they often align it to the nearest multiple of 4. Thus, the height that you will see in most images equal to 28.
So, to calculate the alignment, simply calculate the highest power of two (up to 8), which are divided by height. If the image height is 28, the highest power is 4. Set the value to GL_UNPACK_ALIGNMENT . You can usually stay at 4 because most of the images will use the most alignment.
The time when you need to use GL_ROW_LENGTH is when the calculated step ( align(width * bpp, alignment) ) does not match the actual tash. If this happens, you need to use alignment and string length. But it is such a rare occurrence that you probably should simply discard any image that uses such an incredibly wrong step.
source share