Skip to content

Commit

Permalink
[SUTK] when changing font in SmallText, mark it as redraw
Browse files Browse the repository at this point in the history
 - this fixes no visual updates upon font change on SmallText after previous commit (GPU usage reduction)
  • Loading branch information
ravi688 committed Dec 10, 2024
1 parent cf4b918 commit 1b123ae
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
7 changes: 7 additions & 0 deletions sutk/include/sutk/Renderable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ namespace SUTK
RenderableContainer* m_container;
u32 m_drawOrder;
bool m_isDrawOrderDirty;
com::Bool m_isRedraw;

// Called by UIDriver to reset the redraw flag
void setRedraw(com::Bool isRedraw) noexcept { m_isRedraw = isRedraw; }

protected:
// Rendering Geometries (or Text) requires conversion from local coordinates to global coordinates (target rendering backend, SGE)
Expand Down Expand Up @@ -49,6 +53,9 @@ namespace SUTK
void setDrawOrder(u32 drawOrder) { m_drawOrder = drawOrder; m_isDrawOrderDirty = true; }
u32 getDrawOrder() const noexcept { return m_drawOrder; }

com::Bool isRedraw() const noexcept { return com::Bool { m_isRedraw || com::cast_away_const(this)->isDirty() || isDrawOrderDirty() }; }
void redraw() noexcept { m_isRedraw = com::True; }

bool ensureUpdated() noexcept
{
if(isDirty())
Expand Down
2 changes: 1 addition & 1 deletion sutk/source/Renderable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace SUTK
{
Renderable::Renderable(UIDriver& driver, RenderableContainer* container) noexcept : UIDriverObject(driver), m_container(container), m_drawOrder(0), m_isDrawOrderDirty(true)
Renderable::Renderable(UIDriver& driver, RenderableContainer* container) noexcept : UIDriverObject(driver), m_container(container), m_drawOrder(0), m_isDrawOrderDirty(true), m_isRedraw(com::False)
{
if(container != NULL)
{
Expand Down
1 change: 1 addition & 0 deletions sutk/source/SmallText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ namespace SUTK
void SmallText::setFont(UIDriver::FontReference font) noexcept
{
getGfxDriver().setTextFont(getGfxDriverObjectHandle(), font);
redraw();
}
f32 SmallText::getBaselineHeight() noexcept
{
Expand Down
13 changes: 5 additions & 8 deletions sutk/source/UIDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,15 @@ namespace SUTK
for(auto it = m_renderables.begin(); it != m_renderables.end(); it++)
{
Renderable* renderable = *it;
if(renderable->isDirty())
if(!isRerender && renderable->isRedraw())
{
renderable->update();
if(!isRerender)
isRerender = com::True;
isRerender = com::True;
renderable->setRedraw(com::False);
}
if(renderable->isDirty())
renderable->update();
if(renderable->isDrawOrderDirty())
{
isRecalculateDrawOrder = true;
if(!isRerender)
isRerender = com::True;
}
u32 drawOrder = renderable->getDrawOrder();
if(drawOrder < minDrawOrder)
minDrawOrder = drawOrder;
Expand Down

0 comments on commit 1b123ae

Please sign in to comment.