How does glBufferSubData offset work

Started by sublixt, April 15, 2012, 19:25:34

Previous topic - Next topic

sublixt

I am trying to use glBufferSubData to edit my vertex buffer object at runtime, but when I use any off set except 0L it causes really weird glitches.
This is the code I'm using to change the buffer.
public void subData(float bla[], long offset){
		bind();
		FloatBuffer buffer = BufferUtils.createFloatBuffer(bla.length);
		buffer.put(bla);
		buffer.flip();
		GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, offset, buffer);
		unbind();
	}

sublixt

I solved my problem. I didnt realize that offset was in bytes so that caused all my problems.
Here is the modified code if anyone cares for it.
public void subData(float data[], int offset){
		bind();
		FloatBuffer buffer = BufferUtils.createFloatBuffer(data.length);
		buffer.put(data);
		buffer.flip();
		GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, (long)(offset * 4), buffer);
		unbind();
	}