Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fastest image refresh
#1
When using graphics, especially in games, it's often necessary to clear an image from a surface before placing another image in its place because of alpha transparency issues. The method I usually use to do this was way to slow for the current project I'm working on. So I started playing with and timing alternative methods.

Thought I would pass this tidbit of information along.

Using a 512x736 32bit image and each method repeated 10000 times I get the following.

My usual method: 0.644 seconds

Odest = _DEST
_DEST Image
CLS
_DEST Odest


Using LINE BF method: 0.620 seconds (curious that LINE is faster than CLS)

Odest = _DEST
_DEST Image
LINE(0, 0)-(_WIDTH(Image) - 1, _HEIGHT(Image) -1), _RGB32(0, 0, 0), BF
_DEST Odest


Freeing and recreating: 0.042 to 0.061 seconds (no idea why it fluctuates so much)

Iwidth = _WIDTH(Image)
Iheight = _HEIGHT(Image)
_FREEIMAGE Image
Image = _NEWIMAGE(Iwidth, Iheight, 32)

Well, as you can see, the 3rd method is superior. I created a simple subroutine to handle this for me now:

SUB RENEW_IMAGE (Image AS LONG)

    DIM Iwidth AS INTEGER '  width of image
    DIM Iheight AS INTEGER ' height of image

    Iwidth = _WIDTH(Image) '                get width of image
    Iheight = _HEIGHT(Image) '              get height of image
    _FREEIMAGE Image '                      remove the image from RAM
    Image = _NEWIMAGE(Iwidth, Iheight, 32) ' recreate a blank surface

END SUB
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#2
Even faster: use hardware images as they automatically free themselves from the display buffer after any _DISPLAY command.
Reply
#3
(03-06-2023, 11:13 PM)SMcNeill Wrote: Even faster: use hardware images as they automatically free themselves from the display buffer after any _DISPLAY command.

I still have not had an opportunity to play with and convert this project to hardware yet.

Does this mean they clear their contents after a _DISPLAY command or need to be recreated after each _DISPLAY command?
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply




Users browsing this thread: 1 Guest(s)