VolatileImage vs. Automatic Images or something.

I’ve seen a lot about ‘Automatic Images’ . . . I think that’s the term, but all these discussions seem to be long-running ones so I’m not sure I follow it.

Basically from what I understand this . . .


BufferedImage autoImage=gc.createCompatibleImage(width,height);

. . . creates an image which is hardware accelerated, provided I don’t modify it in any way. If I paste anything onto it with . . .


Graphics2D g2 = autoImage.createGraphics();
g2.drawImage(someImage,x,y,null);

. . . makes it so it’s not hardware accellerated. Is that right, or am I off somewhere?

I’m not doing it this way ATM. I’m using BufferedImages to hold raw images so that I can composite them and still preserve any transparency. So I take and composite them all onto a VolatileImage. If the contents change, or I lose the contents of the VolatileImage, I rebuild the background, but as it happens so infrequently, each refresh I’m just pasting the VolatileImage Background . . . for sure accellerated . . . and slapping foreground stuff on top of it. (don’t need transparency for that stuff yet.)

The reason I ask is that I’m hitting a slow framerate and I think it’s 'cause I’m doing something wrong. I’m trying to figure out if using these ‘automatic images’ might be faster, or if I might be hitting a bottleneck somewhere I don’t know about.

So . . . here’s a rough outline of the code I’m using.


public class ContentWindow extends Component
{
  VolatileImage myBG;
  
  private void buildBG()
  {
    Graphics2D g2=myBG.createGraphics();
    //Bunch of draw operations
    g2.dispose();
  }

  public void render(Graphics2D g2)
  {
    if(myBG.contentsLost())
    {
           buildBG();
    }
    g2.drawImage(myBG,getX(),getY(),null);
    g2.setColor(Color.yellow);
    g2.fillRect(mouseX-5,mouseY-5,mouseX+5,mouseY+5);
  }
}

Right now, this component is 640x430 . . . running in windowed mode, and it’s the ONLY component being redrawn. I’ve limited the framerate to 20 refreshes per second and STILL it chunks every half-second or so. Is there something I’m doing wrong here? Some way to optimize this?

I’m running on some sort of P3 (not sure what) a TON of memory, but a piece of crap graphics card. Still . . . not doing anything OVERLY taxing. Anybody with advice, I’d be more than happy to hear it.

the chunk is most likely the GC kicking in. profile your code to see where you create a lot of garbage.

What version of JVM are you using? Garbage collection pauses have become pretty much unnoticeable in 1.4, unless you are creating really huge amounts of garbage.

Also, if you have a lot of large textures out then you could be suffering from texture swapping on the video card. How much video memory do you have and how big and/or numerous are your textures?

JVM version is . . . 1.4.2beta

Memory on card is . . . I think 16MB, but it’s a POS card. Right now I’m using a 640x430 VolatileImage, a 640x50 VolatileImage and three 30X30 VolatileImages.

That’s it. Really, it should be able to handle that much, I would think. I dunno . . . another thing I noticed. There’s only one chunk when I run it in fullscreen mode then it’s smooth at 30 fps after that.

sigh I’m stumped.