[Bf-blender-cvs] [67e38d313b0] greasepencil-refactor: GPencil: Cleanup

Antonio Vazquez noreply at git.blender.org
Wed Jan 8 16:22:44 CET 2020


Commit: 67e38d313b0076c05a90c8f51b332c9a6d211e49
Author: Antonio Vazquez
Date:   Wed Jan 8 16:22:26 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB67e38d313b0076c05a90c8f51b332c9a6d211e49

GPencil: Cleanup

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

M	source/blender/draw/engines/gpencil/gpencil_cache_utils.c
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/gpencil_render.c
M	source/blender/draw/engines/overlay/overlay_outline.c
M	source/blender/draw/intern/draw_manager.c

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
index da21d1a0c21..108fc040485 100644
--- a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
@@ -250,113 +250,6 @@ static bool gpencil_has_noninstanced_object(Object *ob_instance)
   return false;
 }
 
-/* add a gpencil object to cache to defer drawing */
-tGPencilObjectCache *gpencil_object_cache_add(tGPencilObjectCache *cache_array,
-                                              Object *ob,
-                                              int *gp_cache_size,
-                                              int *gp_cache_used)
-{
-  const DRWContextState *draw_ctx = DRW_context_state_get();
-  tGPencilObjectCache *cache_elem = NULL;
-  RegionView3D *rv3d = draw_ctx->rv3d;
-  View3D *v3d = draw_ctx->v3d;
-  tGPencilObjectCache *p = NULL;
-
-  /* By default a cache is created with one block with a predefined number of free slots,
-   * if the size is not enough, the cache is reallocated adding a new block of free slots.
-   * This is done in order to keep cache small. */
-  if (*gp_cache_used + 1 > *gp_cache_size) {
-    if ((*gp_cache_size == 0) || (cache_array == NULL)) {
-      p = MEM_callocN(sizeof(struct tGPencilObjectCache) * GP_CACHE_BLOCK_SIZE,
-                      "tGPencilObjectCache");
-      *gp_cache_size = GP_CACHE_BLOCK_SIZE;
-    }
-    else {
-      *gp_cache_size += GP_CACHE_BLOCK_SIZE;
-      p = MEM_recallocN(cache_array, sizeof(struct tGPencilObjectCache) * *gp_cache_size);
-    }
-    cache_array = p;
-  }
-  /* zero out all pointers */
-  cache_elem = &cache_array[*gp_cache_used];
-  memset(cache_elem, 0, sizeof(*cache_elem));
-
-  cache_elem->ob = ob;
-  cache_elem->gpd = (bGPdata *)ob->data;
-  cache_elem->name = BKE_id_to_unique_string_key(&ob->id);
-
-  copy_v3_v3(cache_elem->loc, ob->obmat[3]);
-  copy_m4_m4(cache_elem->obmat, ob->obmat);
-  cache_elem->idx = *gp_cache_used;
-
-  /* object is duplicated (particle) */
-  if (ob->base_flag & BASE_FROM_DUPLI) {
-    /* Check if the original object is not in the viewlayer
-     * and cannot be managed as dupli. This is slower, but required to keep
-     * the particle drawing FPS and display instanced objects in scene
-     * without the original object */
-    bool has_original = gpencil_has_noninstanced_object(ob);
-    cache_elem->is_dup_ob = (has_original) ? ob->base_flag & BASE_FROM_DUPLI : false;
-  }
-  else {
-    cache_elem->is_dup_ob = false;
-  }
-
-  cache_elem->scale = mat4_to_scale(ob->obmat);
-
-  /* save FXs */
-  cache_elem->pixfactor = cache_elem->gpd->pixfactor;
-  cache_elem->shader_fx = ob->shader_fx;
-
-  /* save wire mode (object mode is always primary option) */
-  if (ob->dt == OB_WIRE) {
-    cache_elem->shading_type[0] = (int)OB_WIRE;
-  }
-  else {
-    if (v3d) {
-      cache_elem->shading_type[0] = (int)v3d->shading.type;
-    }
-  }
-
-  /* shgrp array */
-  cache_elem->tot_layers = 0;
-  int totgpl = BLI_listbase_count(&cache_elem->gpd->layers);
-  if (totgpl > 0) {
-    cache_elem->shgrp_array = MEM_callocN(sizeof(tGPencilObjectCache_shgrp) * totgpl, __func__);
-  }
-
-  /* calculate zdepth from point of view */
-  float zdepth = 0.0;
-  if (rv3d) {
-    if (rv3d->is_persp) {
-      zdepth = ED_view3d_calc_zfac(rv3d, ob->obmat[3], NULL);
-    }
-    else {
-      zdepth = -dot_v3v3(rv3d->viewinv[2], ob->obmat[3]);
-    }
-  }
-  else {
-    /* In render mode, rv3d is not available, so use the distance to camera.
-     * The real distance is not important, but the relative distance to the camera plane
-     * in order to sort by z_depth of the objects
-     */
-    float vn[3] = {0.0f, 0.0f, -1.0f}; /* always face down */
-    float plane_cam[4];
-    struct Object *camera = draw_ctx->scene->camera;
-    if (camera) {
-      mul_m4_v3(camera->obmat, vn);
-      normalize_v3(vn);
-      plane_from_point_normal_v3(plane_cam, camera->loc, vn);
-      zdepth = dist_squared_to_plane_v3(ob->obmat[3], plane_cam);
-    }
-  }
-  cache_elem->zdepth = zdepth;
-  /* increase slots used in cache */
-  (*gp_cache_used)++;
-
-  return cache_array;
-}
-
 /* get current cache data */
 static GpencilBatchCache *gpencil_batch_get_element(Object *ob)
 {
@@ -419,18 +312,6 @@ static GpencilBatchCache *gpencil_batch_cache_init(Object *ob, int cfra)
   return cache;
 }
 
