LWJGL Forum

Programming => Bug Reports / RFE => Topic started by: intrigus on September 15, 2015, 19:24:03

Title: glGetBufferPointer() now returns long instead of a Buffer LWJGL2 -> 3
Post by: intrigus on September 15, 2015, 19:24:03
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?
Title: Re: glGetBufferPointer() now returns long instead of a Buffer LWJGL2 -> 3
Post by: spasi on September 15, 2015, 20:25:59
You have two options:

Code: [Select]
// 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);
Title: Re: glGetBufferPointer() now returns long instead of a Buffer LWJGL2 -> 3
Post by: intrigus on September 16, 2015, 15:40:25
Code: [Select]
// 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?
Title: Re: glGetBufferPointer() now returns long instead of a Buffer LWJGL2 -> 3
Post by: spasi on September 16, 2015, 15:54:39
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.