Efficiency of render code

Hi! I’m wondering if you have any tips for the following render loop:


public void render() {
	BufferStrategy bufferStrat = getBufferStrategy();
	if (bufferStrat == null) {
	    createBufferStrategy(3);
	    return;
	}
	do {
	    if (StateManager.state == StateManager.INGAME) {
		do {
		    for (int i = 0; i < overlay.length; i++)
			overlay[i] = 0;
		    Graphics2D g2d = (Graphics2D) bufferStrat.getDrawGraphics();
		    // Draw to layer1 using its data buffer (pixel by pixel)
                    // Contains stuff like level, player, blocks, entities, etc.
		    g2d.drawImage(layer1, 0, 0, getWidth(), getHeight(), null);
		    // Draw to layer2 using its data buffer (pixel by pixel)
                    // Contains stuff like mouse, HUD and other overlay stuff
		    g2d.drawImage(layer2, 0, 0, getWidth(), getHeight(), null);
		    g2d.dispose();
		} while (bufferStrat.contentsRestored());
		bufferStrat.show();
	    }
	} while (bufferStrat.contentsLost());
    }

The textures that are drawn to the layers are stored as a 1D array of pixels (ints). As you can see, I’ve read up on the recommendations of people here, but I’m not so sure I’ve implemented it correctly. My main question is: is it a good idea, performance wise, to have the pixels stored in an array or as a BufferedImage?

If you use BufferedImages then Java2D can hardware accelerate your images, making drawing much MUCH faster (Basically java2D puts your image onto the Graphics card). If you use pixel arrays then you lose this optimization.