some vbo questions

i created a vbo, and i am able to draw it. so far, so good.
but how can i release the memory it uses ?

this code


   public void releaseVBO(GL gl)
   {
      if (isVBO)
      {
         gl.glDeleteBuffersARB(GL.GL_ARRAY_BUFFER_ARB, ivec);
         if (hasNormals)
         {
            gl.glDeleteBuffersARB(GL.GL_ARRAY_BUFFER_ARB, iNorm);
         }
         if (hasColors)
         {
            gl.glDeleteBuffersARB(GL.GL_ARRAY_BUFFER_ARB, iCol);
         }
         if (hasFog)
         {
            gl.glDeleteBuffersARB(GL.GL_ARRAY_BUFFER_ARB, iFog);
         }
         if (hasUnit0TexCoords)
         {
            gl.glClientActiveTextureARB(GL.GL_TEXTURE0_ARB);
            gl.glDeleteBuffersARB(GL.GL_ARRAY_BUFFER_ARB, itex0);
         }
         if (hasUnit1TexCoords)
         {
            gl.glClientActiveTextureARB(GL.GL_TEXTURE1_ARB);
            gl.glDeleteBuffersARB(GL.GL_ARRAY_BUFFER_ARB, itex1);
         }
         if (hasUnit2TexCoords)
         {
            gl.glClientActiveTextureARB(GL.GL_TEXTURE2_ARB);
            gl.glDeleteBuffersARB(GL.GL_ARRAY_BUFFER_ARB, itex2);
         }
         if (hasUnit3TexCoords)
         {
            gl.glClientActiveTextureARB(GL.GL_TEXTURE3_ARB);
            gl.glDeleteBuffersARB(GL.GL_ARRAY_BUFFER_ARB, itex3);
         }
      } else
      {
         throw new UnsupportedOperationException("Cannot free VBOs - not allocated");
      }
   }

ends up in an excpetion in native code
ivec is an int[1], which is used like this :


gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, ivec[0]);
         gl.glVertexPointer(3, GL.GL_FLOAT, 0, null );

and


gl.glGenBuffersARB(1, ivec);
         gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, ivec[0]);
         gl.glBufferDataARB(GL.GL_ARRAY_BUFFER_ARB,  vecNum * 3 * 4, fbVec,GL.GL_STATIC_DRAW_ARB );

next question : i need to update the vertex data sometimes (once per minute or so)
can i just overwrite the buffer data, or do i have to delete the old buffers first ? (the amount of vertices remains the same, only the position changes)

hi,

try
gl.glDeleteBuffersARB(1, ivec);
instead of
gl.glDeleteBuffersARB(GL.GL_ARRAY_BUFFER_ARB, ivec);

first param is the number of elements in you ivec-array, not the type of VBO you want to delete. I got confused there the first time as well. On developer.nvidia.com, there’s a pretty good paper about VBO’s and how to use them.
I think they also say something about updates. You can map the VBO’s memory in vram to a ByteBuffer (that can be wrapped in a FloatBuffer), so you can write to it directly (glMapBufferARB, I think More in the mentioned paper @nvidia)

If the data just switches between several states, you might be better of using several VBO’s.

Hope I was of some help.

Jan