Cleanup: Clarify string usage in PBVH draw
Use StringRef where possible to avoid copying strings, avoid redundant string returns, and use std::string for attribute request names now that all the relevant code is C++.
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
* \brief A BVH for high poly meshes.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "BLI_bitmap.h"
|
||||
#include "BLI_compiler_compat.h"
|
||||
#include "BLI_ghash.h"
|
||||
@@ -87,7 +89,7 @@ struct PBVHPixelsNode {
|
||||
};
|
||||
|
||||
struct PBVHAttrReq {
|
||||
char name[MAX_CUSTOMDATA_LAYER_NAME];
|
||||
std::string name;
|
||||
eAttrDomain domain;
|
||||
eCustomDataType type;
|
||||
};
|
||||
|
||||
@@ -1398,11 +1398,9 @@ void DRW_shgroup_call_sculpt(DRWShadingGroup *shgroup,
|
||||
scd.use_mats = false;
|
||||
scd.use_mask = use_mask;
|
||||
|
||||
PBVHAttrReq attrs[16];
|
||||
PBVHAttrReq attrs[16] = {};
|
||||
int attrs_num = 0;
|
||||
|
||||
memset(attrs, 0, sizeof(attrs));
|
||||
|
||||
/* NOTE: these are NOT #eCustomDataType, they are extended values, ASAN may warn about this. */
|
||||
attrs[attrs_num++].type = (eCustomDataType)CD_PBVH_CO_TYPE;
|
||||
attrs[attrs_num++].type = (eCustomDataType)CD_PBVH_NO_TYPE;
|
||||
@@ -1426,7 +1424,7 @@ void DRW_shgroup_call_sculpt(DRWShadingGroup *shgroup,
|
||||
attrs[attrs_num].type = eCustomDataType(layer->type);
|
||||
attrs[attrs_num].domain = domain;
|
||||
|
||||
STRNCPY(attrs[attrs_num].name, layer->name);
|
||||
attrs[attrs_num].name = layer->name;
|
||||
attrs_num++;
|
||||
}
|
||||
}
|
||||
@@ -1438,7 +1436,7 @@ void DRW_shgroup_call_sculpt(DRWShadingGroup *shgroup,
|
||||
|
||||
attrs[attrs_num].type = CD_PROP_FLOAT2;
|
||||
attrs[attrs_num].domain = ATTR_DOMAIN_CORNER;
|
||||
STRNCPY(attrs[attrs_num].name, layer->name);
|
||||
attrs[attrs_num].name = layer->name;
|
||||
|
||||
attrs_num++;
|
||||
}
|
||||
@@ -1484,7 +1482,7 @@ void DRW_shgroup_call_sculpt_with_materials(DRWShadingGroup **shgroups,
|
||||
|
||||
attrs[attrs_i].type = req->cd_type;
|
||||
attrs[attrs_i].domain = req->domain;
|
||||
STRNCPY(attrs[attrs_i].name, req->attribute_name);
|
||||
attrs[attrs_i].name = req->attribute_name;
|
||||
attrs_i++;
|
||||
}
|
||||
|
||||
@@ -1499,7 +1497,7 @@ void DRW_shgroup_call_sculpt_with_materials(DRWShadingGroup **shgroups,
|
||||
if (layer) {
|
||||
attrs[attrs_i].type = CD_PROP_FLOAT2;
|
||||
attrs[attrs_i].domain = ATTR_DOMAIN_CORNER;
|
||||
STRNCPY(attrs[attrs_i].name, layer->name);
|
||||
attrs[attrs_i].name = layer->name;
|
||||
attrs_i++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,8 @@ using blender::FunctionRef;
|
||||
using blender::IndexRange;
|
||||
using blender::Map;
|
||||
using blender::short3;
|
||||
using blender::StringRef;
|
||||
using blender::StringRefNull;
|
||||
using blender::uchar3;
|
||||
using blender::ushort3;
|
||||
using blender::ushort4;
|
||||
@@ -91,8 +93,8 @@ struct PBVHVbo {
|
||||
GPUVertBuf *vert_buf = nullptr;
|
||||
std::string key;
|
||||
|
||||
PBVHVbo(eAttrDomain _domain, uint64_t _type, std::string _name)
|
||||
: type(_type), domain(_domain), name(_name)
|
||||
PBVHVbo(eAttrDomain domain, uint64_t type, std::string name)
|
||||
: type(type), domain(domain), name(std::move(name))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -101,20 +103,18 @@ struct PBVHVbo {
|
||||
GPU_vertbuf_clear(vert_buf);
|
||||
}
|
||||
|
||||
std::string build_key()
|
||||
void build_key()
|
||||
{
|
||||
char buf[512];
|
||||
|
||||
SNPRINTF(buf, "%d:%d:%s", int(type), int(domain), name.c_str());
|
||||
|
||||
key = std::string(buf);
|
||||
return key;
|
||||
}
|
||||
};
|
||||
|
||||
struct PBVHBatch {
|
||||
Vector<int> vbos;
|
||||
std::string key;
|
||||
GPUBatch *tris = nullptr, *lines = nullptr;
|
||||
int tris_count = 0, lines_count = 0;
|
||||
/* Coarse multi-resolution, will use full-sized VBOs only index buffer changes. */
|
||||
@@ -138,7 +138,7 @@ struct PBVHBatch {
|
||||
|
||||
std::string build_key(Vector<PBVHVbo> &master_vbos)
|
||||
{
|
||||
key = "";
|
||||
std::string key = "";
|
||||
|
||||
if (is_coarse) {
|
||||
key += "c:";
|
||||
@@ -252,7 +252,6 @@ struct PBVHBatches {
|
||||
|
||||
std::string build_key(PBVHAttrReq *attrs, int attrs_num, bool do_coarse_grids)
|
||||
{
|
||||
std::string key;
|
||||
PBVHBatch batch;
|
||||
Vector<PBVHVbo> vbos;
|
||||
|
||||
@@ -271,11 +270,10 @@ struct PBVHBatches {
|
||||
}
|
||||
|
||||
batch.is_coarse = do_coarse_grids;
|
||||
batch.build_key(vbos);
|
||||
return batch.key;
|
||||
return batch.build_key(vbos);
|
||||
}
|
||||
|
||||
bool has_vbo(eAttrDomain domain, int type, std::string name)
|
||||
bool has_vbo(eAttrDomain domain, int type, const StringRef name)
|
||||
{
|
||||
for (PBVHVbo &vbo : vbos) {
|
||||
if (vbo.domain == domain && vbo.type == type && vbo.name == name) {
|
||||
@@ -297,7 +295,7 @@ struct PBVHBatches {
|
||||
return -1;
|
||||
}
|
||||
|
||||
PBVHVbo *get_vbo(eAttrDomain domain, int type, std::string name)
|
||||
PBVHVbo *get_vbo(eAttrDomain domain, int type, const StringRef name)
|
||||
{
|
||||
for (PBVHVbo &vbo : vbos) {
|
||||
if (vbo.domain == domain && vbo.type == type && vbo.name == name) {
|
||||
@@ -852,7 +850,7 @@ struct PBVHBatches {
|
||||
|
||||
void create_vbo(eAttrDomain domain,
|
||||
const uint32_t type,
|
||||
std::string name,
|
||||
const StringRefNull name,
|
||||
const PBVH_GPU_Args &args)
|
||||
{
|
||||
PBVHVbo vbo(domain, type, name);
|
||||
@@ -914,8 +912,8 @@ struct PBVHBatches {
|
||||
|
||||
if (ELEM(type, CD_PROP_COLOR, CD_PROP_BYTE_COLOR)) {
|
||||
prefix = "c";
|
||||
is_active = blender::StringRef(args.active_color) == layer->name;
|
||||
is_render = blender::StringRef(args.render_color) == layer->name;
|
||||
is_active = StringRef(args.active_color) == layer->name;
|
||||
is_render = StringRef(args.render_color) == layer->name;
|
||||
}
|
||||
else {
|
||||
switch (type) {
|
||||
@@ -1313,8 +1311,7 @@ struct PBVHBatches {
|
||||
}
|
||||
}
|
||||
|
||||
batch.build_key(vbos);
|
||||
batches.add(batch.key, batch);
|
||||
batches.add(batch.build_key(vbos), batch);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ Vector<SculptBatch> sculpt_batches_get(Object *ob, SculptBatchFeature features)
|
||||
if (layer) {
|
||||
attrs[attrs_len].type = eCustomDataType(layer->type);
|
||||
attrs[attrs_len].domain = BKE_id_attribute_domain(&mesh->id, layer);
|
||||
STRNCPY(attrs[attrs_len].name, layer->name);
|
||||
attrs[attrs_len].name = layer->name;
|
||||
attrs_len++;
|
||||
}
|
||||
}
|
||||
@@ -186,7 +186,7 @@ Vector<SculptBatch> sculpt_batches_get(Object *ob, SculptBatchFeature features)
|
||||
CustomDataLayer *layer = mesh->loop_data.layers + layer_i;
|
||||
attrs[attrs_len].type = CD_PROP_FLOAT2;
|
||||
attrs[attrs_len].domain = ATTR_DOMAIN_CORNER;
|
||||
STRNCPY(attrs[attrs_len].name, layer->name);
|
||||
attrs[attrs_len].name = layer->name;
|
||||
attrs_len++;
|
||||
}
|
||||
}
|
||||
@@ -216,7 +216,7 @@ Vector<SculptBatch> sculpt_batches_per_material_get(Object *ob,
|
||||
DRW_AttributeRequest *req = draw_attrs.requests + i;
|
||||
attrs[attrs_len].type = req->cd_type;
|
||||
attrs[attrs_len].domain = req->domain;
|
||||
STRNCPY(attrs[attrs_len].name, req->attribute_name);
|
||||
attrs[attrs_len].name = req->attribute_name;
|
||||
attrs_len++;
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ Vector<SculptBatch> sculpt_batches_per_material_get(Object *ob,
|
||||
if (layer) {
|
||||
attrs[attrs_len].type = CD_PROP_FLOAT2;
|
||||
attrs[attrs_len].domain = ATTR_DOMAIN_CORNER;
|
||||
STRNCPY(attrs[attrs_len].name, layer->name);
|
||||
attrs[attrs_len].name = layer->name;
|
||||
attrs_len++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user