Chris,
Thanks for your reply. I have now changed my PoC to use the Swing backbuffer.
> What kind of image is this? Is it a BufferedImage?
It is a plain old Image. This is being returned (asynchronously) by a third
party API, then blitted to the screen in paintComponent().
> Are you rendering the 5000 shapes to the image just
> once, or is the
> image being constantly updated (like in an animated
> fashion)?
It is being constantly panned and zoomed, and occasionally updated with new
shapes.
Now that I am using the Swing backbuffer, everything appears to be working fine
except for the following:
1) Menus are quite slow to paint (because of the time taken to render beneath
it and also repainting the area where a menu was (the "grey rect")
2) Enabling OpenGL kills it completely. Only parts of the menu and toolbars
render, and none of the shapes.
It is possible to get OpenGL working in this case (to improve the performance)?
Or, alternatively, is it possible to have a separate thread to render the
shapes to take the load off the Event Thread?
Below is the relevant parts of my PoC (its a little messy) - any comments /
suggestions/ help would be greatly appreciated.
Mark
public class MapRenderer
// Constructor creates an ArrayList of random ShapePrimitives, which are just
Java2D Shapes which know how to render themselves
public void render (Graphics2D graphics)
{
try
{
isRendering = true;
StopWatch watch = new StopWatch ();
watch.startWatch ("Starting Rendering");
Rectangle bounds = graphics.getClipBounds ();
graphics.setComposite (AlphaComposite.getInstance
(AlphaComposite.SRC_OVER, 0.25f));
ShapePrimitive s = null;
for (int i = 0; i < shapeCount && i < shapes.size (); i++)
{
s = shapes.get (i);
if (s.isWithin (bounds))
s.drawShape (graphics);
}
watch.stopWatch ("Rendering");
isRendering = false;
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
public class MapPanel extends JPanel implements Runnable
{
public MapPanel ()
{
super (true);
initComponents ();
this.setSize (SCREEN_WIDTH, SCREEN_HEIGHT);
this.setName ("Map Panel");
RepaintManager rm = RepaintManager.currentManager (this);
rm.setDoubleBufferingEnabled (true);
rend = new MapRenderer (shapeCount);
}
public void render ()
{
try
{
for (int i = 0; i < iterations; i++)
{
try
{
Thread.sleep (SLEEP_TIME);
}
catch (InterruptedException ex)
{
ex.printStackTrace();
}
while (rend.isRendering ())
{
Thread.sleep (100);
}
System.out.println("Repainting Now");
this.repaint ();
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
public void run ()
{
render ();
}
protected void paintComponent (Graphics g)
{
Graphics2D graphics = (Graphics2D) g;
rend.render (graphics);
graphics.dispose ();
graphics = null;
g.dispose ();
g = null;
}
}
public class PanelTest extends javax.swing.JFrame
{
private static MapPanel mapPanel = new MapPanel ();
public PanelTest (MapPanel mp)
{
initComponents ();
this.add (mp);
Thread t = new Thread (mp);
t.setName ("Map Compositor");
t.start ();
this.setSize (SCREEN_WIDTH, SCREEN_HEIGHT);
}
public static void main (String args[])
{
SwingUtilities.invokeLater (new Runnable ()
{
public void run ()
{
new PanelTest (mapPanel).setVisible (true);
}
});
}
}
}
[Message sent by forum member 'markgrantham' (markgrantham)]
http://forums.java.net/jive/thread.jspa?messageID=154042
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".