Buffer Usage in LWJGL

Started by TeamworkGuy2, October 02, 2012, 22:01:18

Previous topic - Next topic

TeamworkGuy2

LWJGL uses Java.nio Buffers as parameters for various methods, in Java buffers are native memory wrapped in an object with internal fields like limit, capacity, etc.
Which of these buffer fields/values does LWJGL adhere to when a method like glBufferData() is called?

If I pass a buffer of allocated size 1MB to a LWJGL method that requires a buffer, but if I only fill the first 2800 bytes and set the limit to 2800, what does LWJGL read? All 1MB or just 2800 bytes?

In short, does LWJGL obey limit() or capacity() when uploading buffered data?

Thanks for your time  :)

Fool Running

Here is the code for glBufferData with a FloatBuffer. Notice it uses the remaining() method to determine how much data it has and uses position() to determine where to start reading data:
public static void glBufferData(int target, FloatBuffer data, int usage) {
		ContextCapabilities caps = GLContext.getCapabilities();
		long function_pointer = caps.glBufferData;
		BufferChecks.checkFunctionAddress(function_pointer);
		BufferChecks.checkDirect(data);
		nglBufferData(target, (data.remaining() << 2), data, data.position() << 2, usage, function_pointer);
	}
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

TeamworkGuy2

Ok, cool, I was afraid I was going to have to use slice() before uploading a buffer.
I guess I will just need to remember to set position() and limit() before send a buffer to LWJGL.
Thanks so much for your time and advice :)