Hi everyone,
somehow I don’t get it: If I use a BufferStrategy with more than 2 Buffers how do I get an instance of Graphics for the backbuffers other than the one that will be displayed next.
Say we got 4 buffers. Buffer 0 is being showed, Buffer 1 has been done and now I want to render on Buffer 2 but I don’t want to show buffer 1 already because I want a constant framerate of 30. (grr 3x want :-X )
If that’s not possible what is the sense of more than 3 buffers?
living in the past -> use 1 buffer
no tearing -> use 2 buffers
no wait for vsync -> use 3 buffers
4 and more buffers would behave the same as 3 buffers (not?)
My basic intention:
Assume we are using n buffers. There are n-1 buffers left for “prerendering”. If I have a constant fps=30 my rendercode has to be able to render n-1 frames in the time (1s/30)*(n-1) which ist not the same limitation as 1 frame in the time (1s/30) because one of these n-1 frames could have been a bit more complex and another one less: 3/60 seconds+1/60 second = 4/60=2/30 seconds. In this example though one took too long both together didn’t take too long -> smooth fps. (If we are lucky.)
See what I mean? Or see what I miss ???
I read the following: http://java.sun.com/docs/books/tutorial/extra/fullscreen/example-1dot4/MultiBufferTest.java
They say it’s a “MultiBufferTest”?! I don’t think that it tests multiple buffers. Their render loop:
BufferStrategy bufferStrategy = mainFrame.getBufferStrategy();
for (float lag = 2000.0f; lag > 0.00000006f; lag = lag / 1.33f) {
for (int i = 0; i < numBuffers; i++) {
Graphics g = bufferStrategy.getDrawGraphics();
if (!bufferStrategy.contentsLost()) {
g.setColor(COLORS[i]);
g.fillRect(0,0,bounds.width, bounds.height);
bufferStrategy.show();
g.dispose();
}
try {
Thread.sleep((int)lag);
} catch (InterruptedException e) {}
}
}
This code changes the color on the screen always the same way no matter how many buffers it really uses?! Doesn’t it?
It could check the existence of n buffers if it did only color every buffer once and than never again. But still loop through bufferStrategy.show().
I am not sure wether I’d know what I am asking if it weren’t myself ;D
LastBoyScout