aboutsummaryrefslogtreecommitdiffstats
path: root/fakecanvas.lua
diff options
context:
space:
mode:
authorxgoff <antipotroast@gmail.com>2012-08-03 13:26:16 -0500
committerxgoff <antipotroast@gmail.com>2012-08-03 13:26:16 -0500
commit4c9176ee3ab1f434d9bccb2955f852df105c1702 (patch)
treebbb600dff6d6eff24471fd19dce5e90691cb4a0b /fakecanvas.lua
parent0a822c648427155c2649665f5f083ee299644ab9 (diff)
downloadlove2d-fakecanvas-4c9176ee3ab1f434d9bccb2955f852df105c1702.tar.gz
love2d-fakecanvas-4c9176ee3ab1f434d9bccb2955f852df105c1702.tar.bz2
love2d-fakecanvas-4c9176ee3ab1f434d9bccb2955f852df105c1702.tar.xz
love2d-fakecanvas-4c9176ee3ab1f434d9bccb2955f852df105c1702.zip
add setOption and getOption functions.
to start off, there is an option "vflip", used for potential performance increase, at the cost of incorrect texture coordinates
Diffstat (limited to 'fakecanvas.lua')
-rw-r--r--fakecanvas.lua36
1 files changed, 30 insertions, 6 deletions
diff --git a/fakecanvas.lua b/fakecanvas.lua
index 39482ce..b170896 100644
--- a/fakecanvas.lua
+++ b/fakecanvas.lua
@@ -39,6 +39,16 @@ local canvasmt = { __index = canvas }
local canvases = setmetatable({ }, { __mode = "k" })
+local options = {
+ -- flip fake canvas images vertically (then unflip with quad) in order to
+ -- match real canvas orientation. this only makes a difference inside
+ -- shaders, when using the canvas' texture coordinates. if you do not need
+ -- to use this information, you can get a performance boost by disabling
+ -- this option. you can enable or disable vflipping for individual fake
+ -- canvases by placing setOption() calls around the newCanvas() call.
+ vflip = true,
+}
+
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("#", ...)
@@ -115,8 +125,11 @@ local function Canvas (width, height)
c._imagedata = love.image.newImageData(w, h)
c._image = love.graphics.newImage(c._imagedata)
c._quad = love.graphics.newQuad(0, 0, w, h, w, h)
+ c._vflip = options.vflip
- c._quad:flip(false, true) -- flip vertically part 0
+ if options.vflip then
+ c._quad:flip(false, true) -- flip vertically part 0
+ end
local p = newproxy(true)
@@ -166,11 +179,14 @@ local function setCanvas (...)
love.graphics.setBackgroundColor(0, 0, 0, 0)
love.graphics.clear()
- -- flip vertically (unfortunately) so it can later be drawn unflipped in order to match texcoords of real canvases. part 1
- local flipped = love.graphics.newImage(tempdata)
- love.graphics.draw(flipped, 0, current_canvas._imagedata:getHeight(), 0, 1, -1)
-
- local newdata = love.graphics.newScreenshot()
+ local newdata = tempdata
+ if current_canvas._vflip then
+ -- flip vertically (unfortunately) so it can later be drawn unflipped in order to match texcoords of real canvases. part 1
+ local flipped = love.graphics.newImage(tempdata)
+ love.graphics.draw(flipped, 0, current_canvas._imagedata:getHeight(), 0, 1, -1)
+
+ newdata = love.graphics.newScreenshot()
+ end
--newdata:encode("__canvas.png")
@@ -284,6 +300,14 @@ function M.getMaxCanvasSize (hw, hh)
end
end
+function M.setOption (name, value)
+ options[name] = value
+end
+
+function M.getOption (name)
+ return options[name]
+end
+
M.enable()
return M \ No newline at end of file