Problems with BufferStrategy

I am having problems with the bufferstrategy, and I do not know why. The code compiles and works, mas the performence it’s much wort than if i do not user buferstrategy. I am gonna pass part of the code, in hope somo of you guys find a mistake. Tankz.

Here I try to get a good GC


/******* init code *****/
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();

Arena a = new Arena(gc);

(...)

Arena is a Component that draws all my map and actors. It extends canvas and it’s in the paint method that she paint’s all the stuff. In Arena ctor, I call super(gc);
On the other hand I have a thread that sleeps for a while and then calls repaint(from Agenda).


/***************** where i use buffering ******/
public void paint( Graphics g )
{
      if(firstTime) {
            createBufferStrategy(2);
            bufferStrategy = getBufferStrategy();
      firstTime=false;
      }

      Graphics graphics = bufferStrategy.getDrawGraphics();

      if( bufferStrategy.contentsLost() )
      return;
      try {
            for( int i = 0; i < vTiles; ++i ) {
                  for( int j = 0; j < hTiles; ++j ) {
                        if( g.getClipBounds().intersects(terrain[i][j].getRectangle()) ) {
                              terrain[i][j].paint(graphics);
                        }
                  }
            }
            m.paint(graphics);
      } finally {
            graphics.dispose();
      }

      bufferStrategy.show();
}

What am I doind wrong? Thankz for any help guys.

[]

Its not how your rendering, its what your rendering that might cause BufferStrategy to be slower than regular back buffering.

What is occuring inside this method?


terrain[i][j].paint(graphics);

I simply paint an Image:


public void paint( Graphics g )
      {
            if( img == null )
                  throw new RuntimeException("Calling Paint and image not Created!!!");
            g.drawImage(img,tile.x,tile.y,TILE_SIZE,TILE_SIZE,null);
      }

And image is loaded like this:


      public static Image getImage( String fileName )
      {
            File file = new File(fileName);
            if( !file.exists() ) {
                  reportFatalError("Image not found: /" + file.getAbsolutePath() );
            }
            return toolkit.createImage(fileName);
      }

EDIT: Oh, and the images are 45x45 png’s.

do they have an alpha channel?

if they do, then that is why it is slower drawing them using BufferStrategy.

at the moment, AlphaCompositing is not hardware accelerated, so any drawing operation that uses AlphaCompositing will be slower when done on an image stored in vram. (such as the buffers used in BufferStrategy)

The reason for this, is because java has to read back the image from vram into main memory, perform the alphacomposite, and copy it back to vram.

Humz… they are very simply images, I do not even know if they have an alpha chanel (how can I know that?). I tried with jpg format and itś the same.

Whats your advice? I tried to save again the images (using gimp), and there were no option about alpha chanel.

What is the platform?

Sun’s JDK for Linux currently runs ontop of X, which means Page Flipping is impossible. Instead its simulated and is likely to be slow.

JK

yep… itś on linux,

So, how do I do this so that it works ok on linux and win?