2048 tiny triangles (to take fillrate out of the equation)
glBufferDataARB => 50ms
for (int i = 0; i < 256; i++)
{
javaSideBuffer.clear();
glBufferDataARB(GL_ARRAY_BUFFER_ARB, javaSideBuffer, GL_STREAM_DRAW_ARB);
glVertexPointer(3, GL_FLOAT, 0, 0);
glColorPointer(3, GL_FLOAT, 0, byteCount >> 1);
glDrawArrays(GL_TRIANGLES, 0, quadCount * 3 * 2);
}
glBufferSubData() => 50ms
glBufferDataARB(GL_ARRAY_BUFFER_ARB, byteCount, GL_STREAM_DRAW_ARB);
for (int i = 0; i < 256; i++)
{
javaSideBuffer.clear();
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, javaSideBuffer);
glVertexPointer(3, GL_FLOAT, 0, 0);
glColorPointer(3, GL_FLOAT, 0, byteCount >> 1);
glDrawArrays(GL_TRIANGLES, 0, quadCount * 3 * 2);
}
glMapBuffer() => 32ms
glBufferDataARB(GL_ARRAY_BUFFER_ARB, byteCount, GL_STREAM_DRAW_ARB);
for (int i = 0; i < 256; i++)
{
ByteBuffer driverSideBuffer;
driverSideBuffer = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB, null);
javaSideBuffer.clear();
driverSideBuffer.put(javaSideBuffer);
glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
glVertexPointer(3, GL_FLOAT, 0, 0);
glColorPointer(3, GL_FLOAT, 0, byteCount >> 1);
glDrawArrays(GL_TRIANGLES, 0, quadCount * 3 * 2);
}
And the boring code to fill the vertex array:
float quadSize = 5.0f;
int quadRepeat = 32;
int quadCount = quadRepeat * quadRepeat;
int byteCount = quadCount
* 2 /* triangles per quad */
* 3 /* vertices per triangle */
* 3 /* coordinates per vertex */
* 2 /* vertex+color */
* 4 /* float_sizeof */;
ByteBuffer javaSideBuffer = BufferUtils.createByteBuffer(byteCount);
// vertices
{
for (int x = 0; x < quadRepeat; x++)
{
for (int y = 0; y < quadRepeat; y++)
{
float x0 = (x + 1) * quadSize;
float y0 = (y + 1) * quadSize;
float x1 = (x + 2) * quadSize;
float y1 = (y + 2) * quadSize;
javaSideBuffer.putFloat(x0).putFloat(y0).putFloat(0.0f);
javaSideBuffer.putFloat(x1).putFloat(y0).putFloat(0.0f);
javaSideBuffer.putFloat(x1).putFloat(y1).putFloat(0.0f);
javaSideBuffer.putFloat(x1).putFloat(y1).putFloat(0.0f);
javaSideBuffer.putFloat(x0).putFloat(y1).putFloat(0.0f);
javaSideBuffer.putFloat(x0).putFloat(y0).putFloat(0.0f);
}
}
}
// colors
{
for (int x = 0; x < quadRepeat; x++)
{
for (int y = 0; y < quadRepeat; y++)
{
float[] cornerA = new float[] { 1, 0, 0 }; // red
float[] cornerB = new float[] { 0, 1, 0 }; // green
float[] cornerC = new float[] { 0, 0, 1 }; // blue
float[] cornerD = new float[] { 1, 1, 0 }; // yellow
for (float v : cornerA)
javaSideBuffer.putFloat(v);
for (float v : cornerB)
javaSideBuffer.putFloat(v);
for (float v : cornerC)
javaSideBuffer.putFloat(v);
for (float v : cornerC)
javaSideBuffer.putFloat(v);
for (float v : cornerD)
javaSideBuffer.putFloat(v);
for (float v : cornerA)
javaSideBuffer.putFloat(v);
}
}
}