2014-10-22 02:48:19 +00:00
|
|
|
local util = {}
|
|
|
|
|
2014-12-19 15:14:24 +00:00
|
|
|
function util.process(canvas, options)
|
|
|
|
util.drawCanvasToCanvas(canvas, canvas, options)
|
|
|
|
end
|
|
|
|
|
2014-10-22 02:48:19 +00:00
|
|
|
function util.drawCanvasToCanvas(canvas, other_canvas, options)
|
|
|
|
options = options or {}
|
|
|
|
|
2014-12-14 18:17:56 +00:00
|
|
|
util.drawto(other_canvas, 0, 0, 1, function()
|
|
|
|
if options["blendmode"] then
|
|
|
|
love.graphics.setBlendMode(options["blendmode"])
|
|
|
|
end
|
|
|
|
if options["shader"] then
|
|
|
|
love.graphics.setShader(options["shader"])
|
|
|
|
end
|
2014-12-16 22:14:16 +00:00
|
|
|
if options["stencil"] then
|
|
|
|
love.graphics.setInvertedStencil(options["stencil"])
|
|
|
|
end
|
|
|
|
if options["istencil"] then
|
2014-12-18 04:16:29 +00:00
|
|
|
love.graphics.setInvertedStencil(options["istencil"])
|
2014-12-16 22:14:16 +00:00
|
|
|
end
|
2014-12-14 18:17:56 +00:00
|
|
|
if options["color"] then
|
|
|
|
love.graphics.setColor(unpack(options["color"]))
|
|
|
|
else
|
2014-10-22 02:48:19 +00:00
|
|
|
love.graphics.setColor(255,255,255)
|
2014-12-14 18:17:56 +00:00
|
|
|
end
|
|
|
|
love.graphics.draw(canvas,0,0)
|
2014-10-22 02:48:19 +00:00
|
|
|
if options["blendmode"] then
|
|
|
|
love.graphics.setBlendMode("alpha")
|
|
|
|
end
|
|
|
|
if options["shader"] then
|
|
|
|
love.graphics.setShader()
|
|
|
|
end
|
2014-12-16 22:14:16 +00:00
|
|
|
if options["stencil"] then
|
|
|
|
love.graphics.setInvertedStencil()
|
|
|
|
end
|
|
|
|
if options["istencil"] then
|
|
|
|
love.graphics.setInvertedStencil()
|
|
|
|
end
|
2014-12-14 18:17:56 +00:00
|
|
|
end)
|
2014-10-22 02:48:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function util.drawto(canvas, x, y, scale, cb)
|
|
|
|
local last_buffer = love.graphics.getCanvas()
|
|
|
|
love.graphics.push()
|
|
|
|
love.graphics.origin()
|
|
|
|
love.graphics.setCanvas(canvas)
|
|
|
|
love.graphics.translate(x, y)
|
|
|
|
love.graphics.scale(scale)
|
|
|
|
cb()
|
|
|
|
love.graphics.setCanvas(last_buffer)
|
|
|
|
love.graphics.pop()
|
|
|
|
end
|
|
|
|
|
|
|
|
return util
|