Fix T42653, solidify modifier not displaying correctly under edit mode.

Basically, our drawing code assumed we always use the edit mesh
materials, which can be different from the derived mesh
materials in modifiers doing overrides. We usually we want to use the
derived mesh when it is available instead.

There are two fixes here for both solid and textured mode. Unfortunately
the fixes do not help to make the display code less labyrinthian but I
expect this "should work" (tm and famous last words)

Solid mode fix is 95% from Bastien, thanks!
This commit is contained in:
2014-11-27 19:12:48 +01:00
parent 3d3f82a8df
commit 2e8ba179f7
6 changed files with 33 additions and 27 deletions

View File

@@ -147,6 +147,7 @@ typedef int (*DMSetMaterial)(int mat_nr, void *attribs);
typedef int (*DMCompareDrawOptions)(void *userData, int cur_index, int next_index); typedef int (*DMCompareDrawOptions)(void *userData, int cur_index, int next_index);
typedef void (*DMSetDrawInterpOptions)(void *userData, int index, float t); typedef void (*DMSetDrawInterpOptions)(void *userData, int index, float t);
typedef DMDrawOption (*DMSetDrawOptions)(void *userData, int index); typedef DMDrawOption (*DMSetDrawOptions)(void *userData, int index);
typedef DMDrawOption (*DMSetDrawOptionsMappedTex)(void *userData, int origindex, int index);
typedef DMDrawOption (*DMSetDrawOptionsTex)(struct MTFace *tface, const bool has_vcol, int matnr); typedef DMDrawOption (*DMSetDrawOptionsTex)(struct MTFace *tface, const bool has_vcol, int matnr);
typedef enum DMDrawFlag { typedef enum DMDrawFlag {
@@ -423,7 +424,7 @@ struct DerivedMesh {
* - Drawing options too complicated to enumerate, look at code. * - Drawing options too complicated to enumerate, look at code.
*/ */
void (*drawMappedFacesTex)(DerivedMesh *dm, void (*drawMappedFacesTex)(DerivedMesh *dm,
DMSetDrawOptions setDrawOptions, DMSetDrawOptionsMappedTex setDrawOptions,
DMCompareDrawOptions compareDrawOptions, DMCompareDrawOptions compareDrawOptions,
void *userData, DMDrawFlag uvflag); void *userData, DMDrawFlag uvflag);

View File

@@ -667,7 +667,7 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm,
static void cdDM_drawFacesTex_common(DerivedMesh *dm, static void cdDM_drawFacesTex_common(DerivedMesh *dm,
DMSetDrawOptionsTex drawParams, DMSetDrawOptionsTex drawParams,
DMSetDrawOptions drawParamsMapped, DMSetDrawOptionsMappedTex drawParamsMapped,
DMCompareDrawOptions compareDrawOptions, DMCompareDrawOptions compareDrawOptions,
void *userData, DMDrawFlag uvflag) void *userData, DMDrawFlag uvflag)
{ {
@@ -759,7 +759,7 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
draw_option = DM_DRAW_OPTION_NORMAL; draw_option = DM_DRAW_OPTION_NORMAL;
} }
else if (drawParamsMapped) { else if (drawParamsMapped) {
draw_option = drawParamsMapped(userData, orig); draw_option = drawParamsMapped(userData, orig, i);
} }
else { else {
if (nors) { if (nors) {
@@ -769,7 +769,7 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
} }
} }
else if (drawParamsMapped) { else if (drawParamsMapped) {
draw_option = drawParamsMapped(userData, i); draw_option = drawParamsMapped(userData, i, i);
} }
else { else {
if (nors) { if (nors) {
@@ -880,11 +880,11 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
draw_option = DM_DRAW_OPTION_NORMAL; draw_option = DM_DRAW_OPTION_NORMAL;
} }
else if (drawParamsMapped) { else if (drawParamsMapped) {
draw_option = drawParamsMapped(userData, orig); draw_option = drawParamsMapped(userData, orig, actualFace);
} }
} }
else if (drawParamsMapped) { else if (drawParamsMapped) {
draw_option = drawParamsMapped(userData, actualFace); draw_option = drawParamsMapped(userData, actualFace, actualFace);
} }
} }
@@ -1089,6 +1089,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
else { else {
/* we need to check if the next material changes */ /* we need to check if the next material changes */
int next_actualFace = dm->drawObject->triangle_to_mface[0]; int next_actualFace = dm->drawObject->triangle_to_mface[0];
int prev_mat_nr = -1;
for (i = 0; i < tottri; i++) { for (i = 0; i < tottri; i++) {
//int actualFace = dm->drawObject->triangle_to_mface[i]; //int actualFace = dm->drawObject->triangle_to_mface[i];
@@ -1103,9 +1104,14 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
orig = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, actualFace) : actualFace; orig = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, actualFace) : actualFace;
if (orig == ORIGINDEX_NONE) if (mface->mat_nr != prev_mat_nr) {
if (setMaterial)
draw_option = setMaterial(mface->mat_nr + 1, NULL); draw_option = setMaterial(mface->mat_nr + 1, NULL);
else if (setDrawOptions != NULL)
prev_mat_nr = mface->mat_nr;
}
if (setDrawOptions != NULL && (orig != ORIGINDEX_NONE))
draw_option = setDrawOptions(userData, orig); draw_option = setDrawOptions(userData, orig);
if (draw_option == DM_DRAW_OPTION_STIPPLE) { if (draw_option == DM_DRAW_OPTION_STIPPLE) {
@@ -1150,7 +1156,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
} }
static void cdDM_drawMappedFacesTex(DerivedMesh *dm, static void cdDM_drawMappedFacesTex(DerivedMesh *dm,
DMSetDrawOptions setDrawOptions, DMSetDrawOptionsMappedTex setDrawOptions,
DMCompareDrawOptions compareDrawOptions, DMCompareDrawOptions compareDrawOptions,
void *userData, DMDrawFlag flag) void *userData, DMDrawFlag flag)
{ {

View File

@@ -717,7 +717,7 @@ static void bmdm_get_tri_colpreview(BMLoop *ls[3], MLoopCol *lcol[3], unsigned c
static void emDM_drawFacesTex_common(DerivedMesh *dm, static void emDM_drawFacesTex_common(DerivedMesh *dm,
DMSetDrawOptionsTex drawParams, DMSetDrawOptionsTex drawParams,
DMSetDrawOptions drawParamsMapped, DMSetDrawOptionsMappedTex drawParamsMapped,
DMCompareDrawOptions compareDrawOptions, DMCompareDrawOptions compareDrawOptions,
void *userData) void *userData)
{ {
@@ -785,7 +785,7 @@ static void emDM_drawFacesTex_common(DerivedMesh *dm,
if (drawParams) if (drawParams)
draw_option = drawParams(&mtf, has_vcol, efa->mat_nr); draw_option = drawParams(&mtf, has_vcol, efa->mat_nr);
else if (drawParamsMapped) else if (drawParamsMapped)
draw_option = drawParamsMapped(userData, BM_elem_index_get(efa)); draw_option = drawParamsMapped(userData, BM_elem_index_get(efa), BM_elem_index_get(efa));
else else
draw_option = DM_DRAW_OPTION_NORMAL; draw_option = DM_DRAW_OPTION_NORMAL;
@@ -854,7 +854,7 @@ static void emDM_drawFacesTex_common(DerivedMesh *dm,
if (drawParams) if (drawParams)
draw_option = drawParams(&mtf, has_vcol, efa->mat_nr); draw_option = drawParams(&mtf, has_vcol, efa->mat_nr);
else if (drawParamsMapped) else if (drawParamsMapped)
draw_option = drawParamsMapped(userData, BM_elem_index_get(efa)); draw_option = drawParamsMapped(userData, BM_elem_index_get(efa), BM_elem_index_get(efa));
else else
draw_option = DM_DRAW_OPTION_NORMAL; draw_option = DM_DRAW_OPTION_NORMAL;
@@ -916,7 +916,7 @@ static void emDM_drawFacesTex(DerivedMesh *dm,
} }
static void emDM_drawMappedFacesTex(DerivedMesh *dm, static void emDM_drawMappedFacesTex(DerivedMesh *dm,
DMSetDrawOptions setDrawOptions, DMSetDrawOptionsMappedTex setDrawOptions,
DMCompareDrawOptions compareDrawOptions, DMCompareDrawOptions compareDrawOptions,
void *userData, DMDrawFlag UNUSED(flag)) void *userData, DMDrawFlag UNUSED(flag))
{ {

View File

@@ -2289,7 +2289,7 @@ static void ccgDM_drawMappedFacesMat(DerivedMesh *dm,
static void ccgDM_drawFacesTex_common(DerivedMesh *dm, static void ccgDM_drawFacesTex_common(DerivedMesh *dm,
DMSetDrawOptionsTex drawParams, DMSetDrawOptionsTex drawParams,
DMSetDrawOptions drawParamsMapped, DMSetDrawOptionsMappedTex drawParamsMapped,
DMCompareDrawOptions compareDrawOptions, DMCompareDrawOptions compareDrawOptions,
void *userData, DMDrawFlag flag) void *userData, DMDrawFlag flag)
{ {
@@ -2361,7 +2361,7 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm,
if (drawParams) if (drawParams)
draw_option = drawParams(tf, (mcol != NULL), mat_nr); draw_option = drawParams(tf, (mcol != NULL), mat_nr);
else if (index != ORIGINDEX_NONE) else if (index != ORIGINDEX_NONE)
draw_option = (drawParamsMapped) ? drawParamsMapped(userData, index) : DM_DRAW_OPTION_NORMAL; draw_option = (drawParamsMapped) ? drawParamsMapped(userData, index, i) : DM_DRAW_OPTION_NORMAL;
else else
draw_option = GPU_enable_material(mat_nr, NULL) ? DM_DRAW_OPTION_NORMAL : DM_DRAW_OPTION_SKIP; draw_option = GPU_enable_material(mat_nr, NULL) ? DM_DRAW_OPTION_NORMAL : DM_DRAW_OPTION_SKIP;
@@ -2530,7 +2530,7 @@ static void ccgDM_drawFacesTex(DerivedMesh *dm,
} }
static void ccgDM_drawMappedFacesTex(DerivedMesh *dm, static void ccgDM_drawMappedFacesTex(DerivedMesh *dm,
DMSetDrawOptions setDrawOptions, DMSetDrawOptionsMappedTex setDrawOptions,
DMCompareDrawOptions compareDrawOptions, DMCompareDrawOptions compareDrawOptions,
void *userData, DMDrawFlag flag) void *userData, DMDrawFlag flag)
{ {

View File

@@ -668,20 +668,20 @@ static void update_tface_color_layer(DerivedMesh *dm)
} }
} }
static DMDrawOption draw_tface_mapped__set_draw(void *userData, int index) static DMDrawOption draw_tface_mapped__set_draw(void *userData, int origindex, int UNUSED(index))
{ {
Mesh *me = ((drawTFace_userData *)userData)->me; Mesh *me = ((drawTFace_userData *)userData)->me;
/* array checked for NULL before calling */ /* array checked for NULL before calling */
MPoly *mpoly = &me->mpoly[index]; MPoly *mpoly = &me->mpoly[origindex];
BLI_assert(index >= 0 && index < me->totpoly); BLI_assert(origindex >= 0 && origindex < me->totpoly);
if (mpoly->flag & ME_HIDE) { if (mpoly->flag & ME_HIDE) {
return DM_DRAW_OPTION_SKIP; return DM_DRAW_OPTION_SKIP;
} }
else { else {
MTexPoly *tpoly = (me->mtpoly) ? &me->mtpoly[index] : NULL; MTexPoly *tpoly = (me->mtpoly) ? &me->mtpoly[origindex] : NULL;
MTFace mtf = {{{0}}}; MTFace mtf = {{{0}}};
int matnr = mpoly->mat_nr; int matnr = mpoly->mat_nr;
@@ -693,23 +693,23 @@ static DMDrawOption draw_tface_mapped__set_draw(void *userData, int index)
} }
} }
static DMDrawOption draw_em_tf_mapped__set_draw(void *userData, int index) static DMDrawOption draw_em_tf_mapped__set_draw(void *userData, int origindex, int index)
{ {
drawEMTFMapped_userData *data = userData; drawEMTFMapped_userData *data = userData;
BMEditMesh *em = data->em; BMEditMesh *em = data->em;
BMFace *efa; BMFace *efa;
if (UNLIKELY(index >= em->bm->totface)) if (UNLIKELY(origindex >= em->bm->totface))
return DM_DRAW_OPTION_NORMAL; return DM_DRAW_OPTION_NORMAL;
efa = BM_face_at_index(em->bm, index); efa = BM_face_at_index(em->bm, origindex);
if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) { if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
return DM_DRAW_OPTION_SKIP; return DM_DRAW_OPTION_SKIP;
} }
else { else {
MTFace mtf = {{{0}}}; MTFace mtf = {{{0}}};
int matnr = efa->mat_nr; int matnr = (data->mf) ? data->mf[index].mat_nr : efa->mat_nr;
if (data->has_mtface) { if (data->has_mtface) {
MTexPoly *tpoly = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); MTexPoly *tpoly = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);

View File

@@ -3374,7 +3374,6 @@ static DMDrawOption draw_em_fancy__setFaceOpts(void *userData, int index)
efa = BM_face_at_index(em->bm, index); efa = BM_face_at_index(em->bm, index);
if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) { if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
GPU_enable_material(efa->mat_nr + 1, NULL);
return DM_DRAW_OPTION_NORMAL; return DM_DRAW_OPTION_NORMAL;
} }
else { else {