I am using an extended Applet class as an Image Producer (for my software sprite rendering):
public class myApplet extends Applet implements ImageProducer
Setup code:
_model = new DirectColorModel(32,0x00FF0000,0x000FF00,0x000000FF,0);
_image = createImage(_width,_height);
_graphics = getGraphics();
Now by getting the graphics object (from the Component I presume) this means that my render is using AWT, right?
My render function contains:
// get current buffer
int pixels[] = myStrategy.current.dest;
// check consumer
if (_consumer!=null)
{
// copy integer pixel data to image consumer
_consumer.setPixels(0,0,_width,_height,_model,pixels,0,_width);
// notify image consumer that the frame is done
_consumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
}
// draw image to graphics context
_graphics.drawImage(_image, 0, 0, _width, _height, null);
paint() & update() are both empty functions.
I get the feeling that this ‘drawImage’ call can stall for quite a while - I am averaging 25 fps at the moment (Athlon 2 GHz, ATI Radeon 9500, - I should be able to render a bit faster than 25 fps!
If I cover up most of the rendering window, I get a tasty 60 fps - the refresh rate. All my software sprite rendering is still filling the whole screen as it does not account for visible window area, so it must be just the render to the window. Taking close to 24ms just to draw my 640x480 window when I can fill it (with about 2x overdraw) and do the game logic in under 16ms is crazy.
A profile shows most of time in the event loop, & Im not sure exactly what this means. All the articles on profiling I have looked at normally say ‘we’ll ignore the entry for the event loop’. Bah! :-/
My question is really this:
How do I draw to the window, in the fastest, most efficient way possible? Oh - and Java 1.1 compatible too.
- Dom