Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/draw/intern/draw_cache_extract_mesh.c')
-rw-r--r--source/blender/draw/intern/draw_cache_extract_mesh.c317
1 files changed, 220 insertions, 97 deletions
diff --git a/source/blender/draw/intern/draw_cache_extract_mesh.c b/source/blender/draw/intern/draw_cache_extract_mesh.c
index 503232fa560..528a6eec69e 100644
--- a/source/blender/draw/intern/draw_cache_extract_mesh.c
+++ b/source/blender/draw/intern/draw_cache_extract_mesh.c
@@ -99,8 +99,6 @@ typedef struct MeshRenderData {
float obmat[4][4];
const ToolSettings *toolsettings;
- /* HACK not supposed to be there but it's needed. */
- struct MeshBatchCache *cache;
/** Edit Mesh */
BMEditMesh *edit_bmesh;
BMesh *bm;
@@ -480,10 +478,9 @@ BLI_INLINE const float *bm_vert_co_get(const MeshRenderData *mr, const BMVert *e
if (vert_coords != NULL) {
return vert_coords[BM_elem_index_get(eve)];
}
- else {
- UNUSED_VARS(mr);
- return eve->co;
- }
+
+ UNUSED_VARS(mr);
+ return eve->co;
}
BLI_INLINE const float *bm_vert_no_get(const MeshRenderData *mr, const BMVert *eve)
@@ -492,10 +489,9 @@ BLI_INLINE const float *bm_vert_no_get(const MeshRenderData *mr, const BMVert *e
if (vert_normals != NULL) {
return vert_normals[BM_elem_index_get(eve)];
}
- else {
- UNUSED_VARS(mr);
- return eve->no;
- }
+
+ UNUSED_VARS(mr);
+ return eve->no;
}
BLI_INLINE const float *bm_face_no_get(const MeshRenderData *mr, const BMFace *efa)
@@ -504,10 +500,9 @@ BLI_INLINE const float *bm_face_no_get(const MeshRenderData *mr, const BMFace *e
if (poly_normals != NULL) {
return poly_normals[BM_elem_index_get(efa)];
}
- else {
- UNUSED_VARS(mr);
- return efa->no;
- }
+
+ UNUSED_VARS(mr);
+ return efa->no;
}
/** \} */
@@ -760,8 +755,13 @@ typedef void(ExtractLVertMeshFn)(const MeshRenderData *mr,
/** \name Mesh Elements Extract Struct
* \{ */
-typedef void *(ExtractInitFn)(const MeshRenderData *mr, void *buffer);
-typedef void(ExtractFinishFn)(const MeshRenderData *mr, void *buffer, void *data);
+typedef void *(ExtractInitFn)(const MeshRenderData *mr,
+ struct MeshBatchCache *cache,
+ void *buffer);
+typedef void(ExtractFinishFn)(const MeshRenderData *mr,
+ struct MeshBatchCache *cache,
+ void *buffer,
+ void *data);
typedef struct MeshExtract {
/** Executed on main thread and return user data for iteration functions. */
@@ -805,7 +805,9 @@ typedef struct MeshExtract_Tri_Data {
int *tri_mat_end;
} MeshExtract_Tri_Data;
-static void *extract_tris_init(const MeshRenderData *mr, void *UNUSED(ibo))
+static void *extract_tris_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(ibo))
{
MeshExtract_Tri_Data *data = MEM_callocN(sizeof(*data), __func__);
@@ -891,14 +893,17 @@ static void extract_tris_iter_looptri_mesh(const MeshRenderData *mr,
EXTRACT_TRIS_LOOPTRI_FOREACH_MESH_END;
}
-static void extract_tris_finish(const MeshRenderData *mr, void *ibo, void *_data)
+static void extract_tris_finish(const MeshRenderData *mr,
+ struct MeshBatchCache *cache,
+ void *ibo,
+ void *_data)
{
MeshExtract_Tri_Data *data = _data;
GPU_indexbuf_build_in_place(&data->elb, ibo);
/* HACK: Create ibo sub-ranges and assign them to each #GPUBatch. */
/* The `surface_per_mat` tests are there when object shading type is set to Wire or Bounds. In
* these cases there isn't a surface per material. */
- if (mr->use_final_mesh && mr->cache->surface_per_mat && mr->cache->surface_per_mat[0]) {
+ if (mr->use_final_mesh && cache->surface_per_mat && cache->surface_per_mat[0]) {
for (int i = 0; i < mr->mat_len; i++) {
/* Multiply by 3 because these are triangle indices. */
const int mat_start = data->tri_mat_start[i];
@@ -907,7 +912,7 @@ static void extract_tris_finish(const MeshRenderData *mr, void *ibo, void *_data
const int len = (mat_end - mat_start) * 3;
GPUIndexBuf *sub_ibo = GPU_indexbuf_create_subrange(ibo, start, len);
/* WARNING: We modify the #GPUBatch here! */
- GPU_batch_elembuf_set(mr->cache->surface_per_mat[i], sub_ibo, true);
+ GPU_batch_elembuf_set(cache->surface_per_mat[i], sub_ibo, true);
}
}
MEM_freeN(data->tri_mat_start);
@@ -930,7 +935,9 @@ static const MeshExtract extract_tris = {
/** \name Extract Edges Indices
* \{ */
-static void *extract_lines_init(const MeshRenderData *mr, void *UNUSED(buf))
+static void *extract_lines_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(buf))
{
GPUIndexBufBuilder *elb = MEM_mallocN(sizeof(*elb), __func__);
/* Put loose edges at the end. */
@@ -1048,7 +1055,10 @@ static void extract_lines_iter_ledge_mesh(const MeshRenderData *mr,
EXTRACT_LEDGE_FOREACH_MESH_END;
}
-static void extract_lines_finish(const MeshRenderData *UNUSED(mr), void *ibo, void *elb)
+static void extract_lines_finish(const MeshRenderData *UNUSED(mr),
+ struct MeshBatchCache *UNUSED(cache),
+ void *ibo,
+ void *elb)
{
GPU_indexbuf_build_in_place(elb, ibo);
MEM_freeN(elb);
@@ -1070,21 +1080,24 @@ static const MeshExtract extract_lines = {
/** \name Extract Loose Edges Sub Buffer
* \{ */
-static void extract_lines_loose_subbuffer(const MeshRenderData *mr)
+static void extract_lines_loose_subbuffer(const MeshRenderData *mr, struct MeshBatchCache *cache)
{
- BLI_assert(mr->cache->final.ibo.lines);
+ BLI_assert(cache->final.ibo.lines);
/* Multiply by 2 because these are edges indices. */
const int start = mr->edge_len * 2;
const int len = mr->edge_loose_len * 2;
GPU_indexbuf_create_subrange_in_place(
- mr->cache->final.ibo.lines_loose, mr->cache->final.ibo.lines, start, len);
- mr->cache->no_loose_wire = (len == 0);
+ cache->final.ibo.lines_loose, cache->final.ibo.lines, start, len);
+ cache->no_loose_wire = (len == 0);
}
-static void extract_lines_with_lines_loose_finish(const MeshRenderData *mr, void *ibo, void *elb)
+static void extract_lines_with_lines_loose_finish(const MeshRenderData *mr,
+ struct MeshBatchCache *cache,
+ void *ibo,
+ void *elb)
{
GPU_indexbuf_build_in_place(elb, ibo);
- extract_lines_loose_subbuffer(mr);
+ extract_lines_loose_subbuffer(mr, cache);
MEM_freeN(elb);
}
@@ -1105,7 +1118,9 @@ static const MeshExtract extract_lines_with_lines_loose = {
/** \name Extract Point Indices
* \{ */
-static void *extract_points_init(const MeshRenderData *mr, void *UNUSED(buf))
+static void *extract_points_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(buf))
{
GPUIndexBufBuilder *elb = MEM_mallocN(sizeof(*elb), __func__);
GPU_indexbuf_init(elb, GPU_PRIM_POINTS, mr->vert_len, mr->loop_len + mr->loop_loose_len);
@@ -1209,7 +1224,10 @@ static void extract_points_iter_lvert_mesh(const MeshRenderData *mr,
EXTRACT_LVERT_FOREACH_MESH_END;
}
-static void extract_points_finish(const MeshRenderData *UNUSED(mr), void *ibo, void *elb)
+static void extract_points_finish(const MeshRenderData *UNUSED(mr),
+ struct MeshBatchCache *UNUSED(cache),
+ void *ibo,
+ void *elb)
{
GPU_indexbuf_build_in_place(elb, ibo);
MEM_freeN(elb);
@@ -1234,7 +1252,9 @@ static const MeshExtract extract_points = {
/** \name Extract Facedots Indices
* \{ */
-static void *extract_fdots_init(const MeshRenderData *mr, void *UNUSED(buf))
+static void *extract_fdots_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(buf))
{
GPUIndexBufBuilder *elb = MEM_mallocN(sizeof(*elb), __func__);
GPU_indexbuf_init(elb, GPU_PRIM_POINTS, mr->poly_len, mr->poly_len);
@@ -1289,7 +1309,10 @@ static void extract_fdots_iter_poly_mesh(const MeshRenderData *mr,
}
}
-static void extract_fdots_finish(const MeshRenderData *UNUSED(mr), void *ibo, void *elb)
+static void extract_fdots_finish(const MeshRenderData *UNUSED(mr),
+ struct MeshBatchCache *UNUSED(cache),
+ void *ibo,
+ void *elb)
{
GPU_indexbuf_build_in_place(elb, ibo);
MEM_freeN(elb);
@@ -1316,7 +1339,9 @@ typedef struct MeshExtract_LinePaintMask_Data {
BLI_bitmap select_map[0];
} MeshExtract_LinePaintMask_Data;
-static void *extract_lines_paint_mask_init(const MeshRenderData *mr, void *UNUSED(buf))
+static void *extract_lines_paint_mask_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(buf))
{
size_t bitmap_size = BLI_BITMAP_SIZE(mr->edge_len);
MeshExtract_LinePaintMask_Data *data = MEM_callocN(sizeof(*data) + bitmap_size, __func__);
@@ -1363,6 +1388,7 @@ static void extract_lines_paint_mask_iter_poly_mesh(const MeshRenderData *mr,
EXTRACT_POLY_AND_LOOP_FOREACH_MESH_END;
}
static void extract_lines_paint_mask_finish(const MeshRenderData *UNUSED(mr),
+ struct MeshBatchCache *UNUSED(cache),
void *ibo,
void *_data)
{
@@ -1396,7 +1422,9 @@ typedef struct MeshExtract_LineAdjacency_Data {
uint vert_to_loop[0];
} MeshExtract_LineAdjacency_Data;
-static void *extract_lines_adjacency_init(const MeshRenderData *mr, void *UNUSED(buf))
+static void *extract_lines_adjacency_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(buf))
{
/* Similar to poly_to_tri_count().
* There is always (loop + triangle - 1) edges inside a polygon.
@@ -1492,7 +1520,10 @@ static void extract_lines_adjacency_iter_looptri_mesh(const MeshRenderData *mr,
EXTRACT_TRIS_LOOPTRI_FOREACH_MESH_END;
}
-static void extract_lines_adjacency_finish(const MeshRenderData *mr, void *ibo, void *_data)
+static void extract_lines_adjacency_finish(const MeshRenderData *UNUSED(mr),
+ struct MeshBatchCache *cache,
+ void *ibo,
+ void *_data)
{
MeshExtract_LineAdjacency_Data *data = _data;
/* Create edges for remaining non manifold edges. */
@@ -1515,7 +1546,7 @@ static void extract_lines_adjacency_finish(const MeshRenderData *mr, void *ibo,
BLI_edgehashIterator_free(ehi);
BLI_edgehash_free(data->eh, NULL);
- mr->cache->is_manifold = data->is_manifold;
+ cache->is_manifold = data->is_manifold;
GPU_indexbuf_build_in_place(&data->elb, ibo);
MEM_freeN(data);
@@ -1543,7 +1574,9 @@ typedef struct MeshExtract_EditUvElem_Data {
bool sync_selection;
} MeshExtract_EditUvElem_Data;
-static void *extract_edituv_tris_init(const MeshRenderData *mr, void *UNUSED(ibo))
+static void *extract_edituv_tris_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(ibo))
{
MeshExtract_EditUvElem_Data *data = MEM_callocN(sizeof(*data), __func__);
GPU_indexbuf_init(&data->elb, GPU_PRIM_TRIS, mr->tri_len, mr->loop_len);
@@ -1592,7 +1625,10 @@ static void extract_edituv_tris_iter_looptri_mesh(const MeshRenderData *mr,
EXTRACT_TRIS_LOOPTRI_FOREACH_MESH_END;
}
-static void extract_edituv_tris_finish(const MeshRenderData *UNUSED(mr), void *ibo, void *data)
+static void extract_edituv_tris_finish(const MeshRenderData *UNUSED(mr),
+ struct MeshBatchCache *UNUSED(cache),
+ void *ibo,
+ void *data)
{
MeshExtract_EditUvElem_Data *extract_data = data;
GPU_indexbuf_build_in_place(&extract_data->elb, ibo);
@@ -1614,7 +1650,9 @@ static const MeshExtract extract_edituv_tris = {
/** \name Extract Edit UV Line Indices around faces
* \{ */
-static void *extract_edituv_lines_init(const MeshRenderData *mr, void *UNUSED(ibo))
+static void *extract_edituv_lines_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(ibo))
{
MeshExtract_EditUvElem_Data *data = MEM_callocN(sizeof(*data), __func__);
GPU_indexbuf_init(&data->elb, GPU_PRIM_LINES, mr->loop_len, mr->loop_len);
@@ -1664,7 +1702,10 @@ static void extract_edituv_lines_iter_poly_mesh(const MeshRenderData *mr,
EXTRACT_POLY_AND_LOOP_FOREACH_MESH_END;
}
-static void extract_edituv_lines_finish(const MeshRenderData *UNUSED(mr), void *ibo, void *data)
+static void extract_edituv_lines_finish(const MeshRenderData *UNUSED(mr),
+ struct MeshBatchCache *UNUSED(cache),
+ void *ibo,
+ void *data)
{
MeshExtract_EditUvElem_Data *extract_data = data;
GPU_indexbuf_build_in_place(&extract_data->elb, ibo);
@@ -1686,7 +1727,9 @@ static const MeshExtract extract_edituv_lines = {
/** \name Extract Edit UV Points Indices
* \{ */
-static void *extract_edituv_points_init(const MeshRenderData *mr, void *UNUSED(ibo))
+static void *extract_edituv_points_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(ibo))
{
MeshExtract_EditUvElem_Data *data = MEM_callocN(sizeof(*data), __func__);
GPU_indexbuf_init(&data->elb, GPU_PRIM_POINTS, mr->loop_len, mr->loop_len);
@@ -1733,7 +1776,10 @@ static void extract_edituv_points_iter_poly_mesh(const MeshRenderData *mr,
EXTRACT_POLY_AND_LOOP_FOREACH_MESH_END;
}
-static void extract_edituv_points_finish(const MeshRenderData *UNUSED(mr), void *ibo, void *data)
+static void extract_edituv_points_finish(const MeshRenderData *UNUSED(mr),
+ struct MeshBatchCache *UNUSED(cache),
+ void *ibo,
+ void *data)
{
MeshExtract_EditUvElem_Data *extract_data = data;
GPU_indexbuf_build_in_place(&extract_data->elb, ibo);
@@ -1755,7 +1801,9 @@ static const MeshExtract extract_edituv_points = {
/** \name Extract Edit UV Facedots Indices
* \{ */
-static void *extract_edituv_fdots_init(const MeshRenderData *mr, void *UNUSED(ibo))
+static void *extract_edituv_fdots_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(ibo))
{
MeshExtract_EditUvElem_Data *data = MEM_callocN(sizeof(*data), __func__);
GPU_indexbuf_init(&data->elb, GPU_PRIM_POINTS, mr->poly_len, mr->poly_len);
@@ -1822,7 +1870,10 @@ static void extract_edituv_fdots_iter_poly_mesh(const MeshRenderData *mr,
}
}
-static void extract_edituv_fdots_finish(const MeshRenderData *UNUSED(mr), void *ibo, void *_data)
+static void extract_edituv_fdots_finish(const MeshRenderData *UNUSED(mr),
+ struct MeshBatchCache *UNUSED(cache),
+ void *ibo,
+ void *_data)
{
MeshExtract_EditUvElem_Data *data = _data;
GPU_indexbuf_build_in_place(&data->elb, ibo);
@@ -1854,7 +1905,9 @@ typedef struct MeshExtract_PosNor_Data {
GPUPackedNormal packed_nor[];
} MeshExtract_PosNor_Data;
-static void *extract_pos_nor_init(const MeshRenderData *mr, void *buf)
+static void *extract_pos_nor_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
@@ -2000,7 +2053,10 @@ static void extract_pos_nor_iter_lvert_mesh(const MeshRenderData *mr,
EXTRACT_LVERT_FOREACH_MESH_END;
}
-static void extract_pos_nor_finish(const MeshRenderData *UNUSED(mr), void *UNUSED(vbo), void *data)
+static void extract_pos_nor_finish(const MeshRenderData *UNUSED(mr),
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(vbo),
+ void *data)
{
MEM_freeN(data);
}
@@ -2027,7 +2083,9 @@ typedef struct gpuHQNor {
short x, y, z, w;
} gpuHQNor;
-static void *extract_lnor_hq_init(const MeshRenderData *mr, void *buf)
+static void *extract_lnor_hq_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
@@ -2113,7 +2171,9 @@ static const MeshExtract extract_lnor_hq = {
/** \name Extract Loop Normal
* \{ */
-static void *extract_lnor_init(const MeshRenderData *mr, void *buf)
+static void *extract_lnor_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
@@ -2204,16 +2264,15 @@ static const MeshExtract extract_lnor = {
/** \name Extract UV layers
* \{ */
-static void *extract_uv_init(const MeshRenderData *mr, void *buf)
+static void *extract_uv_init(const MeshRenderData *mr, struct MeshBatchCache *cache, void *buf)
{
GPUVertFormat format = {0};
GPU_vertformat_deinterleave(&format);
CustomData *cd_ldata = (mr->extract_type == MR_EXTRACT_BMESH) ? &mr->bm->ldata : &mr->me->ldata;
- uint32_t uv_layers = mr->cache->cd_used.uv;
-
+ uint32_t uv_layers = cache->cd_used.uv;
/* HACK to fix T68857 */
- if (mr->extract_type == MR_EXTRACT_BMESH && mr->cache->cd_used.edit_uv == 1) {
+ if (mr->extract_type == MR_EXTRACT_BMESH && cache->cd_used.edit_uv == 1) {
int layer = CustomData_get_active_layer(cd_ldata, CD_MLOOPUV);
if (layer != -1) {
uv_layers |= (1 << layer);
@@ -2301,7 +2360,10 @@ static const MeshExtract extract_uv = {
/** \name Extract Tangent layers
* \{ */
-static void extract_tan_ex(const MeshRenderData *mr, GPUVertBuf *vbo, const bool do_hq)
+static void extract_tan_ex(const MeshRenderData *mr,
+ struct MeshBatchCache *cache,
+ GPUVertBuf *vbo,
+ const bool do_hq)
{
GPUVertCompType comp_type = do_hq ? GPU_COMP_I16 : GPU_COMP_I10;
GPUVertFetchMode fetch_mode = GPU_FETCH_INT_TO_FLOAT_UNIT;
@@ -2311,10 +2373,10 @@ static void extract_tan_ex(const MeshRenderData *mr, GPUVertBuf *vbo, const bool
CustomData *cd_ldata = (mr->extract_type == MR_EXTRACT_BMESH) ? &mr->bm->ldata : &mr->me->ldata;
CustomData *cd_vdata = (mr->extract_type == MR_EXTRACT_BMESH) ? &mr->bm->vdata : &mr->me->vdata;
- uint32_t tan_layers = mr->cache->cd_used.tan;
+ uint32_t tan_layers = cache->cd_used.tan;
float(*orco)[3] = CustomData_get_layer(cd_vdata, CD_ORCO);
bool orco_allocated = false;
- const bool use_orco_tan = mr->cache->cd_used.tan_orco != 0;
+ const bool use_orco_tan = cache->cd_used.tan_orco != 0;
int tan_len = 0;
char tangent_names[MAX_MTFACE][MAX_CUSTOMDATA_LAYER_NAME];
@@ -2470,9 +2532,9 @@ static void extract_tan_ex(const MeshRenderData *mr, GPUVertBuf *vbo, const bool
CustomData_free(&loop_data, mr->loop_len);
}
-static void *extract_tan_init(const MeshRenderData *mr, void *buf)
+static void *extract_tan_init(const MeshRenderData *mr, struct MeshBatchCache *cache, void *buf)
{
- extract_tan_ex(mr, buf, false);
+ extract_tan_ex(mr, cache, buf, false);
return NULL;
}
@@ -2488,9 +2550,9 @@ static const MeshExtract extract_tan = {
/** \name Extract HQ Tangent layers
* \{ */
-static void *extract_tan_hq_init(const MeshRenderData *mr, void *buf)
+static void *extract_tan_hq_init(const MeshRenderData *mr, struct MeshBatchCache *cache, void *buf)
{
- extract_tan_ex(mr, buf, true);
+ extract_tan_ex(mr, cache, buf, true);
return NULL;
}
@@ -2506,15 +2568,15 @@ static const MeshExtract extract_tan_hq = {
/** \name Extract VCol
* \{ */
-static void *extract_vcol_init(const MeshRenderData *mr, void *buf)
+static void *extract_vcol_init(const MeshRenderData *mr, struct MeshBatchCache *cache, void *buf)
{
GPUVertFormat format = {0};
GPU_vertformat_deinterleave(&format);
CustomData *cd_ldata = (mr->extract_type == MR_EXTRACT_BMESH) ? &mr->bm->ldata : &mr->me->ldata;
CustomData *cd_vdata = (mr->extract_type == MR_EXTRACT_BMESH) ? &mr->bm->vdata : &mr->me->vdata;
- uint32_t vcol_layers = mr->cache->cd_used.vcol;
- uint32_t svcol_layers = mr->cache->cd_used.sculpt_vcol;
+ uint32_t vcol_layers = cache->cd_used.vcol;
+ uint32_t svcol_layers = cache->cd_used.sculpt_vcol;
for (int i = 0; i < MAX_MCOL; i++) {
if (vcol_layers & (1 << i)) {
@@ -2661,7 +2723,9 @@ typedef struct MeshExtract_Orco_Data {
float (*orco)[3];
} MeshExtract_Orco_Data;
-static void *extract_orco_init(const MeshRenderData *mr, void *buf)
+static void *extract_orco_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
@@ -2714,7 +2778,10 @@ static void extract_orco_iter_poly_mesh(const MeshRenderData *mr,
EXTRACT_POLY_AND_LOOP_FOREACH_MESH_END;
}
-static void extract_orco_finish(const MeshRenderData *UNUSED(mr), void *UNUSED(buf), void *data)
+static void extract_orco_finish(const MeshRenderData *UNUSED(mr),
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(buf),
+ void *data)
{
MEM_freeN(data);
}
@@ -2758,7 +2825,9 @@ static float loop_edge_factor_get(const float f_no[3],
return d;
}
-static void *extract_edge_fac_init(const MeshRenderData *mr, void *buf)
+static void *extract_edge_fac_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
@@ -2883,7 +2952,10 @@ static void extract_edge_fac_iter_ledge_mesh(const MeshRenderData *mr,
EXTRACT_LEDGE_FOREACH_MESH_END;
}
-static void extract_edge_fac_finish(const MeshRenderData *mr, void *buf, void *_data)
+static void extract_edge_fac_finish(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf,
+ void *_data)
{
MeshExtract_EdgeFac_Data *data = _data;
@@ -2943,7 +3015,7 @@ static float evaluate_vertex_weight(const MDeformVert *dvert, const DRW_MeshWeig
if ((wstate->defgroup_active < 0) && (wstate->defgroup_len > 0)) {
return -2.0f;
}
- else if (dvert == NULL) {
+ if (dvert == NULL) {
return (wstate->alert_mode != OB_DRAW_GROUPUSER_NONE) ? -1.0f : 0.0f;
}
@@ -2990,7 +3062,9 @@ static float evaluate_vertex_weight(const MDeformVert *dvert, const DRW_MeshWeig
return input;
}
-static void *extract_weights_init(const MeshRenderData *mr, void *buf)
+static void *extract_weights_init(const MeshRenderData *mr,
+ struct MeshBatchCache *cache,
+ void *buf)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
@@ -3002,7 +3076,7 @@ static void *extract_weights_init(const MeshRenderData *mr, void *buf)
MeshExtract_Weight_Data *data = MEM_callocN(sizeof(*data), __func__);
data->vbo_data = (float *)vbo->data;
- data->wstate = &mr->cache->weight_state;
+ data->wstate = &cache->weight_state;
if (data->wstate->defgroup_active == -1) {
/* Nothing to show. */
@@ -3065,7 +3139,10 @@ static void extract_weights_iter_poly_mesh(const MeshRenderData *mr,
}
}
-static void extract_weights_finish(const MeshRenderData *UNUSED(mr), void *UNUSED(buf), void *data)
+static void extract_weights_finish(const MeshRenderData *UNUSED(mr),
+ struct MeshBatchCache *UNUSED(cache),
+ void *UNUSED(buf),
+ void *data)
{
MEM_freeN(data);
}
@@ -3223,7 +3300,9 @@ static void mesh_render_data_vert_flag(const MeshRenderData *mr, BMVert *eve, Ed
}
}
-static void *extract_edit_data_init(const MeshRenderData *mr, void *buf)
+static void *extract_edit_data_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
@@ -3374,7 +3453,9 @@ typedef struct MeshExtract_EditUVData_Data {
int cd_ofs;
} MeshExtract_EditUVData_Data;
-static void *extract_edituv_data_init(const MeshRenderData *mr, void *buf)
+static void *extract_edituv_data_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
@@ -3451,6 +3532,7 @@ static void extract_edituv_data_iter_poly_mesh(const MeshRenderData *mr,
}
static void extract_edituv_data_finish(const MeshRenderData *UNUSED(mr),
+ struct MeshBatchCache *UNUSED(cache),
void *UNUSED(buf),
void *data)
{
@@ -3472,7 +3554,9 @@ static const MeshExtract extract_edituv_data = {
/** \name Extract Edit UV area stretch
* \{ */
-static void *extract_stretch_area_init(const MeshRenderData *mr, void *buf)
+static void *extract_stretch_area_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
@@ -3501,7 +3585,10 @@ BLI_INLINE float area_ratio_to_stretch(float ratio, float tot_ratio, float inv_t
return (ratio > 1.0f) ? (1.0f / ratio) : ratio;
}
-static void mesh_stretch_area_finish(const MeshRenderData *mr, void *buf, void *UNUSED(data))
+static void mesh_stretch_area_finish(const MeshRenderData *mr,
+ struct MeshBatchCache *cache,
+ void *buf,
+ void *UNUSED(data))
{
float tot_area = 0.0f, tot_uv_area = 0.0f;
float *area_ratio = MEM_mallocN(sizeof(float) * mr->poly_len, __func__);
@@ -3537,8 +3624,8 @@ static void mesh_stretch_area_finish(const MeshRenderData *mr, void *buf, void *
BLI_assert(0);
}
- mr->cache->tot_area = tot_area;
- mr->cache->tot_uv_area = tot_uv_area;
+ cache->tot_area = tot_area;
+ cache->tot_uv_area = tot_uv_area;
/* Convert in place to avoid an extra allocation */
uint16_t *poly_stretch = (uint16_t *)area_ratio;
@@ -3620,12 +3707,14 @@ static void compute_normalize_edge_vectors(float auv[2][2],
normalize_v3(av[1]);
}
-static short v2_to_short_angle(float v[2])
+static short v2_to_short_angle(const float v[2])
{
return atan2f(v[1], v[0]) * (float)M_1_PI * SHRT_MAX;
}
-static void edituv_get_stretch_angle(float auv[2][2], float av[2][3], UVStretchAngle *r_stretch)
+static void edituv_get_stretch_angle(float auv[2][2],
+ const float av[2][3],
+ UVStretchAngle *r_stretch)
{
/* Send UV's to the shader and let it compute the aspect corrected angle. */
r_stretch->uv_angles[0] = v2_to_short_angle(auv[0]);
@@ -3641,7 +3730,9 @@ static void edituv_get_stretch_angle(float auv[2][2], float av[2][3], UVStretchA
#endif
}
-static void *extract_stretch_angle_init(const MeshRenderData *mr, void *buf)
+static void *extract_stretch_angle_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
@@ -3762,6 +3853,7 @@ static void extract_stretch_angle_iter_poly_mesh(const MeshRenderData *mr,
}
static void extract_stretch_angle_finish(const MeshRenderData *UNUSED(mr),
+ struct MeshBatchCache *UNUSED(cache),
void *UNUSED(buf),
void *data)
{
@@ -3783,7 +3875,9 @@ static const MeshExtract extract_stretch_angle = {
/** \name Extract Edit Mesh Analysis Colors
* \{ */
-static void *extract_mesh_analysis_init(const MeshRenderData *mr, void *buf)
+static void *extract_mesh_analysis_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
@@ -4301,7 +4395,7 @@ static void statvis_calc_sharp(const MeshRenderData *mr, float *r_sharp)
/* non-manifold edge, yet... */
continue;
}
- else if (*pval != NULL) {
+ if (*pval != NULL) {
const float *f1_no = mr->poly_normals[mp_index];
const float *f2_no = *pval;
angle = angle_normalized_v3v3(f1_no, f2_no);
@@ -4344,7 +4438,10 @@ static void statvis_calc_sharp(const MeshRenderData *mr, float *r_sharp)
MEM_freeN(vert_angles);
}
-static void extract_mesh_analysis_finish(const MeshRenderData *mr, void *buf, void *UNUSED(data))
+static void extract_mesh_analysis_finish(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf,
+ void *UNUSED(data))
{
BLI_assert(mr->edit_bmesh);
@@ -4385,7 +4482,9 @@ static const MeshExtract extract_mesh_analysis = {
/** \name Extract Facedots positions
* \{ */
-static void *extract_fdots_pos_init(const MeshRenderData *mr, void *buf)
+static void *extract_fdots_pos_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
@@ -4471,7 +4570,9 @@ static const MeshExtract extract_fdots_pos = {
#define NOR_AND_FLAG_ACTIVE -1
#define NOR_AND_FLAG_HIDDEN -2
-static void *extract_fdots_nor_init(const MeshRenderData *mr, void *buf)
+static void *extract_fdots_nor_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
@@ -4484,7 +4585,10 @@ static void *extract_fdots_nor_init(const MeshRenderData *mr, void *buf)
return NULL;
}
-static void extract_fdots_nor_finish(const MeshRenderData *mr, void *buf, void *UNUSED(data))
+static void extract_fdots_nor_finish(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf,
+ void *UNUSED(data))
{
static float invalid_normal[3] = {0.0f, 0.0f, 0.0f};
GPUVertBuf *vbo = buf;
@@ -4549,7 +4653,9 @@ typedef struct MeshExtract_FdotUV_Data {
int cd_ofs;
} MeshExtract_FdotUV_Data;
-static void *extract_fdots_uv_init(const MeshRenderData *mr, void *buf)
+static void *extract_fdots_uv_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
@@ -4618,6 +4724,7 @@ static void extract_fdots_uv_iter_poly_mesh(const MeshRenderData *mr,
}
static void extract_fdots_uv_finish(const MeshRenderData *UNUSED(mr),
+ struct MeshBatchCache *UNUSED(cache),
void *UNUSED(buf),
void *data)
{
@@ -4643,7 +4750,9 @@ typedef struct MeshExtract_EditUVFdotData_Data {
int cd_ofs;
} MeshExtract_EditUVFdotData_Data;
-static void *extract_fdots_edituv_data_init(const MeshRenderData *mr, void *buf)
+static void *extract_fdots_edituv_data_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
@@ -4691,6 +4800,7 @@ static void extract_fdots_edituv_data_iter_poly_mesh(const MeshRenderData *mr,
}
static void extract_fdots_edituv_data_finish(const MeshRenderData *UNUSED(mr),
+ struct MeshBatchCache *UNUSED(cache),
void *UNUSED(buf),
void *data)
{
@@ -4716,7 +4826,9 @@ typedef struct SkinRootData {
float local_pos[3];
} SkinRootData;
-static void *extract_skin_roots_init(const MeshRenderData *mr, void *buf)
+static void *extract_skin_roots_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf)
{
/* Exclusively for edit mode. */
BLI_assert(mr->bm);
@@ -4765,7 +4877,9 @@ static const MeshExtract extract_skin_roots = {
/** \name Extract Selection Index
* \{ */
-static void *extract_select_idx_init(const MeshRenderData *mr, void *buf)
+static void *extract_select_idx_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
@@ -4957,7 +5071,9 @@ static const MeshExtract extract_vert_idx = {
.use_threading = true,
};
-static void *extract_select_fdot_idx_init(const MeshRenderData *mr, void *buf)
+static void *extract_select_fdot_idx_init(const MeshRenderData *mr,
+ struct MeshBatchCache *UNUSED(cache),
+ void *buf)
{
static GPUVertFormat format = {0};
if (format.attr_len == 0) {
@@ -5026,6 +5142,7 @@ typedef enum ExtractTaskDataType {
typedef struct ExtractTaskData {
void *next, *prev;
const MeshRenderData *mr;
+ struct MeshBatchCache *cache;
const MeshExtract *extract;
ExtractTaskDataType tasktype;
eMRIterType iter_type;
@@ -5037,6 +5154,7 @@ typedef struct ExtractTaskData {
} ExtractTaskData;
static ExtractTaskData *extract_task_data_create_mesh_extract(const MeshRenderData *mr,
+ struct MeshBatchCache *cache,
const MeshExtract *extract,
void *buf,
int32_t *task_counter)
@@ -5046,6 +5164,7 @@ static ExtractTaskData *extract_task_data_create_mesh_extract(const MeshRenderDa
taskdata->prev = NULL;
taskdata->tasktype = EXTRACT_MESH_EXTRACT;
taskdata->mr = mr;
+ taskdata->cache = cache;
taskdata->extract = extract;
taskdata->buf = buf;
@@ -5063,11 +5182,13 @@ static ExtractTaskData *extract_task_data_create_mesh_extract(const MeshRenderDa
return taskdata;
}
-static ExtractTaskData *extract_task_data_create_lines_loose(const MeshRenderData *mr)
+static ExtractTaskData *extract_task_data_create_lines_loose(const MeshRenderData *mr,
+ struct MeshBatchCache *cache)
{
ExtractTaskData *taskdata = MEM_callocN(sizeof(*taskdata), __func__);
taskdata->tasktype = EXTRACT_LINES_LOOSE;
taskdata->mr = mr;
+ taskdata->cache = cache;
return taskdata;
}
@@ -5159,7 +5280,7 @@ BLI_INLINE void mesh_extract_iter(const MeshRenderData *mr,
static void extract_init(ExtractTaskData *data)
{
if (data->tasktype == EXTRACT_MESH_EXTRACT) {
- data->user_data->user_data = data->extract->init(data->mr, data->buf);
+ data->user_data->user_data = data->extract->init(data->mr, data->cache, data->buf);
}
}
@@ -5177,11 +5298,11 @@ static void extract_run(void *__restrict taskdata)
/* If this is the last task, we do the finish function. */
int remainin_tasks = atomic_sub_and_fetch_int32(data->task_counter, 1);
if (remainin_tasks == 0 && data->extract->finish != NULL) {
- data->extract->finish(data->mr, data->buf, data->user_data->user_data);
+ data->extract->finish(data->mr, data->cache, data->buf, data->user_data->user_data);
}
}
else if (data->tasktype == EXTRACT_LINES_LOOSE) {
- extract_lines_loose_subbuffer(data->mr);
+ extract_lines_loose_subbuffer(data->mr, data->cache);
}
}
@@ -5348,6 +5469,7 @@ static void extract_task_create(struct TaskGraph *task_graph,
ListBase *user_data_init_task_datas,
const Scene *scene,
const MeshRenderData *mr,
+ MeshBatchCache *cache,
const MeshExtract *extract,
void *buf,
int32_t *task_counter)
@@ -5363,7 +5485,7 @@ static void extract_task_create(struct TaskGraph *task_graph,
/* Divide extraction of the VBO/IBO into sensible chunks of works. */
ExtractTaskData *taskdata = extract_task_data_create_mesh_extract(
- mr, extract, buf, task_counter);
+ mr, cache, extract, buf, task_counter);
/* Simple heuristic. */
const int chunk_size = 8192;
@@ -5526,7 +5648,6 @@ void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph,
ts,
iter_flag,
data_flag);
- mr->cache = cache; /* HACK */
mr->use_hide = use_hide;
mr->use_subsurf_fdots = use_subsurf_fdots;
mr->use_final_mesh = do_final;
@@ -5558,6 +5679,7 @@ void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph,
&user_data_init_task_data->task_datas, \
scene, \
mr, \
+ cache, \
&extract_##name, \
mbc.buf.name, \
&task_counters[counter_used++]); \
@@ -5601,13 +5723,14 @@ void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph,
&user_data_init_task_data->task_datas,
scene,
mr,
+ cache,
lines_extractor,
mbc.ibo.lines,
&task_counters[counter_used++]);
}
else {
if (do_lines_loose_subbuffer) {
- ExtractTaskData *taskdata = extract_task_data_create_lines_loose(mr);
+ ExtractTaskData *taskdata = extract_task_data_create_lines_loose(mr, cache);
BLI_addtail(&single_threaded_task_data->task_datas, taskdata);
}
}