[Bf-blender-cvs] [39b654f4ff1] blender2.8: UI: Perf: Use widget base batching

Clément Foucault noreply at git.blender.org
Fri Apr 6 14:24:32 CEST 2018


Commit: 39b654f4ff123e3e9bc345b25d4883df4de4ad5e
Author: Clément Foucault
Date:   Fri Apr 6 14:30:20 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB39b654f4ff123e3e9bc345b25d4883df4de4ad5e

UI: Perf: Use widget base batching

Overall 10% more performance on general UI drawing time.

This commit can introduce ordering problem on some elements.
In this case you need to flush the widget cache to ensure the element that
is going to be drawn is drawn on top of any widget base.

To flush the cache use UI_widgetbase_draw_cache_flush.

This is already done for BLF and Icons.

===================================================================

M	source/blender/blenfont/intern/blf_font.c
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_icons.c

===================================================================

diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 07e568dd279..cc7eb336b21 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -58,6 +58,8 @@
 #include "BIF_gl.h"
 #include "BLF_api.h"
 
+#include "UI_interface.h"
+
 #include "GPU_immediate.h"
 #include "GPU_matrix.h"
 #include "GPU_batch.h"
@@ -184,6 +186,9 @@ void blf_batch_draw(void)
 	glEnable(GL_BLEND);
 	glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
 
+	/* We need to flush widget base first to ensure correct ordering. */
+	UI_widgetbase_draw_cache_flush();
+
 	BLI_assert(g_batch.font->tex_bind_state != 0); /* must still be valid */
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, g_batch.font->tex_bind_state);
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 0c786874180..12ee1ad35a1 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -1429,6 +1429,7 @@ void UI_block_draw(const bContext *C, uiBlock *block)
 
 	BLF_batch_draw_begin();
 	UI_icon_draw_cache_begin();
+	UI_widgetbase_draw_cache_begin();
 
 	/* widgets */
 	for (but = block->buttons.first; but; but = but->next) {
@@ -1442,6 +1443,7 @@ void UI_block_draw(const bContext *C, uiBlock *block)
 		}
 	}
 
+	UI_widgetbase_draw_cache_end();
 	UI_icon_draw_cache_end();
 	BLF_batch_draw_end();
 	
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 9fbb5efdcf3..682eac6a352 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -1009,6 +1009,9 @@ static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect),
 		rect = ima->rect;
 	}
 
+	/* We need to flush widget base first to ensure correct ordering. */
+	UI_widgetbase_draw_cache_flush();
+
 	/* draw */
 	IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
 	immDrawPixelsTex(&state, draw_x, draw_y, draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect,
@@ -1049,6 +1052,12 @@ static void icon_draw_cache_flush_ex(void)
 	if (g_icon_draw_cache.calls == 0)
 		return;
 
+	/* We need to flush widget base first to ensure correct ordering. */
+	glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+	UI_widgetbase_draw_cache_flush();
+
+	glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
 	glActiveTexture(GL_TEXTURE0);
 	glBindTexture(GL_TEXTURE_2D, icongltex.id);
 
@@ -1078,7 +1087,6 @@ void UI_icon_draw_cache_end(void)
 		return;
 
 	glEnable(GL_BLEND);
-	glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
 
 	icon_draw_cache_flush_ex();
 
@@ -1125,6 +1133,10 @@ static void icon_draw_texture(
 		return;
 	}
 
+	/* We need to flush widget base first to ensure correct ordering. */
+	glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+	UI_widgetbase_draw_cache_flush();
+
 	float x1, x2, y1, y2;
 
 	x1 = ix * icongltex.invw;



More information about the Bf-blender-cvs mailing list