offset for Vertex Buffer Objects

Hello,

I’m currently trying to implement the geomipmapping LOD technique for a heightmap based terrain using jogl as OpenGL wrapper.
The technique basically divides the terrain into quadratic tiles and then renders, depending on distance from viewer, the tile with different resolutions (e.g. leaving out every second vertex, etc). Since there is only a fixed number of resolutions (and the vertices used stay the same), I want to create an index-array (stored in graphics memory with VBO-support) for each one.

The vertices of the terrain are all put in a single VBO, first the vertices of the first chunk, then for the second and so on.

Since the chunks are all organized in the same way, I could use the same set of index arrays for all of them, if I can specify and offset in the glVertexPointer call (which works in C, according to the spec).

Currently I’m using something like this:

gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, vboID);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, (Buffer)null);

and what I would like to to is something like this
gl.glVertexPointer(3, GL.GL_FLOAT, 0, (Buffer)null + chunk*chunksize);

Is it possible to do this somehow in java?

I hope I could make clear what my problem is. Any ideas would be greatly appreciated.

Jan Eickmann

P.S.: Same thing applies to “normal” vertex arrays. I have to have them as a fallback, since apple has not yet implemented the Vertex Buffer Objects ARB extension in their drivers.

JOGL BufferUtils contain convenience method for that:

public static ByteBuffer bufferOffset(int offset);

JavaDoc from JOGL sources:

[quote]Creates an “offset buffer” for use with the ARB_vertex_buffer_object extension. The resulting Buffers are suitable for use with routines such as glVertexPointer when used in conjunction with that extension. They have no capacity and are not suitable for passing to OpenGL routines that do not support buffer offsets, or to non-OpenGL routines.
[/quote]
Yuri

Hello,

thank you very much, that should work very well for the VBO’s (didn’t see it, should read the docs more :slight_smile: )

That just leaves the fallback version with vertex arrays, where I pass a “real” Buffer Object.
Here, I also would need to add an offset, but I still have no idea how. Of course, I could always put the chunks in different arrays, but this adds even more code that’s different between VBOs and the fallback. Any ideas?

Jan

Again, the question concerning the “normal” Vertex-Array solution:
How to give an offset into a vertex array passed with glVertexPointer?

e.g.:

FloatBuffer vb = BufferUtils.newFloatBuffer(…)

gl.glVertexPointer(…, vb)

and I want it to start at element 500.

vb.position(500)
and even an additional vb.mark() didn’t do it.

Any suggestions?
I would really appreciate it, since I want to keep the code between VBOs and vertex arrays as similar as possible.

Jan

First buffer.position(…) then buffer.slice() should do the trick.

[quote]First buffer.position(…) then buffer.slice() should do the trick.
[/quote]
Thanks, that did it.