Access stencil data

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
IsawU
Prole
Posts: 16
Joined: Sat May 02, 2015 6:26 pm

Access stencil data

Post 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.
Last edited by IsawU on Fri Jul 28, 2017 4:02 pm, edited 1 time in total.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Access stencil data

Post 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.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
IsawU
Prole
Posts: 16
Joined: Sat May 02, 2015 6:26 pm

Re: Access stencil data

Post 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
User avatar
IsawU
Prole
Posts: 16
Joined: Sat May 02, 2015 6:26 pm

Re: Access stencil data

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 130 guests