-/* clear cache */
-static void gpencil_batch_cache_clear(GpencilBatchCache *cache)
-{
-  if (!cache) {
-    return;
-  }
-
-  MEM_SAFE_FREE(cache->grp_cache);
-  cache->grp_size = 0;
-  cache->grp_used = 0;
-}
-
 /* get cache */
 GpencilBatchCache *gpencil_batch_cache_get(Object *ob, int cfra)
 {
@@ -438,9 +319,6 @@ GpencilBatchCache *gpencil_batch_cache_get(Object *ob, int cfra)
 
   GpencilBatchCache *cache = gpencil_batch_get_element(ob);
   if (!gpencil_batch_cache_valid(cache, gpd, cfra)) {
-    if (cache) {
-      gpencil_batch_cache_clear(cache);
-    }
     return gpencil_batch_cache_init(ob, cfra);
   }
   else {
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index cfc5b001fd4..5b2b9d0f2ee 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -672,50 +672,6 @@ void GPENCIL_cache_finish(void *ved)
   }
 }
 
-void DRW_gpencil_free_runtime_data(void *ved)
-{
-  GPENCIL_Data *vedata = (GPENCIL_Data *)ved;
-  GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
-
-  if (stl->g_data == NULL) {
-    return;
-  }
-
-  /* free gpu data */
-  GPU_BATCH_DISCARD_SAFE(stl->g_data->batch_buffer_stroke);
-  MEM_SAFE_FREE(stl->g_data->batch_buffer_stroke);
-
-  GPU_BATCH_DISCARD_SAFE(stl->g_data->batch_buffer_fill);
-  MEM_SAFE_FREE(stl->g_data->batch_buffer_fill);
-
-  GPU_BATCH_DISCARD_SAFE(stl->g_data->batch_buffer_ctrlpoint);
-  MEM_SAFE_FREE(stl->g_data->batch_buffer_ctrlpoint);
-
-  GPU_BATCH_DISCARD_SAFE(stl->g_data->batch_grid);
-  MEM_SAFE_FREE(stl->g_data->batch_grid);
-
-  if (stl->g_data->gp_object_cache == NULL) {
-    return;
-  }
-
-  /* reset all cache flags */
-  for (int i = 0; i < stl->g_data->gp_cache_used; i++) {
-    tGPencilObjectCache *cache_ob = &stl->g_data->gp_object_cache[i];
-    if (cache_ob) {
-      bGPdata *gpd = cache_ob->gpd;
-      gpd->flag &= ~GP_DATA_CACHE_IS_DIRTY;
-
-      /* free shgrp array */
-      cache_ob->tot_layers = 0;
-      MEM_SAFE_FREE(cache_ob->name);
-      MEM_SAFE_FREE(cache_ob->shgrp_array);
-    }
-  }
-
-  /* free the cache itself */
-  MEM_SAFE_FREE(stl->g_data->gp_object_cache);
-}
-
 static void GPENCIL_draw_scene_depth_only(void *ved)
 {
   GPENCIL_Data *vedata = (GPENCIL_Data *)ved;
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index db62cf840ae..a0052ef0a6d 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -42,20 +42,12 @@ struct GPUBatch;
 struct GPUVertBuf;
 struct GPUVertFormat;
 
-#define GPENCIL_CACHE_BLOCK_SIZE 8
-#define GPENCIL_MAX_SHGROUPS 65536
-#define GPENCIL_GROUPS_BLOCK_SIZE 1024
-
 /* used to convert pixel scale. */
 #define GPENCIL_PIXEL_FACTOR 2000.0f
 
 /* used to expand VBOs. Size has a big impact in the speed */
 #define GPENCIL_VBO_BLOCK_SIZE 128
 
-#define GPENCIL_COLOR_SOLID 0
-#define GPENCIL_COLOR_TEXTURE 1
-#define GPENCIL_COLOR_PATTERN 2
-
 #define GP_IS_CAMERAVIEW ((rv3d != NULL) && (rv3d->persp == RV3D_CAMOB && v3d->camera))
 
 /* UBO structure. Watch out for padding. Must match GLSL declaration. */
@@ -108,61 +100,7 @@ typedef struct gpLight {
 BLI_STATIC_ASSERT_ALIGN(gpMaterial, 16)
 BLI_STATIC_ASSERT_ALIGN(gpLight, 16)
 
-/* *********** OBJECTS CACHE *********** */
-typedef struct tGPencilObjectCache_shgrp {
-  /** type of blend (regular, add, mult, etc...) */
-  int mode;
-  /** flag to enable the layer clamping */
-  bool mask_layer;
-  /** factor to define the opacity of the layer */
-  float blend_opacity;
-  DRWShadingGroup *init_shgrp;
-  DRWShadingGroup *end_shgrp;
-} tGPencilObjectCache_shgrp;
-
-/* used to save gpencil object data for drawing */
-typedef struct tGPencilObjectCache {
-  struct Object *ob;
-  struct bGPdata *gpd;
-  int idx; /*original index, can change after sort */
-  char *name;
-
-  /* effects */
-  bool has_fx;
-  ListBase shader_fx;
-  float pixfactor;
-  DRWShadingGroup *fx_wave_sh;
-  DRWShadingGroup *fx_blur_sh;
-  DRWShadingGroup *fx_colorize_sh;
-  DRWShadingGroup *fx_pixel_sh;
-  DRWShadingGroup *fx_rim_sh;
-  DRWShadingGroup *fx_shadow_sh;
-  DRWShadingGroup *fx_glow_sh;
-  DRWShadingGroup *fx_swirl_sh;
-  DRWShadingGroup *fx_flip_sh;
-  DRWShadingGroup *fx_light_sh;
-
-  float loc[3];
-  float obmat[4][4];
-  float zdepth;   /* z-depth value to sort gp object */
-  bool is_dup_ob; /* flag to tag duplicate objects */
-  float scale;
-
-  /* shading type */
-  int shading_type[2];
-
-  /* GPU data size */
-  int tot_vertex;
-  int tot_triangles;
-
-  /* Save shader groups by layer */
-  int tot_layers;
-  tGPencilObjectCache_shgrp *shgrp_array;
-
-} tGPencilObjectCache;
-
 /* *********** Draw Datas *********** */
-
 typedef struct GPENCIL_MaterialPool {
   /* Linklist. */
   struct GPENCIL_MaterialPool *next;
@@ -243,108 +181,19 @@ typedef struct GPENCIL_tObject {
 } GPENCIL_tObject;
 
 /* *********** LISTS *********** */
-typedef struct GPENCIL_shgroup {
-  int s_clamp;
-  int stroke_style;
-  int color_type;
-  int mode;
-  int texture_mix;
-  int texture_flip;
-  int texture_clamp;
-  int fill_style;
-  int keep_size;
-  int caps_mode[2];
-  float obj_scale;
-  int xray_mode;
-  int alignment_mode;
-
-  float gradient_f;
-  float gradient_s[2];
-
-  float mix_stroke_factor;
-
-  /* color of the wireframe */
-  float wire_color[4];
-  /* shading type and mode */
-  int shading_type[2];
-  int is_xray;
-} GPENCIL_shgroup;
-
 typedef struct GPENCIL_Storage {
-  int shgroup_id; /* total elements */
-  int stroke_style;
-  int color_type;
-  int mode;
-  int xray;
-  int keep_size;
-  float obj_scale;
-  float pixfactor;
-  bool is_playing;
-  bool is_render;
-  bool is_ma

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list