diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 36039130c..ab0dd3726 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1552,6 +1552,11 @@ void TextEdit::_notification(int p_what) { line_drawing_cache[line] = cache_entry; } + // Flush out any text in the drawer BEFORE + // drawing the completion box, as we want the completion + // box to overwrite the underlying text. + drawer.flush(); + bool completion_below = false; if (completion_active && is_cursor_visible && completion_options.size() > 0) { // Completion panel diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index dfc6542b2..f3437bd8b 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -544,16 +544,19 @@ FontDrawer::FontDrawer(const Ref &p_font, const Color &p_outline_color) : font(p_font), outline_color(p_outline_color) { has_outline = p_font->has_outline(); - multirect.begin(); } -FontDrawer::~FontDrawer() { +void FontDrawer::flush() { for (int i = 0; i < pending_draws.size(); ++i) { const PendingDraw &draw = pending_draws[i]; font->draw_char_ex(draw.canvas_item, draw.pos, draw.chr, draw.next, draw.modulate, false, &multirect); } - multirect.end(); + multirect.flush(); +} + +FontDrawer::~FontDrawer() { + flush(); } void BitmapFont::set_fallback(const Ref &p_fallback) { diff --git a/scene/resources/font.h b/scene/resources/font.h index 563dfe085..5d4244ed3 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -114,6 +114,7 @@ public: } MultiRect &get_multirect() { return multirect; } + void flush(); ~FontDrawer(); }; diff --git a/servers/rendering/rendering_server_canvas_helper.cpp b/servers/rendering/rendering_server_canvas_helper.cpp index 747fd6ee0..747a2418e 100644 --- a/servers/rendering/rendering_server_canvas_helper.cpp +++ b/servers/rendering/rendering_server_canvas_helper.cpp @@ -38,22 +38,6 @@ Mutex RenderingServerCanvasHelper::_tilemap_mutex; bool RenderingServerCanvasHelper::_multirect_enabled = true; -MultiRect::MultiRect() { - begin(); -} -MultiRect::~MultiRect() { - end(); -} - -void MultiRect::begin() { - DEV_CHECK_ONCE(!rects.size()); - rects.clear(); - sources.clear(); - - state.flags = 0; - state_set = false; -} - void MultiRect::add_rect(RID p_canvas_item, const Rect2 &p_rect, RID p_texture, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, RID p_normal_map, bool p_clip_uv) { bool new_common_data = true; @@ -101,7 +85,7 @@ void MultiRect::add_rect(RID p_canvas_item, const Rect2 &p_rect, RID p_texture, if (!is_empty()) { if ((state != s) || (rects.size() >= MAX_RECTS)) { - end(); + flush(); } else { new_common_data = false; } @@ -113,6 +97,11 @@ void MultiRect::add_rect(RID p_canvas_item, const Rect2 &p_rect, RID p_texture, rects.push_back(rect); sources.push_back(source); + + // Legacy path + if (!VisualServerCanvasHelper::_multirect_enabled) { + flush(); + } } void MultiRect::begin(const RenderingServerCanvasHelper::State &p_state) { @@ -184,7 +173,7 @@ bool MultiRect::add(const Rect2 &p_rect, const Rect2 &p_src_rect, bool p_commit_ return true; } -void MultiRect::end() { +void MultiRect::flush() { if (!is_empty()) { if (RenderingServerCanvasHelper::_multirect_enabled) { RenderingServer::get_singleton()->canvas_item_add_texture_multirect_region(state.item, rects, state.texture, sources, state.modulate, state.flags, state.normal_map); @@ -203,6 +192,9 @@ void MultiRect::end() { sources.clear(); } state_set = false; + + // This may not be necessary (if needing to eek out maximum speed). + state.flags = 0; } void RenderingServerCanvasHelper::tilemap_begin() { @@ -272,7 +264,7 @@ void RenderingServerCanvasHelper::tilemap_end() { } for (uint32_t n = 0; n < _tilemap_multirects.size(); n++) { - _tilemap_multirects[n].end(); + _tilemap_multirects[n].flush(); } _tilemap_multirects.clear(); diff --git a/servers/rendering/rendering_server_canvas_helper.h b/servers/rendering/rendering_server_canvas_helper.h index 7f60805f4..dcd50d9d7 100644 --- a/servers/rendering/rendering_server_canvas_helper.h +++ b/servers/rendering/rendering_server_canvas_helper.h @@ -98,7 +98,6 @@ private: public: // Simple API - void begin(); void add_rect(RID p_canvas_item, const Rect2 &p_rect, RID p_texture, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, RID p_normal_map = RID(), bool p_clip_uv = false); // Efficient API @@ -106,10 +105,12 @@ public: bool add(const Rect2 &p_rect, const Rect2 &p_src_rect, bool p_commit_on_flip_change = true); bool is_empty() const { return rects.is_empty(); } bool is_full() const { return rects.is_full(); } - void end(); - MultiRect(); - ~MultiRect(); + // Always called in destructor, but can be used explicitly + // for multiple draws, or to time the flush. + void flush(); + + ~MultiRect() { flush(); } }; #endif // RENDERING_SERVER_CANVAS_HELPER_H \ No newline at end of file