The reason you’re seeing bad performance with non-subimage modes is that you
use getSubImage() on the “sheet” image, which disables its acceleration.
(it’s easy to see if you run with -Dsun.java2d.trace=log to see what primitives are
being used).
I made some simple mods to your test (which is pretty nicely done, btw):
#> diff -c TestOld.java Test.java
*** TestOld.java Sun May 21 20:24:23 2006
--- ../Test.java Tue May 23 16:55:31 2006
***************
*** 205,218 ****
// there 8 total sprites
// okay, so lets do this
sheet = loadImage("sprites.png");
spriteImg = new BufferedImage[sheet.getHeight()/Sprite.HEIGHT][sheet.getWidth()/Sprite.WIDTH];
int x,y,j = 0;
for (y = 0;y < spriteImg.length;y++) {
for (x = 0;x < spriteImg[y].length;x++) {
spriteImg[y][x] = createBuffer(Sprite.WIDTH,Sprite.HEIGHT);
! spriteImg[y][x].createGraphics().drawImage(sheet.getSubimage(x*Sprite.WIDTH,y*Sprite.HEIGHT,Sprite.WIDTH,Sprite.HEIGHT),0,0,null);
}
}
sprites = new ArrayList();
for (j = 0;j < 25;j++) {
sprites.add(new Sprite(rand(0,7),new Point(rand(0,width),rand(0,height)),new Point(rand(0,width),rand(0,height)),rand(1,3)));
--- 205,220 ----
// there 8 total sprites
// okay, so lets do this
sheet = loadImage("sprites.png");
+ BufferedImage sheet1 = loadImage("sprites.png");
spriteImg = new BufferedImage[sheet.getHeight()/Sprite.HEIGHT][sheet.getWidth()/Sprite.WIDTH];
int x,y,j = 0;
for (y = 0;y < spriteImg.length;y++) {
for (x = 0;x < spriteImg[y].length;x++) {
spriteImg[y][x] = createBuffer(Sprite.WIDTH,Sprite.HEIGHT);
! spriteImg[y][x].createGraphics().drawImage(sheet1.getSubimage(x*Sprite.WIDTH,y*Sprite.HEIGHT,Sprite.WIDTH,Sprite.HEIGHT),0,0,null); }
}
+ sheet1.flush(); sheet1 = null;
sprites = new ArrayList();
for (j = 0;j < 25;j++) {
sprites.add(new Sprite(rand(0,7),new Point(rand(0,width),rand(0,height)),new Point(rand(0,width),rand(0,height)),rand(1,3)));
Basically, I just do getSubImage on a different image instead of the one used
by “mode 0”.
With this change I get much better performance with drawImage method than getSubImage.
Especially with the new Direct3D pipeline in mustang, it costs a lot to change the texture to render from.
In your case, if you have tons of images you’ll change the source texture for every sprite,
which costs a lot.
Also, with tons of smaller images you may be wasting more video memory.
Thanks,
Dmitri
Java2D Team