performance in *my* use of vertex arrays?

What do you guys think about using vertex arrays like what I have below?

This would get called each time my display() method is called, which I believe is each time my mouse moves just a single pixel to rotate the model. So dragging would call it quite often. Specifically, is it ok to use vertex arrays the way I have below, where I populate it w/ an individual triangle, and draw it … or should I build a vertex array the size of my complete triangle list and then draw that.

What I have now sure seems like a lot of loop iterations to go through (10,000 * each triangle side) each time my mouse moves just one pixel. I’m starting to think this isn’t the correct way to use vertex arrays. See how I draw individual triangles. I’m wondering if this is why my model doesn’t move as smooth as it should/could.

Code is cut down just for understanding.


buffer = BufferUtils.newFloatBuffer(9);

// hashmap normally has between 10,000 and 100,000 line edges in it.
Iterator eKeyIter = myHashMap.keySet().iterator();

while (eKeyIter.hasNext()) {
	// ...
	for (int i = 0; i < TRIANGLE_CNT; i++) {
		// ...
		vElementsBuffer.put(idx++, (float) getX());
		vElementsBuffer.put(idx++, (float) getY());
		vElementsBuffer.put(idx++, (float) getZ());
	}

	gl.glVertexPointer(3, GL.GL_FLOAT, 0, vElementsBuffer);
	gl.glDrawArrays(GL.GL_TRIANGLES, 0, 8);
}

That is a dreadful use of vertex arrays. The point is to send a bunch of geometry with a single call. Drawing only a single primitive defeates its purpose.

Create a buffer that holds lets say 1000 of primitives. Fill the buffer and draw it until there is no more triangles left. Create the buffer once at init. Creating direct buffers is expensive and is something you want to avoid.

But does the data change at all? If it do not you can create the buffer at the beginning and reuse it. No need to iterate the triangles every frame.