Revert "Cleanup: use cpp new/delete."

This reverts commit 43464c94f4.
This commit is contained in:
2021-06-08 15:08:09 +02:00
parent 23fd576cf8
commit 5b014911a5
6 changed files with 31 additions and 48 deletions

View File

@@ -35,23 +35,16 @@ namespace blender::draw {
struct MeshExtract_EditUvElem_Data {
GPUIndexBufBuilder elb;
bool sync_selection;
MeshExtract_EditUvElem_Data(const MeshRenderData *mr)
{
sync_selection = (mr->toolsettings->uv_flag & UV_SYNC_SELECTION) != 0;
}
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("DRW:MeshExtract_EditUvElem_Data")
#endif
};
static void *extract_edituv_tris_init(const MeshRenderData *mr,
struct MeshBatchCache *UNUSED(cache),
void *UNUSED(ibo))
{
MeshExtract_EditUvElem_Data *data = new MeshExtract_EditUvElem_Data(mr);
MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(
MEM_callocN(sizeof(*data), __func__));
GPU_indexbuf_init(&data->elb, GPU_PRIM_TRIS, mr->tri_len, mr->loop_len);
data->sync_selection = (mr->toolsettings->uv_flag & UV_SYNC_SELECTION) != 0;
return data;
}
@@ -100,7 +93,7 @@ static void extract_edituv_tris_finish(const MeshRenderData *UNUSED(mr),
MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(_data);
GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
GPU_indexbuf_build_in_place(&data->elb, ibo);
delete data;
MEM_freeN(data);
}
constexpr MeshExtract create_extractor_edituv_tris()
@@ -126,8 +119,10 @@ static void *extract_edituv_lines_init(const MeshRenderData *mr,
struct MeshBatchCache *UNUSED(cache),
void *UNUSED(ibo))
{
MeshExtract_EditUvElem_Data *data = new MeshExtract_EditUvElem_Data(mr);
MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(
MEM_callocN(sizeof(*data), __func__));
GPU_indexbuf_init(&data->elb, GPU_PRIM_LINES, mr->loop_len, mr->loop_len);
data->sync_selection = (mr->toolsettings->uv_flag & UV_SYNC_SELECTION) != 0;
return data;
}
@@ -189,7 +184,7 @@ static void extract_edituv_lines_finish(const MeshRenderData *UNUSED(mr),
MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(_data);
GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
GPU_indexbuf_build_in_place(&data->elb, ibo);
delete data;
MEM_freeN(data);
}
constexpr MeshExtract create_extractor_edituv_lines()
@@ -215,8 +210,10 @@ static void *extract_edituv_points_init(const MeshRenderData *mr,
struct MeshBatchCache *UNUSED(cache),
void *UNUSED(ibo))
{
MeshExtract_EditUvElem_Data *data = new MeshExtract_EditUvElem_Data(mr);
MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(
MEM_callocN(sizeof(*data), __func__));
GPU_indexbuf_init(&data->elb, GPU_PRIM_POINTS, mr->loop_len, mr->loop_len);
data->sync_selection = (mr->toolsettings->uv_flag & UV_SYNC_SELECTION) != 0;
return data;
}
@@ -272,7 +269,7 @@ static void extract_edituv_points_finish(const MeshRenderData *UNUSED(mr),
MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(_data);
GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
GPU_indexbuf_build_in_place(&data->elb, ibo);
delete data;
MEM_freeN(data);
}
constexpr MeshExtract create_extractor_edituv_points()
@@ -298,8 +295,10 @@ static void *extract_edituv_fdots_init(const MeshRenderData *mr,
struct MeshBatchCache *UNUSED(cache),
void *UNUSED(ibo))
{
MeshExtract_EditUvElem_Data *data = new MeshExtract_EditUvElem_Data(mr);
MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(
MEM_callocN(sizeof(*data), __func__));
GPU_indexbuf_init(&data->elb, GPU_PRIM_POINTS, mr->poly_len, mr->poly_len);
data->sync_selection = (mr->toolsettings->uv_flag & UV_SYNC_SELECTION) != 0;
return data;
}
@@ -367,7 +366,7 @@ static void extract_edituv_fdots_finish(const MeshRenderData *UNUSED(mr),
MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(_data);
GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
GPU_indexbuf_build_in_place(&data->elb, ibo);
delete data;
MEM_freeN(data);
}
constexpr MeshExtract create_extractor_edituv_fdots()

View File

@@ -36,7 +36,7 @@ static void *extract_fdots_init(const MeshRenderData *mr,
struct MeshBatchCache *UNUSED(cache),
void *UNUSED(buf))
{
GPUIndexBufBuilder *elb = new GPUIndexBufBuilder();
GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(MEM_mallocN(sizeof(*elb), __func__));
GPU_indexbuf_init(elb, GPU_PRIM_POINTS, mr->poly_len, mr->poly_len);
return elb;
}
@@ -93,7 +93,7 @@ static void extract_fdots_finish(const MeshRenderData *UNUSED(mr),
GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(_userdata);
GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
GPU_indexbuf_build_in_place(elb, ibo);
delete elb;
MEM_freeN(elb);
}
constexpr MeshExtract create_extractor_fdots()

View File

@@ -35,7 +35,7 @@ static void *extract_lines_init(const MeshRenderData *mr,
struct MeshBatchCache *UNUSED(cache),
void *UNUSED(buf))
{
GPUIndexBufBuilder *elb = new GPUIndexBufBuilder();
GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(MEM_mallocN(sizeof(*elb), __func__));
/* Put loose edges at the end. */
GPU_indexbuf_init(
elb, GPU_PRIM_LINES, mr->edge_len + mr->edge_loose_len, mr->loop_len + mr->loop_loose_len);
@@ -146,7 +146,7 @@ static void extract_lines_finish(const MeshRenderData *UNUSED(mr),
GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(data);
GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
GPU_indexbuf_build_in_place(elb, ibo);
delete elb;
MEM_freeN(elb);
}
constexpr MeshExtract create_extractor_lines()
@@ -190,7 +190,7 @@ static void extract_lines_with_lines_loose_finish(const MeshRenderData *mr,
GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
GPU_indexbuf_build_in_place(elb, ibo);
extract_lines_loose_subbuffer(mr, cache);
delete (elb);
MEM_freeN(elb);
}
constexpr MeshExtract create_extractor_lines_with_lines_loose()
@@ -221,7 +221,7 @@ static void *extract_lines_loose_only_init(const MeshRenderData *mr,
BLI_assert(buf == cache->final.ibo.lines_loose);
UNUSED_VARS_NDEBUG(buf);
extract_lines_loose_subbuffer(mr, cache);
return nullptr;
return NULL;
}
constexpr MeshExtract create_extractor_lines_loose_only()

View File

@@ -36,7 +36,7 @@ static void *extract_points_init(const MeshRenderData *mr,
struct MeshBatchCache *UNUSED(cache),
void *UNUSED(buf))
{
GPUIndexBufBuilder *elb = new GPUIndexBufBuilder();
GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(MEM_mallocN(sizeof(*elb), __func__));
GPU_indexbuf_init(elb, GPU_PRIM_POINTS, mr->vert_len, mr->loop_len + mr->loop_loose_len);
return elb;
}
@@ -145,7 +145,7 @@ static void extract_points_finish(const MeshRenderData *UNUSED(mr),
GPUIndexBufBuilder *elb = static_cast<GPUIndexBufBuilder *>(_userdata);
GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
GPU_indexbuf_build_in_place(elb, ibo);
delete elb;
MEM_freeN(elb);
}
constexpr MeshExtract create_extractor_points()

View File

@@ -35,31 +35,18 @@ struct MeshExtract_Tri_Data {
GPUIndexBufBuilder elb;
int *tri_mat_start;
int *tri_mat_end;
MeshExtract_Tri_Data(int mat_len)
{
tri_mat_start = new int[mat_len];
tri_mat_end = new int[mat_len];
}
~MeshExtract_Tri_Data()
{
delete tri_mat_start;
delete tri_mat_end;
}
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("DRW:MeshExtract_Tri_Data")
#endif
};
static void *extract_tris_init(const MeshRenderData *mr,
struct MeshBatchCache *UNUSED(cache),
void *UNUSED(ibo))
{
MeshExtract_Tri_Data *data = new MeshExtract_Tri_Data(mr->mat_len);
MeshExtract_Tri_Data *data = static_cast<MeshExtract_Tri_Data *>(
MEM_callocN(sizeof(*data), __func__));
size_t mat_tri_idx_size = sizeof(int) * mr->mat_len;
data->tri_mat_start = static_cast<int *>(MEM_callocN(mat_tri_idx_size, __func__));
data->tri_mat_end = static_cast<int *>(MEM_callocN(mat_tri_idx_size, __func__));
int *mat_tri_len = data->tri_mat_start;
/* Count how many triangle for each material. */
@@ -161,7 +148,9 @@ static void extract_tris_finish(const MeshRenderData *mr,
GPU_indexbuf_create_subrange_in_place(mbc_final->tris_per_mat[i], ibo, start, len);
}
}
delete (data);
MEM_freeN(data->tri_mat_start);
MEM_freeN(data->tri_mat_end);
MEM_freeN(data);
}
constexpr MeshExtract create_extractor_tris()

View File

@@ -44,11 +44,6 @@ typedef struct GPUIndexBufBuilder {
uint index_max;
GPUPrimType prim_type;
uint32_t *data;
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("GPU:GPUIndexBufBuilder")
#endif
} GPUIndexBufBuilder;
/* supports all primitive types. */