Qbasicnews.com

Full Version: standard GfxLib speed
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I wanted to make a mouse cursor. But the screencopy is sooooo slow. WHY? In 640x480x24 mode on my P500MHz the cursor jumps and it looks like it's about 10-15 FPS.

Here is the sample code. Any ideas gow to make it faster/more efficient?


Code:
screen 18, 24, 2, 1
screenset 1,0

line (0,0)-(27,27), rgb(255,0,255), BF
line (0,0)-(27,27), rgb(255,255,255)
dim cursor((28 * 28 * 4) + 4)
get (0,0)-(27,27), cursor

do
   if MULTIKEY(&h01) then end
   getmouse mx,my
   cls
   circle (320, 240), 200, rgb(255,0,0)
   put (mx, my), cursor, TRANS
   screencopy 1,0
loop
The code seems to run just fine on my PC (P4 1.7Ghz). If I turn off the CLS, I can see that the "mouse graphic" stutters across the screen, but if you really pay attention to the windows mouse cursor it also has a slightly jerky movement.
You only draw on every second page, or so it seems.

Don't you have to set the working page?
1.- Do page flipping instead of double buffering.
2.- Remove that CLS! NOW!! Big Grin
Remember gfxlib is a software renderer. As such, when you do big memory copies, the speed decreases a lot... gfxlib uses MMX, but copying a whole 640x480x24 screen buffer on a P500 will surely degrade performance. This happens with gfxlib, but also with other software based libs like TinyPTC, Allegro and SDL (these last two of course when you use software surfaces).
Doing double buffering in hires modes is widely known to be slow for this reason. Better use page flipping as na_th_an suggested :wink:
Also, do to the layout of the memory in a 24-bit mode, it will be slow. Better to go with 32-bit which can be accelerated (even though it's not with gfxlib) or 16-bit which can alos be accelerated but is only half the memory.
Thanks for all the replies, this is really helpful.
One more question: How to do the "page flipping"? The FLIP function is just an alias of SCREENCOPY...

Is it something like this?:


Code:
do
   screenset 1,0
   ' drawing routines here
   screenset 0,1
loop
Exactly. Look at the gfxlib.txt documentation, MULTIKEY example; it uses page flipping. Let me know how well it performs!
Oh yeah, never use 24-bit modes, they are 3 to 5 times slower than 16-bit or even 32-bit, due the way pixels are stored.
On my comp, 32bit is way faster than 16bit, not to mention how SLOW! 8bit is... but it's prolly because of my drawing routines Tongue
Pages: 1 2