[Bf-blender-cvs] [55087b84b80] master: Cleanup: Node: Use checker shader for preview background

Clément Foucault noreply at git.blender.org
Tue Aug 18 16:15:49 CEST 2020


Commit: 55087b84b8080063dac47e4ba7bcaea3a0d58aab
Author: Clément Foucault
Date:   Tue Aug 18 16:12:56 2020 +0200
Branches: master
https://developer.blender.org/rB55087b84b8080063dac47e4ba7bcaea3a0d58aab

Cleanup: Node: Use checker shader for preview background

Removes many drawcalls which might have slowdown the UI.

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

M	source/blender/editors/space_node/node_draw.c

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

diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c
index 0a754b6ec2a..fd18583195d 100644
--- a/source/blender/editors/space_node/node_draw.c
+++ b/source/blender/editors/space_node/node_draw.c
@@ -867,46 +867,18 @@ void ED_node_socket_draw(bNodeSocket *sock, const rcti *rect, const float color[
 
 static void node_draw_preview_background(float tile, rctf *rect)
 {
-  float x, y;
-
   GPUVertFormat *format = immVertexFormat();
   uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
 
-  immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+  immBindBuiltinProgram(GPU_SHADER_2D_CHECKER);
 
-  /* draw checkerboard backdrop to show alpha */
-  immUniformColor3ub(120, 120, 120);
+  /* Drawing the checkerboard. */
+  const float checker_dark = UI_ALPHA_CHECKER_DARK / 255.0f;
+  const float checker_light = UI_ALPHA_CHECKER_LIGHT / 255.0f;
+  immUniform4f("color1", checker_dark, checker_dark, checker_dark, 1.0f);
+  immUniform4f("color2", checker_light, checker_light, checker_light, 1.0f);
+  immUniform1i("size", 8);
   immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
-  immUniformColor3ub(160, 160, 160);
-
-  for (y = rect->ymin; y < rect->ymax; y += tile * 2) {
-    for (x = rect->xmin; x < rect->xmax; x += tile * 2) {
-      float tilex = tile, tiley = tile;
-
-      if (x + tile > rect->xmax) {
-        tilex = rect->xmax - x;
-      }
-      if (y + tile > rect->ymax) {
-        tiley = rect->ymax - y;
-      }
-
-      immRectf(pos, x, y, x + tilex, y + tiley);
-    }
-  }
-  for (y = rect->ymin + tile; y < rect->ymax; y += tile * 2) {
-    for (x = rect->xmin + tile; x < rect->xmax; x += tile * 2) {
-      float tilex = tile, tiley = tile;
-
-      if (x + tile > rect->xmax) {
-        tilex = rect->xmax - x;
-      }
-      if (y + tile > rect->ymax) {
-        tiley = rect->ymax - y;
-      }
-
-      immRectf(pos, x, y, x + tilex, y + tiley);
-    }
-  }
   immUnbindProgram();
 }



More information about the Bf-blender-cvs mailing list