Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Double-Buffering Without drawImage? (http://www.velocityreviews.com/forums/t135062-double-buffering-without-drawimage.html)

Lash Rambo 07-09-2004 11:00 PM

Double-Buffering Without drawImage?
 
Is is possible to do away with the drawImage(offscreenImage) step of
double-buffering in Java?

Specifically, what I'm thinking of is two graphics contexts that can be
toggled between. One graphics context will be off-screen and drawn to,
while the other is on-screen and left alone. When the drawing is done and
it's time to present a new frame, simply swap the two graphics contexts's
references. In other words, the graphics context that was the off-screen
one becomes the on-screen one, and vice versa.

Is this possible, for instance, with java.applet.Applet? If so, it'd seem
to eliminate a lot of overhead, particularly for large scenes that need to
be completely redrawn each frame.

William Brogden 07-10-2004 11:43 AM

Re: Double-Buffering Without drawImage?
 
On Fri, 09 Jul 2004 23:00:48 GMT, Lash Rambo <lrambo@obmarl.com> wrote:

> Is is possible to do away with the drawImage(offscreenImage) step of
> double-buffering in Java?
>
> Specifically, what I'm thinking of is two graphics contexts that can be
> toggled between. One graphics context will be off-screen and drawn to,
> while the other is on-screen and left alone. When the drawing is done
> and
> it's time to present a new frame, simply swap the two graphics contexts's
> references. In other words, the graphics context that was the off-screen
> one becomes the on-screen one, and vice versa.
>
> Is this possible, for instance, with java.applet.Applet? If so, it'd
> seem
> to eliminate a lot of overhead, particularly for large scenes that need
> to
> be completely redrawn each frame.


You seem to be applying the "Graphics Context" idea exported
from another language. In Java, it does NOT imply a chunk of
memory you can "simply swap"

Bill

--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/

Ryan Stewart 07-10-2004 12:12 PM

Re: Double-Buffering Without drawImage?
 
"Lash Rambo" <lrambo@obmarl.com> wrote in message
news:Xns9521B76D54976lramboobmarlcom@68.12.19.6...
> Is is possible to do away with the drawImage(offscreenImage) step of
> double-buffering in Java?
>
> Specifically, what I'm thinking of is two graphics contexts that can be
> toggled between. One graphics context will be off-screen and drawn to,
> while the other is on-screen and left alone. When the drawing is done and
> it's time to present a new frame, simply swap the two graphics contexts's
> references. In other words, the graphics context that was the off-screen
> one becomes the on-screen one, and vice versa.
>
> Is this possible, for instance, with java.applet.Applet? If so, it'd seem
> to eliminate a lot of overhead, particularly for large scenes that need to
> be completely redrawn each frame.

You want page flipping. Have a look at the createBufferStrategy and
getBufferStrategy methods of java.awt.Window. A caution: the book I read
about it said that there were occasional problems calling getBufferStrategy
immediately after createBufferStrategy. It recommended trying the get every
20 ms or so in a loop until it is successful or a couple of seconds has
passed (in which case throw an Exception and exit).



Lash Rambo 07-10-2004 10:11 PM

Re: Double-Buffering Without drawImage?
 
"Ryan Stewart" <zzanNOtozz@gSPAMo.com> wrote in
news:eqOdnQTuqtDOQHLdRVn-hQ@texas.net:

> "Lash Rambo" <lrambo@obmarl.com> wrote in message
> news:Xns9521B76D54976lramboobmarlcom@68.12.19.6...
>> Is is possible to do away with the drawImage(offscreenImage) step of
>> double-buffering in Java?
>>
>> Specifically, what I'm thinking of is two graphics contexts that can
>> be toggled between. One graphics context will be off-screen and
>> drawn to, while the other is on-screen and left alone. When the
>> drawing is done and it's time to present a new frame, simply swap the
>> two graphics contexts's references. In other words, the graphics
>> context that was the off-screen one becomes the on-screen one, and
>> vice versa.
>>
>> Is this possible, for instance, with java.applet.Applet? If so, it'd
>> seem to eliminate a lot of overhead, particularly for large scenes
>> that need to be completely redrawn each frame.

>
> You want page flipping. Have a look at the createBufferStrategy and
> getBufferStrategy methods of java.awt.Window. A caution: the book I
> read about it said that there were occasional problems calling
> getBufferStrategy immediately after createBufferStrategy. It
> recommended trying the get every 20 ms or so in a loop until it is
> successful or a couple of seconds has passed (in which case throw an
> Exception and exit).


Yes! That's exactly what I was looking for. Not sure if it will work
the way I think it will, but it looks promising. Thanks, Ryan!

nospam@nowhere.com 07-11-2004 04:36 AM

Re: Double-Buffering Without drawImage?
 
Lash Rambo <lrambo@obmarl.com> wrote:
> Is is possible to do away with the drawImage(offscreenImage) step of
> double-buffering in Java?
>
> Specifically, what I'm thinking of is two graphics contexts that can be
> toggled between. One graphics context will be off-screen and drawn to,
> while the other is on-screen and left alone. When the drawing is done and
> it's time to present a new frame, simply swap the two graphics contexts's
> references. In other words, the graphics context that was the off-screen
> one becomes the on-screen one, and vice versa.
>
> Is this possible, for instance, with java.applet.Applet? If so, it'd seem
> to eliminate a lot of overhead, particularly for large scenes that need to
> be completely redrawn each frame.


If you're not limited to AWT, and can use Swing, I think you get
double buffering "for free"; i.e., extend javax.swing.JPanel, override
paintComponent() to do your painting, and allow Swing to handle all
the double buffering details for you. With luck, Swing is already
designed to leverage the most efficient kind of double buffering
available to the underlying platform (whether that be bit blitting
from main memory, or from graphics memory, or page flipping, or
whatever).

Lash Rambo 07-14-2004 11:32 PM

Re: Double-Buffering Without drawImage?
 
nospam@nowhere.com wrote in
news:40f0c3d9$0$175$a1866201@newsreader.visi.com:

> Lash Rambo <lrambo@obmarl.com> wrote:
>> Is is possible to do away with the drawImage(offscreenImage) step of
>> double-buffering in Java?
>>
>> Specifically, what I'm thinking of is two graphics contexts that can
>> be toggled between. One graphics context will be off-screen and
>> drawn to, while the other is on-screen and left alone. When the
>> drawing is done and it's time to present a new frame, simply swap the
>> two graphics contexts's references. In other words, the graphics
>> context that was the off-screen one becomes the on-screen one, and
>> vice versa.
>>
>> Is this possible, for instance, with java.applet.Applet? If so, it'd
>> seem to eliminate a lot of overhead, particularly for large scenes
>> that need to be completely redrawn each frame.

>
> If you're not limited to AWT, and can use Swing, I think you get
> double buffering "for free"; i.e., extend javax.swing.JPanel, override
> paintComponent() to do your painting, and allow Swing to handle all
> the double buffering details for you. With luck, Swing is already
> designed to leverage the most efficient kind of double buffering
> available to the underlying platform (whether that be bit blitting
> from main memory, or from graphics memory, or page flipping, or
> whatever).


Alright, I'll research this, as well. It'd certainly make things a lot
easier!


All times are GMT. The time now is 09:25 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.