samb90 samb90 - 1 year ago 97
iOS Question

pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);

I've been trying to find out what the equivalent of the line, UNPACK_FLIP_Y_WEBGL would be if using OpenGL ES. I have been unable to find a solution.

Could anyone please help me with finding an equivalent?


Answer Source

It doesn't exist in ES 2.0.

Solutions in order from best to worst

  1. Flip your images at compile time.

    This is what the pros do. Why waste memory and code and why make your user wait to flip an image if you don't have to?

  2. Load your images upside down, (libpng has that option)

  3. Flip after loading.

    assuming an RGBA 8bits per channel image the code to flip in place is something like

     void flipInPlace(unsigned char* data, int width, int height) {
       size_t line_size = width * 4;
       unsigned char* line_buffer = new unsigned char[line_size];
       int half_height = height / 2
       for (int y = 0; y < halfHeight) {
         void* top_line = data + y * line_size;
         void* bottom_line = data + (height - y - 1) * line_size;
         memcpy(line_buffer, top_line, line_size);
         memcpy(top_line, bottom_line, line_size);
         memcpy(bottom_line, line_buffer, line_size);
       delete [] line_buffer;