[Bf-blender-cvs] [3f04118a1fd] uvimage-editor-drawing: Removed Instance drawing

Jeroen Bakker noreply at git.blender.org
Tue Aug 18 16:03:37 CEST 2020


Commit: 3f04118a1fdf5bb5b68dd4a320d8ef46e89cba91
Author: Jeroen Bakker
Date:   Tue Aug 18 16:00:25 2020 +0200
Branches: uvimage-editor-drawing
https://developer.blender.org/rB3f04118a1fdf5bb5b68dd4a320d8ef46e89cba91

Removed Instance drawing

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

M	source/blender/blenkernel/BKE_image.h
M	source/blender/blenkernel/intern/image_gpu.c
M	source/blender/draw/engines/image/image_batches.c
M	source/blender/draw/engines/image/image_engine.c
M	source/blender/draw/engines/image/image_private.h
M	source/blender/draw/engines/image/shaders/engine_image_frag.glsl
M	source/blender/draw/engines/image/shaders/engine_image_vert.glsl
M	source/blender/draw/engines/overlay/overlay_edit_uv.c
M	source/blender/draw/engines/overlay/overlay_private.h

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

diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index a9b731717d5..87d0d7dba1e 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -382,7 +382,8 @@ struct GPUTexture *BKE_image_get_gpu_tiles(struct Image *image,
 struct GPUTexture *BKE_image_get_gpu_tilemap(struct Image *image,
                                              struct ImageUser *iuser,
                                              struct ImBuf *ibuf);
-struct GPUBatch *BKE_image_tiled_gpu_instance_batch_create(struct Image *image);
+struct GPUBatch *BKE_image_tiled_gpu_batch_create(struct Image *image);
+struct GPUBatch *BKE_image_tiled_border_gpu_batch_create(struct Image *image);
 
 void BKE_image_update_gputexture(
     struct Image *ima, struct ImageUser *iuser, int x, int y, int w, int h);
diff --git a/source/blender/blenkernel/intern/image_gpu.c b/source/blender/blenkernel/intern/image_gpu.c
index a8261c8e5f9..ab14648a6b5 100644
--- a/source/blender/blenkernel/intern/image_gpu.c
+++ b/source/blender/blenkernel/intern/image_gpu.c
@@ -405,32 +405,113 @@ void BKE_image_free_unused_gpu_textures()
 /* -------------------------------------------------------------------- */
 /** \name GPU batch creation
  * \{ */
-GPUBatch *BKE_image_tiled_gpu_instance_batch_create(Image *image)
+GPUBatch *BKE_image_tiled_gpu_batch_create(Image *image)
 {
   BLI_assert(image);
   BLI_assert(image->source == IMA_SRC_TILED);
 
   static GPUVertFormat format = {0};
   if (format.attr_len == 0) {
-    GPU_vertformat_attr_add(&format, "local_pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+    GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
   }
 
   GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
 
-  int32_t num_instances = BLI_listbase_count(&image->tiles);
+  const int32_t num_tiles = BLI_listbase_count(&image->tiles);
+  const int32_t num_verts = num_tiles * 4;
+  const int32_t num_patches = num_tiles * 2;
 
-  GPU_vertbuf_data_alloc(vbo, num_instances);
+  GPU_vertbuf_data_alloc(vbo, num_verts);
 
   float local_pos[3] = {0.0f, 0.0f, 0.0f};
   int vbo_index = 0;
 
+  const int32_t num_tris = num_patches * 2;
+  GPUIndexBufBuilder elb;
+  GPU_indexbuf_init(&elb, GPU_PRIM_TRIS, num_tris * 3, num_verts);
+
   LISTBASE_FOREACH (ImageTile *, tile, &image->tiles) {
-    local_pos[0] = ((tile->tile_number - 1001) % 10);
-    local_pos[1] = ((tile->tile_number - 1001) / 10);
-    GPU_vertbuf_vert_set(vbo, vbo_index++, &local_pos);
+    const int min_x = ((tile->tile_number - 1001) % 10);
+    const int min_y = ((tile->tile_number - 1001) / 10);
+    const int max_x = min_x + 1;
+    const int max_y = min_y + 1;
+    local_pos[0] = min_x;
+    local_pos[1] = min_y;
+    GPU_vertbuf_vert_set(vbo, vbo_index, &local_pos);
+    local_pos[0] = max_x;
+    local_pos[1] = min_y;
+    GPU_vertbuf_vert_set(vbo, vbo_index + 1, &local_pos);
+    local_pos[0] = max_x;
+    local_pos[1] = max_y;
+    GPU_vertbuf_vert_set(vbo, vbo_index + 2, &local_pos);
+    local_pos[0] = min_x;
+    local_pos[1] = max_y;
+    GPU_vertbuf_vert_set(vbo, vbo_index + 3, &local_pos);
+
+    GPU_indexbuf_add_tri_verts(&elb, vbo_index, vbo_index + 1, vbo_index + 2);
+    GPU_indexbuf_add_tri_verts(&elb, vbo_index + 2, vbo_index + 3, vbo_index);
+
+    vbo_index += 4;
+  }
+
+  GPUBatch *batch = GPU_batch_create_ex(
+      GPU_PRIM_TRIS, vbo, GPU_indexbuf_build(&elb), GPU_BATCH_OWNS_VBO | GPU_BATCH_OWNS_INDEX);
+  return batch;
+}
+
+GPUBatch *BKE_image_tiled_border_gpu_batch_create(Image *image)
+{
+  BLI_assert(image);
+  BLI_assert(image->source == IMA_SRC_TILED);
+
+  static GPUVertFormat format = {0};
+  if (format.attr_len == 0) {
+    GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
   }
 
-  GPUBatch *batch = GPU_batch_create_ex(GPU_PRIM_POINTS, vbo, NULL, GPU_BATCH_OWNS_VBO);
+  GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
+
+  const int32_t num_tiles = BLI_listbase_count(&image->tiles);
+  const int32_t num_verts = num_tiles * 4;
+  const int32_t num_lines = num_tiles * 4;
+  const int32_t num_indexes = num_lines * 2;
+
+  GPU_vertbuf_data_alloc(vbo, num_verts);
+
+  float local_pos[3] = {0.0f, 0.0f, 0.0f};
+  int vbo_index = 0;
+
+  GPUIndexBufBuilder elb;
+  GPU_indexbuf_init(&elb, GPU_PRIM_LINES, num_indexes, num_verts);
+
+  LISTBASE_FOREACH (ImageTile *, tile, &image->tiles) {
+    const int min_x = ((tile->tile_number - 1001) % 10);
+    const int min_y = ((tile->tile_number - 1001) / 10);
+    const int max_x = min_x + 1;
+    const int max_y = min_y + 1;
+    local_pos[0] = min_x;
+    local_pos[1] = min_y;
+    GPU_vertbuf_vert_set(vbo, vbo_index, &local_pos);
+    local_pos[0] = max_x;
+    local_pos[1] = min_y;
+    GPU_vertbuf_vert_set(vbo, vbo_index + 1, &local_pos);
+    local_pos[0] = max_x;
+    local_pos[1] = max_y;
+    GPU_vertbuf_vert_set(vbo, vbo_index + 2, &local_pos);
+    local_pos[0] = min_x;
+    local_pos[1] = max_y;
+    GPU_vertbuf_vert_set(vbo, vbo_index + 3, &local_pos);
+
+    GPU_indexbuf_add_line_verts(&elb, vbo_index, vbo_index + 1);
+    GPU_indexbuf_add_line_verts(&elb, vbo_index + 1, vbo_index + 2);
+    GPU_indexbuf_add_line_verts(&elb, vbo_index + 2, vbo_index + 3);
+    GPU_indexbuf_add_line_verts(&elb, vbo_index + 3, vbo_index);
+
+    vbo_index += 4;
+  }
+
+  GPUBatch *batch = GPU_batch_create_ex(
+      GPU_PRIM_LINES, vbo, GPU_indexbuf_build(&elb), GPU_BATCH_OWNS_VBO | GPU_BATCH_OWNS_INDEX);
   return batch;
 }
 /** \} */
diff --git a/source/blender/draw/engines/image/image_batches.c b/source/blender/draw/engines/image/image_batches.c
index 62b244c03d5..e68febdf6cb 100644
--- a/source/blender/draw/engines/image/image_batches.c
+++ b/source/blender/draw/engines/image/image_batches.c
@@ -31,32 +31,50 @@ static GPUVertFormat *image_batches_instance_format(void)
 {
   static GPUVertFormat format = {0};
   if (format.attr_len == 0) {
-    GPU_vertformat_attr_add(&format, "local_pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+    GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
   }
   return &format;
 }
 
-GPUBatch *IMAGE_batches_image_instance_create(rcti *rect)
+/* Creates a GPU batch for drawing images in the image editor. */
+GPUBatch *IMAGE_batches_image_create(rcti *rect)
 {
   GPUVertFormat *format = image_batches_instance_format();
-  GPUVertBuf *vbo = GPU_vertbuf_create_with_format(format);
-
-  int32_t num_instances_x = (rect->xmax - rect->xmin) + 1;
-  int32_t num_instances_y = (rect->ymax - rect->ymin) + 1;
-  int32_t num_instances = num_instances_x * num_instances_y;
 
-  GPU_vertbuf_data_alloc(vbo, num_instances);
+  const int32_t num_patches_x = (rect->xmax - rect->xmin) + 1;
+  const int32_t num_patches_y = (rect->ymax - rect->ymin) + 1;
+  const int32_t num_verts_x = num_patches_x + 1;
+  const int32_t num_verts_y = num_patches_y + 1;
+  const int32_t num_verts = num_verts_x * num_verts_y;
 
+  GPUVertBuf *vbo = GPU_vertbuf_create_with_format(format);
+  GPU_vertbuf_data_alloc(vbo, num_verts);
   int v = 0;
-  for (int y = rect->ymin; y <= rect->ymax; y++) {
-    float yf = (float)y;
-    for (int x = rect->xmin; x <= rect->xmax; x++) {
-      float xf = (float)x;
+  for (int iy = 0; iy < num_verts_y; iy++) {
+    float yf = (float)(rect->ymin + iy);
+    for (int ix = 0; ix < num_verts_x; ix++) {
+      float xf = (float)(rect->xmin + ix);
       float local_pos[3] = {xf, yf, 0.0f};
       GPU_vertbuf_vert_set(vbo, v++, &local_pos);
     }
   }
 
-  GPUBatch *batch = GPU_batch_create_ex(GPU_PRIM_POINTS, vbo, NULL, GPU_BATCH_OWNS_VBO);
+  const int32_t num_tris = num_patches_x * num_patches_y * 2;
+  GPUIndexBufBuilder elb;
+  GPU_indexbuf_init(&elb, GPU_PRIM_TRIS, num_tris * 3, num_verts);
+  int32_t index_offset = 0;
+  for (int y = 0; y < num_patches_y; y++) {
+    index_offset = y * num_verts_x;
+    for (int x = 0; x < num_patches_x; x++) {
+      GPU_indexbuf_add_tri_verts(&elb, index_offset, index_offset + 1, index_offset + num_verts_x);
+      GPU_indexbuf_add_tri_verts(
+          &elb, index_offset + 1, index_offset + num_verts_x + 1, index_offset + num_verts_x);
+      index_offset += 1;
+    }
+  }
+
+  GPUBatch *batch = GPU_batch_create_ex(
+      GPU_PRIM_TRIS, vbo, GPU_indexbuf_build(&elb), GPU_BATCH_OWNS_VBO | GPU_BATCH_OWNS_INDEX);
+
   return batch;
 }
diff --git a/source/blender/draw/engines/image/image_engine.c b/source/blender/draw/engines/image/image_engine.c
index 1051e4278c1..0b67d04ecb2 100644
--- a/source/blender/draw/engines/image/image_engine.c
+++ b/source/blender/draw/engines/image/image_engine.c
@@ -46,50 +46,36 @@
 #define SIMA_DRAW_FLAG_DEPTH (1 << 3)
 #define SIMA_DRAW_FLAG_TILED (1 << 4)
 
-static struct {
-  rcti gpu_batch_instances_rect;
-  GPUBatch *gpu_batch_instances;
-
-} e_data = {{0}};
-
-static void image_batch_instances_update(Image *image)
+static void image_batch_instances_update(IMAGE_Data *id, Image *image)
 {
+  IMAGE_StorageList *stl = id->stl;
+  IMAGE_PrivateData *pd = stl->pd;
   const DRWContextState *draw_ctx = DRW_context_state_get();
   SpaceImage *sima = (SpaceImage *)draw_ctx->space_data;
   const bool is_tiled_texture = image && image->source == IMA_SRC_TILED;
   rcti instances;
 
   if (is_tiled_texture) {
-    GPU_BATCH_DISCARD_SAFE(e_data.gpu_batch_instances);
-    e_data.gpu_batch_instances = BKE_image_tiled_gpu_instance_batch_create(image);
-    return;
-  }
-
-  /* repeat */
-  BLI_rcti_init(&instances, 0, 0, 0, 0);
-  if ((sima->flag & SI_DRAW_TILE) != 0) {
-    float view_inv_m4[4][4];
-    DRW_view_viewmat_get(NULL, view_inv_m4, true);
-    float v3min[3] = {0.0f, 0.0f, 0.0f};
-    float v3max[3] = {1.0f, 1.0f, 0.0f};
-    mul_m4_v3(view_inv_m4, v3min);
-    mul_m4_v3(view_inv_m4, v3max);
-
-    instances.xmin = (int)floorf(v3min[0]);
-    instances.ymin = (int)floorf(v3min[1]);
-    instances.xmax = (int)floorf(v3max[0]);
-    instances.ymax = (int)floorf(v3max[1]);
+    pd->draw_batch = BKE_image_tiled_gpu_batch_create(image);
   }
-
-  if (e_data.gpu_batch_instances) {
-    if (!BLI_rcti_compare(&e_data.gpu_batch_instances_rect, &instances)) {
-      GPU_BATCH_DISCARD_SAFE(e_data.gpu_batch_instances);
+  else {
+    /* repeat */

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list