Skip to content
Advertisement

LWJGL: glMapBuffer/Range what is the use of old buffer?

//length > 0 for all cases
ByteBuffer oldBuffer=BufferUtils.createByteBuffer(length);
ByteBuffer newBuffer=GL30.glMapBufferRange(GL15.GL_ARRAY_BUFFER,0,length,GL30.GL_MAP_READ_BIT ,oldBuffer);
   
for(int i=0;i<length;i++){System.out.println(oldBuffer.get(i));}
System.out.println();

It prints out all zero’s but the new buffer contains the correct data which is fine. And if i specify null as parameter for the old buffer it works fine too.

So is there any optimization/memory saving being done behind the scenes when using an non null old buffer? The output is the same for LWJGL 2.9.3 and 3.1.3

Advertisement

Answer

This is an LWJGL-specific optimization. It is intended to avoid having to allocate a new NIO Buffer object pointing to the mapped address in case when OpenGL returns the same address that was previously returned as a NIO Buffer, that you now provide as old_buffer.

See also in the LWJGL 3 sources of GL15C.glMapBuffer() as well as the called APIUtil.apiGetMappedBuffer().

However, when the OpenGL driver decides to map the buffer memory to another virtual address, then you still will get a new/fresh NIO Buffer instance.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement