aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--fakecanvas.lua6
2 files changed, 6 insertions, 2 deletions
diff --git a/README.md b/README.md
index e58a47e..373a72c 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ it is more or less a drop-in library, in that all you need to do is call `requir
it uses (a few) screenshots in order to isolate drawing operations, which means there are some amusing drawbacks:
* `setCanvas()` is fairly expensive
-* clearing a canvas is really expensive
+* non zero-argument versions of canvas:clear() are really expensive
* each `setCanvas()` call will allocate several megs of ram, this isn't a huge deal if you draw to canvases only occasionally. draw to one every frame, though...
* possible drawing issues if you call `love.graphics.present()` yourself, specifically between `setCanvas()` calls
* canvas width/height cannot exceed the window's width/height, and if your hardware lacks PO2 support, canvases will be further limited to that as well. ie: for an 800x600 display the max canvas size is 512x512. 1024x768 will limit you to 1024x512, and so on.
diff --git a/fakecanvas.lua b/fakecanvas.lua
index c311b7e..863dca7 100644
--- a/fakecanvas.lua
+++ b/fakecanvas.lua
@@ -50,11 +50,13 @@ local options = {
vflip = true,
}
+local blank
function canvas:clear (...) -- other option is chucking out the imagedata and creating a new one, but i'd probably end up using mapPixel anyway
local nargs = select("#", ...)
if nargs == 0 then
- canvases[self]._imagedata:mapPixel(function () return 0, 0, 0, 0 end)
+ local id = canvases[self]._imagedata
+ id:paste(blank, 0, 0, 0, 0, id:getWidth(), id:getHeight())
elseif nargs == 1 and type(...) == "table" then
local t = ...
local r, g, b, a = tonumber(t[1]) or 0, tonumber(t[2]) or 0, tonumber(t[3]) or 0, tonumber(t[4]) or 255
@@ -318,6 +320,8 @@ function M.getOption (name)
return options[name]
end
+blank = love.image.newImageData(M.getMaxCanvasSize())
+
M.enable()
return M \ No newline at end of file