glGetBufferPointer() now returns long instead of a Buffer LWJGL2 -> 3

Started by intrigus, September 15, 2015, 19:24:03

Previous topic - Next topic

intrigus

LWJGL 2 returned a Buffer when using http://javadoc.lwjgl.org/org/lwjgl/opengl/GL15.html#glGetBufferPointer(int,%20int) .
But LWJGL 3 only returns a long.

It looks like I could simply copy and paste https://github.com/LWJGL/lwjgl3-generated/blob/master/java/org/lwjgl/opengl/GL15.java#L583-L588 and remove pointerValue(params) from
return __buffer.pointerValue(params);

Is this possible or could you also generate a version of glGetBufferPointer() that returns a Buffer?

spasi

You have two options:

// option 1
PointerBuffer params = BufferUtils.createPointerBuffer(1);
glGetBufferPointerv(GL_ARRAY_BUFFER, GL_BUFFER_MAP_POINTER, params);
ByteBuffer buffer = params.getByteBuffer(0, size);

// option 2 (more efficient)
ByteBuffer buffer = MemoryUtil.memByteBuffer(glGetBufferPointer(GL_ARRAY_BUFFER, GL_BUFFER_MAP_POINTER), size);

intrigus

Quote from: spasi on September 15, 2015, 20:25:59
// option 1
PointerBuffer params = BufferUtils.createPointerBuffer(1);
glGetBufferPointerv(GL_ARRAY_BUFFER, GL_BUFFER_MAP_POINTER, params);
ByteBuffer buffer = params.getByteBuffer(0, size);

// option 2 (more efficient)
ByteBuffer buffer = MemoryUtil.memByteBuffer(glGetBufferPointer(GL_ARRAY_BUFFER, GL_BUFFER_MAP_POINTER), size);

Thank you for answering, but I have some questions:
What is size in option 2?
The docs say that there also other values than GL_ARRAY_BUFFER, why do you only use GL_ARRAY_BUFFER?

spasi

This was just an example, you can of course use other targets.

The size argument must be specified to create a buffer with a finite capacity. It should be <= to the size of the buffer being queried. Note that both options have it, not only option 2.