Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (711)
Games in Android Showcase (213)
games submitted by our members
Games in WIP (785)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  About multiple buffers when using BufferStrategy  (Read 4677 times)
0 Members and 1 Guest are viewing this topic.
Offline Seb

Senior Newbie

import com.acme.Bomb;

« Posted 2002-11-01 20:52:31 »

I would like to know what reason there is to support more than a single back buffer when using a bufferstrategy.

As far as I know this has 2 uses, both of which are apparently not possible with the API as it stands.

The first use is, when using 3 buffers, to have the first buffer (the primary surface)  being displayed, the second buffer ready and waiting for the vertical retrace so that it can appear next, and the third buffer being drawn on.
This can't be done in Java since there's no way to intercept the retrace, and show() is not syncronized with the retrace either.

The second use is to draw on as many buffers as we can and optimally do PAGE FLIPPING between them, another impossibility since apparently we can only access one buffer at a time.

The last line of this tutorial:, states that 'It may be end up being wasteful to use more than one back buffer. Multi-buffering is only useful when the drawing time exceeds the time spent to do a show. Profile your application.'

But that's no real use for multiple buffers. As it says in the tutorial, one should think about optimizing if it gets to that, specially for games.

I know there's a gaming API being developed by Sun, but they should think about adding this functionality to BufferStrategy since that's where it belongs.

Any comments on this? I'm mostly curious as to why they would add this functionality if it's mostly useless as it is. Maybe there's another use and I'm missing something.


Offline Seb

Senior Newbie

import com.acme.Bomb;

« Reply #1 - Posted 2002-11-02 04:45:16 »

Allright, I just found Jeff's article on image types in java posted on this site thanks to google.

In there he does state that show() is scan synchronized, which is the only place where I found this documented, but I'm left wondering how the synching works.
1. Does it return immediattely or does it return after the retrace?
3. If it returns immediately, what happens to subsequent .getDrawGraphics() calls before the retrace? Do they return the same back buffer?

I think I could figure out the third one experimenting a bit. My little scroller tilemap test (it's quite evolved now, I'll post a .jar somewhere when it's more useful) drops from 128 to 60 fps when I implement page flipping. This is what hinted me about the vertical retrace synching. It also seems that show() makes the thread sleep, and that's why I only get 60 fps now.

Jeff, can you expand on the inner workings of this a bit cause I'm just guessing.


Offline chet

Senior Newbie

Java games rock!

« Reply #2 - Posted 2002-11-05 21:15:41 »

I'm not sure which of your multiple questions to respond to, but I'll maybe summarize your posts as "What the heck is up with BufferStrategy?" and try to answer that catch-all...

BufferStrategy _is_ synchronized to the retrace when you are doing page-flipping.  Way deep in the internals of Java2D on Windows, we implement show() as a ddraw Flip() command with the flag DDFLIP_WAIT.  This means that (a) the flip command will wait for the vertical refresh to occur and (b) we will wait for the Flip command to process before we return from the show() call.  Make sense?

Note that the same is not true for non-page-flipping BufferStrategy classes; if you are in windowed mode, you will probably end up using a BltBufferStrategy, which simply uses a ddraw Blt command (on Windows, of course) to copy to the screen.  That command is not sync'd to the vertical retrace, so show() will return as soon as we've sent off the Blt command.

Your guess about vertical retrace being linked to the 60 fps is correct; since you are now waiting for the Flip to occur, your frame rate is maxed at the current refresh rate.

If your code is simply waiting for the show() command to return, that is one place where triple buffering _might_ help; if you had a third buffer available, then show() would return immediately and you could start drawing on the free buffer.  But it's not always a win; if you are drawing much faster than the frame rate, then you will simply get one frame ahead and sit there waiting for the following show() to return.

My explanations are Windows-specific, but the same should be true on any platform that support page-flipping.

Hope that helps...

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline swpalmer

JGO Coder

Exp: 12 years

Where's the Kaboom?

« Reply #3 - Posted 2002-11-05 21:53:17 »

Is it not possible for BltBufferStrategy to sync to the vertical retrace?

Having animations in a window that have a big tear line through the middle kinda stinks.

It seems to me that this should be possible and that if it is possible it is also desirable.  What's the deal?

Offline chet

Senior Newbie

Java games rock!

« Reply #4 - Posted 2002-11-06 18:08:59 »

Unfortunately, it is not possible to sync while using Blt.  This is simply a hole in the API.  The capability exists on some platforms to allow it, but there is no way to access it through the current BufferStrategy (or other class) methods.

This is something we should add for jdk1.5...
Offline Seb

Senior Newbie

import com.acme.Bomb;

« Reply #5 - Posted 2002-11-06 18:53:34 »

thanks chet,

that pretty much takes care of my doubts. Although, as you said yourself, there are some holes in the API, it's pretty workable as it is, I just needed to know how it worked, there isn't that much documentation on this.


PD: I still miss interrupts!

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Archive (53 views)
2017-02-27 19:41:49

Riven (62 views)
2017-02-27 17:26:59

numerical (433 views)
2017-02-21 07:32:16

numerical (434 views)
2017-02-21 07:31:46

theagentd (548 views)
2017-02-18 13:42:33

theagentd (544 views)
2017-02-18 13:35:16

h.pernpeintner (1719 views)
2017-01-24 22:39:11

h.pernpeintner (1680 views)
2017-01-24 22:38:32

Galdo (2261 views)
2017-01-12 13:44:09

Archive (2182 views)
2017-01-02 05:31:41
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!