Page 1 of 1

Possible to use stencil with Canvas:renderTo?

Posted: Thu Nov 22, 2018 4:38 am
by Jasoco
I just learned how to properly use a stencil with a canvas, but it only works with setCanvas. Is there any way to use it with renderTo as well? Since renderTo is just a shortcut to setCanvas, but it doesn't seem to support stencil unless I'm using it wrong.

I just like to use renderTo because it's cleaner looking.

Re: Possible to use stencil with Canvas:renderTo?

Posted: Thu Nov 22, 2018 5:18 pm
by pgimeno
No, we'd need a renderTo which accepts {stencil = true}.

Re: Possible to use stencil with Canvas:renderTo?

Posted: Fri Nov 23, 2018 6:17 am
by Jasoco
Maybe they can add it somehow? Would be nice. Thanks. At least I know I'm not missing something. lol

Re: Possible to use stencil with Canvas:renderTo?

Posted: Wed Dec 12, 2018 12:00 pm
by Juckey
This would definitely be a good addition. Perhaps you could use a temporary hack for now, like this:

Code: Select all

local Canvas_mt = debug.getregistry().Canvas
local renderTo = Canvas_mt.renderTo
function Canvas_mt:renderTo(func, stencil)
	if stencil ~= true then
		return renderTo(self, func)
	end
	local orig_canvas = love.graphics.getCanvas()
	love.graphics.setCanvas { self, stencil = true }
	func()
	love.graphics.setCanvas(orig_canvas)
end
This way canvas:renderTo(function() end, true) would enable the stencil buffer.
Perhaps they could add vararg support also? It's a shame you can only pass a function to it.