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
vertexData.put(vertices);
vertexData.flip();
//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?
Why not just use an
ArrayListto generate your data, copy the vertices into aFloatBuffer, and then use that?