Mesh: Draw: Replace extractor abstraction for mesh analysis buffer
Part of #116901. The code was already structured to not use the extractor iterators, so I only changed the entry point.
This commit is contained in:
@@ -533,6 +533,7 @@ static void mesh_extract_render_data_node_exec(void *__restrict task_data)
|
||||
const bool request_face_normals = DRW_vbo_requested(buffers.vbo.nor) ||
|
||||
DRW_vbo_requested(buffers.vbo.fdots_nor) ||
|
||||
DRW_vbo_requested(buffers.vbo.edge_fac) ||
|
||||
DRW_vbo_requested(buffers.vbo.mesh_analysis) ||
|
||||
(data_flag & (MR_DATA_POLY_NOR | MR_DATA_LOOP_NOR)) != 0;
|
||||
const bool request_corner_normals = DRW_vbo_requested(buffers.vbo.nor) ||
|
||||
(data_flag & MR_DATA_LOOP_NOR) != 0;
|
||||
@@ -646,7 +647,6 @@ void mesh_buffer_cache_create_requested(TaskGraph &task_graph,
|
||||
EXTRACT_ADD_REQUESTED(vbo, edituv_data);
|
||||
EXTRACT_ADD_REQUESTED(vbo, edituv_stretch_area);
|
||||
EXTRACT_ADD_REQUESTED(vbo, edituv_stretch_angle);
|
||||
EXTRACT_ADD_REQUESTED(vbo, mesh_analysis);
|
||||
EXTRACT_ADD_REQUESTED(vbo, fdots_edituv_data);
|
||||
for (int i = 0; i < GPU_MAX_ATTR; i++) {
|
||||
EXTRACT_ADD_REQUESTED(vbo, attr[i]);
|
||||
@@ -673,7 +673,7 @@ void mesh_buffer_cache_create_requested(TaskGraph &task_graph,
|
||||
!DRW_vbo_requested(buffers.vbo.uv) && !DRW_ibo_requested(buffers.ibo.lines_paint_mask) &&
|
||||
!DRW_ibo_requested(buffers.ibo.lines_adjacency) &&
|
||||
!DRW_vbo_requested(buffers.vbo.skin_roots) && !DRW_vbo_requested(buffers.vbo.sculpt_data) &&
|
||||
!DRW_vbo_requested(buffers.vbo.orco))
|
||||
!DRW_vbo_requested(buffers.vbo.orco) && !DRW_vbo_requested(buffers.vbo.mesh_analysis))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -1052,6 +1052,21 @@ void mesh_buffer_cache_create_requested(TaskGraph &task_graph,
|
||||
[](void *task_data) { delete static_cast<TaskData *>(task_data); });
|
||||
BLI_task_graph_edge_create(task_node_mesh_render_data, task_node);
|
||||
}
|
||||
if (DRW_vbo_requested(buffers.vbo.mesh_analysis)) {
|
||||
struct TaskData {
|
||||
MeshRenderData &mr;
|
||||
MeshBufferList &buffers;
|
||||
};
|
||||
TaskNode *task_node = BLI_task_graph_node_create(
|
||||
&task_graph,
|
||||
[](void *__restrict task_data) {
|
||||
const TaskData &data = *static_cast<TaskData *>(task_data);
|
||||
extract_mesh_analysis(data.mr, *data.buffers.vbo.mesh_analysis);
|
||||
},
|
||||
new TaskData{*mr, buffers},
|
||||
[](void *task_data) { delete static_cast<TaskData *>(task_data); });
|
||||
BLI_task_graph_edge_create(task_node_mesh_render_data, task_node);
|
||||
}
|
||||
|
||||
if (use_thread) {
|
||||
/* First run the requested extractors that do not support asynchronous ranges. */
|
||||
|
||||
@@ -466,6 +466,8 @@ void extract_sculpt_data_subdiv(const MeshRenderData &mr,
|
||||
|
||||
void extract_orco(const MeshRenderData &mr, gpu::VertBuf &vbo);
|
||||
|
||||
void extract_mesh_analysis(const MeshRenderData &mr, gpu::VertBuf &vbo);
|
||||
|
||||
extern const MeshExtract extract_edituv_tris;
|
||||
extern const MeshExtract extract_edituv_lines;
|
||||
extern const MeshExtract extract_edituv_points;
|
||||
@@ -473,7 +475,6 @@ extern const MeshExtract extract_edituv_fdots;
|
||||
extern const MeshExtract extract_edituv_data;
|
||||
extern const MeshExtract extract_edituv_stretch_area;
|
||||
extern const MeshExtract extract_edituv_stretch_angle;
|
||||
extern const MeshExtract extract_mesh_analysis;
|
||||
extern const MeshExtract extract_fdots_edituv_data;
|
||||
extern const MeshExtract extract_attr[GPU_MAX_ATTR];
|
||||
extern const MeshExtract extract_attr_viewer;
|
||||
|
||||
@@ -22,25 +22,6 @@
|
||||
|
||||
namespace blender::draw {
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/** \name Extract Edit Mesh Analysis Colors
|
||||
* \{ */
|
||||
|
||||
static void extract_mesh_analysis_init(const MeshRenderData &mr,
|
||||
MeshBatchCache & /*cache*/,
|
||||
void *buf,
|
||||
void * /*tls_data*/)
|
||||
{
|
||||
gpu::VertBuf *vbo = static_cast<gpu::VertBuf *>(buf);
|
||||
static GPUVertFormat format = {0};
|
||||
if (format.attr_len == 0) {
|
||||
GPU_vertformat_attr_add(&format, "weight", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
|
||||
}
|
||||
|
||||
GPU_vertbuf_init_with_format(vbo, &format);
|
||||
GPU_vertbuf_data_alloc(vbo, mr.corners_num);
|
||||
}
|
||||
|
||||
static void axis_from_enum_v3(float v[3], const char axis)
|
||||
{
|
||||
zero_v3(v);
|
||||
@@ -68,7 +49,7 @@ BLI_INLINE float overhang_remap(float fac, float min, float max, float minmax_ir
|
||||
return fac;
|
||||
}
|
||||
|
||||
static void statvis_calc_overhang(const MeshRenderData &mr, float *r_overhang)
|
||||
static void statvis_calc_overhang(const MeshRenderData &mr, MutableSpan<float> r_overhang)
|
||||
{
|
||||
const MeshStatVis *statvis = &mr.toolsettings->statvis;
|
||||
const float min = statvis->overhang_min / float(M_PI);
|
||||
@@ -139,11 +120,11 @@ BLI_INLINE float thickness_remap(float fac, float min, float max, float minmax_i
|
||||
return fac;
|
||||
}
|
||||
|
||||
static void statvis_calc_thickness(const MeshRenderData &mr, float *r_thickness)
|
||||
static void statvis_calc_thickness(const MeshRenderData &mr, MutableSpan<float> r_thickness)
|
||||
{
|
||||
const float eps_offset = 0.00002f; /* values <= 0.00001 give errors */
|
||||
/* cheating to avoid another allocation */
|
||||
float *face_dists = r_thickness + (mr.corners_num - mr.faces_num);
|
||||
float *face_dists = r_thickness.data() + (mr.corners_num - mr.faces_num);
|
||||
BMEditMesh *em = mr.edit_bmesh;
|
||||
const float scale = 1.0f / mat4_to_scale(mr.object_to_world.ptr());
|
||||
const MeshStatVis *statvis = &mr.toolsettings->statvis;
|
||||
@@ -303,7 +284,7 @@ static bool bvh_overlap_cb(void *userdata, int index_a, int index_b, int /*threa
|
||||
((verts_shared == 0) || (len_squared_v3v3(ix_pair[0], ix_pair[1]) > data->epsilon)));
|
||||
}
|
||||
|
||||
static void statvis_calc_intersect(const MeshRenderData &mr, float *r_intersect)
|
||||
static void statvis_calc_intersect(const MeshRenderData &mr, MutableSpan<float> r_intersect)
|
||||
{
|
||||
BMEditMesh *em = mr.edit_bmesh;
|
||||
|
||||
@@ -384,7 +365,7 @@ BLI_INLINE float distort_remap(float fac, float min, float /*max*/, float minmax
|
||||
return fac;
|
||||
}
|
||||
|
||||
static void statvis_calc_distort(const MeshRenderData &mr, float *r_distort)
|
||||
static void statvis_calc_distort(const MeshRenderData &mr, MutableSpan<float> r_distort)
|
||||
{
|
||||
BMEditMesh *em = mr.edit_bmesh;
|
||||
const MeshStatVis *statvis = &mr.toolsettings->statvis;
|
||||
@@ -487,7 +468,7 @@ BLI_INLINE float sharp_remap(float fac, float min, float /*max*/, float minmax_i
|
||||
return fac;
|
||||
}
|
||||
|
||||
static void statvis_calc_sharp(const MeshRenderData &mr, float *r_sharp)
|
||||
static void statvis_calc_sharp(const MeshRenderData &mr, MutableSpan<float> r_sharp)
|
||||
{
|
||||
BMEditMesh *em = mr.edit_bmesh;
|
||||
const MeshStatVis *statvis = &mr.toolsettings->statvis;
|
||||
@@ -581,51 +562,35 @@ static void statvis_calc_sharp(const MeshRenderData &mr, float *r_sharp)
|
||||
MEM_freeN(vert_angles);
|
||||
}
|
||||
|
||||
static void extract_analysis_iter_finish_mesh(const MeshRenderData &mr,
|
||||
MeshBatchCache & /*cache*/,
|
||||
void *buf,
|
||||
void * /*data*/)
|
||||
void extract_mesh_analysis(const MeshRenderData &mr, gpu::VertBuf &vbo)
|
||||
{
|
||||
gpu::VertBuf *vbo = static_cast<gpu::VertBuf *>(buf);
|
||||
BLI_assert(mr.edit_bmesh);
|
||||
|
||||
float *l_weight = (float *)GPU_vertbuf_get_data(vbo);
|
||||
static GPUVertFormat format = {0};
|
||||
if (format.attr_len == 0) {
|
||||
GPU_vertformat_attr_add(&format, "weight", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
|
||||
}
|
||||
GPU_vertbuf_init_with_format(&vbo, &format);
|
||||
GPU_vertbuf_data_alloc(&vbo, mr.corners_num);
|
||||
MutableSpan<float> vbo_data(static_cast<float *>(GPU_vertbuf_get_data(&vbo)), mr.corners_num);
|
||||
|
||||
switch (mr.toolsettings->statvis.type) {
|
||||
case SCE_STATVIS_OVERHANG:
|
||||
statvis_calc_overhang(mr, l_weight);
|
||||
statvis_calc_overhang(mr, vbo_data);
|
||||
break;
|
||||
case SCE_STATVIS_THICKNESS:
|
||||
statvis_calc_thickness(mr, l_weight);
|
||||
statvis_calc_thickness(mr, vbo_data);
|
||||
break;
|
||||
case SCE_STATVIS_INTERSECT:
|
||||
statvis_calc_intersect(mr, l_weight);
|
||||
statvis_calc_intersect(mr, vbo_data);
|
||||
break;
|
||||
case SCE_STATVIS_DISTORT:
|
||||
statvis_calc_distort(mr, l_weight);
|
||||
statvis_calc_distort(mr, vbo_data);
|
||||
break;
|
||||
case SCE_STATVIS_SHARP:
|
||||
statvis_calc_sharp(mr, l_weight);
|
||||
statvis_calc_sharp(mr, vbo_data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr MeshExtract create_extractor_mesh_analysis()
|
||||
{
|
||||
MeshExtract extractor = {nullptr};
|
||||
extractor.init = extract_mesh_analysis_init;
|
||||
extractor.finish = extract_analysis_iter_finish_mesh;
|
||||
/* This is not needed for all visualization types.
|
||||
* Maybe split into different extract. */
|
||||
extractor.data_type = MR_DATA_POLY_NOR;
|
||||
extractor.data_size = 0;
|
||||
extractor.use_threading = false;
|
||||
extractor.mesh_buffer_offset = offsetof(MeshBufferList, vbo.mesh_analysis);
|
||||
return extractor;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
const MeshExtract extract_mesh_analysis = create_extractor_mesh_analysis();
|
||||
|
||||
} // namespace blender::draw
|
||||
|
||||
Reference in New Issue
Block a user