glBufferSubData : buffer limits

Started by mikage, January 27, 2009, 11:04:38

Previous topic - Next topic

mikage

I have questions concerning the method
GL15.glBufferSubData(int target, long offset, java.nio.FloatBuffer data)

and I haven't managed to find the answer anywhere.

1. Is the offset taken from the buffers current position or from the start of the buffer ?
2. Will the data being transfered stop at the buffers current limit or at the buffers capacity ?

Thanks for your help :)

Mikage

Matzon

code says:
public static void glBufferSubData(int target, long offset, FloatBuffer data)
  which maps to:
private static native void nglBufferSubData(int target, long offset, long size, Buffer data, int data_position, long function_pointer);
  which is called like this:
glBufferSubData(target, offset, (data.remaining()), data, data.position(), function_pointer);

I'm actually not sure what the relation between offset IS in this case ...

assuming a buffer with 4 elements, position = 2
then offset 2 would mean from the 4th elements, get data.remaining (which would be 2) == invalid.

*ponder*

VeAr

See: http://www.opengl.org/sdk/docs/man/xhtml/glBufferSubData.xml

The offset is in bytes where the data is to be copyed in the target buffer (eg VBO), and is not related to the source buffer. With a FloatBuffer (4 byte long elements) and offset =2 its the 3'rd byte of the first float, which wont give a meaningful result. The offset should always be in multiples of the element size.

Quote
An error is thrown if offset and size together define a range beyond the bounds of the buffer object's data store.

So OpenGL will throw an error, if too much data is provided in the buffer, but you should check it yourself beforehand.

mikage

Quote from: VeAr on January 27, 2009, 14:54:18
The offset is in bytes where the data is to be copyed in the target buffer (eg VBO), and is not related to the source buffer.

You're right I misread the documentation. :) From Matzon's post I understand that the buffers current position is used as a starting point to copy the data from the source buffer.

Quote from: Matzon on January 27, 2009, 12:02:17
code says:
public static void glBufferSubData(int target, long offset, FloatBuffer data)
  which maps to:
private static native void nglBufferSubData(int target, long offset, long size, Buffer data, int data_position, long function_pointer);
  which is called like this:
glBufferSubData(target, offset, (data.remaining()), data, data.position(), function_pointer);

I see, the size of the data to be transfered is given by the Buffer.remaining method. I'll check to see if a larger buffer causes an exception.

Thanks guys :)