Page 1 of 1

Access stencil data

Posted: Sat Jul 22, 2017 6:28 pm
by IsawU
Hi,

I'd like to experiment with a code that needs to go pixel by pixel and do some additional calculations. Now the area could be (most of the time) greatly reduced by accessing only pixels of a newly drawn shape (before I actually draw it).

I thought it could be nice to use stencils for that, however I have no way to access the data to determine which pixels I really need to check.

I thought of drawing (not necessarily) stencils to a Canvas and then reading the data without displaying anything, howewer that would involve (to my best knowledge) Canvas:newImageData(), which the wiki says to be slow, and then reading the ImageData. And since Canvas:getPixel() is removed, there seems to be no other legit way to read Canvas data.

This, on the other hand, needs to be lightning fast (which seems hard when dealing with pixel to pixel, but I chose to ignore this fact for time being).

Of course I could use my own math for the shapes, but why not exploit the built-ins...

Thanks.

Re: Access stencil data

Posted: Sun Jul 23, 2017 7:12 pm
by Nixola
You can use Shaders I guess; I don't think I can help much more unless you explain in a bit more detail what you need to do.

Re: Access stencil data

Posted: Mon Jul 24, 2017 7:13 am
by IsawU
Nixola wrote: Sun Jul 23, 2017 7:12 pm You can use Shaders I guess;
Not sure about shaders, I have never worked with them though.

To describe it more thoroughly.

Let's suppose I want to draw a shape. The shape takes up only specific pixels on the screen, while other stay untouched. I'd like to check all the pixels that WILL be affected by drawing this shape and check (math + access a table + the shape itself) if the pixel is a valid drawing area for this shape, if not, mask it out.

(What I am currently thinking is that I could check all pixels, which would not cause any functional issues, just performance drop.)

Then I will actually draw the shape, but it will be visible only on the valid pixels

Re: Access stencil data

Posted: Wed Jul 26, 2017 9:16 am
by IsawU
You are probably right with the shaders, just need to learn how to do them now :)

I fact you are probably 100% right. The shaders should allow me to do calculations for each pixel of the shape using pixel effects.