[Bf-blender-cvs] [f2695c9c1d8] master: Cleanup: Remove view3d_draw_legacy.c

Dalai Felinto noreply at git.blender.org
Fri Feb 7 11:50:57 CET 2020


Commit: f2695c9c1d8da179ce155817ba620b56b5ff5e62
Author: Dalai Felinto
Date:   Fri Feb 7 10:58:07 2020 +0100
Branches: master
https://developer.blender.org/rBf2695c9c1d8da179ce155817ba620b56b5ff5e62

Cleanup: Remove view3d_draw_legacy.c

This file was originally a placeholder for all the old functions that
have not yet been ported to the new draw system. Over time all the
functions that needed refactor were gone, and the functions here are
still needed.

While moving the functions around I removed dead code and made sure the
existent comments start with a capital letter and end with a full stop.

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

M	source/blender/editors/space_view3d/CMakeLists.txt
M	source/blender/editors/space_view3d/view3d_draw.c
D	source/blender/editors/space_view3d/view3d_draw_legacy.c

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

diff --git a/source/blender/editors/space_view3d/CMakeLists.txt b/source/blender/editors/space_view3d/CMakeLists.txt
index 95d7f79f666..9e3c9d6725d 100644
--- a/source/blender/editors/space_view3d/CMakeLists.txt
+++ b/source/blender/editors/space_view3d/CMakeLists.txt
@@ -48,7 +48,6 @@ set(SRC
   view3d_buttons.c
   view3d_camera_control.c
   view3d_draw.c
-  view3d_draw_legacy.c
   view3d_edit.c
   view3d_fly.c
   view3d_gizmo_armature.c
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 0e5592abfd2..6704fc9908f 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -33,7 +33,9 @@
 #include "BKE_camera.h"
 #include "BKE_collection.h"
 #include "BKE_context.h"
+#include "BKE_customdata.h"
 #include "BKE_global.h"
+#include "BKE_layer.h"
 #include "BKE_key.h"
 #include "BKE_main.h"
 #include "BKE_scene.h"
@@ -56,11 +58,13 @@
 #include "DNA_windowmanager_types.h"
 
 #include "DRW_engine.h"
+#include "DRW_select_buffer.h"
 
 #include "ED_armature.h"
 #include "ED_keyframing.h"
 #include "ED_gpencil.h"
 #include "ED_screen.h"
+#include "ED_screen_types.h"
 #include "ED_transform.h"
 
 #include "DEG_depsgraph_query.h"
@@ -1936,11 +1940,476 @@ static bool view3d_clipping_test(const float co[3], const float clip[6][4])
   return true;
 }
 
-/* for 'local' ED_view3d_clipping_local must run first
- * then all comparisons can be done in localspace */
+/* For 'local' ED_view3d_clipping_local must run first
+ * then all comparisons can be done in localspace. */
 bool ED_view3d_clipping_test(const RegionView3D *rv3d, const float co[3], const bool is_local)
 {
   return view3d_clipping_test(co, is_local ? rv3d->clip_local : rv3d->clip);
 }
 
