LWJGL Forum

Programming => OpenGL => Topic started by: TeamworkGuy2 on October 02, 2012, 22:01:18

Title: Buffer Usage in LWJGL
Post by: TeamworkGuy2 on October 02, 2012, 22:01:18
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  :)
Title: Re: Buffer Usage in LWJGL
Post by: Fool Running on October 03, 2012, 12:34:07
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);
}
Title: Re: Buffer Usage in LWJGL
Post by: TeamworkGuy2 on October 03, 2012, 12:48:37
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 :)