[Bf-blender-cvs] [141382d6f2a] soc-2019-npr: LANPR: Moved non-drawing related chaining code to ED.
YimingWu
noreply at git.blender.org
Sat Jul 13 11:08:03 CEST 2019
Commit: 141382d6f2acce90f3906c6b718e725a136482eb
Author: YimingWu
Date: Sat Jul 13 17:07:29 2019 +0800
Branches: soc-2019-npr
https://developer.blender.org/rB141382d6f2acce90f3906c6b718e725a136482eb
LANPR: Moved non-drawing related chaining code to ED.
===================================================================
M source/blender/draw/CMakeLists.txt
A source/blender/draw/engines/lanpr/lanpr_chain_draw.c
M source/blender/editors/lanpr/CMakeLists.txt
R086 source/blender/draw/engines/lanpr/lanpr_chain.c source/blender/editors/lanpr/lanpr_chain.c
===================================================================
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 7d8b8c6c7bd..b4ebff62668 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -131,7 +131,7 @@ set(SRC
engines/lanpr/lanpr_snake.c
engines/lanpr/lanpr_ops.c
engines/lanpr/lanpr_util.c
- engines/lanpr/lanpr_chain.c
+ engines/lanpr/lanpr_chain_draw.c
engines/lanpr/lanpr_access.c
DRW_engine.h
diff --git a/source/blender/draw/engines/lanpr/lanpr_chain_draw.c b/source/blender/draw/engines/lanpr/lanpr_chain_draw.c
new file mode 100644
index 00000000000..511b4e78dfe
--- /dev/null
+++ b/source/blender/draw/engines/lanpr/lanpr_chain_draw.c
@@ -0,0 +1,168 @@
+#include "DRW_engine.h"
+#include "DRW_render.h"
+#include "BLI_listbase.h"
+#include "BLI_linklist.h"
+#include "BLI_math.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 "DNA_meshdata_types.h"
+#include "BKE_customdata.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"
+
+#include <math.h>
+
+int lanpr_count_chain(LANPR_RenderLineChain *rlc);
+
+float lanpr_compute_chain_length_draw(LANPR_RenderLineChain *rlc, float *lengths, int begin_index)
+{
+ LANPR_RenderLineChainItem *rlci;
+ int i = 0;
+ float offset_accum = 0;
+ float dist;
+ float last_point[2];
+
+ rlci = rlc->chain.first;
+ copy_v2_v2(last_point, rlci->pos);
+ for (rlci = rlc->chain.first; rlci; rlci = rlci->next) {
+ dist = len_v2v2(rlci->pos, last_point);
+ offset_accum += dist;
+ lengths[begin_index + i] = offset_accum;
+ copy_v2_v2(last_point, rlci->pos);
+ i++;
+ }
+ return offset_accum;
+}
+
+int lanpr_get_gpu_line_type(LANPR_RenderLineChainItem *rlci)
+{
+ switch (rlci->line_type) {
+ case LANPR_EDGE_FLAG_CONTOUR:
+ return 0;
+ case LANPR_EDGE_FLAG_CREASE:
+ return 1;
+ case LANPR_EDGE_FLAG_MATERIAL:
+ return 2;
+ case LANPR_EDGE_FLAG_EDGE_MARK:
+ return 3;
+ case LANPR_EDGE_FLAG_INTERSECTION:
+ return 4;
+ default:
+ return 0;
+ }
+}
+
+void lanpr_chain_generate_draw_command(LANPR_RenderBuffer *rb)
+{
+ LANPR_RenderLineChain *rlc;
+ LANPR_RenderLineChainItem *rlci;
+ int vert_count = 0;
+ int i = 0;
+ int arg;
+ float total_length;
+ float *lengths;
+ float length_target[2];
+
+ static GPUVertFormat format = {0};
+ static struct {
+ uint pos, uvs, normal, type, level;
+ } attr_id;
+ if (format.attr_len == 0) {
+ attr_id.pos = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ attr_id.uvs = GPU_vertformat_attr_add(&format, "uvs", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ attr_id.normal = GPU_vertformat_attr_add(&format, "normal", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ attr_id.type = GPU_vertformat_attr_add(&format, "type", GPU_COMP_I32, 1, GPU_FETCH_INT);
+ attr_id.level = GPU_vertformat_attr_add(&format, "level", GPU_COMP_I32, 1, GPU_FETCH_INT);
+ }
+
+ GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
+
+ for (rlc = rb->chains.first; rlc; rlc = rlc->next) {
+ int count = lanpr_count_chain(rlc);
+ /* printf("seg contains %d verts\n", count); */
+ vert_count += count;
+ }
+
+ GPU_vertbuf_data_alloc(vbo, vert_count + 1); /* serve as end point's adj. */
+
+ lengths = MEM_callocN(sizeof(float) * vert_count, "chain lengths");
+
+ GPUIndexBufBuilder elb;
+ GPU_indexbuf_init_ex(&elb, GPU_PRIM_LINES_ADJ, vert_count * 4, vert_count);
+
+ for (rlc = rb->chains.first; rlc; rlc = rlc->next) {
+
+ total_length = lanpr_compute_chain_length_draw(rlc, lengths, i);
+
+ for (rlci = rlc->chain.first; rlci; rlci = rlci->next) {
+
+ length_target[0] = lengths[i];
+ length_target[1] = total_length - lengths[i];
+
+ GPU_vertbuf_attr_set(vbo, attr_id.pos, i, rlci->pos);
+ GPU_vertbuf_attr_set(vbo, attr_id.normal, i, rlci->normal);
+ GPU_vertbuf_attr_set(vbo, attr_id.uvs, i, length_target);
+
+ arg = lanpr_get_gpu_line_type(rlci);
+ GPU_vertbuf_attr_set(vbo, attr_id.type, i, &arg);
+
+ arg = (int)rlci->occlusion;
+ GPU_vertbuf_attr_set(vbo, attr_id.level, i, &arg);
+
+ if (rlci == rlc->chain.last) {
+ if (rlci->prev == rlc->chain.first) {
+ length_target[1] = total_length;
+ GPU_vertbuf_attr_set(vbo, attr_id.uvs, i, length_target);
+ }
+ i++;
+ continue;
+ }
+
+ if (rlci == rlc->chain.first) {
+ if (rlci->next == rlc->chain.last) {
+ GPU_indexbuf_add_line_adj_verts(&elb, vert_count, i, i + 1, vert_count);
+ }
+ else {
+ GPU_indexbuf_add_line_adj_verts(&elb, vert_count, i, i + 1, i + 2);
+ }
+ }
+ else {
+ if (rlci->next == rlc->chain.last) {
+ GPU_indexbuf_add_line_adj_verts(&elb, i - 1, i, i + 1, vert_count);
+ }
+ else {
+ GPU_indexbuf_add_line_adj_verts(&elb, i - 1, i, i + 1, i + 2);
+ }
+ }
+
+ i++;
+ }
+ }
+ /* set end point flag value. */
+ length_target[0] = 3e30f;
+ length_target[1] = 3e30f;
+ GPU_vertbuf_attr_set(vbo, attr_id.pos, vert_count, length_target);
+
+ MEM_freeN(lengths);
+
+ if (rb->chain_draw_batch) {
+ GPU_batch_discard(rb->chain_draw_batch);
+ }
+ rb->chain_draw_batch = GPU_batch_create_ex(
+ GPU_PRIM_LINES_ADJ, vbo, GPU_indexbuf_build(&elb), GPU_USAGE_DYNAMIC | GPU_BATCH_OWNS_VBO);
+}
+
diff --git a/source/blender/editors/lanpr/CMakeLists.txt b/source/blender/editors/lanpr/CMakeLists.txt
index bbf61c89079..1108e82321e 100644
--- a/source/blender/editors/lanpr/CMakeLists.txt
+++ b/source/blender/editors/lanpr/CMakeLists.txt
@@ -33,6 +33,7 @@ set(INC_SYS
set(SRC
lanpr_ops.c
+ lanpr_chain.c
)
set(LIB
diff --git a/source/blender/draw/engines/lanpr/lanpr_chain.c b/source/blender/editors/lanpr/lanpr_chain.c
similarity index 86%
rename from source/blender/draw/engines/lanpr/lanpr_chain.c
rename to source/blender/editors/lanpr/lanpr_chain.c
index 7701333a5ad..ccaf51fbf7f 100644
--- a/source/blender/draw/engines/lanpr/lanpr_chain.c
+++ b/source/blender/editors/lanpr/lanpr_chain.c
@@ -1,29 +1,19 @@
-#include "DRW_engine.h"
-#include "DRW_render.h"
#include "BLI_listbase.h"
#include "BLI_linklist.h"
#include "BLI_math.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 "DNA_scene_types.h"
#include "DNA_meshdata_types.h"
#include "BKE_customdata.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"
+#include "ED_lanpr.h"
+
#include <math.h>
int lanpr_get_line_bounding_areas(LANPR_RenderBuffer *rb,
@@ -777,143 +767,6 @@ int lanpr_count_chain(LANPR_RenderLineChain *rlc)
return Count;
}
-float lanpr_compute_chain_length_draw(LANPR_RenderLineChain *rlc, float *lengths, int begin_index)
-{
- LANPR_RenderLineChainItem *rlci;
- int i = 0;
- float offset_accum = 0;
- float dist;
- float last_point[2];
-
- rlci = rlc->chain.first;
- copy_v2_v2(last_point, rlci->pos);
- for (rlci = rlc->chain.first; rlci; rlci = rlci->next) {
- dist = len_v2v2(rlci->pos, last_point);
- offset_accum += dist;
- lengths[begin_index + i] = offset_accum;
- copy_v2_v2(last_point, rlci->pos);
- i++;
- }
- return offset_accum;
-}
-
-int lanpr_get_gpu_line_type(LANPR_RenderLineChainItem *rlci)
-{
- switch (rlci->line_type) {
- case LANPR_EDGE_FLAG_CONTOUR:
- return 0;
- case LANPR_EDGE_FLAG_CREASE:
- return 1;
- case LANPR_EDGE_FLAG_MATERIAL:
- return 2;
- case LANPR_EDGE_FLAG_EDGE_MARK:
- return 3;
- case LANPR_EDGE_FLAG_INTERSECTION:
- return 4;
- default:
- return 0;
- }
-}
-
-void lanpr_chain_generate_draw_command(LANPR_RenderBuffer *rb)
-{
- LANPR_RenderLineChain *rlc;
- LANPR_RenderLineChainItem *rlci;
- int vert_count = 0;
- int i = 0;
- int arg;
- float total_length;
- float *lengths;
- float length_target[2];
-
- static GPUVertFormat format = {0};
- static struct {
- uint pos, uvs, normal, type, level;
- } attr_id;
- if (format.attr_len == 0) {
- attr_id.pos = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- attr_id.uvs = GPU_vertformat_attr_add(&format, "uvs", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- attr_id.normal = GPU_vertformat_attr_add(&format, "normal", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- attr_id.type = GPU_vertformat_attr_add(&format, "type", GPU_COMP_I32, 1, GPU_FETCH_INT);
- attr_id.level = GPU_vertformat_attr_add(&format, "level", GPU_COMP_I32, 1, GPU_FETCH_INT);
- }
-
- GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
-
- for (rlc = rb->chains.first; rlc; rlc = rlc->next) {
- int count = lanpr_count_chain(rlc);
- /* printf("seg contains %d verts\n", count); */
- vert_count += count;
- }
-
- GPU_vertbuf_data_alloc(vbo, vert_count + 1); /* serve as end point's adj. */
-
- lengths = MEM_callocN(sizeof(float) * vert_count, "chain lengths");
-
- GPUIndexBufBuilder elb;
- GPU_indexbuf_init_ex(&elb, GPU_PRIM_LINES_ADJ, vert_count * 4, vert_count);
-
- for (rlc = rb->chains.first; rlc; rlc = rlc->next) {
-
- total_length = lanpr_compute_chain_length_draw(rlc, lengths, i);
-
- for (rlci = rlc->chain.first; rlci; rlci = rlci->next) {
-
- length_target[0] = lengths[i];
- length_target[1] = total_length - lengths[i];
-
- GPU_vertbuf_attr_set(vbo, attr_id.pos, i, rlci->pos);
- GPU_vertbuf_attr_set(vbo, attr_id.normal, i, rlci->normal);
- GPU_vertbuf_attr_set(vbo, attr_id.uvs, i, length_target);
-
- arg = lanpr_get_gpu_line_type(rlci);
- GPU_vertbuf_attr_set
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list