Hi
I've been looking into using JMEDesktop for an UI overlay and found it quite nice but also relatively slow at updating (the AGP speed on my laptop is low).
To slightly improve the speed of the desktop I decided to try to optimize it a bit - for instance by queueing and manipulating what areas of the screen should be updated rather than simply updating the biggest rectangle that fits. So far the results have been interesting but rather useless.
However, I ran into a question of whether it is indeed necessary to update the entire texture when text is painted to it:
[src/com/jmex/awt/swingui/LWJGLImageGraphics.java]
public void drawString( String str, int x, int y ) {
if ( mipMapChild != null ) {
mipMapChild.drawString( str, x, y );
}
synchronized ( dirty ) {
makeDirty();
delegate.drawString( str, x, y );
}
}
Wouldn't it be smarter to fetch out the the font metrics and use that instead? (Just writing off the top of my head here, feel free to syntax check it or even test it ;) )
public void drawString( String str, int x, int y ) {
if ( mipMapChild != null ) {
mipMapChild.drawString( str, x, y );
}
Rectangle2D bounds = delegate.getFontMetrics().getStringBounds(str, delegate);
synchronized ( dirty ) {
makeDirty(x+(int)bounds.getX(), y+(int)bounds.getY(), (int)bounds.getWidth(), (int)bounds.getHeight());
delegate.drawString( str, x, y );
}
}
Since this is called rather often it may be worth the change:
drawLine:239749
drawString:109139
drawImage_basic:91225
fillRect:58539
drawImage_width:32127
drawImage_yummi:7380
fillOval:6906
drawSWhape:4011
clearRect:2134
copyArea:1819
scale_dobuleit:1
translate_double:1
What do you think?