fix: better handling of indirect rendering

This commit is contained in:
Kazhnuz 2021-09-03 11:44:17 +02:00
parent 07400ce991
commit 6c55a070fe
10 changed files with 64 additions and 21 deletions

View file

@ -138,6 +138,7 @@ end
-- Draw the whole game
function CoreSystem:draw()
self.scenemanager:redraw()
self.scenemanager:draw()
end

View file

@ -127,4 +127,8 @@ function SceneManager:draw()
self.controller.screen:cease()
end
function SceneManager:redraw()
self.currentScene:redraw()
end
return SceneManager

View file

@ -20,9 +20,6 @@ end
function CanvasElement:updateElement(dt)
CanvasElement.super.updateElement(self, dt)
if (self.canvas.needRedraw or self.canvas.isAnimated) then
self:redraw()
end
end
function CanvasElement:getCanvasDimensions()
@ -30,6 +27,12 @@ function CanvasElement:getCanvasDimensions()
end
function CanvasElement:redraw()
if (self.canvas.needRedraw or self.canvas.isAnimated) then
self:generateTexture()
end
end
function CanvasElement:generateTexture()
local w, h = self:getDimensions()
local canvas = love.graphics.newCanvas(w + (self.canvas.padding*2), h + (self.canvas.padding*2))

View file

@ -110,6 +110,10 @@ end
-- DRAW FUNCTIONS
-- Draw the menu and its content
function GuiElement:redraw()
end
function GuiElement:drawElement()
self:draw()
end

View file

@ -162,6 +162,12 @@ end
-- DRAW FUNCTIONS
-- Draw the menu and its content
function Gui:redraw()
for _, element in pairs(self.elements) do
element:redraw()
end
end
function Gui:drawTop()
for _, element in ipairs(self:getVisibleElement(true)) do
element:drawElement()

View file

@ -185,5 +185,12 @@ function MenuModel:moveCursor(relative)
page:moveCursor(relative)
end
-- DRAW
-- Draw widget
function MenuModel:redraw()
local page = self:getCurrentPage()
page:redraw()
end
return MenuModel

View file

@ -189,5 +189,11 @@ function Page:moveCursor(relative)
self:moveCursorAbsolute(self.selected + relative)
end
-- DRAW
function Page:redraw()
for _, widget in ipairs(self.widgets) do
widget:redraw()
end
end
return Page

View file

@ -169,6 +169,11 @@ function Menu:drawWidgetBackground(x, y, w, h)
end
function Menu:redraw()
self.widget:redraw()
Menu.super.redraw(self)
end
-- WIDGET FUNCTIONS
-- Handle widgets of the functions

View file

@ -73,7 +73,13 @@ function BaseWidget:register()
self.menu:addWidget(self)
end
function BaseWidget:redrawCanvas()
function BaseWidget:redraw()
if (self.canvas.needRedraw) then
self:generateTexture()
end
end
function BaseWidget:generateTexture()
self.width, self.height = self.menu:getWidgetSize(self.id)
local canvas = love.graphics.newCanvas(self.width, self.height)
@ -134,9 +140,6 @@ end
-- Update the widget
function BaseWidget:update(dt)
if (self.canvas.needRedraw) then
self:redrawCanvas()
end
-- N/A
end

View file

@ -149,6 +149,10 @@ end
-- DRAW FUNCTIONS
-- Draw the scene and its content
function Scene:redraw()
self.gui:redraw()
end
function Scene:drawScene()
self:drawStart()
self:drawWorld()