GPencil: Reduce VBO memory footprint when using modifiers

Before, the modifiers were evaluated in Draw Engine and this required to calculate a factor to increase the VBO size.

Now, the modifiers are evaluated in Depsgraph and the Draw Engine receives the evaluated stroke with the final number of vertices. As the number of vertices is the final value already, if Draw Manager increases the number with the modifiers only increases the memory with empty space because never would be used. This commit removes this double calculation, reducing the memory usage and removes a loop to calculate the size by modifier too.

Also, the function getDuplicationFactor() has been removed because is not required anymore.
This commit is contained in:
Antonio Vazquez 2019-10-04 10:14:49 +02:00
parent fbc096cf07
commit 03bf290eae
18 changed files with 0 additions and 71 deletions

View File

@ -261,12 +261,6 @@ typedef struct GpencilModifierTypeInfo {
struct Object *ob,
GreasePencilTexWalkFunc walk,
void *userData);
/**
* Get the number of times the strokes are duplicated in this modifier.
* This is used to calculate the size of the GPU VBOs
*/
int (*getDuplicationFactor)(struct GpencilModifierData *md);
} GpencilModifierTypeInfo;
/* Initialize modifier's global data (type info and some common global storages). */

View File

@ -37,7 +37,6 @@
#include "DNA_gpencil_types.h"
#include "DNA_material_types.h"
#include "DNA_view3d_types.h"
#include "DNA_gpencil_modifier_types.h"
/* If builtin shaders are needed */
#include "GPU_shader.h"
@ -225,23 +224,6 @@ static void gpencil_calc_vertex(GPENCIL_StorageList *stl,
cache->b_point.tot_vertex = cache_ob->tot_vertex;
cache->b_edit.tot_vertex = cache_ob->tot_vertex;
cache->b_edlin.tot_vertex = cache_ob->tot_vertex;
/* some modifiers can change the number of points */
int factor = 0;
GpencilModifierData *md;
for (md = ob->greasepencil_modifiers.first; md; md = md->next) {
const GpencilModifierTypeInfo *mti = BKE_gpencil_modifierType_getInfo(md->type);
/* only modifiers that change size */
if (mti && mti->getDuplicationFactor) {
factor = mti->getDuplicationFactor(md);
cache->b_fill.tot_vertex *= factor;
cache->b_stroke.tot_vertex *= factor;
cache->b_point.tot_vertex *= factor;
cache->b_edit.tot_vertex *= factor;
cache->b_edlin.tot_vertex *= factor;
}
}
}
/* Helper for doing all the checks on whether a stroke can be drawn */

View File

@ -203,5 +203,4 @@ GpencilModifierTypeInfo modifierType_Gpencil_Armature = {
/* foreachObjectLink */ foreachObjectLink,
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
/* getDuplicationFactor */ NULL,
};

View File

