Fastest image refresh - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2) +--- Thread: Fastest image refresh (/showthread.php?tid=1534) |
Fastest image refresh - TerryRitchie - 03-06-2023 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 RE: Fastest image refresh - SMcNeill - 03-06-2023 Even faster: use hardware images as they automatically free themselves from the display buffer after any _DISPLAY command. RE: Fastest image refresh - TerryRitchie - 03-06-2023 (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? |