[Bf-blender-cvs] [84869b551fb] temp-gpu-image-engine: Cleanup: Split in more files.

Jeroen Bakker noreply at git.blender.org
Wed Dec 8 15:55:52 CET 2021


Commit: 84869b551fb2d5a69100d39cf439ea90c967d3f9
Author: Jeroen Bakker
Date:   Wed Dec 8 14:14:52 2021 +0100
Branches: temp-gpu-image-engine
https://developer.blender.org/rB84869b551fb2d5a69100d39cf439ea90c967d3f9

Cleanup: Split in more files.

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

M	source/blender/draw/CMakeLists.txt
A	source/blender/draw/engines/image/image_batches.hh
R073	source/blender/draw/engines/image/image_drawing_mode_screen_space.hh	source/blender/draw/engines/image/image_drawing_mode_one_texture.hh
M	source/blender/draw/engines/image/image_engine.cc
A	source/blender/draw/engines/image/image_instance_data.hh
A	source/blender/draw/engines/image/image_partial_updater.hh
M	source/blender/draw/engines/image/image_private.hh
A	source/blender/draw/engines/image/image_texture_info.hh
A	source/blender/draw/engines/image/image_wrappers.hh

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 81cb8df3f6a..15f85f817f3 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -223,7 +223,7 @@ set(SRC
   engines/external/external_engine.h
   engines/image/image_engine.h
   engines/image/image_private.hh
-  engines/image/image_drawing_mode_screen_space.hh
+  engines/image/image_drawing_mode_one_texture.hh
   engines/image/image_space_image.hh
   engines/image/image_space_node.hh
   engines/workbench/workbench_engine.h
diff --git a/source/blender/draw/engines/image/image_batches.hh b/source/blender/draw/engines/image/image_batches.hh
new file mode 100644
index 00000000000..c8a99256996
--- /dev/null
+++ b/source/blender/draw/engines/image/image_batches.hh
@@ -0,0 +1,106 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Copyright 2021, Blender Foundation.
+ */
+
+/** \file
+ * \ingroup draw_engine
+ */
+
+#pragma once
+
+#include "image_texture_info.hh"
+
+/** \brief Create GPUBatch for a IMAGE_ScreenSpaceTextureInfo. */
+class BatchUpdater {
+  IMAGE_TextureInfo &info;
+
+  GPUVertFormat format = {0};
+  int pos_id;
+  int uv_id;
+
+ public:
+  BatchUpdater(IMAGE_TextureInfo &info) : info(info)
+  {
+  }
+
+  void update_batch()
+  {
+    ensure_clear_batch();
+    ensure_format();
+    init_batch();
+  }
+
+  void discard_batch()
+  {
+    GPU_BATCH_DISCARD_SAFE(info.batch);
+  }
+
+ private:
+  void ensure_clear_batch()
+  {
+    GPU_BATCH_CLEAR_SAFE(info.batch);
+    if (info.batch == nullptr) {
+      info.batch = GPU_batch_calloc();
+    }
+  }
+
+  void init_batch()
+  {
+    GPUVertBuf *vbo = create_vbo();
+    GPU_batch_init_ex(info.batch, GPU_PRIM_TRI_FAN, vbo, nullptr, GPU_BATCH_OWNS_VBO);
+  }
+
+  GPUVertBuf *create_vbo()
+  {
+    GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
+    GPU_vertbuf_data_alloc(vbo, 4);
+    float pos[4][2];
+    fill_tri_fan_from_rctf(pos, info.clipping_bounds);
+    float uv[4][2];
+    fill_tri_fan_from_rctf(uv, info.uv_bounds);
+
+    for (int i = 0; i < 4; i++) {
+      GPU_vertbuf_attr_set(vbo, pos_id, i, pos[i]);
+      GPU_vertbuf_attr_set(vbo, uv_id, i, uv[i]);
+    }
+
+    return vbo;
+  }
+
+  static void fill_tri_fan_from_rctf(float result[4][2], rctf &rect)
+  {
+    result[0][0] = rect.xmin;
+    result[0][1] = rect.ymin;
+    result[1][0] = rect.xmax;
+    result[1][1] = rect.ymin;
+    result[2][0] = rect.xmax;
+    result[2][1] = rect.ymax;
+    result[3][0] = rect.xmin;
+    result[3][1] = rect.ymax;
+  }
+
+  void ensure_format()
+  {
+    if (format.attr_len == 0) {
+      GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+      GPU_vertformat_attr_add(&format, "uv", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+
+      pos_id = GPU_vertformat_attr_id_get(&format, "pos");
+      uv_id = GPU_vertformat_attr_id_get(&format, "uv");
+    }
+  }
+};
diff --git a/source/blender/draw/engines/image/image_drawing_mode_screen_space.hh b/source/blender/draw/engines/image/image_drawing_mode_one_texture.hh
similarity index 73%
rename from source/blender/draw/engines/image/image_drawing_mode_screen_space.hh
rename to source/blender/draw/engines/image/image_drawing_mode_one_texture.hh
index 040a141cac4..dd0652fc034 100644
--- a/source/blender/draw/engines/image/image_drawing_mode_screen_space.hh
+++ b/source/blender/draw/engines/image/image_drawing_mode_one_texture.hh
@@ -22,7 +22,9 @@
 
 #pragma once
 
+#include "image_batches.hh"
 #include "image_private.hh"
+#include "image_wrappers.hh"
 
 #include "BKE_image_partial_update.hh"
 
@@ -30,87 +32,6 @@ namespace blender::draw::image_engine {
 
 constexpr float EPSILON_UV_BOUNDS = 0.00001f;
 
-/** \brief Create GPUBatch for a IMAGE_ScreenSpaceTextureInfo. */
-class BatchUpdater {
-  IMAGE_ScreenSpaceTextureInfo &info;
-
-  GPUVertFormat format = {0};
-  int pos_id;
-  int uv_id;
-
- public:
-  BatchUpdater(IMAGE_ScreenSpaceTextureInfo &info) : info(info)
-  {
-  }
-
-  void update_batch()
-  {
-    ensure_clear_batch();
-    ensure_format();
-    init_batch();
-  }
-
-  void discard_batch()
-  {
-    GPU_BATCH_DISCARD_SAFE(info.batch);
-  }
-
- private:
-  void ensure_clear_batch()
-  {
-    GPU_BATCH_CLEAR_SAFE(info.batch);
-    if (info.batch == nullptr) {
-      info.batch = GPU_batch_calloc();
-    }
-  }
-
-  void init_batch()
-  {
-    GPUVertBuf *vbo = create_vbo();
-    GPU_batch_init_ex(info.batch, GPU_PRIM_TRI_FAN, vbo, nullptr, GPU_BATCH_OWNS_VBO);
-  }
-
-  GPUVertBuf *create_vbo()
-  {
-    GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
-    GPU_vertbuf_data_alloc(vbo, 4);
-    float pos[4][2];
-    fill_tri_fan_from_rctf(pos, info.clipping_bounds);
-    float uv[4][2];
-    fill_tri_fan_from_rctf(uv, info.uv_bounds);
-
-    for (int i = 0; i < 4; i++) {
-      GPU_vertbuf_attr_set(vbo, pos_id, i, pos[i]);
-      GPU_vertbuf_attr_set(vbo, uv_id, i, uv[i]);
-    }
-
-    return vbo;
-  }
-
-  static void fill_tri_fan_from_rctf(float result[4][2], rctf &rect)
-  {
-    result[0][0] = rect.xmin;
-    result[0][1] = rect.ymin;
-    result[1][0] = rect.xmax;
-    result[1][1] = rect.ymin;
-    result[2][0] = rect.xmax;
-    result[2][1] = rect.ymax;
-    result[3][0] = rect.xmin;
-    result[3][1] = rect.ymax;
-  }
-
-  void ensure_format()
-  {
-    if (format.attr_len == 0) {
-      GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
-      GPU_vertformat_attr_add(&format, "uv", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
-
-      pos_id = GPU_vertformat_attr_id_get(&format, "pos");
-      uv_id = GPU_vertformat_attr_id_get(&format, "uv");
-    }
-  }
-};
-
 /**
  * \brief Accessor to texture slots.
  *
@@ -124,14 +45,6 @@ struct InstanceDataAccessor {
   {
   }
 
-  /** \brief Clear dirty flag from all texture slots. */
-  void clear_dirty_flag()
-  {
-    for (int i = 0; i < SCREEN_SPACE_DRAWING_MODE_TEXTURE_LEN; i++) {
-      instance_data->texture_infos[i].dirty = false;
-    }
-  }
-
   /** \brief Update the texture slot uv and screen space bounds. */
   void update_screen_space_bounds(const ARegion *region)
   {
@@ -176,7 +89,7 @@ struct InstanceDataAccessor {
     }
   }
 
-  void update_uv_to_texture_matrix(IMAGE_ScreenSpaceTextureInfo *info)
+  void update_uv_to_texture_matrix(IMAGE_TextureInfo *info)
   {
     // TODO: I remember that there was a function for this somewhere.
     unit_m4(info->uv_to_texture);
@@ -190,42 +103,6 @@ struct InstanceDataAccessor {
     info->uv_to_texture[3][0] = translate_x;
     info->uv_to_texture[3][1] = translate_y;
   }
-
-  void update_batches()
-  {
-    for (int i = 0; i < SCREEN_SPACE_DRAWING_MODE_TEXTURE_LEN; i++) {
-      IMAGE_ScreenSpaceTextureInfo &info = instance_data->texture_infos[i];
-      if (!info.dirty) {
-        continue;
-      }
-      BatchUpdater batch_updater(info);
-      batch_updater.update_batch();
-    }
-  }
-};
-
-struct ImageTileAccessor {
-  ImageTile *image_tile;
-  ImageTileAccessor(ImageTile *image_tile) : image_tile(image_tile)
-  {
-  }
-
-  int get_tile_number() const
-  {
-    return image_tile->tile_number;
-  }
-
-  int get_tile_x_offset() const
-  {
-    int tile_number = get_tile_number();
-    return (tile_number - 1001) % 10;
-  }
-
-  int get_tile_y_offset() const
-  {
-    int tile_number = get_tile_number();
-    return (tile_number - 1001) / 10;
-  }
 };
 
 using namespace blender::bke::image::partial_update;
@@ -256,7 +133,7 @@ class ScreenSpaceDrawingMode : public AbstractDrawingMode {
     float image_mat[4][4];
     unit_m4(image_mat);
     for (int i = 0; i < SCREEN_SPACE_DRAWING_MODE_TEXTURE_LEN; i++) {
-      const IMAGE_ScreenSpaceTextureInfo &info = instance_data->texture_infos[i];
+      const IMAGE_TextureInfo &info = instance_data->texture_infos[i];
       if (!info.visible) {
         continue;
       }
@@ -272,64 +149,6 @@ class ScreenSpaceDrawingMode : public AbstractDrawingMode {
     }
   }
 
-  /**
-   * \brief check if the partial update user in the private data can still be used.
-   *
-   * When switching to a different image the partial update user should be recreated.
-   */
-  bool partial_update_is_valid(const IMAGE_InstanceData *instance_data, const Image *image) const
-  {
-    if (instance_data->partial_update_image != image) {
-      return false;
-    }
-
-    return instance_data->partial_update_user != nullptr;
-  }
-
-  void partial_update_allocate(IMAGE_InstanceData *instance_data, const Image *image) const
-  {
-    BLI_assert(instance_data->partial_update_user == nullptr);
-    instance_data->partial_update_user = BKE_image_partial_update_create(image);
-    instance_data->partial_update_image = image;
-  }
-
-  void partial_update_free(IMAGE_InstanceData *instance_data) const
-  {
-    if (instance_data->partial_update_user != nullptr) {
-      BKE_image_partial_update_free(instance_data->partial_update_user);
-      instance_data->partial_update_user = nullptr;
-    }
-  }
-
-  void update_texture_slot_allocation(IMAGE_InstanceData *instance_data) const
-  {
-    for (int i = 0; i < SCREEN_SPACE_DRAWING_MODE_TEXTURE_LEN; i++) {
-      IMAGE_ScreenSpaceTextureInfo &info = instance_data->texture_infos[i];
-      const bool is_allocated = info.texture != nullptr;
-      const bool is_visible = info.visible;
-      const bool should_be_freed = !is_visible && is_allocated;
-      const bool should_be_created = is_visible && !is_allocated;
-
-      if (should_be_freed) {
-        GPU_texture_free(info.texture);
-        info.texture = nullptr;
-      }
-

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list