Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT canvas, images and tranparancies performance issue
SWT canvas, images and tranparancies performance issue [message #452160] |
Mon, 14 March 2005 19:12 |
Builder Chad Messages: 5 Registered: July 2009 |
Junior Member |
|
|
Hi,
I have tried implementing a tile based mapping tool for a little game I
am writting using double buffering and have come across some poor
performance results.
canvas = new Canvas(shell, SWT.NO_BACKGROUND);
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
Image image = new Image(shell.getDisplay(), canvas.getBounds());
GC gcImage = new GC(image);
gcImage.setBackground(event.gc.getBackground());
gcImage.fillRectangle(image.getBounds());
int lx = 0;
int ly = 0;
int i;
int j;
boolean indent = false;
for (i = 0; i < 20; i++) {
if (indent) {
lx = 32;
indent = false;
} else {
lx = 0;
indent = true;
}
for (j = 0; j < 12; j++) {
gcImage.drawImage(ImageManager.t1, lx, ly);
lx += 64;
}
ly += 16;
}
gcImage.drawImage(ImageManager.t2, x, y);
event.gc.drawImage(image, 0, 0);
image.dispose();
gcImage.dispose();
}
});
}
This uses simple isometric tiles (64x32). ImageManager.t1 is repeated
across the whole canvase and ImageManager.t2 is used just to demonstrate
animation (x and y are set outside by a runnable to make that tile move
around)
This code is infact straight out of "The definitive guide to SWT and
JFace" by Robert Warner with the addition of the loop to draw my tiles.
If I use t1 and t2 as they are (without setting a transparancy bit) then
performance is great.
But if I extract the ImageData and set transparentPixel then performance
drops off to an unacceptable level.
Even if I extract the ImageData and create an new image from that
without even setting transparentPixel performance is notably reduced.
public class ImageManager {
private Image blob;
static Image t1;
static Image t2;
ImageManager(Display display) {
blob = new Image(display, "all_tiles.png");
Image xt1 = new Image(display, 64, 32);
ImageData tData = xt1.getImageData();
int purplePixel =
tData.palette.getPixel(new RGB(127,0,127));
tData.transparentPixel = purplePixel;
t1 = new Image(display, tData);
Image xt2 = new Image(display, 64, 32);
ImageData tData2 = xt2.getImageData();
tData2.transparentPixel = purplePixel;
t2 = new Image(display, tData2);
GC dest = new GC(t1);
dest.drawImage(blob, 65, 0, 64, 32, 0, 0, 64, 32);
GC dest2 = new GC(t2);
dest2.drawImage(blob, 0, 0, 64, 32, 0, 0, 64, 32);
}
}
Am I doing something wrong? Or should I be going for the Java2D
solution as demonstrated by Yannick Saillet:
http://www-128.ibm.com/developerworks/java/library/j-2dswt/
I wanted to avoid using any AWT stuff but it looks like I may have to
for this project. But from the above article it looks like there is a
huge bottleneck in first painting on an AWT surface, then copying to an
SWT image and then to the canvas - 2 copy ops instead of just one.
If you have any ideas or advice please let me know.
Thanks,
Chad.
|
|
| | |
Goto Forum:
Current Time: Tue Apr 23 15:50:44 GMT 2024
Powered by FUDForum. Page generated in 0.02923 seconds
|