[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Antialiased circle
Am 26.02.12 20:18, schrieb Lenard Lindstrom:
I guess I need to take another look at pexdra.
I played around a bit with pexdra the last two days and created a small
demo for drawing rounded rectangles:
You can either use the Zip Archive download link or check it out via SVN:
svn co svn://svn.chrisarndt.de/projects/pgs4a/aarrrects
This also runs on Android with PyGame Subset for Android.
The demo just displays some moving rectangles with rounded corners,
which are anti-aliased via supersampling (there are some screenshots in
SVN). My modification of the pexdra module is included in the demo, but
if you want to use my Cython speedups extension module (see below), you
should also check out my clone of pexdra here:
Like the author of the module said, this method of anti-aliasing is
rather slow, so re-drawing the shapes at every screen refresh is a
no-go, but if you just want to render some static (i.e. not changing
size) shapes you can use sprite.RenderUpdates and get three-digit
The main bottleneck here seems to be the pygame.transform.smoothscale
function, so the framerate drops radically the bigger your shapes are
and the higher the super-sampling rate. I was able to speed up things
quite a bit (70-80% framerate increase) by compiling pygame from source
with processor-specific optimizations and -msse and and -mfpmath=sse on
my otherwise rather slow Eee PC 901.
Nethertheless I tried to optimize the 'draw_rounded_rect' function a bit
by putting all coordinate calculations into a Cython module. Although
the Cython version is 10 times faster than the Python one, the framerate
increase is only about 10-20%. Most time is still spend in scaling down
the blown up surface. I also changed the Python code quite a bit, mostly
to accomodate dirty-rect drawing but also some minor optimizations here.
My demo has lots of command line options which are listed when you run
'./main.py -h', so you can play around with them and see how they impact
performance. By default the program only draws the shapes once at the
beginning and then just moves their surfaces around. If you use the '-r'
option, the shapes are redrawn every cycle and you can watch the FPS
plummet. ;) Still, with 3-times super-sampling, an update rate of
~18/sec and <20 shapes I get (barely) acceptable framerates on my weak
Eee PC even then. On my Android tablet though, were the Cython speedups
are not present, it's basically a slideshow...
In a nutshell: this is usable for mostly static shapes (i.e. a scalable
GUI) but no general solution. We should still make the effort to some
implement some optimized curve aa-drawing algos for pygame.