[Bf-blender-cvs] [a52f0070fdd] temp-lanpr-cleanup2: LANPR: More clear statement of the endpoint value in chain drawing code.

YimingWu noreply at git.blender.org
Mon Nov 4 15:41:27 CET 2019


Commit: a52f0070fddfdab99a63d31ddbea808cb7ac1738
Author: YimingWu
Date:   Mon Nov 4 22:40:31 2019 +0800
Branches: temp-lanpr-cleanup2
https://developer.blender.org/rBa52f0070fddfdab99a63d31ddbea808cb7ac1738

LANPR: More clear statement of the endpoint value in chain drawing code.

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

M	source/blender/draw/engines/lanpr/lanpr_all.h
M	source/blender/draw/engines/lanpr/lanpr_chain_draw.c
D	source/blender/draw/engines/lanpr/lanpr_snake.c
M	source/blender/draw/engines/lanpr/shaders/lanpr_software_chain_geom.glsl

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

diff --git a/source/blender/draw/engines/lanpr/lanpr_all.h b/source/blender/draw/engines/lanpr/lanpr_all.h
index eb12f71a08d..588760d0762 100644
--- a/source/blender/draw/engines/lanpr/lanpr_all.h
+++ b/source/blender/draw/engines/lanpr/lanpr_all.h
@@ -61,12 +61,6 @@
 
 #define LANPR_ENGINE "BLENDER_LANPR"
 
-#define deg(r) r / M_PI * 180.0
-#define rad(d) d *M_PI / 180.0
-
-#define tMatDist2v(p1, p2) \
-  sqrt(((p1)[0] - (p2)[0]) * ((p1)[0] - (p2)[0]) + ((p1)[1] - (p2)[1]) * ((p1)[1] - (p2)[1]))
-
 extern struct RenderEngineType DRW_engine_viewport_lanpr_type;
 extern struct DrawEngineType draw_engine_lanpr_type;
 
diff --git a/source/blender/draw/engines/lanpr/lanpr_chain_draw.c b/source/blender/draw/engines/lanpr/lanpr_chain_draw.c
index 2f5fc095f88..007ee506439 100644
--- a/source/blender/draw/engines/lanpr/lanpr_chain_draw.c
+++ b/source/blender/draw/engines/lanpr/lanpr_chain_draw.c
@@ -92,6 +92,12 @@ static int lanpr_get_gpu_line_type(LANPR_RenderLineChainItem *rlci)
   }
 }
 
+/** Endpoint flag,
+ * use an unreasonably big value in lanpr but within float range.
+ * This value is used to determin endpoint in the shader.
+ * Keep in sync with the one in lanpr_software_chain_geom.glsl */
+#define LANPR_CHAIN_ENDPOINT_FLAG 3e30f
+
 void lanpr_chain_generate_draw_command(LANPR_RenderBuffer *rb)
 {
   LANPR_RenderLineChain *rlc;
@@ -178,9 +184,10 @@ void lanpr_chain_generate_draw_command(LANPR_RenderBuffer *rb)
       i++;
     }
   }
-  /*  set end point flag value. */
-  length_target[0] = 3e30f;
-  length_target[1] = 3e30f;
+
+  /* set end point flag value. */
+  length_target[0] = LANPR_CHAIN_ENDPOINT_FLAG;
+  length_target[1] = LANPR_CHAIN_ENDPOINT_FLAG;
   GPU_vertbuf_attr_set(vbo, attr_id.pos, vert_count, length_target);
 
   MEM_freeN(lengths);
