LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: elias4444 on October 29, 2008, 21:40:36

Title: Best way to update information for VBO?
Post by: elias4444 on October 29, 2008, 21:40:36
I'm finally implementing 3D model animation and am interpolating between keyframes. I'm just wondering if I'm using java FloatBuffers correctly for this.

Each frame, I need to update the VBO coordinates and normals data. I thought I could loop through the floatBuffer doing something like this:

for (int i=0;i<coordinates.length;i++) {
    float newcoordinate = coordinates[i];
    floatBuffer.put(i, newcoordinate);
}


But that gives me a java.lang.IndexOutOfBoundsException (either 0, with the above example, or the high number with "i" reaches it's limit), so instead I'm doing this:


floatBuffer.clear();
for (int i=0;i<coordinates.length;i++) {
    float newcoordinate = coordinates[i];
    floatBuffer.put(newcoordinate);
}


I'm mostly worried about the overhead of clearing the FloatBuffer every frame. Or is this just the way it's meant to be done?

Any help is appreciated! Thanks!
Title: Re: Best way to update information for VBO?
Post by: princec on October 29, 2008, 22:45:53
clear() doesn't have any overhead, it just resets a couple of pointers.

Cas :)
Title: Re: Best way to update information for VBO?
Post by: elias4444 on October 30, 2008, 02:59:29
Well that's good news. That means I'm done.  ;D

Always a good feeling.

Thanks!