temp-sculpt-colors: vcol extractor rewrite
Draw cache system now properly uploads all three vcol types to the gpu.
This commit is contained in:
parent
1a5ea3c8b3
commit
d42acadba5
Binary file not shown.
|
@ -576,7 +576,7 @@ class DATA_PT_mesh_attributes(MeshButtonsPanel, Panel):
|
|||
col.operator("geometry.attribute_remove", icon='REMOVE', text="")
|
||||
|
||||
active = mesh.attributes.active
|
||||
print(active.domain, active.data_type)
|
||||
|
||||
if active.domain == "POINT" and active.data_type == "FLOAT_COLOR":
|
||||
layout.operator("sculpt.vertex_to_loop_colors", text="Save To Corners")
|
||||
layout.operator("sculpt.loop_to_vertex_colors", text="Load From Corners")
|
||||
|
|
|
@ -457,15 +457,37 @@ static void mesh_cd_calc_active_mask_uv_layer(const Mesh *me, DRW_MeshCDMask *cd
|
|||
}
|
||||
}
|
||||
|
||||
static void mesh_cd_calc_active_vcol_layer(const Mesh *me, DRW_MeshAttributes *attrs_used)
|
||||
static bool mesh_cd_calc_active_vcol_layer(Mesh *me, DRW_MeshAttributes *attrs_used)
|
||||
{
|
||||
CustomDataLayer *layer = BKE_id_attributes_active_get((ID *)me);
|
||||
|
||||
const Mesh *me_final = editmesh_final_or_this(me);
|
||||
const CustomData *cd_vdata = mesh_cd_vdata_get_from_mesh(me_final);
|
||||
const CustomData *cd_ldata = mesh_cd_ldata_get_from_mesh(me_final);
|
||||
|
||||
int layer = CustomData_get_active_layer(cd_vdata, CD_PROP_COLOR);
|
||||
if (layer != -1) {
|
||||
drw_mesh_attributes_add_request(attrs_used, CD_PROP_COLOR, layer, ATTR_DOMAIN_POINT);
|
||||
int type, idx = -1;
|
||||
AttributeDomain domain;
|
||||
|
||||
if (layer && ELEM(layer->type, CD_PROP_FLOAT3, CD_PROP_COLOR, CD_MLOOPCOL)) {
|
||||
domain = BKE_id_attribute_domain((ID *)me, layer);
|
||||
type = layer->type;
|
||||
|
||||
idx = CustomData_get_named_layer(
|
||||
domain == ATTR_DOMAIN_POINT ? cd_vdata : cd_ldata, type, layer->name);
|
||||
}
|
||||
else {
|
||||
idx = CustomData_get_active_layer(cd_vdata, CD_PROP_COLOR);
|
||||
type = CD_PROP_COLOR;
|
||||
domain = ATTR_DOMAIN_POINT;
|
||||
}
|
||||
|
||||
if (idx != -1) {
|
||||
if (type != CD_MLOOPCOL) {
|
||||
drw_mesh_attributes_add_request(attrs_used, type, idx, domain);
|
||||
}
|
||||
}
|
||||
|
||||
return idx != -1;
|
||||
}
|
||||
|
||||
static void mesh_cd_calc_active_mloopcol_layer(const Mesh *me, DRW_MeshCDMask *cd_used)
|
||||
|
@ -622,13 +644,15 @@ static DRW_MeshCDMask mesh_cd_calc_used_gpu_layers(const Mesh *me,
|
|||
break;
|
||||
}
|
||||
case CD_MCOL: {
|
||||
const CustomData *cdata = domain == ATTR_DOMAIN_POINT ? cd_vdata : cd_ldata;
|
||||
|
||||
/* Vertex Color Data */
|
||||
if (layer == -1) {
|
||||
layer = (name[0] != '\0') ? CustomData_get_named_layer(cd_ldata, CD_MLOOPCOL, name) :
|
||||
CustomData_get_render_layer(cd_ldata, CD_MLOOPCOL);
|
||||
layer = (name[0] != '\0') ? CustomData_get_named_layer(cdata, CD_MLOOPCOL, name) :
|
||||
CustomData_get_render_layer(cdata, CD_MLOOPCOL);
|
||||
}
|
||||
if (layer != -1) {
|
||||
cd_used.vcol |= (1 << layer);
|
||||
cd_used.vcol = 1;
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -637,12 +661,15 @@ static DRW_MeshCDMask mesh_cd_calc_used_gpu_layers(const Mesh *me,
|
|||
cd_used.orco = 1;
|
||||
break;
|
||||
}
|
||||
case CD_PROP_FLOAT3:
|
||||
case CD_PROP_COLOR:
|
||||
cd_used.vcol = 1;
|
||||
|
||||
/* fallthrough */
|
||||
case CD_PROP_BOOL:
|
||||
case CD_PROP_INT32:
|
||||
case CD_PROP_FLOAT:
|
||||
case CD_PROP_FLOAT2:
|
||||
case CD_PROP_FLOAT3:
|
||||
case CD_PROP_COLOR: {
|
||||
case CD_PROP_FLOAT2: {
|
||||
if (layer != -1 && domain != ATTR_DOMAIN_NUM) {
|
||||
drw_mesh_attributes_add_request(attributes, type, layer, domain);
|
||||
}
|
||||
|
@ -1112,7 +1139,10 @@ static void sculpt_request_active_vcol(MeshBatchCache *cache, Mesh *me)
|
|||
{
|
||||
DRW_MeshAttributes attrs_needed;
|
||||
drw_mesh_attributes_clear(&attrs_needed);
|
||||
mesh_cd_calc_active_vcol_layer(me, &attrs_needed);
|
||||
|
||||
if (mesh_cd_calc_active_vcol_layer(me, &attrs_needed)) {
|
||||
cache->cd_used.vcol = 1;
|
||||
}
|
||||
|
||||
BLI_assert(attrs_needed.num_requests != 0 &&
|
||||
"No MPropCol layer available in Sculpt, but batches requested anyway!");
|
||||
|
@ -1138,6 +1168,7 @@ GPUBatch *DRW_mesh_batch_cache_get_surface(Mesh *me)
|
|||
{
|
||||
MeshBatchCache *cache = mesh_batch_cache_get(me);
|
||||
mesh_batch_cache_request_surface_batches(cache);
|
||||
|
||||
return cache->batch.surface;
|
||||
}
|
||||
|
||||
|
|
|
@ -95,6 +95,18 @@ template<> struct attribute_type_converter<MPropCol, gpuMeshCol> {
|
|||
}
|
||||
};
|
||||
|
||||
template<> struct attribute_type_converter<MLoopCol, gpuMeshCol> {
|
||||
static gpuMeshCol convert_value(MLoopCol value)
|
||||
{
|
||||
gpuMeshCol result;
|
||||
result.r = value.r * 257;
|
||||
result.g = value.g * 257;
|
||||
result.b = value.b * 257;
|
||||
result.a = value.a * 257;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
/* Return the number of component for the attribute's value type, or 0 if is it unsupported. */
|
||||
static uint gpu_component_size_for_attribute_type(CustomDataType type)
|
||||
{
|
||||
|
@ -328,6 +340,10 @@ static void extract_attr_init(const MeshRenderData *mr,
|
|||
extract_attr_generic<MPropCol, gpuMeshCol>(mr, vbo, request);
|
||||
break;
|
||||
}
|
||||
case CD_MLOOPCOL: {
|
||||
extract_attr_generic<MLoopCol, gpuMeshCol>(mr, vbo, request);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
BLI_assert(false);
|
||||
}
|
||||
|
|
|
@ -44,9 +44,9 @@ static void extract_vcol_init(const MeshRenderData *mr,
|
|||
|
||||
CustomData *cd_vdata = (mr->extract_type == MR_EXTRACT_BMESH) ? &mr->bm->vdata : &mr->me->vdata;
|
||||
CustomData *cd_ldata = (mr->extract_type == MR_EXTRACT_BMESH) ? &mr->bm->ldata : &mr->me->ldata;
|
||||
uint32_t vcol_layers = cache->cd_used.vcol;
|
||||
|
||||
#if 0
|
||||
uint32_t vcol_layers = cache->cd_used.vcol;
|
||||
for (int i = 0; i < MAX_MCOL; i++) {
|
||||
if (vcol_layers & (1 << i)) {
|
||||
char attr_name[32], attr_safe_name[GPU_MAX_SAFE_ATTR_NAME];
|
||||
|
@ -79,27 +79,42 @@ static void extract_vcol_init(const MeshRenderData *mr,
|
|||
*/
|
||||
int vcol_types[3] = {CD_MLOOPCOL, CD_PROP_COLOR, CD_PROP_FLOAT3};
|
||||
|
||||
CustomDataLayer *actlayer = BKE_id_attributes_active_get((ID *)mr->me);
|
||||
AttributeDomain actdomain = actlayer ? BKE_id_attribute_domain((ID *)mr->me, actlayer) :
|
||||
ATTR_DOMAIN_AUTO;
|
||||
int actn = -1;
|
||||
|
||||
if (actlayer && ELEM(actdomain, ATTR_DOMAIN_POINT, ATTR_DOMAIN_CORNER)) {
|
||||
CustomData *cdata = actdomain == ATTR_DOMAIN_POINT ? &mr->me->vdata : &mr->me->ldata;
|
||||
actn = actlayer - (cdata->layers + cdata->typemap[actlayer->type]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int type = vcol_types[i];
|
||||
|
||||
for (int step = 0; step < 2; step++) {
|
||||
CustomData *cdata = step ? cd_ldata : cd_vdata;
|
||||
int count = CustomData_number_of_layers(cdata, type);
|
||||
AttributeDomain domain = step ? ATTR_DOMAIN_CORNER : ATTR_DOMAIN_POINT;
|
||||
|
||||
for (int j = 0; j < count; j++) {
|
||||
int idx = CustomData_get_layer_index_n(cdata, type, j);
|
||||
|
||||
char attr_name[32], attr_safe_name[GPU_MAX_SAFE_ATTR_NAME];
|
||||
const char *layer_name = CustomData_get_layer_name(cdata, type, i);
|
||||
const char *layer_name = CustomData_get_layer_name(cdata, type, j);
|
||||
GPU_vertformat_safe_attr_name(layer_name, attr_safe_name, GPU_MAX_SAFE_ATTR_NAME);
|
||||
|
||||
BLI_snprintf(attr_name, sizeof(attr_name), "c%s", attr_safe_name);
|
||||
GPU_vertformat_attr_add(&format, attr_name, GPU_COMP_U16, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
|
||||
|
||||
if (i == CustomData_get_render_layer(cdata, type)) {
|
||||
if (j == CustomData_get_render_layer(cdata, type)) {
|
||||
GPU_vertformat_alias_add(&format, "c");
|
||||
}
|
||||
if (i == CustomData_get_active_layer(cdata, type)) {
|
||||
|
||||
bool is_active = actn == -1 && j == CustomData_get_active_layer(cdata, type);
|
||||
is_active |= actn != -1 && domain == actdomain && j == actn && type == actlayer->type;
|
||||
|
||||
if (is_active) {
|
||||
GPU_vertformat_alias_add(&format, "ac");
|
||||
}
|
||||
|
||||
|
|
|
@ -742,6 +742,7 @@ set_property(GLOBAL PROPERTY ICON_GEOM_NAMES
|
|||
brush.particle.puff
|
||||
brush.particle.smooth
|
||||
brush.particle.weight
|
||||
brush.sculpt.array
|
||||
brush.sculpt.blob
|
||||
brush.sculpt.boundary
|
||||
brush.sculpt.clay
|
||||
|
@ -750,11 +751,11 @@ set_property(GLOBAL PROPERTY ICON_GEOM_NAMES
|
|||
brush.sculpt.cloth
|
||||
brush.sculpt.crease
|
||||
brush.sculpt.displacement_eraser
|
||||
brush.sculpt.displacement_smear
|
||||
brush.sculpt.draw
|
||||
brush.sculpt.draw_face_sets
|
||||
brush.sculpt.draw_sharp
|
||||
brush.sculpt.elastic_deform
|
||||
brush.sculpt.fairing
|
||||
brush.sculpt.fill
|
||||
brush.sculpt.flatten
|
||||
brush.sculpt.grab
|
||||
|
@ -767,13 +768,15 @@ set_property(GLOBAL PROPERTY ICON_GEOM_NAMES
|
|||
brush.sculpt.pinch
|
||||
brush.sculpt.pose
|
||||
brush.sculpt.rotate
|
||||
brush.sculpt.smear
|
||||
brush.sculpt.scene_project
|
||||
brush.sculpt.scrape
|
||||
brush.sculpt.simplify
|
||||
brush.sculpt.smear
|
||||
brush.sculpt.smooth
|
||||
brush.sculpt.snake_hook
|
||||
brush.sculpt.thumb
|
||||
brush.sculpt.topology
|
||||
brush.sculpt.vcol_boundary
|
||||
brush.uv_sculpt.grab
|
||||
brush.uv_sculpt.pinch
|
||||
brush.uv_sculpt.relax
|
||||
|
@ -863,6 +866,7 @@ set_property(GLOBAL PROPERTY ICON_GEOM_NAMES
|
|||
ops.sculpt.lasso_trim
|
||||
ops.sculpt.line_mask
|
||||
ops.sculpt.line_project
|
||||
ops.sculpt.mask_select
|
||||
ops.sculpt.mesh_filter
|
||||
ops.sequencer.blade
|
||||
ops.transform.bone_envelope
|
||||
|
|
Loading…
Reference in New Issue