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:
authorJoseph Eagar <joeedh@gmail.com>2022-08-31 18:26:57 +0300
committerJoseph Eagar <joeedh@gmail.com>2022-08-31 18:29:16 +0300
commita6ba8e5f38dbf62392088c3020aab549b7c80554 (patch)
tree812fbdf7460efad21d3e93816033881072ff0107
parent0864ab52480c585a7b38e510303d7cd718ba1e38 (diff)
Core: Remove color attribute limit from CustomData API
Note: does not fix the limit in PBVH draw which is caused by VBO limits not MAX_MCOL.
-rw-r--r--source/blender/blenkernel/intern/customdata.cc16
-rw-r--r--source/blender/blenkernel/intern/mesh_validate.cc7
-rw-r--r--source/blender/draw/intern/draw_cache_impl_particles.c34
-rw-r--r--source/blender/draw/intern/draw_hair_private.h6
-rw-r--r--source/blender/editors/mesh/mesh_data.cc20
-rw-r--r--source/blender/io/alembic/intern/abc_customdata.cc4
-rw-r--r--source/blender/makesdna/DNA_customdata_types.h1
-rw-r--r--source/blender/modifiers/intern/MOD_ocean.c102
8 files changed, 87 insertions, 103 deletions
diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc
index 82356e06d2c..1c7b78fd902 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -978,11 +978,6 @@ static void layerInterp_mloopcol(const void **sources,
mc->a = round_fl_to_uchar_clamp(col.a);
}
-static int layerMaxNum_mloopcol()
-{
- return MAX_MCOL;
-}
-
/** \} */
/* -------------------------------------------------------------------- */
@@ -1484,11 +1479,6 @@ static void layerInterp_propcol(const void **sources,
copy_v4_v4(mc->color, col);
}
-static int layerMaxNum_propcol()
-{
- return MAX_MCOL;
-}
-
/** \} */
/* -------------------------------------------------------------------- */
@@ -1662,7 +1652,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
nullptr,
nullptr,
nullptr,
- layerMaxNum_mloopcol},
+ nullptr},
/* 7: CD_ORIGINDEX */
{sizeof(int), "", 0, nullptr, nullptr, nullptr, nullptr, nullptr, layerDefault_origindex},
/* 8: CD_NORMAL */
@@ -1771,7 +1761,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
nullptr,
nullptr,
nullptr,
- layerMaxNum_mloopcol},
+ nullptr},
/* 18: CD_TANGENT */
{sizeof(float[4][4]), "", 0, N_("Tangent"), nullptr, nullptr, nullptr, nullptr, nullptr},
/* 19: CD_MDISPS */
@@ -1964,7 +1954,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
nullptr,
nullptr,
nullptr,
- layerMaxNum_propcol},
+ nullptr},
/* 48: CD_PROP_FLOAT3 */
{sizeof(float[3]),
"vec3f",
diff --git a/source/blender/blenkernel/intern/mesh_validate.cc b/source/blender/blenkernel/intern/mesh_validate.cc
index 9b2697ecc84..d17885e1214 100644
--- a/source/blender/blenkernel/intern/mesh_validate.cc
+++ b/source/blender/blenkernel/intern/mesh_validate.cc
@@ -1025,13 +1025,6 @@ bool BKE_mesh_validate_all_customdata(CustomData *vdata,
MAX_MTFACE,
tot_uvloop - MAX_MTFACE);
}
- if (tot_vcolloop > MAX_MCOL) {
- PRINT_ERR(
- "\tMore VCol layers than %d allowed, %d last ones won't be available for render, shaders, "
- "etc.\n",
- MAX_MCOL,
- tot_vcolloop - MAX_MCOL);
- }
/* check indices of clone/stencil */
if (do_fixes && CustomData_get_clone_layer(ldata, CD_MLOOPUV) >= tot_uvloop) {
diff --git a/source/blender/draw/intern/draw_cache_impl_particles.c b/source/blender/draw/intern/draw_cache_impl_particles.c
index dee7a8cec37..02afbab6899 100644
--- a/source/blender/draw/intern/draw_cache_impl_particles.c
+++ b/source/blender/draw/intern/draw_cache_impl_particles.c
@@ -11,6 +11,7 @@
#include "MEM_guardedalloc.h"
+#include "BLI_alloca.h"
#include "BLI_ghash.h"
#include "BLI_math_vector.h"
#include "BLI_string.h"
@@ -182,10 +183,11 @@ static void particle_batch_cache_clear_hair(ParticleHairCache *hair_cache)
GPU_VERTBUF_DISCARD_SAFE(hair_cache->proc_uv_buf[i]);
DRW_TEXTURE_FREE_SAFE(hair_cache->uv_tex[i]);
}
- for (int i = 0; i < MAX_MCOL; i++) {
+ for (int i = 0; i < hair_cache->num_col_layers; i++) {
GPU_VERTBUF_DISCARD_SAFE(hair_cache->proc_col_buf[i]);
DRW_TEXTURE_FREE_SAFE(hair_cache->col_tex[i]);
}
+
for (int i = 0; i < MAX_HAIR_SUBDIV; i++) {
GPU_VERTBUF_DISCARD_SAFE(hair_cache->final[i].proc_buf);
DRW_TEXTURE_FREE_SAFE(hair_cache->final[i].proc_tex);
@@ -218,9 +220,24 @@ static void particle_batch_cache_clear(ParticleSystem *psys)
GPU_VERTBUF_DISCARD_SAFE(cache->edit_tip_pos);
}
+static void particle_batch_cache_free_hair(ParticleHairCache *hair)
+{
+ MEM_SAFE_FREE(hair->proc_col_buf);
+ MEM_SAFE_FREE(hair->col_tex);
+ MEM_SAFE_FREE(hair->col_layer_names);
+}
+
void DRW_particle_batch_cache_free(ParticleSystem *psys)
{
particle_batch_cache_clear(psys);
+
+ ParticleBatchCache *cache = psys->batch_cache;
+
+ if (cache) {
+ particle_batch_cache_free_hair(&cache->hair);
+ particle_batch_cache_free_hair(&cache->edit_hair);
+ }
+
MEM_SAFE_FREE(psys->batch_cache);
}
@@ -833,10 +850,10 @@ static void particle_batch_cache_ensure_procedural_strand_data(PTCacheEdit *edit
GPUVertBufRaw data_step, seg_step;
GPUVertBufRaw uv_step[MAX_MTFACE];
- GPUVertBufRaw col_step[MAX_MCOL];
+ GPUVertBufRaw *col_step = BLI_array_alloca(col_step, cache->num_col_layers);
const MTFace *mtfaces[MAX_MTFACE] = {NULL};
- const MCol *mcols[MAX_MCOL] = {NULL};
+ const MCol **mcols = BLI_array_alloca(mcols, cache->num_col_layers);
float(**parent_uvs)[2] = NULL;
MCol **parent_mcol = NULL;
@@ -854,7 +871,6 @@ static void particle_batch_cache_ensure_procedural_strand_data(PTCacheEdit *edit
&format_col, "col", GPU_COMP_U16, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
memset(cache->uv_layer_names, 0, sizeof(cache->uv_layer_names));
- memset(cache->col_layer_names, 0, sizeof(cache->col_layer_names));
/* Strand Data */
cache->proc_strand_buf = GPU_vertbuf_create_with_format(&format_data);
@@ -885,6 +901,16 @@ static void particle_batch_cache_ensure_procedural_strand_data(PTCacheEdit *edit
BLI_strncpy(cache->uv_layer_names[i][n++], "a", MAX_LAYER_NAME_LEN);
}
}
+
+ MEM_SAFE_FREE(cache->proc_col_buf);
+ MEM_SAFE_FREE(cache->col_tex);
+ MEM_SAFE_FREE(cache->col_layer_names);
+
+ cache->proc_col_buf = MEM_calloc_arrayN(cache->num_col_layers, sizeof(void *), "proc_col_buf");
+ cache->col_tex = MEM_calloc_arrayN(cache->num_col_layers, sizeof(void *), "col_tex");
+ cache->col_layer_names = MEM_calloc_arrayN(
+ cache->num_col_layers, sizeof(*cache->col_layer_names), "col_layer_names");
+
/* Vertex colors */
for (int i = 0; i < cache->num_col_layers; i++) {
cache->proc_col_buf[i] = GPU_vertbuf_create_with_format(&format_col);
diff --git a/source/blender/draw/intern/draw_hair_private.h b/source/blender/draw/intern/draw_hair_private.h
index 5d84c8863f2..c7e9e1e22de 100644
--- a/source/blender/draw/intern/draw_hair_private.h
+++ b/source/blender/draw/intern/draw_hair_private.h
@@ -61,9 +61,9 @@ typedef struct ParticleHairCache {
GPUTexture *uv_tex[MAX_MTFACE];
char uv_layer_names[MAX_MTFACE][MAX_LAYER_NAME_CT][MAX_LAYER_NAME_LEN];
- GPUVertBuf *proc_col_buf[MAX_MCOL];
- GPUTexture *col_tex[MAX_MCOL];
- char col_layer_names[MAX_MCOL][MAX_LAYER_NAME_CT][MAX_LAYER_NAME_LEN];
+ GPUVertBuf **proc_col_buf;
+ GPUTexture **col_tex;
+ char (*col_layer_names)[MAX_LAYER_NAME_CT][MAX_LAYER_NAME_LEN];
int num_uv_layers;
int num_col_layers;
diff --git a/source/blender/editors/mesh/mesh_data.cc b/source/blender/editors/mesh/mesh_data.cc
index 67834bf05ce..c850e2f1e7a 100644
--- a/source/blender/editors/mesh/mesh_data.cc
+++ b/source/blender/editors/mesh/mesh_data.cc
@@ -380,10 +380,6 @@ int ED_mesh_color_add(
em = me->edit_mesh;
layernum = CustomData_number_of_layers(&em->bm->ldata, CD_PROP_BYTE_COLOR);
- if (layernum >= MAX_MCOL) {
- BKE_reportf(reports, RPT_WARNING, "Cannot add more than %i vertex color layers", MAX_MCOL);
- return -1;
- }
/* CD_PROP_BYTE_COLOR */
BM_data_layer_add_named(em->bm, &em->bm->ldata, CD_PROP_BYTE_COLOR, name);
@@ -398,10 +394,6 @@ int ED_mesh_color_add(
}
else {
layernum = CustomData_number_of_layers(&me->ldata, CD_PROP_BYTE_COLOR);
- if (layernum >= MAX_MCOL) {
- BKE_reportf(reports, RPT_WARNING, "Cannot add more than %i vertex color layers", MAX_MCOL);
- return -1;
- }
if (me->mloopcol && do_init) {
CustomData_add_layer_named(
@@ -523,11 +515,6 @@ int ED_mesh_sculpt_color_add(
em = me->edit_mesh;
layernum = CustomData_number_of_layers(&em->bm->vdata, CD_PROP_COLOR);
- if (layernum >= MAX_MCOL) {
- BKE_reportf(
- reports, RPT_WARNING, "Cannot add more than %i sculpt vertex color layers", MAX_MCOL);
- return -1;
- }
/* CD_PROP_COLOR */
BM_data_layer_add_named(em->bm, &em->bm->vdata, CD_PROP_COLOR, name);
@@ -542,12 +529,7 @@ int ED_mesh_sculpt_color_add(
}
else {
layernum = CustomData_number_of_layers(&me->vdata, CD_PROP_COLOR);
- if (layernum >= MAX_MCOL) {
- BKE_reportf(
- reports, RPT_WARNING, "Cannot add more than %i sculpt vertex color layers", MAX_MCOL);
- return -1;
- }
-
+
if (CustomData_has_layer(&me->vdata, CD_PROP_COLOR) && do_init) {
const MPropCol *color_data = (const MPropCol *)CustomData_get_layer(&me->vdata,
CD_PROP_COLOR);
diff --git a/source/blender/io/alembic/intern/abc_customdata.cc b/source/blender/io/alembic/intern/abc_customdata.cc
index 2820a128072..35be9f9fc4d 100644
--- a/source/blender/io/alembic/intern/abc_customdata.cc
+++ b/source/blender/io/alembic/intern/abc_customdata.cc
@@ -583,10 +583,6 @@ void read_custom_data(const std::string &iobject_full_name,
/* Read vertex colors according to convention. */
if (IC3fGeomParam::matches(prop_header) || IC4fGeomParam::matches(prop_header)) {
- if (++num_colors > MAX_MCOL) {
- continue;
- }
-
read_custom_data_mcols(iobject_full_name, prop, prop_header, config, iss);
continue;
}
diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h
index bc29de66cf9..f51b1c790b0 100644
--- a/source/blender/makesdna/DNA_customdata_types.h
+++ b/source/blender/makesdna/DNA_customdata_types.h
@@ -256,7 +256,6 @@ enum {
/* Limits */
#define MAX_MTFACE 8
-#define MAX_MCOL 8
#define DYNTOPO_NODE_NONE -1
diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c
index ea9049200cc..b596d493453 100644
--- a/source/blender/modifiers/intern/MOD_ocean.c
+++ b/source/blender/modifiers/intern/MOD_ocean.c
@@ -373,68 +373,66 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes
/* add vcols before displacement - allows lookup based on position */
if (omd->flag & MOD_OCEAN_GENERATE_FOAM) {
- if (CustomData_number_of_layers(&result->ldata, CD_PROP_BYTE_COLOR) < MAX_MCOL) {
- const int polys_num = result->totpoly;
- const int loops_num = result->totloop;
- MLoop *mloops = result->mloop;
- MLoopCol *mloopcols = CustomData_add_layer_named(
- &result->ldata, CD_PROP_BYTE_COLOR, CD_CALLOC, NULL, loops_num, omd->foamlayername);
-
- MLoopCol *mloopcols_spray = NULL;
- if (omd->flag & MOD_OCEAN_GENERATE_SPRAY) {
- mloopcols_spray = CustomData_add_layer_named(
- &result->ldata, CD_PROP_BYTE_COLOR, CD_CALLOC, NULL, loops_num, omd->spraylayername);
- }
+ const int polys_num = result->totpoly;
+ const int loops_num = result->totloop;
+ MLoop *mloops = result->mloop;
+ MLoopCol *mloopcols = CustomData_add_layer_named(
+ &result->ldata, CD_PROP_BYTE_COLOR, CD_CALLOC, NULL, loops_num, omd->foamlayername);
+
+ MLoopCol *mloopcols_spray = NULL;
+ if (omd->flag & MOD_OCEAN_GENERATE_SPRAY) {
+ mloopcols_spray = CustomData_add_layer_named(
+ &result->ldata, CD_PROP_BYTE_COLOR, CD_CALLOC, NULL, loops_num, omd->spraylayername);
+ }
- if (mloopcols) { /* unlikely to fail */
- MPoly *mpolys = result->mpoly;
- MPoly *mp;
+ if (mloopcols) { /* unlikely to fail */
+ MPoly *mpolys = result->mpoly;
+ MPoly *mp;
- for (i = 0, mp = mpolys; i < polys_num; i++, mp++) {
- MLoop *ml = &mloops[mp->loopstart];
- MLoopCol *mlcol = &mloopcols[mp->loopstart];
+ for (i = 0, mp = mpolys; i < polys_num; i++, mp++) {
+ MLoop *ml = &mloops[mp->loopstart];
+ MLoopCol *mlcol = &mloopcols[mp->loopstart];
- MLoopCol *mlcolspray = NULL;
- if (omd->flag & MOD_OCEAN_GENERATE_SPRAY) {
- mlcolspray = &mloopcols_spray[mp->loopstart];
+ MLoopCol *mlcolspray = NULL;
+ if (omd->flag & MOD_OCEAN_GENERATE_SPRAY) {
+ mlcolspray = &mloopcols_spray[mp->loopstart];
+ }
+
+ for (j = mp->totloop; j--; ml++, mlcol++) {
+ const float *vco = mverts[ml->v].co;
+ const float u = OCEAN_CO(size_co_inv, vco[0]);
+ const float v = OCEAN_CO(size_co_inv, vco[1]);
+ float foam;
+
+ if (omd->oceancache && omd->cached == true) {
+ BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra_for_cache, u, v);
+ foam = ocr.foam;
+ CLAMP(foam, 0.0f, 1.0f);
+ }
+ else {
+ BKE_ocean_eval_uv(omd->ocean, &ocr, u, v);
+ foam = BKE_ocean_jminus_to_foam(ocr.Jminus, omd->foam_coverage);
}
- for (j = mp->totloop; j--; ml++, mlcol++) {
- const float *vco = mverts[ml->v].co;
- const float u = OCEAN_CO(size_co_inv, vco[0]);
- const float v = OCEAN_CO(size_co_inv, vco[1]);
- float foam;
+ mlcol->r = mlcol->g = mlcol->b = (char)(foam * 255);
+ /* This needs to be set (render engine uses) */
+ mlcol->a = 255;
- if (omd->oceancache && omd->cached == true) {
- BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra_for_cache, u, v);
- foam = ocr.foam;
- CLAMP(foam, 0.0f, 1.0f);
+ if (omd->flag & MOD_OCEAN_GENERATE_SPRAY) {
+ if (omd->flag & MOD_OCEAN_INVERT_SPRAY) {
+ mlcolspray->r = ocr.Eminus[0] * 255;
}
else {
- BKE_ocean_eval_uv(omd->ocean, &ocr, u, v);
- foam = BKE_ocean_jminus_to_foam(ocr.Jminus, omd->foam_coverage);
+ mlcolspray->r = ocr.Eplus[0] * 255;
}
-
- mlcol->r = mlcol->g = mlcol->b = (char)(foam * 255);
- /* This needs to be set (render engine uses) */
- mlcol->a = 255;
-
- if (omd->flag & MOD_OCEAN_GENERATE_SPRAY) {
- if (omd->flag & MOD_OCEAN_INVERT_SPRAY) {
- mlcolspray->r = ocr.Eminus[0] * 255;
- }
- else {
- mlcolspray->r = ocr.Eplus[0] * 255;
- }
- mlcolspray->g = 0;
- if (omd->flag & MOD_OCEAN_INVERT_SPRAY) {
- mlcolspray->b = ocr.Eminus[2] * 255;
- }
- else {
- mlcolspray->b = ocr.Eplus[2] * 255;
- }
- mlcolspray->a = 255;
+ mlcolspray->g = 0;
+ if (omd->flag & MOD_OCEAN_INVERT_SPRAY) {
+ mlcolspray->b = ocr.Eminus[2] * 255;
+ }
+ else {
+ mlcolspray->b = ocr.Eplus[2] * 255;
}
+ mlcolspray->a = 255;
}
}
}