Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (542)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (606)
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  
  BufferedImage vs. VolatileImage  (Read 2864 times)
0 Members and 1 Guest are viewing this topic.
Offline zaphod

Senior Newbie




Java Developer by day, Java Developer by ... hey


« Posted 2003-07-06 03:09:00 »

I was under the impression that VolatileImages are the only images that take advantage of VRAM (and hence have much superior speed).  However I've also heard that BufferedImages do this as well.  Can anyone confirm or refute this?

I'd like to be able to use ImageIO.read() to create my images.  Are all BufferedImages accelerated, or only those created using a call to the GraphicsConfiguration ie : graphicsConfiguration.createCompatibleImage( int, int, int)


Thanks!
Offline immudium

Junior Devvie




Gorram it!


« Reply #1 - Posted 2003-07-06 04:33:58 »

Well, I'm by no means an expert on the subject and I only know what I've read, but according to The VolatleImage API User Guide located at ftp://ftp.java.sun.com/docs/j2se1.4/VolatileImage.pdf, "...offscreen images were moved to system memory in the form of the new image type: BufferedImage."  It goes on to say that "the performance of BufferedImage software rendering has improved greatly...however, there is still a need for even better performance".  At which point it simply indicates that, "a VolatileImage allows an application to take advantage of hardware acceleration".

I also remember reading, though I can't remember where, that if you simply made the correct calls to the super class, Image, that the jdk would determine the best derivative to use, i.e. BufferedImage or VolatileImage for the current situation.  I've never really tried verify that method, however.

I hope that helps in answering your question.  I would recommend reading the rest of that API, it's pretty informative not just in the VolatileImage API but in the history and evolution of Swing as well to some degree.
Offline zaphod

Senior Newbie




Java Developer by day, Java Developer by ... hey


« Reply #2 - Posted 2003-07-06 04:53:41 »

I had read through the entire API before I really even got started playing around with this business, but before I got too far with that I started reading the forums here, which is where I heard that BufferedImages were accelerated as well...

Since that API was put out a while ago, and 1.4.2 is now out and all, I thought maybe someone could give me the straight answer on the performance of BufferedImages vs. VolatileImages...  Perhaps I'll have to do the testing myself...

I appreciate all your input though!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Abuse

JGO Knight


Medals: 15


falling into the abyss of reality


« Reply #3 - Posted 2003-07-06 12:04:42 »

Search the forums, its been covered many times before.

but cos i'm nice, i'll summarise it here Smiley

Images returned from these methods are 'ManagedImages' (previously known as Automatic Images)
This means they are elligable for caching in VRAM, and hence are hardware accelerated.
:-

Toolkit.createImage()
Toolkit.getImage()
GraphicsConfiguration.createCompatibleImage()
Component.createImage()

These slides maybe helpful :-
http://servlet.java.sun.com/javaone/resources/content/sf2003/conf/sessions/pdfs/1402.pdf

and also, this example program :-
http://www.pkl.net/~rsc/downloads/Balls.jar

Images returned from ImageIO.read() are not accelerated (in the current java version, though I believe the intention is to make them so)
If you want to load images using ImageIO, you must then subsequently copy the image into a ManagedImage.
The code to do that will look something like this :-

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
import java.awt.*;
import java.awt.image.*;
public class ImageLoader
{
   final GraphicsConfiguration gc;
   public ImageLoader(GraphicsConfiguration gc)
   {
      if(gc==null)
      {
         gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
      }
      this.gc = gc;
   }

   public BufferedImage loadImage(String resource, int transparencyType)
   {
      try
      {
         BufferedImage src = javax.imageio.ImageIO.read(getClass().getResource(resource));
         //Images returned from ImageIO are NOT managedImages
         //Therefor, we copy it into a ManagedImage
         BufferedImage dst = gc.createCompatibleImage(src.getWidth(),src.getHeight(),transparencyType);
         Graphics2D g2d = dst.createGraphics();
         g2d.setComposite(AlphaComposite.Src);
         g2d.drawImage(src,0,0,null);
         g2d.dispose();
         return dst;
      }
      catch(java.io.IOException e)
      {
         return null;
      }
   }
}


Currently accelerated Transparency is only possible using ManagedImages. (not with VolatileImages)

Also, currently only bitmask transparency is *by default* accelerated.
However, there are flags to enabled hardware acceleration for images with a full alpha channel (Translucent). These flags also make AlphaComposite operations hardware accelerated.

The code to set the flags is :-

1  
2  
System.setProperty("sun.java2d.translaccel", "true");
System.setProperty("sun.java2d.ddforcevram", "true");


This Thread covers the flags in more detail
http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=2D;action=display;num=1048663269;start=0#0


Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline zaphod

Senior Newbie




Java Developer by day, Java Developer by ... hey


« Reply #4 - Posted 2003-07-06 13:54:39 »

Abuse,

Many thanks for that.  I've been reading through the forums and APIs and trying to sort out the truth from the "other stuff".  I really appreciate you putting together that fine list of links, as well as all the other info.  Hopefully armed with this new data I can eliminate most of the graphics headaches I've been having of late!

--Zaphod
Offline immudium

Junior Devvie




Gorram it!


« Reply #5 - Posted 2003-07-07 02:42:24 »

I guess I'm still too much of a newb to be of much use to anyone.  Oh well, I'm glad you asked to question though, I learned much more than I expected I would today from Abuse's great summary and explanation.  Grin
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Elsealabs (20 views)
2014-12-28 10:39:27

CopyableCougar4 (21 views)
2014-12-28 02:10:29

BurntPizza (25 views)
2014-12-27 22:38:51

Mr.CodeIt (15 views)
2014-12-27 04:03:04

TheDudeFromCI (20 views)
2014-12-27 02:14:49

Mr.CodeIt (26 views)
2014-12-23 03:34:11

rwatson462 (60 views)
2014-12-15 09:26:44

Mr.CodeIt (48 views)
2014-12-14 19:50:38

BurntPizza (98 views)
2014-12-09 22:41:13

BurntPizza (116 views)
2014-12-08 04:46:31
How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50
java-gaming.org 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‑gaming.org
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!