From be502111139f82e9d8f141001e034a0fc2d8495b Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Sat, 2 Aug 2025 18:39:51 -0300 Subject: [PATCH 01/11] init --- src/framework/ui/uitextedit.cpp | 4 ++-- src/framework/ui/uiwidget.h | 2 +- src/framework/ui/uiwidgetimage.cpp | 6 +++--- src/framework/ui/uiwidgettext.cpp | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/framework/ui/uitextedit.cpp b/src/framework/ui/uitextedit.cpp index e7c1506c00..fb494b6327 100644 --- a/src/framework/ui/uitextedit.cpp +++ b/src/framework/ui/uitextedit.cpp @@ -75,8 +75,8 @@ void UITextEdit::drawSelf(const DrawPoolType drawPane) setProp(PropGlyphsMustRecache, false); // Hack to fix font rendering in atlas - if (!m_atlased && g_drawPool.getAtlas() && m_font->getTexture()->getAtlas(g_drawPool.getAtlas()->getType())) { - m_atlased = true; + if (m_atlased > 0 && g_drawPool.getAtlas() && m_font->getTexture()->getAtlas(g_drawPool.getAtlas()->getType())) { + --m_atlased; update(); } diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index 66013ebbb3..1d931addd3 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -598,7 +598,7 @@ class UIWidget : public LuaObject std::vector> m_colorCoordsBuffer; float m_fontScale{ 1.f }; - bool m_atlased{ false }; + uint8_t m_atlased = 10; // attempts :P public: void resizeToText(); diff --git a/src/framework/ui/uiwidgetimage.cpp b/src/framework/ui/uiwidgetimage.cpp index d18d30fe67..33a81a37be 100644 --- a/src/framework/ui/uiwidgetimage.cpp +++ b/src/framework/ui/uiwidgetimage.cpp @@ -94,9 +94,9 @@ void UIWidget::drawImage(const Rect& screenCoords) return; // Hack to fix font rendering in atlas - if (!m_atlased && g_drawPool.getAtlas() && m_font->getTexture()->getAtlas(g_drawPool.getAtlas()->getType())) { - m_atlased = true; - m_imageCachedScreenCoords = {}; + if (m_atlased > 0 && g_drawPool.getAtlas() && m_imageTexture->getAtlas(g_drawPool.getAtlas()->getType())) { + --m_atlased; + updateImageCache(); } // cache vertex buffers if (m_imageCachedScreenCoords != screenCoords) { diff --git a/src/framework/ui/uiwidgettext.cpp b/src/framework/ui/uiwidgettext.cpp index d53132b9fa..f0ec44acf7 100644 --- a/src/framework/ui/uiwidgettext.cpp +++ b/src/framework/ui/uiwidgettext.cpp @@ -106,9 +106,9 @@ void UIWidget::drawText(const Rect& screenCoords) return; // Hack to fix font rendering in atlas - if (!m_atlased && g_drawPool.getAtlas() && m_font->getTexture()->getAtlas(g_drawPool.getAtlas()->getType())) { - m_atlased = true; - m_textCachedScreenCoords = {}; + if (m_atlased > 0 && g_drawPool.getAtlas() && m_font->getTexture()->getAtlas(g_drawPool.getAtlas()->getType())) { + --m_atlased; + updateText(); } if (screenCoords != m_textCachedScreenCoords) { From f12ccfe6d52692c0e5a0d75464651cf2f28f44a0 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Sat, 2 Aug 2025 18:40:48 -0300 Subject: [PATCH 02/11] Update uiwidget.h --- src/framework/ui/uiwidget.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index 1d931addd3..f7fbe6ff04 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -598,7 +598,7 @@ class UIWidget : public LuaObject std::vector> m_colorCoordsBuffer; float m_fontScale{ 1.f }; - uint8_t m_atlased = 10; // attempts :P + uint8_t m_atlased = 10; // attempts(hack) :P public: void resizeToText(); From 5460777082a57c419ff50576d8f88390a4466e28 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Sat, 2 Aug 2025 20:03:15 -0300 Subject: [PATCH 03/11] Update spritemanager.cpp --- src/client/spritemanager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/spritemanager.cpp b/src/client/spritemanager.cpp index 108a325f5a..8d01fddb9a 100644 --- a/src/client/spritemanager.cpp +++ b/src/client/spritemanager.cpp @@ -213,7 +213,7 @@ ImagePtr SpriteManager::getSpriteImage(const int id, bool& isLoading) const auto threadId = g_app.isLoadingAsyncTexture() ? stdext::getThreadId() : 0; if (const auto& sf = m_spritesFiles[threadId % m_spritesFiles.size()]) { - if (g_app.isLoadingAsyncTexture() && sf->m_loadingState.exchange(SpriteLoadState::LOADING, std::memory_order_acq_rel) == SpriteLoadState::LOADING) { + if (sf->m_loadingState.exchange(SpriteLoadState::LOADING, std::memory_order_acq_rel) == SpriteLoadState::LOADING) { isLoading = true; return nullptr; } @@ -273,8 +273,8 @@ ImagePtr SpriteManager::getSpriteImage(const int id, const FileStreamPtr& file) int read = 0; bool hasAlpha = false; - constexpr int MAX_PIXEL_BLOCK = 4096; - uint8_t tempBuffer[MAX_PIXEL_BLOCK * 4]; // 4 = max channels + static constexpr int MAX_PIXEL_BLOCK = 4096; + static thread_local uint8_t tempBuffer[MAX_PIXEL_BLOCK * 4]; // 4 = max channels while (read < pixelDataSize && writePos < maxWriteSize) { const uint16_t transparentPixels = file->getU16(); From 5a71a51dd6583ec310dda153d60750ec98699560 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Sat, 2 Aug 2025 20:08:38 -0300 Subject: [PATCH 04/11] Update spritemanager.cpp --- src/client/spritemanager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/client/spritemanager.cpp b/src/client/spritemanager.cpp index 8d01fddb9a..4c639b831c 100644 --- a/src/client/spritemanager.cpp +++ b/src/client/spritemanager.cpp @@ -220,8 +220,7 @@ ImagePtr SpriteManager::getSpriteImage(const int id, bool& isLoading) auto image = m_spritesHd ? getSpriteImageHd(id, sf->file) : getSpriteImage(id, sf->file); - if (g_app.isLoadingAsyncTexture()) - sf->m_loadingState.store(SpriteLoadState::LOADED, std::memory_order_release); + sf->m_loadingState.store(SpriteLoadState::LOADED, std::memory_order_release); return image; } From 7e499ab774e1bc99fb568ed3dce7ab1b92bd227c Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Sat, 2 Aug 2025 20:15:35 -0300 Subject: [PATCH 05/11] fix warning --- src/framework/ui/uitextedit.cpp | 6 +++--- src/framework/ui/uitextedit.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/framework/ui/uitextedit.cpp b/src/framework/ui/uitextedit.cpp index fb494b6327..8ccd0fffd7 100644 --- a/src/framework/ui/uitextedit.cpp +++ b/src/framework/ui/uitextedit.cpp @@ -77,7 +77,7 @@ void UITextEdit::drawSelf(const DrawPoolType drawPane) // Hack to fix font rendering in atlas if (m_atlased > 0 && g_drawPool.getAtlas() && m_font->getTexture()->getAtlas(g_drawPool.getAtlas()->getType())) { --m_atlased; - update(); + update(false, true); } const int textLength = std::min(m_glyphsCoords.size(), m_text.length()); @@ -133,7 +133,7 @@ void UITextEdit::drawSelf(const DrawPoolType drawPane) } } -void UITextEdit::update(const bool focusCursor) +void UITextEdit::update(const bool focusCursor, bool disableAreaUpdate) { if (!getProp(PropUpdatesEnabled)) return; @@ -388,7 +388,7 @@ void UITextEdit::update(const bool focusCursor) m_colorCoordsBuffer.emplace_back(Color(rgba), crds); } - if (fireAreaUpdate) + if (!disableAreaUpdate && fireAreaUpdate) onTextAreaUpdate(m_textVirtualOffset, m_textVirtualSize, m_textTotalSize); repaint(); diff --git a/src/framework/ui/uitextedit.h b/src/framework/ui/uitextedit.h index ea06d362ae..dfbeb6f5c5 100644 --- a/src/framework/ui/uitextedit.h +++ b/src/framework/ui/uitextedit.h @@ -33,7 +33,7 @@ class UITextEdit final : public UIWidget void drawSelf(DrawPoolType drawPane) override; private: - void update(bool focusCursor = false); + void update(bool focusCursor = false, bool disableAreaUpdate = false); public: void setCursorPos(int pos); From 498f5b197e15f4474f89ebccac044f4d33d063cc Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Sat, 2 Aug 2025 22:04:43 -0300 Subject: [PATCH 06/11] update --- src/framework/ui/uiwidgetimage.cpp | 2 ++ src/framework/ui/uiwidgettext.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/src/framework/ui/uiwidgetimage.cpp b/src/framework/ui/uiwidgetimage.cpp index 33a81a37be..8d5b2bce62 100644 --- a/src/framework/ui/uiwidgetimage.cpp +++ b/src/framework/ui/uiwidgetimage.cpp @@ -220,6 +220,8 @@ void UIWidget::setImageSource(const std::string_view source, const bool base64) if (!m_imageTexture) return; + m_atlased = 0; + if (m_imageTexture->isAnimatedTexture()) { if (isImageIndividualAnimation()) { m_imageAnimatorTimer.restart(); diff --git a/src/framework/ui/uiwidgettext.cpp b/src/framework/ui/uiwidgettext.cpp index f0ec44acf7..cfd739f154 100644 --- a/src/framework/ui/uiwidgettext.cpp +++ b/src/framework/ui/uiwidgettext.cpp @@ -215,6 +215,7 @@ void UIWidget::setColoredText(const std::string_view coloredText, bool dontFireL void UIWidget::setFont(const std::string_view fontName) { m_font = g_fonts.getFont(fontName); + m_atlased = 0; updateText(); onFontChange(fontName); } \ No newline at end of file From 50b2fd1f8157997400e2e9a2c079522946c59a53 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Sat, 2 Aug 2025 22:25:20 -0300 Subject: [PATCH 07/11] update --- src/framework/graphics/drawpool.cpp | 16 ++++++++++------ src/framework/graphics/drawpool.h | 4 ++-- src/framework/graphics/textureatlas.cpp | 4 ++-- src/framework/graphics/textureatlas.h | 2 +- src/framework/ui/uiwidget.h | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/framework/graphics/drawpool.cpp b/src/framework/graphics/drawpool.cpp index b1cc70ccc3..909213ea08 100644 --- a/src/framework/graphics/drawpool.cpp +++ b/src/framework/graphics/drawpool.cpp @@ -48,12 +48,13 @@ DrawPool* DrawPool::create(const DrawPoolType type) return pool; } -void DrawPool::add(const Color& color, TexturePtr texture, DrawMethod&& method, const CoordsBufferPtr& coordsBuffer) +void DrawPool::add(const Color& color, const TexturePtr& texture, DrawMethod&& method, const CoordsBufferPtr& coordsBuffer) { + Texture* textureAtlas = nullptr; if (m_atlas && texture && texture->isCached(m_atlas->getType())) { const auto& atlas = texture->getAtlas(m_atlas->getType()); if (atlas->isEnabled()) { - texture = m_atlas->getTexture(atlas->layer, texture->isSmooth()); + textureAtlas = m_atlas->getTexture(atlas->layer, texture->isSmooth()); if (method.src.isValid()) method.src = Rect(atlas->x + method.src.x(), atlas->y + method.src.y(), method.src.width(), method.src.height()); } @@ -67,7 +68,7 @@ void DrawPool::add(const Color& color, TexturePtr texture, DrawMethod&& method, if (m_alwaysGroupDrawings) { auto& coords = m_coords.try_emplace(getCurrentState().hash, nullptr).first->second; if (!coords) { - auto state = getState(texture, color); + auto state = getState(texture, textureAtlas, color); coords = list.emplace_back(std::move(state), getCoordsBuffer()).coords.get(); } @@ -91,7 +92,7 @@ void DrawPool::add(const Color& color, TexturePtr texture, DrawMethod&& method, } if (addNewObj) { - auto state = getState(texture, color); + auto state = getState(texture, textureAtlas, color); auto& draw = list.emplace_back(std::move(state), getCoordsBuffer()); if (coordsBuffer) { @@ -176,13 +177,16 @@ bool DrawPool::updateHash(const DrawMethod& method, const TexturePtr& texture, c return true; } -DrawPool::PoolState DrawPool::getState(const TexturePtr& texture, const Color& color) +DrawPool::PoolState DrawPool::getState(const TexturePtr& texture, Texture* textureAtlas, const Color& color) { PoolState copy = getCurrentState(); if (copy.color != color) copy.color = color; - if (texture) { + if (textureAtlas) { + copy.textureId = textureAtlas->getId(); + copy.textureMatrixId = textureAtlas->getTransformMatrixId(); + } else if (texture) { if (texture->isEmpty() || !texture->canCacheInAtlas() || texture->canCacheInAtlas() && m_atlas) { copy.texture = texture; } else { diff --git a/src/framework/graphics/drawpool.h b/src/framework/graphics/drawpool.h index c93d72f159..1fcdb059a6 100644 --- a/src/framework/graphics/drawpool.h +++ b/src/framework/graphics/drawpool.h @@ -272,7 +272,7 @@ class DrawPool STATE_BLEND_EQUATION = 1 << 4, }; - void add(const Color& color, TexturePtr texture, DrawMethod&& method, const CoordsBufferPtr& coordsBuffer = nullptr); + void add(const Color& color, const TexturePtr& texture, DrawMethod&& method, const CoordsBufferPtr& coordsBuffer = nullptr); void addAction(const std::function& action); void bindFrameBuffer(const Size& size, const Color& color = Color::white); @@ -281,7 +281,7 @@ class DrawPool void setFPS(const uint16_t fps) { m_refreshDelay = 1000 / fps; } bool updateHash(const DrawMethod& method, const TexturePtr& texture, const Color& color, bool hasCoord); - PoolState getState(const TexturePtr& texture, const Color& color); + PoolState getState(const TexturePtr& texture, Texture* textureAtlas, const Color& color); PoolState& getCurrentState() { return m_states[m_lastStateIndex]; } const PoolState& getCurrentState() const { return m_states[m_lastStateIndex]; } diff --git a/src/framework/graphics/textureatlas.cpp b/src/framework/graphics/textureatlas.cpp index 0f7d0f011d..f499ed9819 100644 --- a/src/framework/graphics/textureatlas.cpp +++ b/src/framework/graphics/textureatlas.cpp @@ -117,6 +117,6 @@ void TextureAtlas::flush() { } } -TexturePtr TextureAtlas::getTexture(int layer, bool smooth) const { - return m_filterGroups[smooth].layers[layer].framebuffer->getTexture(); +Texture* TextureAtlas::getTexture(int layer, bool smooth) const { + return m_filterGroups[smooth].layers[layer].framebuffer->getTexture().get(); } \ No newline at end of file diff --git a/src/framework/graphics/textureatlas.h b/src/framework/graphics/textureatlas.h index 9b0f31cdbd..5552998990 100644 --- a/src/framework/graphics/textureatlas.h +++ b/src/framework/graphics/textureatlas.h @@ -77,7 +77,7 @@ class TextureAtlas void addTexture(const TexturePtr& texture); void removeTexture(uint32_t id, bool smooth); - TexturePtr getTexture(int layer, bool smooth) const; + Texture* getTexture(int layer, bool smooth) const; Size getSize() const { return m_size; } diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index f7fbe6ff04..c065f8818e 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -598,7 +598,7 @@ class UIWidget : public LuaObject std::vector> m_colorCoordsBuffer; float m_fontScale{ 1.f }; - uint8_t m_atlased = 10; // attempts(hack) :P + uint8_t m_atlased = 100; // attempts(hack) :P public: void resizeToText(); From b46126915c1d46d21a5f440004af43f87d6a751e Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Sat, 2 Aug 2025 22:39:28 -0300 Subject: [PATCH 08/11] fix --- src/framework/ui/uitextedit.cpp | 4 ++-- src/framework/ui/uiwidget.h | 2 +- src/framework/ui/uiwidgetimage.cpp | 6 ++---- src/framework/ui/uiwidgettext.cpp | 5 ++--- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/framework/ui/uitextedit.cpp b/src/framework/ui/uitextedit.cpp index 8ccd0fffd7..91ef2aff59 100644 --- a/src/framework/ui/uitextedit.cpp +++ b/src/framework/ui/uitextedit.cpp @@ -75,8 +75,8 @@ void UITextEdit::drawSelf(const DrawPoolType drawPane) setProp(PropGlyphsMustRecache, false); // Hack to fix font rendering in atlas - if (m_atlased > 0 && g_drawPool.getAtlas() && m_font->getTexture()->getAtlas(g_drawPool.getAtlas()->getType())) { - --m_atlased; + if (g_drawPool.getAtlas() && m_font->getTexture()->getAtlas(g_drawPool.getAtlas()->getType()) != m_lastAtlasRegion) { + m_lastAtlasRegion = m_font->getTexture()->getAtlas(g_drawPool.getAtlas()->getType()); update(false, true); } diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index c065f8818e..bd552bca9f 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -598,7 +598,7 @@ class UIWidget : public LuaObject std::vector> m_colorCoordsBuffer; float m_fontScale{ 1.f }; - uint8_t m_atlased = 100; // attempts(hack) :P + AtlasRegion* m_lastAtlasRegion = nullptr; public: void resizeToText(); diff --git a/src/framework/ui/uiwidgetimage.cpp b/src/framework/ui/uiwidgetimage.cpp index 8d5b2bce62..bbe293496e 100644 --- a/src/framework/ui/uiwidgetimage.cpp +++ b/src/framework/ui/uiwidgetimage.cpp @@ -94,8 +94,8 @@ void UIWidget::drawImage(const Rect& screenCoords) return; // Hack to fix font rendering in atlas - if (m_atlased > 0 && g_drawPool.getAtlas() && m_imageTexture->getAtlas(g_drawPool.getAtlas()->getType())) { - --m_atlased; + if (g_drawPool.getAtlas() && m_imageTexture->getAtlas(g_drawPool.getAtlas()->getType()) != m_lastAtlasRegion) { + m_lastAtlasRegion = m_imageTexture->getAtlas(g_drawPool.getAtlas()->getType()); updateImageCache(); } // cache vertex buffers @@ -220,8 +220,6 @@ void UIWidget::setImageSource(const std::string_view source, const bool base64) if (!m_imageTexture) return; - m_atlased = 0; - if (m_imageTexture->isAnimatedTexture()) { if (isImageIndividualAnimation()) { m_imageAnimatorTimer.restart(); diff --git a/src/framework/ui/uiwidgettext.cpp b/src/framework/ui/uiwidgettext.cpp index cfd739f154..df69e34232 100644 --- a/src/framework/ui/uiwidgettext.cpp +++ b/src/framework/ui/uiwidgettext.cpp @@ -106,8 +106,8 @@ void UIWidget::drawText(const Rect& screenCoords) return; // Hack to fix font rendering in atlas - if (m_atlased > 0 && g_drawPool.getAtlas() && m_font->getTexture()->getAtlas(g_drawPool.getAtlas()->getType())) { - --m_atlased; + if (g_drawPool.getAtlas() && m_font->getTexture()->getAtlas(g_drawPool.getAtlas()->getType()) != m_lastAtlasRegion) { + m_lastAtlasRegion = m_font->getTexture()->getAtlas(g_drawPool.getAtlas()->getType()); updateText(); } @@ -215,7 +215,6 @@ void UIWidget::setColoredText(const std::string_view coloredText, bool dontFireL void UIWidget::setFont(const std::string_view fontName) { m_font = g_fonts.getFont(fontName); - m_atlased = 0; updateText(); onFontChange(fontName); } \ No newline at end of file From a85a620a628d8c98a9245a13341d118911066d5e Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Sat, 2 Aug 2025 23:07:06 -0300 Subject: [PATCH 09/11] melhoria --- src/framework/ui/uitextedit.cpp | 8 ++--- src/framework/ui/uiwidget.h | 2 +- src/framework/ui/uiwidgetimage.cpp | 48 ++++++++++++++++++------------ 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/framework/ui/uitextedit.cpp b/src/framework/ui/uitextedit.cpp index 91ef2aff59..68d1a68874 100644 --- a/src/framework/ui/uitextedit.cpp +++ b/src/framework/ui/uitextedit.cpp @@ -362,16 +362,16 @@ void UITextEdit::update(const bool focusCursor, bool disableAreaUpdate) glyphScreenCoords.setRight(textScreenCoords.right()); } + // render glyph + m_glyphsCoords[i].first = glyphScreenCoords; + m_glyphsCoords[i].second = glyphTextureCoords; + TextureAtlas* atlas = nullptr; if (g_drawPool.isValid()) atlas = g_drawPool.getAtlas(); else atlas = g_drawPool.get(DrawPoolType::FOREGROUND)->getAtlas(); - // render glyph - m_glyphsCoords[i].first = glyphScreenCoords; - m_glyphsCoords[i].second = glyphTextureCoords; - if (atlas) { if (const auto region = m_font->getTexture()->getAtlas(atlas->getType())) glyphTextureCoords = Rect(region->x + glyphTextureCoords.x(), region->y + glyphTextureCoords.y(), glyphTextureCoords.width(), glyphTextureCoords.height()); diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index bd552bca9f..23d1fd44f4 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -508,7 +508,7 @@ class UIWidget : public LuaObject void updateImageCache() { if (!m_imageCachedScreenCoords.isNull()) m_imageCachedScreenCoords = {}; } void configureBorderImage() { setProp(PropImageBordered, true); updateImageCache(); } - std::vector> m_imageCoordsCache; + CoordsBufferPtr m_imageCoordsCache; Rect m_imageCachedScreenCoords; diff --git a/src/framework/ui/uiwidgetimage.cpp b/src/framework/ui/uiwidgetimage.cpp index bbe293496e..9531dab2ba 100644 --- a/src/framework/ui/uiwidgetimage.cpp +++ b/src/framework/ui/uiwidgetimage.cpp @@ -28,7 +28,9 @@ #include #include -void UIWidget::initImage() {} +void UIWidget::initImage() { + m_imageCoordsCache = std::make_shared(); +} void UIWidget::parseImageStyle(const OTMLNodePtr& styleNode) { @@ -88,6 +90,18 @@ void UIWidget::parseImageStyle(const OTMLNodePtr& styleNode) } } +void addImageRect(const TexturePtr& texture, const CoordsBufferPtr& coords, bool useRepeated, const Rect& dest, Rect src) { + if (const auto atlas = g_drawPool.getAtlas()) { + if (const auto region = texture->getAtlas(atlas->getType())) + src = Rect(region->x + src.x(), region->y + src.y(), src.width(), src.height()); + } + + if (useRepeated) + coords->addRepeatedRects(dest, src); + else + coords->addRect(dest, src); +}; + void UIWidget::drawImage(const Rect& screenCoords) { if (!m_imageTexture || !screenCoords.isValid()) @@ -101,13 +115,15 @@ void UIWidget::drawImage(const Rect& screenCoords) // cache vertex buffers if (m_imageCachedScreenCoords != screenCoords) { m_imageCachedScreenCoords = screenCoords; - m_imageCoordsCache.clear(); + m_imageCoordsCache->clear(); Rect drawRect = screenCoords; drawRect.translate(m_imageRect.topLeft()); if (m_imageRect.isValid()) drawRect.resize(m_imageRect.size()); + const bool useRepeated = hasProp(PropImageBordered) || hasProp(PropImageRepeated); + auto clipRect = m_imageClipRect.isValid() ? m_imageClipRect : Rect(0, 0, m_imageTexture->getSize()); if (hasProp(PropImageBordered)) { @@ -133,32 +149,32 @@ void UIWidget::drawImage(const Rect& screenCoords) // first the center if (centerSize.area() > 0) { rectCoords = Rect(drawRect.left() + leftBorder.width(), drawRect.top() + topBorder.height(), centerSize); - m_imageCoordsCache.emplace_back(rectCoords, center); + addImageRect(m_imageTexture, m_imageCoordsCache, useRepeated, rectCoords, center); } // top left corner rectCoords = Rect(drawRect.topLeft(), topLeftCorner.size()); - m_imageCoordsCache.emplace_back(rectCoords, topLeftCorner); + addImageRect(m_imageTexture, m_imageCoordsCache, useRepeated, rectCoords, topLeftCorner); // top rectCoords = Rect(drawRect.left() + topLeftCorner.width(), drawRect.topLeft().y, centerSize.width(), topBorder.height()); - m_imageCoordsCache.emplace_back(rectCoords, topBorder); + addImageRect(m_imageTexture, m_imageCoordsCache, useRepeated, rectCoords, topBorder); // top right corner rectCoords = Rect(drawRect.left() + topLeftCorner.width() + centerSize.width(), drawRect.top(), topRightCorner.size()); - m_imageCoordsCache.emplace_back(rectCoords, topRightCorner); + addImageRect(m_imageTexture, m_imageCoordsCache, useRepeated, rectCoords, topRightCorner); // left rectCoords = Rect(drawRect.left(), drawRect.top() + topLeftCorner.height(), leftBorder.width(), centerSize.height()); - m_imageCoordsCache.emplace_back(rectCoords, leftBorder); + addImageRect(m_imageTexture, m_imageCoordsCache, useRepeated, rectCoords, leftBorder); // right rectCoords = Rect(drawRect.left() + leftBorder.width() + centerSize.width(), drawRect.top() + topRightCorner.height(), rightBorder.width(), centerSize.height()); - m_imageCoordsCache.emplace_back(rectCoords, rightBorder); + addImageRect(m_imageTexture, m_imageCoordsCache, useRepeated, rectCoords, rightBorder); // bottom left corner rectCoords = Rect(drawRect.left(), drawRect.top() + topLeftCorner.height() + centerSize.height(), bottomLeftCorner.size()); - m_imageCoordsCache.emplace_back(rectCoords, bottomLeftCorner); + addImageRect(m_imageTexture, m_imageCoordsCache, useRepeated, rectCoords, bottomLeftCorner); // bottom rectCoords = Rect(drawRect.left() + bottomLeftCorner.width(), drawRect.top() + topBorder.height() + centerSize.height(), centerSize.width(), bottomBorder.height()); - m_imageCoordsCache.emplace_back(rectCoords, bottomBorder); + addImageRect(m_imageTexture, m_imageCoordsCache, useRepeated, rectCoords, bottomBorder); // bottom right corner rectCoords = Rect(drawRect.left() + bottomLeftCorner.width() + centerSize.width(), drawRect.top() + topRightCorner.height() + centerSize.height(), bottomRightCorner.size()); - m_imageCoordsCache.emplace_back(rectCoords, bottomRightCorner); + addImageRect(m_imageTexture, m_imageCoordsCache, useRepeated, rectCoords, bottomRightCorner); } else { if (isImageFixedRatio()) { Size textureSize = m_imageTexture->getSize(), @@ -175,25 +191,19 @@ void UIWidget::drawImage(const Rect& screenCoords) clipRect = Rect(texCoordsOffset, textureClipSize); } - m_imageCoordsCache.emplace_back(drawRect, clipRect); + addImageRect(m_imageTexture, m_imageCoordsCache, useRepeated, drawRect, clipRect); } } // smooth is now enabled by default for all textures //m_imageTexture->setSmooth(m_imageSmooth); - const bool useRepeated = hasProp(PropImageBordered) || hasProp(PropImageRepeated); const auto& texture = m_imageTexture->isAnimatedTexture() && isImageIndividualAnimation() ? std::static_pointer_cast(m_imageTexture)->get(m_currentFrame, m_imageAnimatorTimer) : m_imageTexture; g_drawPool.setDrawOrder(m_imageDrawOrder); - for (const auto& [dest, src] : m_imageCoordsCache) { - if (useRepeated) - g_drawPool.addTexturedRepeatedRect(dest, texture, src, m_imageColor); - else - g_drawPool.addTexturedRect(dest, texture, src, m_imageColor); - } + g_drawPool.addTexturedCoordsBuffer(texture, m_imageCoordsCache, m_imageColor); g_drawPool.resetDrawOrder(); } From b9d7a082988d58995f2aa27390ea7f27dc54df59 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Sat, 2 Aug 2025 23:19:38 -0300 Subject: [PATCH 10/11] fix --- src/framework/graphics/framebuffer.h | 1 + src/framework/graphics/textureatlas.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/framework/graphics/framebuffer.h b/src/framework/graphics/framebuffer.h index 6b00c9d7aa..cf67fd7294 100644 --- a/src/framework/graphics/framebuffer.h +++ b/src/framework/graphics/framebuffer.h @@ -49,6 +49,7 @@ class FrameBuffer void setAutoResetState(bool v) { m_isScene = v; } TexturePtr getTexture() const { return m_texture; } + Texture* rawTexture() const { return m_texture.get(); } TexturePtr extractTexture(); Size getSize() const { return m_texture->getSize(); } diff --git a/src/framework/graphics/textureatlas.cpp b/src/framework/graphics/textureatlas.cpp index f499ed9819..c53ecde182 100644 --- a/src/framework/graphics/textureatlas.cpp +++ b/src/framework/graphics/textureatlas.cpp @@ -118,5 +118,5 @@ void TextureAtlas::flush() { } Texture* TextureAtlas::getTexture(int layer, bool smooth) const { - return m_filterGroups[smooth].layers[layer].framebuffer->getTexture().get(); + return m_filterGroups[smooth].layers[layer].framebuffer->rawTexture(); } \ No newline at end of file From cd0f18fed072563c9eaacac668d19cbf256de079 Mon Sep 17 00:00:00 2001 From: Renato Machado Date: Sat, 2 Aug 2025 23:51:05 -0300 Subject: [PATCH 11/11] fix --- src/framework/graphics/drawpool.cpp | 8 ++++---- src/framework/graphics/framebuffer.h | 1 - src/framework/graphics/textureatlas.cpp | 7 ++----- src/framework/graphics/textureatlas.h | 9 ++++----- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/framework/graphics/drawpool.cpp b/src/framework/graphics/drawpool.cpp index 909213ea08..9822f06f13 100644 --- a/src/framework/graphics/drawpool.cpp +++ b/src/framework/graphics/drawpool.cpp @@ -52,11 +52,11 @@ void DrawPool::add(const Color& color, const TexturePtr& texture, DrawMethod&& m { Texture* textureAtlas = nullptr; if (m_atlas && texture && texture->isCached(m_atlas->getType())) { - const auto& atlas = texture->getAtlas(m_atlas->getType()); - if (atlas->isEnabled()) { - textureAtlas = m_atlas->getTexture(atlas->layer, texture->isSmooth()); + const auto region = texture->getAtlas(m_atlas->getType()); + if (region->isEnabled()) { + textureAtlas = region->atlas; if (method.src.isValid()) - method.src = Rect(atlas->x + method.src.x(), atlas->y + method.src.y(), method.src.width(), method.src.height()); + method.src = Rect(region->x + method.src.x(), region->y + method.src.y(), method.src.width(), method.src.height()); } } diff --git a/src/framework/graphics/framebuffer.h b/src/framework/graphics/framebuffer.h index cf67fd7294..6b00c9d7aa 100644 --- a/src/framework/graphics/framebuffer.h +++ b/src/framework/graphics/framebuffer.h @@ -49,7 +49,6 @@ class FrameBuffer void setAutoResetState(bool v) { m_isScene = v; } TexturePtr getTexture() const { return m_texture; } - Texture* rawTexture() const { return m_texture.get(); } TexturePtr extractTexture(); Size getSize() const { return m_texture->getSize(); } diff --git a/src/framework/graphics/textureatlas.cpp b/src/framework/graphics/textureatlas.cpp index c53ecde182..d0475198cf 100644 --- a/src/framework/graphics/textureatlas.cpp +++ b/src/framework/graphics/textureatlas.cpp @@ -71,7 +71,8 @@ void TextureAtlas::addTexture(const TexturePtr& texture) { region.layer, static_cast(width), static_cast(height), - texture->getTransformMatrixId() + texture->getTransformMatrixId(), + m_filterGroups[texture->isSmooth()].layers[region.layer].framebuffer->getTexture().get() ); texture->m_atlas[m_type] = info.get(); @@ -115,8 +116,4 @@ void TextureAtlas::flush() { } } } -} - -Texture* TextureAtlas::getTexture(int layer, bool smooth) const { - return m_filterGroups[smooth].layers[layer].framebuffer->rawTexture(); } \ No newline at end of file diff --git a/src/framework/graphics/textureatlas.h b/src/framework/graphics/textureatlas.h index 5552998990..241bce6af3 100644 --- a/src/framework/graphics/textureatlas.h +++ b/src/framework/graphics/textureatlas.h @@ -23,16 +23,17 @@ class AtlasRegion int16_t width; int16_t height; uint16_t transformMatrixId; - std::atomic_bool enabled = false; + Texture* atlas; + std::atomic_bool enabled; bool isEnabled() const { return enabled.load(std::memory_order_acquire); } AtlasRegion(uint32_t tid, int16_t x, int16_t y, int8_t layer, - int16_t width, int16_t height, uint16_t transformId) + int16_t width, int16_t height, uint16_t transformId, Texture* atlas) : textureID(tid), x(x), y(y), layer(layer), - width(width), height(height), transformMatrixId(transformId) { + width(width), height(height), transformMatrixId(transformId), atlas(atlas) { } }; @@ -77,8 +78,6 @@ class TextureAtlas void addTexture(const TexturePtr& texture); void removeTexture(uint32_t id, bool smooth); - Texture* getTexture(int layer, bool smooth) const; - Size getSize() const { return m_size; } void flush();