Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Fast Pixel Access

Author
Message
tboy
11
Years of Service
User Offline
Joined: 1st Jan 2013
Location: UK
Posted: 17th Apr 2017 09:11 Edited at: 17th Apr 2017 09:12
Hi peeps,

I'm just getting back into AppGameKit after quite sometime and I'm working on a scratch card effect,
I can access pixel data using memblocks but I find the method I have come up with is quite
slow, if the mods read this or if anyone knows, is TGC planning on direct pixel access, especially
for HTML5?

I've managed to do this using JavaScript which is quite fast but I can't seem to get a decent one
working with AGK.

The way I've come up with is draw a red sprite to a temp image and all red pixels are replaced
with the pixel location of the image I want to reveal, it's possible with AppGameKit I see but not that fast,
anyone come up with a better method?

Thanks in advance

main.agc


scratch.agc
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th Apr 2017 09:54 Edited at: 17th Apr 2017 09:56
This has been discussed recently (can't remember which thread). I think that what you are doing is probably as efficient as you can get at the moment, there is no direct backbuffer access. somebody looked into the technicalities and decided it would be quite hard for TGC to implement.

An alternative might be image masks. You could draw your transparency to a second image (e.g as white on black) and apply this as a transparency mask to your actual image. You could maybe have some sprite "stamps" that you draw to the mask to cover a larger area. Check out this thread regarding masks.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 17th Apr 2017 15:03
Quote: " somebody looked into the technicalities and decided it would be quite hard for TGC to implement."

Is it because of the multiple devices supported? They did it with DBP.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th Apr 2017 15:13
It worked really well with DBP, I wrote a tutorial and we had a related competition - https://www.thegamecreators.com/pages/newsletters/newsletter_issue_33.html#12
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 17th Apr 2017 15:18 Edited at: 17th Apr 2017 15:36
pulling the image data from device can be very expensive (the GPU and CPU aren't on the same BUS), so it's not an ideal structure for doing something real time.

anyway the cost per pixel in the GetImageRGBA function seems pretty high with two loops with some redundant calcs inside the inner loops..
so you should be able to restructure and improve the through put of that part of the code, but the bottle neck may well be pulling it fom video memory to begin with or freeing the buffer each time.

So taking a look at this part,



The second loop contains pixel offset calc, so it'd be easier on the runtime to only compute this once.




Depending upon the runtime FOR/NEXT loops can either compute the END expression every loop or they'll pre compute the END loop value once and protect it within a local.. IF it computes the expression every loop, then some free speed can be had just be computing the end values up front.



The problem with this is there's twp loops going over the data byte by byte.. so a 256*256 image gives 256*256*4*2 loops.. which is lot of empty overhead for a runtime to soak up..

You can rid of half of the looping just by merging them..



if you assume 1 to 1 ratio of runtime opcodes to user code (which is very unlikely) but easy to visualize.. The cost per pixel is about say 15 operations compared to 28/29 in the original loop.
Even so it's still not going to sing if you is throw a big image at it... Although if know the section that has changed, then you can selectively grad that section from the memblock->array. So only when the entire image changed would you need to brute force the buffer.

You could just read the pixels as Integers and split up the RGB's, but that's something for you to do.. although the split cost might be heavier than a memblock peek... but that's where the fun is in this stuff


NOTE: All this is untested.

PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
tboy
11
Years of Service
User Offline
Joined: 1st Jan 2013
Location: UK
Posted: 17th Apr 2017 15:28
Some good optimization suggestions and ideas, I'll give them a try and see what difference it could make.

Many thanks!
CodeName
7
Years of Service
User Offline
Joined: 30th Dec 2016
Location:
Posted: 17th Apr 2017 23:49 Edited at: 18th Apr 2017 04:18
http://www.roxlu.com/2014/048/fast-pixel-transfers-with-pixel-buffer-objects

Maybe Mr. Johnston wouldn't mind this implement?

AGK2 dose not use lock_pixels() but this new method runs the GPU then you take information! ( asynchronously ) : Edit

Losing out on just a few FPS.

Would be cool to be able to crunch data or read ABGR in AGK2.

A Get_Image would then become much much faster!

Take care.

Login to post a reply

Server time is: 2024-11-22 15:15:18
Your offset time is: 2024-11-22 15:15:18