diff --git a/source/blender/draw/engines/lanpr/lanpr_snake.c b/source/blender/draw/engines/lanpr/lanpr_snake.c
deleted file mode 100644
index 4a570964a2a..00000000000
--- a/source/blender/draw/engines/lanpr/lanpr_snake.c
+++ /dev/null
@@ -1,623 +0,0 @@
-/*
- * 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 2019, Blender Foundation.
- *
- */
-
-/** \file
- * \ingroup draw
- */
-
-#include "DRW_engine.h"
-#include "DRW_render.h"
-#include "BLI_listbase.h"
-#include "BLI_linklist.h"
-#include "lanpr_all.h"
-#include "DRW_render.h"
-#include "BKE_object.h"
-#include "DNA_mesh_types.h"
-#include "DNA_camera_types.h"
-#include "GPU_immediate.h"
-#include "GPU_immediate_util.h"
-#include "GPU_framebuffer.h"
-#include "DNA_lanpr_types.h"
-#include "DEG_depsgraph_query.h"
-#include "GPU_draw.h"
-#include "GPU_batch.h"
-#include "GPU_framebuffer.h"
-#include "GPU_shader.h"
-#include "GPU_uniformbuffer.h"
-#include "GPU_viewport.h"
-#include "bmesh.h"
-
-extern struct LANPR_SharedResource lanpr_share;
-
-int _TNS_colOffsets[] = {-1, 0, 1, 1, 1, 0, -1, -1};
-int _TNS_rowOffsets[] = {-1, -1, -1, 0, 1, 1, 1, 0};
-
-int _TNS_Deviates[8][8] = {{0, 1, 2, 3, 4, 3, 2, 1},
-                           {1, 0, 1, 2, 3, 4, 3, 2},
-                           {2, 1, 0, 1, 2, 3, 4, 3},
-                           {3, 2, 1, 0, 1, 2, 3, 4},
-                           {4, 3, 2, 1, 0, 1, 2, 3},
-                           {3, 4, 3, 2, 1, 0, 1, 2},
-                           {2, 3, 4, 3, 2, 1, 0, 1},
-                           {1, 2, 3, 4, 3, 2, 1, 0}};
-
-#define TNS_CLAMP_TEXTURE_W(t, col) \
-  { \
-    if (col >= t->width) \
-      col = t->width - 1; \
-    if (col < 0) \
-      col = 0; \
-  }
-
-#define TNS_CLAMP_TEXTURE_H(t, row) \
-  { \
-    if (row >= t->height) \
-      row = t->height - 1; \
-    if (row < 0) \
-      row = 0; \
-  }
-
-#define TNS_CLAMP_TEXTURE_CONTINUE(t, col, row) \
-  { \
-    if (col >= t->width) \
-      continue; \
-    if (col < 0) \
-      continue; \
-    if (row >= t->height) \
-      continue; \
-    if (row < 0) \
-      continue; \
-  }
-
-static LANPR_TextureSample *lanpr_any_uncovered_samples(LANPR_PrivateData *pd)
-{
-  return BLI_pophead(&pd->pending_samples);
-}
-
-int lanpr_direction_deviate(int From, int To)
-{
-  return _TNS_Deviates[From - 1][To - 1];
-}
-
-int lanpr_detect_direction(LANPR_PrivateData *pd, int col, int row, int LastDirection)
-{
-  int Deviate[9] = {100};
-  int MinDeviate = 0;
-  int i;
-  LANPR_TextureSample *ts;
-
-  for (i = 0; i < 8; i++) {
-    TNS_CLAMP_TEXTURE_CONTINUE(pd, (_TNS_colOffsets[i] + col), (_TNS_rowOffsets[i] + row));
-    if (ts = pd->sample_table[(_TNS_colOffsets[i] + col) +
-                              (_TNS_rowOffsets[i] + row) * pd->width]) {
-      if (!LastDirection) {
-        return i + 1;
-      }
-      Deviate[i + 1] = lanpr_direction_deviate(i, LastDirection);
-      if (!MinDeviate || Deviate[MinDeviate] > Deviate[i + 1]) {
-        MinDeviate = i + 1;
-      }
-    }
-  }
-
-  return MinDeviate;
-}
-
-LANPR_LineStrip *lanpr_create_line_strip(LANPR_PrivateData *pd)
-{
-  LANPR_LineStrip *ls = BLI_mempool_calloc(lanpr_share.mp_line_strip);
-  return ls;
-}
-LANPR_LineStripPoint *lanpr_append_point(
-    LANPR_PrivateData *pd, LANPR_LineStrip *ls, real X, real Y, real Z)
-{
-  LANPR_LineStripPoint *lsp = BLI_mempool_calloc(lanpr_share.mp_line_strip_point);
-
-  lsp->P[0] = X;
-  lsp->P[1] = Y;
-  lsp->P[2] = Z;
-
-  BLI_addtail(&ls->points, lsp);
-
-  ls->point_count++;
-
-  return lsp;
-}
-LANPR_LineStripPoint *lanpr_push_point(
-    LANPR_PrivateData *pd, LANPR_LineStrip *ls, real X, real Y, real Z)
-{
-  LANPR_LineStripPoint *lsp = BLI_mempool_calloc(lanpr_share.mp_line_strip_point);
-
-  lsp->P[0] = X;
-  lsp->P[1] = Y;
-  lsp->P[2] = Z;
-
-  BLI_addhead(&ls->points, lsp);
-
-  ls->point_count++;
-
-  return lsp;
-}
-
-void lanpr_destroy_line_strip(LANPR_PrivateData *pd, LANPR_LineStrip *ls)
-{
-  LANPR_LineStripPoint *lsp;
-  while (lsp = BLI_pophead(&ls->points)) {
-    BLI_mempool_free(lanpr_share.mp_line_strip_point, lsp);
-  }
-  BLI_mempool_free(lanpr_share.mp_line_strip, ls);
-}
-
-void lanpr_remove_sample(LANPR_PrivateData *pd, int row, int col)
-{
-  LANPR_TextureSample *ts;
-  ts = pd->sample_table[row * pd->width + col];
-  pd->sample_table[row * pd->width + col] = NULL;
-
-  BLI_remlink(&pd->pending_samples, ts);
-  ts->prev = NULL;
-  ts->next = NULL;
-  BLI_addtail(&pd->erased_samples, ts);
-}
-
-void lanpr_grow_snake_r(LANPR_PrivateData *pd,
-                        LANPR_LineStrip *ls,
-                        LANPR_LineStripPoint *ThisP,
-                        int Direction)
-{
-  LANPR_LineStripPoint *NewP = ThisP, *p2;
-  int Length = 5;
-  int l = 0;
-  int Deviate, Dir = Direction, NewDir;
-  int AddPoint;
-  int TX = NewP->P[0], TY = NewP->P[1];
-
-  while (NewDir = lanpr_detect_direction(pd, TX, TY, Dir)) {
-    AddPoint = 0;
-    Deviate = lanpr_direction_deviate(NewDir, Dir);
-    Dir = NewDir;
-
-    l++;
-    TX += _TNS_colOffsets[NewDir - 1];
-    TY += _TNS_rowOffsets[NewDir - 1];
-
-    if (Deviate < 2) {
-      lanpr_remove_sample(pd, TY, TX);
-    }
-    else if (Deviate < 3) {
-      lanpr_remove_sample(pd, TY, TX);
-      AddPoint = 1;
-    }
-    else {
-      lanpr_remove_sample(pd, TY, TX);
-      return;
-    }
-
-    if (AddPoint || l == Length) {
-      p2 = lanpr_append_point(pd, ls, TX, TY, 0);
-      NewP = p2;
-      l = 0;
-    }
-  }
-  if (TX != ThisP->P[0] || TY != ThisP->P[1]) {
-    lanpr_append_point(pd, ls, TX, TY, 0);
-  }
-}
-
-void lanpr_grow_snake_l(LANPR_PrivateData *pd,
-                        LANPR_LineStrip *ls,
-                        LANPR_LineStripPoint *ThisP,
-                        int Direction)
-{
-  LANPR_LineStripPoint *NewP = ThisP, *p2;
-  int Length = 5;
-  int l = 0;
-  int Deviate, Dir = Direction, NewDir;
-  int AddPoint;
-  int TX = NewP->P[0], TY = NewP->P[1];
-
-  while (NewDir = lanpr_detect_direction(pd, TX, TY, Dir)) {
-    AddPoint = 0;
-    Deviate = lanpr_direction_deviate(NewDir, Dir);
-    Dir = NewDir;
-
-    l++;
-    TX += _TNS_colOffsets[NewDir - 1];
-    TY += _TNS_rowOffsets[NewDir - 1];
-
-    if (Deviate < 2) {
-      lanpr_remove_sample(pd, TY, TX);
-    }
-    else if (Deviate < 4) {
-      lanpr_remove_sample(pd, TY, TX);
-      AddPoint = 1;
-    }
-    else {
-      lanpr_remove_sample(pd, TY, TX);
-      return;
-    }
-
-    if (AddPoint || l == Length) {
-      p2 = lanpr_push_point(pd, ls, TX, TY, 0);
-      NewP = p2;
-      l = 0;
-    }
-  }
-  if (TX != ThisP->P[0] || TY != ThisP->P[1]) {
-    lanpr_push_point(pd, ls, TX, TY, 0);
-  }
-}
-
-int lanpr_reverse_direction(int From)
-{
-  From -= 4;
-  if (From <= 0) {
-    From += 8;
-  }
-  return From;
-}
-
-void lanpr_texture_to_ndc(int x, int y, int w, int h, float *x_ndc, float *y_ndc)
-{
-  *x_ndc = interpf(1, -1, (float)x / (float)w);
-  *y_ndc = interpf(1, -1, (float)y / (float)h);
-}
-
-void lanpr_count_drawing_elements(LANPR_PrivateData *pd,
-                                  int *vert_count,
-                                  int *index_adjacent_count)
-{
-  int v_count = 0;
-  int e_count = 0;
-  LANPR_LineStrip *ls;
-  for (ls = (LANPR_LineStrip *)(pd->line_strips.first); ls; ls = (ls->next)) {
-    v_count += (ls->point_count);
-    e_count += ((ls->point_count - 1) * 4);
-  }
-  *vert_count = v_count;
-  *index_adjacent_count = e_count;
-}
-
-GPUBatch *lanpr_get_snake_batch(LANPR_PrivateData *pd)
-{
-  LANPR_LineStrip *ls;
-  LANPR_LineStripPoint *lsp, *plsp;
-  int i;
-  float *Verts;
-  float *Lengths;
-  float TotalLength = 0;
-  int v_count, e_count;
-
-  lanpr_count_drawing_elements(pd, &v_count, &e_count);
-
-  Verts = MEM_callocN(sizeof(float) * v_count * 2

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list