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
It doesn't exist in ES 2.0.
Solutions in order from best to worst
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?
Load your images upside down, (libpng has that option)
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;
}
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:
js call gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true). WebGL store it as m_unpackFlipY.
js call gl.texImage2D, WebGL check m_unpackFlipY, if true, flip the image in memory, then call glTexImage2D
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With