@ -317,14 +317,6 @@ static void foreachObjectLink(GpencilModifierData *md,
walk(userData, ob, &mmd->object, IDWALK_CB_NOP);
}
static int getDuplicationFactor(GpencilModifierData *md)
{
ArrayGpencilModifierData *mmd = (ArrayGpencilModifierData *)md;
int t = mmd->count;
CLAMP_MIN(t, 1);
return t;
}
GpencilModifierTypeInfo modifierType_Gpencil_Array = {
/* name */ "Array",
/* structName */ "ArrayGpencilModifierData",
@ -347,5 +339,4 @@ GpencilModifierTypeInfo modifierType_Gpencil_Array = {
/* foreachObjectLink */ foreachObjectLink,
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
/* getDuplicationFactor */ getDuplicationFactor,
};

View File

@ -550,5 +550,4 @@ GpencilModifierTypeInfo modifierType_Gpencil_Build = {
/* foreachObjectLink */ NULL,
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
/* getDuplicationFactor */ NULL,
};

View File

@ -168,5 +168,4 @@ GpencilModifierTypeInfo modifierType_Gpencil_Color = {
/* foreachObjectLink */ NULL,
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
/* getDuplicationFactor */ NULL,
};

View File

@ -357,5 +357,4 @@ GpencilModifierTypeInfo modifierType_Gpencil_Hook = {
/* foreachObjectLink */ foreachObjectLink,
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
/* getDuplicationFactor */ NULL,
};

View File

@ -219,5 +219,4 @@ GpencilModifierTypeInfo modifierType_Gpencil_Lattice = {
/* foreachObjectLink */ foreachObjectLink,
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
/* getDuplicationFactor */ NULL,
};

View File

@ -203,21 +203,6 @@ static void foreachObjectLink(GpencilModifierData *md,
walk(userData, ob, &mmd->object, IDWALK_CB_NOP);
}
static int getDuplicationFactor(GpencilModifierData *md)
{
MirrorGpencilModifierData *mmd = (MirrorGpencilModifierData *)md;
int factor = 1;
/* create a duplication for each axis */
for (int xi = 0; xi < 3; xi++) {
if (mmd->flag & (GP_MIRROR_AXIS_X << xi)) {
factor++;
}
}
CLAMP_MIN(factor, 1);
return factor;
}
GpencilModifierTypeInfo modifierType_Gpencil_Mirror = {
/* name */ "Mirror",
/* structName */ "MirrorGpencilModifierData",
@ -240,5 +225,4 @@ GpencilModifierTypeInfo modifierType_Gpencil_Mirror = {
/* foreachObjectLink */ foreachObjectLink,
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
/* getDuplicationFactor */ getDuplicationFactor,
};

View File

@ -274,5 +274,4 @@ GpencilModifierTypeInfo modifierType_Gpencil_Noise = {
/* foreachObjectLink */ NULL,
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
/* getDuplicationFactor */ NULL,
};

View File

@ -148,5 +148,4 @@ GpencilModifierTypeInfo modifierType_Gpencil_Offset = {
/* foreachObjectLink */ NULL,
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
/* getDuplicationFactor */ NULL,
};

View File

@ -206,5 +206,4 @@ GpencilModifierTypeInfo modifierType_Gpencil_Opacity = {
/* foreachObjectLink */ NULL,
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
/* getDuplicationFactor */ NULL,
};

View File

@ -144,5 +144,4 @@ GpencilModifierTypeInfo modifierType_Gpencil_Simplify = {
/* foreachObjectLink */ NULL,
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
/* getDuplicationFactor */ NULL,
};

View File

@ -155,5 +155,4 @@ GpencilModifierTypeInfo modifierType_Gpencil_Smooth = {
/* foreachObjectLink */ NULL,
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
/* getDuplicationFactor */ NULL,
};

View File

@ -103,14 +103,6 @@ static void bakeModifier(struct Main *UNUSED(bmain),
}
}
static int getDuplicationFactor(GpencilModifierData *md)
{
SubdivGpencilModifierData *mmd = (SubdivGpencilModifierData *)md;
int t = (mmd->level + 1) * (mmd->level + 1);
CLAMP_MIN(t, 2);
return t;
}
GpencilModifierTypeInfo modifierType_Gpencil_Subdiv = {
/* name */ "Subdivision",
/* structName */ "SubdivGpencilModifierData",
@ -133,5 +125,4 @@ GpencilModifierTypeInfo modifierType_Gpencil_Subdiv = {
/* foreachObjectLink */ NULL,
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
/* getDuplicationFactor */ getDuplicationFactor,
};

View File

@ -210,5 +210,4 @@ GpencilModifierTypeInfo modifierType_Gpencil_Thick = {
/* foreachObjectLink */ NULL,
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
/* getDuplicationFactor */ NULL,
};

View File

@ -182,5 +182,4 @@ GpencilModifierTypeInfo modifierType_Gpencil_Time = {
/* foreachObjectLink */ NULL,
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
/* getDuplicationFactor */ NULL,
};

View File

@ -174,5 +174,4 @@ GpencilModifierTypeInfo modifierType_Gpencil_Tint = {
/* foreachObjectLink */ NULL,
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
/* getDuplicationFactor */ NULL,
};