Possible to use stencil with Canvas:renderTo?

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
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Possible to use stencil with Canvas:renderTo?

Post 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.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Possible to use stencil with Canvas:renderTo?

Post by pgimeno »

No, we'd need a renderTo which accepts {stencil = true}.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Possible to use stencil with Canvas:renderTo?

Post by Jasoco »

Maybe they can add it somehow? Would be nice. Thanks. At least I know I'm not missing something. lol
User avatar
Juckey
Prole
Posts: 2
Joined: Wed Apr 04, 2018 1:19 pm
Location: Finland

Re: Possible to use stencil with Canvas:renderTo?

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

Who is online

Users browsing this forum: No registered users and 48 guests