Commit: 052538edc1fba109d3427471047611888ed13bea
Author: Clément Foucault
Date:   Mon Aug 31 18:39:17 2020 +0200
Branches: master
https://developer.blender.org/rB052538edc1fba109d3427471047611888ed13bea

Cleanup: Use GPUBatch for icon and area drawing

This is in order to remove GPU_draw_primitive to streamline the drawing
abstraction.

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

M       source/blender/editors/interface/interface_icons.c
M       source/blender/gpu/GPU_batch_presets.h
M       source/blender/gpu/intern/gpu_batch_presets.c
M       source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl
M       source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl
M       source/blender/windowmanager/intern/wm_draw.c

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

diff --git a/source/blender/editors/interface/interface_icons.c 
b/source/blender/editors/interface/interface_icons.c
index 887f149ee12..aae0d7c525f 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -28,6 +28,7 @@
 #include "MEM_guardedalloc.h"
 
 #include "GPU_batch.h"
+#include "GPU_batch_presets.h"
 #include "GPU_immediate.h"
 #include "GPU_matrix.h"
 #include "GPU_state.h"
@@ -1573,7 +1574,9 @@ static void icon_draw_cache_texture_flush_ex(GPUTexture 
*texture,
   GPU_shader_uniform_vector(
       shader, data_loc, 4, ICON_DRAW_CACHE_SIZE * 3, (float 
*)texture_draw_calls->drawcall_cache);
 
-  GPU_draw_primitive(GPU_PRIM_TRIS, 6 * texture_draw_calls->calls);
+  GPUBatch *quad = GPU_batch_preset_quad();
+  GPU_batch_set_shader(quad, shader);
+  GPU_batch_draw_instanced(quad, texture_draw_calls->calls);
 
   GPU_texture_unbind(texture);
 
@@ -1721,7 +1724,9 @@ static void icon_draw_texture(float x,
   GPU_texture_bind(texture, img_binding);
   GPU_sampler_icon_bind(img_binding);
 
-  GPU_draw_primitive(GPU_PRIM_TRI_STRIP, 4);
+  GPUBatch *quad = GPU_batch_preset_quad();
+  GPU_batch_set_shader(quad, shader);
+  GPU_batch_draw(quad);
 
   GPU_texture_unbind(texture);
 
diff --git a/source/blender/gpu/GPU_batch_presets.h 
b/source/blender/gpu/GPU_batch_presets.h
index 7a235dd0e12..19f200fecbf 100644
--- a/source/blender/gpu/GPU_batch_presets.h
+++ b/source/blender/gpu/GPU_batch_presets.h
@@ -43,6 +43,8 @@ struct GPUBatch *GPU_batch_preset_panel_drag_widget(const 
float pixelsize,
                                                     const float col_dark[4],
                                                     const float width) 
ATTR_WARN_UNUSED_RESULT;
 
+struct GPUBatch *GPU_batch_preset_quad(void);
+
 void gpu_batch_presets_init(void);
 void gpu_batch_presets_register(struct GPUBatch *preset_batch);
 bool gpu_batch_presets_unregister(struct GPUBatch *preset_batch);
diff --git a/source/blender/gpu/intern/gpu_batch_presets.c 
b/source/blender/gpu/intern/gpu_batch_presets.c
index 8adb1ba1ed3..6a1645a71d8 100644
--- a/source/blender/gpu/intern/gpu_batch_presets.c
+++ b/source/blender/gpu/intern/gpu_batch_presets.c
@@ -62,6 +62,7 @@ static struct {
 static struct {
   struct {
     GPUBatch *panel_drag_widget;
+    GPUBatch *quad;
   } batch;
 
   float panel_drag_widget_pixelsize;
@@ -330,6 +331,24 @@ GPUBatch *GPU_batch_preset_panel_drag_widget(const float 
pixelsize,
   return g_presets_2d.batch.panel_drag_widget;
 }
 
+/* To be used with procedural placement inside shader. */
+GPUBatch *GPU_batch_preset_quad(void)
+{
+  if (!g_presets_2d.batch.quad) {
+    GPUVertBuf *vbo = GPU_vertbuf_create_with_format(preset_2d_format());
+    GPU_vertbuf_data_alloc(vbo, 4);
+
+    float pos_data[4][2] = {{0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}, {1.0f, 
0.0f}};
+    GPU_vertbuf_attr_fill(vbo, g_presets_2d.attr_id.pos, pos_data);
+    /* Don't fill the color. */
+
+    g_presets_2d.batch.quad = GPU_batch_create_ex(GPU_PRIM_TRI_FAN, vbo, NULL, 
GPU_BATCH_OWNS_VBO);
+
+    gpu_batch_presets_register(g_presets_2d.batch.quad);
+  }
+  return g_presets_2d.batch.quad;
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git 
a/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl 
b/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl
index d25cd586e65..640ceb97e5b 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl
@@ -13,34 +13,19 @@ flat out vec4 finalColor;
 
 void main()
 {
-  /* Rendering 2 triangle per icon. */
-  int i = gl_VertexID / 6;
-  int v = gl_VertexID % 6;
+  vec4 pos = calls_data[gl_InstanceID * 3];
+  vec4 tex = calls_data[gl_InstanceID * 3 + 1];
+  finalColor = calls_data[gl_InstanceID * 3 + 2];
 
-  vec4 pos = calls_data[i * 3];
-  vec4 tex = calls_data[i * 3 + 1];
-  finalColor = calls_data[i * 3 + 2];
-
-  /* TODO Remove this */
-  if (v == 2) {
-    v = 4;
-  }
-  else if (v == 3) {
-    v = 0;
-  }
-  else if (v == 5) {
-    v = 2;
+  if (gl_VertexID == 0) {
+    pos.xy = pos.xz;
+    tex.xy = tex.xz;
   }
-
-  if (v == 0) {
+  else if (gl_VertexID == 1) {
     pos.xy = pos.xw;
     tex.xy = tex.xw;
   }
-  else if (v == 1) {
-    pos.xy = pos.xz;
-    tex.xy = tex.xz;
-  }
-  else if (v == 2) {
+  else if (gl_VertexID == 2) {
     pos.xy = pos.yw;
     tex.xy = tex.yw;
   }
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl 
b/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl
index fcd877a37eb..ab9c30505c2 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl
@@ -14,13 +14,13 @@ void main()
   vec2 uv;
   vec2 co;
   if (gl_VertexID == 0) {
-    co = rect_geom.xw;
-    uv = rect_icon.xw;
-  }
-  else if (gl_VertexID == 1) {
     co = rect_geom.xy;
     uv = rect_icon.xy;
   }
+  else if (gl_VertexID == 1) {
+    co = rect_geom.xw;
+    uv = rect_icon.xw;
+  }
   else if (gl_VertexID == 2) {
     co = rect_geom.zw;
     uv = rect_icon.zw;
diff --git a/source/blender/windowmanager/intern/wm_draw.c 
b/source/blender/windowmanager/intern/wm_draw.c
index a5dfc9893a5..e32db12b596 100644
--- a/source/blender/windowmanager/intern/wm_draw.c
+++ b/source/blender/windowmanager/intern/wm_draw.c
@@ -51,6 +51,7 @@
 #include "ED_screen.h"
 #include "ED_view3d.h"
 
+#include "GPU_batch_presets.h"
 #include "GPU_context.h"
 #include "GPU_framebuffer.h"
 #include "GPU_immediate.h"
@@ -597,7 +598,9 @@ void wm_draw_region_blend(ARegion *region, int view, bool 
blend)
   GPU_shader_uniform_vector(shader, rect_geo_loc, 4, 1, rectg);
   GPU_shader_uniform_vector(shader, color_loc, 4, 1, (const float[4]){1, 1, 1, 
1});
 
-  GPU_draw_primitive(GPU_PRIM_TRI_STRIP, 4);
+  GPUBatch *quad = GPU_batch_preset_quad();
+  GPU_batch_set_shader(quad, shader);
+  GPU_batch_draw(quad);
 
   GPU_texture_unbind(texture);

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to