Reputation: 158
I'm doing some stuff with OpenGL in Java using JOGL and I came across something that surprised me.
There is two glReadPixel functions that points to the same C implementation.
The first one is :
glReadPixels(int x, int y, int width, int height, int format, int type, Buffer pixels)
I understand how it works compared to the C binding but the second one :
glReadPixels(int x, int y, int width, int height, int format, int type, long pixels_buffer_offset)
How can it convert a void* to a long ? Are we really getting the pixels within a long ?
I really do not understand the second binding. I have done some googling and I just found out everyone is using the first one ...
Upvotes: 0
Views: 72
Reputation: 54592
The second binding would be used if you want to read the result into a PBO (Pixel Buffer Object). In that case, the last argument is an offset into the buffer. If a buffer is bound to GL_PIXEL_PACK_BUFFER
, the last argument of glReadPixels()
specifies an offset relative to the start of this buffer.
This is very similar to glVertexAttribPointer()
, where the last argument is overloaded in the C/C++ bindings, but Java needs two bindings because it is more type safe. In that case, if a GL_ARRAY_BUFFER
binding exists, the last argument is an offset relative to the start of the VBO, otherwise it's a pointer to the data.
Upvotes: 1