particles with alpha dropping performances

hi,

i’m currently encountering some performance problems. I was drawing points, using drawRect(x,y,1,1) for my particle engine and it was working ok. But as soon as i added alpha to the color, performance dropped so drastically that it becomes useless. Is there any easy workaround to display alpha particles quickly?
thanks

Try fillRect

oh, the drawRect was a bit silly indeed. ::slight_smile: Using fillRect gives slightly better results, nearly nothing. The drop of performances is still dramatic!

Then switch to JOGL/LWJGL :stuck_out_tongue:

i was asking for an easy workaround :stuck_out_tongue:

Using the OpenGL pipeline might help.

Look at this thread : http://www.java-gaming.org/forums/index.php?topic=12139.0 ,

It is a really simple 2d particle engine, it use alpha and it is very easy to add your own particle computing in it.

I use MemoryImage for jvm 1.1 compatibility but feel free to replace it by BufferedImage to get maximum performance.

Hope it’ll help

I would draw your particles into a transparent bufferedimage and the paint the whole image at once.
This way you’ll only have one vram-readback when using a accalerated non-alpha pipeline.

I guess the engine above does exactly the same…

lg Clemens

Try :-

System.setProperty(“sun.java2d.translaccel”, “true”);

It should make fillRects hardware accelerated (so long as you are drawing them onto an accelerated surface [BufferStrategy/VolatileImage])

thanks for all mates

A. using the openGL pipeline with the ‘-Dsun.java2d.opengl=True’ flag didn’t worked, i just got an ugly error:

B. the ‘System.setProperty(“sun.java2d.translaccel”, “true”);’ made no errors …and no difference. :frowning:

C. …So i guess the last option will be the thing to try out: work on a secondary buffered image and draw the whole image at once. i’ll tell you tommorrow how it performs.

Sadly, i wasn’t able to get something out of the demo source code… the code was fairly obscure… or maybe it’s because i’m not aware enough at such a late time.

thanks anyway, bye

I’m quite convinced in this case hardware acceleration will never be faster than drawing into an int[] and blitting it.

When using a pipeline that is able to handle alpha its quite likely that its faster using the alpha-functionality since painting to an int[] and blitting it means transferring the int[] from system to vram, whereas the pipeline itself simply sends the drawing requests to the hardware, like it does with non-alpha primitives.

Thats evil! Windows only, unsupported non-standard flag, does not work in applets.
To use OpenGL is a better approach but does not work that well since the tons of broken drivers (tank you ATI).
Best is to tune your app so that it does not reply on such features.

[quote]A. using the openGL pipeline with the ‘-Dsun.java2d.opengl=True’ flag didn’t worked, i just got an ugly error:
[/quote]
Crash inside the ATI drivers … you yould try to upgrade.

lg Clemens

C. Painting on a bufferedImage first and then painting the whole at once didn’t worked either. :frowning: The performance is still killed. It’s maybe a little better, that’s all.
…and from the demo i still couldn’t get smart …still very obscure code.
i guess i’ll put this on ice for the moment
thanks

How many particles are you rendering?

few thousands

…just installed JDK 1.6. Performances were even worse! …but playing a little with the flags helped, it’s now more or less OK. However, in my case, the use of openGL pipeline gave bad results, but the other flags improved the situations… :slight_smile:

With those sorts of numbers you will do best drawing them to a BufferedImage (via direct access to the underlying int[])

You will take the constant time hit of a large software blitted image, but the individual pixel array accesses will be fast. (As fast as is possible in Java)

You should be able to reduce the expense of the large software blitted image, by ensuring the BufferedImage is in a pixel format that can be efficiently copied to the screens.(without the blitting routine having to perform pixel format conversion)
This can be achieved by using GraphicsConfiguration.createCompatibleImage.

However, this may mean you need to write several versions of the particle rasterizing code, to deal with each of the different possible pixel formats the returned BufferedImage may use.