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.