post draw - fixes top most shader application

This commit is contained in:
Michael Freno
2025-10-31 09:06:29 -04:00
parent 9e12f7aece
commit 9f215e252e

View File

@@ -2385,15 +2385,20 @@ Gui._backdropCanvas = nil
Gui._canvasDimensions = { width = 0, height = 0 } Gui._canvasDimensions = { width = 0, height = 0 }
---@param gameDrawFunc function|nil -- Function to draw game content, needed for backdrop blur ---@param gameDrawFunc function|nil -- Function to draw game content, needed for backdrop blur
---@param postDrawFunc function|nil -- Optional function to draw after GUI (for top-level shaders/effects)
---function love.draw() ---function love.draw()
--- FlexLove.Gui.draw(function() --- FlexLove.Gui.draw(function()
--- --Game rendering logic --- --Game rendering logic
--- RenderSystem:update() --- RenderSystem:update()
--- end) --- end, function()
--- -- Layers on top of GUI - blurs will not extend to this --- -- Layers on top of GUI - blurs will not extend to this
--- overlayStats.draw() --- overlayStats.draw()
--- end)
---end ---end
function Gui.draw(gameDrawFunc) function Gui.draw(gameDrawFunc, postDrawFunc)
-- Save the current canvas state to support nested rendering
local outerCanvas = love.graphics.getCanvas()
local gameCanvas = nil local gameCanvas = nil
-- Render game content to a canvas if function provided -- Render game content to a canvas if function provided
@@ -2410,15 +2415,12 @@ function Gui.draw(gameDrawFunc)
gameCanvas = Gui._gameCanvas gameCanvas = Gui._gameCanvas
-- Save the current canvas so we can restore it
local previousCanvas = love.graphics.getCanvas()
love.graphics.setCanvas(gameCanvas) love.graphics.setCanvas(gameCanvas)
love.graphics.clear() love.graphics.clear()
gameDrawFunc() -- Call the drawing function gameDrawFunc() -- Call the drawing function
love.graphics.setCanvas(previousCanvas) love.graphics.setCanvas(outerCanvas)
-- Draw game canvas to the previous canvas (or screen if none) -- Draw game canvas to the outer canvas (or screen if none)
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(gameCanvas, 0, 0) love.graphics.draw(gameCanvas, 0, 0)
end end
@@ -2460,20 +2462,20 @@ function Gui.draw(gameDrawFunc)
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(gameCanvas, 0, 0) love.graphics.draw(gameCanvas, 0, 0)
-- Reset to screen -- Reset to outer canvas (screen or parent canvas)
love.graphics.setCanvas() love.graphics.setCanvas(outerCanvas)
love.graphics.setColor(unpack(prevColor)) love.graphics.setColor(unpack(prevColor))
-- Draw each element, updating backdrop canvas progressively -- Draw each element, updating backdrop canvas progressively
for _, win in ipairs(Gui.topElements) do for _, win in ipairs(Gui.topElements) do
-- Draw element with current backdrop state -- Draw element with current backdrop state to outer canvas
win:draw(backdropCanvas) win:draw(backdropCanvas)
-- Update backdrop canvas to include this element (for next elements) -- Update backdrop canvas to include this element (for next elements)
love.graphics.setCanvas(backdropCanvas) love.graphics.setCanvas(backdropCanvas)
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
win:draw(nil) -- Draw without backdrop blur to the backdrop canvas win:draw(nil) -- Draw without backdrop blur to the backdrop canvas
love.graphics.setCanvas() -- Always reset to screen love.graphics.setCanvas(outerCanvas) -- Reset to outer canvas
end end
else else
-- No backdrop blur needed, draw normally -- No backdrop blur needed, draw normally
@@ -2482,8 +2484,13 @@ function Gui.draw(gameDrawFunc)
end end
end end
-- Ensure canvas is reset to screen at the end -- Call post-draw function if provided (for top-level shaders/effects)
love.graphics.setCanvas() if type(postDrawFunc) == "function" then
postDrawFunc()
end
-- Restore the original canvas state
love.graphics.setCanvas(outerCanvas)
end end
--- Find the topmost element at given coordinates (considering z-index) --- Find the topmost element at given coordinates (considering z-index)