Take the 2-minute tour ×

In a voxel game I'm making, I'm using VBO's for rendering the world. I' use somthing like this to send the vertices to the GPU:

    FloatBuffer vertexData = BufferUtils.createFloatBuffer(..?);

    float[] vertices = new float[..?];

    //vertex calculations go here


    //send the vertices
    int vboVertexHandle = glGenBuffers();
    glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
    glBufferData(GL_ARRAY_BUFFER, vertexData, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

However, the vertices are calculated dynamically, and there is no way to know how many I will be rendering beforehand. So I don't know how much space to allocate to the FloatBuffer and to the array.

I thought using ArrayList's but it seems slow and unefficient. Is there any way I can make an array or a FloatBuffer without specifying a size? Or sending the data to the GPU as the vertices are calculated, instead of sending them all in the end?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted


Why not just use an ArrayList to generate your data, copy the vertices into a FloatBuffer, and then use that?

share|improve this answer
You mean ArrayList? –  Luis Cruz Nov 10 '12 at 17:08
@LuisCruz: Yes. –  Nicol Bolas Nov 10 '12 at 17:09
Thanks, I'll try that. –  Luis Cruz Nov 10 '12 at 17:12
add comment

Your Answer


