import java.nio.IntBuffer;
import java.nio.ByteBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.PixelFormat;
public class TextureUploadBenchmark
{
public static void main(String[] args) throws Exception
{
Display.setTitle("Texture Upload Benchmark");
Display.setFullscreen(false);
Display.create();
GL11.glClearColor(0, 0, 1, 1);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
Display.update();
GL11.glEnable(GL11.GL_TEXTURE_2D);
int dim = 1024;
int count = 16;
System.out.println("Texture-Upload Benchmark");
System.out.println();
System.out.println(" Texture dimension: " + dim);
System.out.println(" Number of textures per run: " + count);
System.out.println();
System.out.println(" Results:");
System.out.println(" - LUMI: " + benchmarkUpload(dim, GL11.GL_LUMINANCE, count) + "ms / texture");
System.out.println(" - RGB: " + benchmarkUpload(dim, GL11.GL_RGB, count) + "ms / texture");
System.out.println(" - RGBA: " + benchmarkUpload(dim, GL11.GL_RGBA, count) + "ms / texture");
System.out.println();
System.out.println("Done.");
Display.destroy();
}
private static final float benchmarkUpload(int dim, int format, int count)
{
int bytesPerPixel = -1;
switch (format)
{
case GL11.GL_LUMINANCE:
bytesPerPixel = 1;
break;
case GL11.GL_RGB:
bytesPerPixel = 3;
break;
case GL11.GL_RGBA:
bytesPerPixel = 4;
break;
}
ByteBuffer buf = BufferUtils.createByteBuffer(dim * dim * bytesPerPixel);
IntBuffer idBuf = BufferUtils.createIntBuffer(count);
GL11.glGenTextures(idBuf);
long t0 = System.currentTimeMillis();
for (int i = 0; i < count; i++)
{
GL11.glBindTexture(GL11.GL_TEXTURE_2D, idBuf.get(i));
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, format, dim, dim, 0, format, GL11.GL_UNSIGNED_BYTE, buf);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
}
long t1 = System.currentTimeMillis();
GL11.glDeleteTextures(idBuf);
float took = (t1 - t0) / (float) count;
// format to 1 decimal
return ((int) (took * 10)) / 10.0F;
}
}
Output for:
ATi Radeon 9700 PRO
Texture-Upload Benchmark
Texture dimension: 1024
Number of textures per run: 16
Results:
- LUMI: 3.8ms / texture
- RGB: 229.5ms / texture
- RGBA: 15.6ms / texture
Done.