I am in the making of this game in java,
It runs at 30fps(capped).
As a benchmark, I removed the cap and got 92-97fps…
This was with a BufferedImage…
Then i changed it to VolatileImage, it now runs at 192-197fps…
That was a 100fps increase, that’s just badass
So i have added the following code at the beginning of the rendering code to initialize the BufferGraphics:
if(vBuffer == null && useGPU) {
vBuffer = RandomRPG.GamePanel.createVolatileImage(800, 600);
BufferGraphics = vBuffer.createGraphics();
BufferGraphics.setBackground(Color.BLACK);
BufferGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
} else if(Buffer == null && !useGPU) {
Buffer = new BufferedImage(800, 600, 2);
BufferGraphics = Buffer.createGraphics();
BufferGraphics.setBackground(Color.BLACK);
BufferGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
, and at the end:
if(useGPU) {
g.drawImage(vBuffer, 0, 0, RandomRPG.GamePanel.getPreferredSize().width, RandomRPG.GamePanel.getPreferredSize().height, null);
vBuffer.flush();
} else {
g.drawImage(Buffer, 0, 0, RandomRPG.GamePanel.getPreferredSize().width, RandomRPG.GamePanel.getPreferredSize().height, null);
Buffer.flush();
}
Toolkit.getDefaultToolkit().sync();
This way i can choose either to use the GPU or not…
PS:
CPU Usage was around 17-20% on an Intel Core i5-2540M 2.6GHz 2-Core, 4-Logical Processors
when i used the BufferedImage…
But when i used the VolatileImage, this sank to about 6-7%…
That is because now the GPU is used to take the load of the CPU.
Now i can have lots more stuff in the GameLoop