Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

Regards

like image 579
samb90 Avatar asked Mar 12 '13 14:03

samb90


2 Answers

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;
     }
    
like image 79
gman Avatar answered Oct 04 '22 04:10

gman


there is no UNPACK_PREMULTIPLY_ALPHA_WEBGL and UNPACK_FLIP_Y_WEBGL in OpenGL ES.

In implementation, WebGL call OpenGL ES to implement js WebGL call, and for these two parameters, WebGL will process on CPU before call OpenGL ES API, which means WebGL using memcpy to flip the image(if flipY is true), then call glTexImage2D.

Summary:

  1. js call gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true). WebGL store it as m_unpackFlipY.

  2. js call gl.texImage2D, WebGL check m_unpackFlipY, if true, flip the image in memory, then call glTexImage2D

like image 45
lbsweek Avatar answered Oct 04 '22 04:10

lbsweek