+/* Legacy 2.7x, now use shaders that use clip distance instead.
+ * Remove once clipping is working properly. */
+#define USE_CLIP_PLANES
+
+void ED_view3d_clipping_set(RegionView3D *rv3d)
+{
+#ifdef USE_CLIP_PLANES
+  double plane[4];
+  const uint tot = (rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6;
+
+  for (unsigned a = 0; a < tot; a++) {
+    copy_v4db_v4fl(plane, rv3d->clip[a]);
+    glClipPlane(GL_CLIP_PLANE0 + a, plane);
+    glEnable(GL_CLIP_PLANE0 + a);
+    glEnable(GL_CLIP_DISTANCE0 + a);
+  }
+#else
+  for (unsigned a = 0; a < 6; a++) {
+    glEnable(GL_CLIP_DISTANCE0 + a);
+  }
+#endif
+}
+
+/* Use these to temp disable/enable clipping when 'rv3d->rflag & RV3D_CLIPPING' is set. */
+void ED_view3d_clipping_disable(void)
+{
+  for (unsigned a = 0; a < 6; a++) {
+#ifdef USE_CLIP_PLANES
+    glDisable(GL_CLIP_PLANE0 + a);
+#endif
+    glDisable(GL_CLIP_DISTANCE0 + a);
+  }
+}
+void ED_view3d_clipping_enable(void)
+{
+  for (unsigned a = 0; a < 6; a++) {
+#ifdef USE_CLIP_PLANES
+    glEnable(GL_CLIP_PLANE0 + a);
+#endif
+    glEnable(GL_CLIP_DISTANCE0 + a);
+  }
+}
+
+/* *********************** backdraw for selection *************** */
+
+/**
+ * \note Only use in object mode.
+ */
+static void validate_object_select_id(
+    struct Depsgraph *depsgraph, ViewLayer *view_layer, ARegion *ar, View3D *v3d, Object *obact)
+{
+  Object *obact_eval = DEG_get_evaluated_object(depsgraph, obact);
+
+  BLI_assert(ar->regiontype == RGN_TYPE_WINDOW);
+  UNUSED_VARS_NDEBUG(ar);
+
+  if (obact_eval && (obact_eval->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT) ||
+                     BKE_paint_select_face_test(obact_eval))) {
+    /* do nothing */
+  }
+  /* texture paint mode sampling */
+  else if (obact_eval && (obact_eval->mode & OB_MODE_TEXTURE_PAINT) &&
+           (v3d->shading.type > OB_WIRE)) {
+    /* do nothing */
+  }
+  else if ((obact_eval && (obact_eval->mode & OB_MODE_PARTICLE_EDIT)) && !XRAY_ENABLED(v3d)) {
+    /* do nothing */
+  }
+  else {
+    v3d->flag &= ~V3D_INVALID_BACKBUF;
+    return;
+  }
+
+  if (!(v3d->flag & V3D_INVALID_BACKBUF)) {
+    return;
+  }
+
+  if (obact_eval && ((obact_eval->base_flag & BASE_VISIBLE_DEPSGRAPH) != 0)) {
+    Base *base = BKE_view_layer_base_find(view_layer, obact);
+    DRW_select_buffer_context_create(&base, 1, -1);
+  }
+
+  /* TODO: Create a flag in `DRW_manager` because the drawing is no longer
+   *       made on the backbuffer in this case. */
+  v3d->flag &= ~V3D_INVALID_BACKBUF;
+}
+
+/* TODO: Creating, attaching texture, and destroying a framebuffer is quite slow.
+ *       Calling this function should be avoided during interactive drawing. */
+static void view3d_opengl_read_Z_pixels(GPUViewport *viewport, rcti *rect, void *data)
+{
+  DefaultTextureList *dtxl = (DefaultTextureList *)GPU_viewport_texture_list_get(viewport);
+
+  GPUFrameBuffer *tmp_fb = GPU_framebuffer_create();
+  GPU_framebuffer_texture_attach(tmp_fb, dtxl->depth, 0, 0);
+  GPU_framebuffer_bind(tmp_fb);
+
+  glReadPixels(rect->xmin,
+               rect->ymin,
+               BLI_rcti_size_x(rect),
+               BLI_rcti_size_y(rect),
+               GL_DEPTH_COMPONENT,
+               GL_FLOAT,
+               data);
+
+  GPU_framebuffer_restore();
+  GPU_framebuffer_free(tmp_fb);
+}
+
+void ED_view3d_select_id_validate(ViewContext *vc)
+{
+  /* TODO: Create a flag in `DRW_manager` because the drawing is no longer
+   *       made on the backbuffer in this case. */
+  if (vc->v3d->flag & V3D_INVALID_BACKBUF) {
+    validate_object_select_id(vc->depsgraph, vc->view_layer, vc->ar, vc->v3d, vc->obact);
+  }
+}
+
+void ED_view3d_backbuf_depth_validate(ViewContext *vc)
+{
+  if (vc->v3d->flag & V3D_INVALID_BACKBUF) {
+    ARegion *ar = vc->ar;
+    Object *obact_eval = DEG_get_evaluated_object(vc->depsgraph, vc->obact);
+
+    if (obact_eval && ((obact_eval->base_flag & BASE_VISIBLE_DEPSGRAPH) != 0)) {
+      GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0);
+      DRW_draw_depth_object(vc->ar, vc->v3d, viewport, obact_eval);
+    }
+
+    vc->v3d->flag &= ~V3D_INVALID_BACKBUF;
+  }
+}
+
+/**
+ * allow for small values [0.5 - 2.5],
+ * and large values, FLT_MAX by clamping by the area size
+ */
+int ED_view3d_backbuf_sample_size_clamp(ARegion *ar, const float dist)
+{
+  return (int)min_ff(ceilf(dist), (float)max_ii(ar->winx, ar->winx));
+}
+
+/* *********************** */
+
+void view3d_update_depths_rect(ARegion *ar, ViewDepths *d, rcti *rect)
+{
+  /* clamp rect by region */
+  rcti r = {
+      .xmin = 0,
+      .xmax = ar->winx - 1,
+      .ymin = 0,
+      .ymax = ar->winy - 1,
+  };
+
+  /* Constrain rect to depth bounds */
+  BLI_rcti_isect(&r, rect, rect);
+
+  /* assign values to compare with the ViewDepths */
+  int x = rect->xmin;
+  int y = rect->ymin;
+
+  int w = BLI_rcti_size_x(rect);
+  int h = BLI_rcti_size_y(rect);
+
+  if (w <= 0 || h <= 0) {
+    if (d->depths) {
+      MEM_freeN(d->depths);
+    }
+    d->depths = NULL;
+
+    d->damaged = false;
+  }
+  else if (d->w != w || d->h != h || d->x != x || d->y != y || d->depths == NULL) {
+    d->x = x;
+    d->y = y;
+    d->w = w;
+    d->h = h;
+
+    if (d->depths) {
+      MEM_freeN(d->depths);
+    }
+
+    d->depths = MEM_mallocN(sizeof(float) * d->w * d->h, "View depths Subset");
+
+    d->damaged = true;
+  }
+
+  if (d->damaged) {
+    GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0);
+    view3d_opengl_read_Z_pixels(viewport, rect, d->depths);
+    glGetDoublev(GL_DEPTH_RANGE, d->depth_range);
+    d->damaged = false;
+  }
+}
+
+/* Note, with nouveau drivers the glReadPixels() is very slow. [#24339]. */
+void ED_view3d_depth_update(ARegion *ar)
+{
+  RegionView3D *rv3d = ar->regiondata;
+
+  /* Create storage for, and, if necessary, copy depth buffer. */
+  if (!rv3d->depths) {
+    rv3d->depths = MEM_callocN(sizeof(ViewDepths), "ViewDepths");
+  }
+  if (rv3d->depths) {
+    ViewDepths *d = rv3d->depths;
+    if (d->w != ar->winx || d->h != ar->winy || !d->depths) {
+      d->w = ar->winx;
+      d->h = ar->winy;
+      if (d->depths) {
+        MEM_freeN(d->depths);
+      }
+      d->depths = MEM_mallocN(sizeof(float) * d->w * d->h, "View depths");
+      d->damaged = true;
+    }
+
+    if (d->damaged) {
+      GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0);
+      rcti r = {
+          .xmin = 0,
+          .xmax = d->w,
+          .ymin = 0,
+          .ymax = d->h,
+      };
+      view3d_opengl_read_Z_pixels(viewport, &r, d->depths);
+      glGetDoublev(GL_DEPTH_RANGE, d->depth_range);
+      d->damaged = false;
+    }
+  }
+}
+
+/* Utility function to find the closest Z value, use for autodepth. */
+float view3d_depth_near(ViewDepths *d)
+{
+  /* Convert to float for comparisons. */
+  const float near = (float)d->depth_range[0];
+  const float far_real = (float)d->depth_range[1];
+  float far = far_real;
+
+  const float *depths = d->depths;
+  float depth = FLT_MAX;
+  int i = (int)d->w * (int)d->h; /* Cast to avoid short overflow. */
+
+  /* Far is both the starting 'far' value
+   * and the closest value found. */
+  while (i--) {
+    depth = *depths++;
+    if ((depth < far) && (depth > near)) {
+      far = depth;
+    }
+  }
+
+  return far == far_real ? FLT_MAX : far;
+}
+
+void ED_view3d_draw_depth_gpencil(Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d)
+{
+  /* Setup view matrix. */
+  ED_view3d_draw_setup_view(NULL, depsgraph, scene, ar, v3d, NULL, NULL, NULL);
+
+  GPU_clear(GPU_DEPTH_BIT);
+
+  GPU_depth_test(true);
+
+  GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0);
+  DRW_draw_depth_loop_gpencil(depsgraph, ar, v3d, viewport);
+
+  GPU_depth_test(false);
+}
+
+/* *********************** customdata **************** */
+
+void ED_view3d_datamask(const bContext *C,
+                        const Scene *UNUSED(scene),
+                        const View3D *v3d,
+                        CustomData_MeshMasks *r_cddata_masks)
+{
+  if (ELEM(v3d->shading.type, OB_TEXTURE, OB_MATERIAL, OB_RENDER)) {
+    r_cddata_masks->lmask |= CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL;
+    r_cddata_masks->vmask |= CD_MASK_ORCO;
+  }
+  else if (v3d->shading.type == OB_SOLID) {
+    if (v3d->shading.color_type == V3D_SHADING_TEXTURE_COLOR) {
+      r_cddata_masks->lmask |= CD_MASK_MLOOPUV;
+    }
+    if (v3d->shading.color_type == V3D_SHADING_VERTEX_COLOR) {
+      r_cddata_masks->lmask |= CD_MASK_MLOOPCOL;
+    }
+  }
+
+  if

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list