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


Messages In This Thread
Fastest image refresh - by TerryRitchie - 03-06-2023, 11:04 PM
RE: Fastest image refresh - by SMcNeill - 03-06-2023, 11:13 PM
RE: Fastest image refresh - by TerryRitchie - 03-06-2023, 11:18 PM



Users browsing this thread: 1 Guest(s)