diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index bfc70c9..e1cff61 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -555,6 +555,8 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm, const short (*lnors)[4][3] = dm->getTessFaceDataArray(dm, CD_TESSLOOPNORMAL); int a, glmode = -1, shademodel = -1, matnr = -1, drawCurrentMat = 1; + printf("%s\n", __func__); + if (cddm->pbvh && cddm->pbvh_draw) { if (dm->numTessFaceData) { float (*face_nors)[3] = CustomData_get_layer(&dm->faceData, CD_NORMAL); @@ -689,6 +691,8 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, index_mp_to_orig = NULL; } + printf("%s\n", __func__); + /* TODO: not entirely correct, but currently dynamic topology will * destroy UVs anyway, so textured display wouldn't work anyway * @@ -926,6 +930,7 @@ static void cdDM_drawFacesTex(DerivedMesh *dm, DMCompareDrawOptions compareDrawOptions, void *userData, DMDrawFlag uvflag) { + printf("%s\n", __func__); cdDM_drawFacesTex_common(dm, setDrawOptions, NULL, compareDrawOptions, userData, uvflag); } @@ -952,6 +957,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, index_mp_to_orig = NULL; } + printf("%s\n", __func__); colType = CD_ID_MCOL; mcol = DM_get_tessface_data_layer(dm, colType); @@ -969,17 +975,27 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, /* back-buffer always uses legacy since VBO's would need the * color array temporarily overwritten for drawing, then reset. */ if (GPU_buffer_legacy(dm) || G.f & G_BACKBUFSEL) { + int prev_mat_nr = -1; DEBUG_VBO("Using legacy code. cdDM_drawMappedFaces\n"); + for (i = 0; i < dm->numTessFaceData; i++, mf++) { int drawSmooth = ((flag & DM_DRAW_ALWAYS_SMOOTH) || lnors) ? 1 : (mf->flag & ME_SMOOTH); DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL; orig = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, i) : i; - - if (orig == ORIGINDEX_NONE) - draw_option = setMaterial(mf->mat_nr + 1, NULL); - else if (setDrawOptions != NULL) + + printf("%p, %p, %d (%d)\n", setMaterial, setDrawOptions, mf->mat_nr, prev_mat_nr); + + if (mf->mat_nr != prev_mat_nr) { + if (setMaterial) { + printf("setting mat\n"); + draw_option = setMaterial(mf->mat_nr + 1, NULL); + } + prev_mat_nr = mf->mat_nr; + } + if ((setDrawOptions != NULL) && (orig != ORIGINDEX_NONE)) { draw_option = setDrawOptions(userData, orig); + } if (draw_option != DM_DRAW_OPTION_SKIP) { unsigned char *cp = NULL; @@ -1089,24 +1105,33 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, else { /* we need to check if the next material changes */ int next_actualFace = dm->drawObject->triangle_to_mface[0]; - + int prev_mat_nr = -1; + for (i = 0; i < tottri; i++) { //int actualFace = dm->drawObject->triangle_to_mface[i]; int actualFace = next_actualFace; MFace *mface = mf + actualFace; /*int drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : (mface->flag & ME_SMOOTH);*/ /* UNUSED */ DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL; - int flush = 0; + bool flush = false; if (i != tottri - 1) next_actualFace = dm->drawObject->triangle_to_mface[i + 1]; orig = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, actualFace) : actualFace; - if (orig == ORIGINDEX_NONE) - draw_option = setMaterial(mface->mat_nr + 1, NULL); - else if (setDrawOptions != NULL) + printf("%p, %p, %d (%d)\n", setMaterial, setDrawOptions, mface->mat_nr, prev_mat_nr); + + if (mface->mat_nr != prev_mat_nr) { + if (setMaterial) { + printf("setting mat\n"); + draw_option = setMaterial(mface->mat_nr + 1, NULL); + } + prev_mat_nr = mface->mat_nr; + } + if ((setDrawOptions != NULL) && (orig != ORIGINDEX_NONE)) { draw_option = setDrawOptions(userData, orig); + } if (draw_option == DM_DRAW_OPTION_STIPPLE) { glEnable(GL_POLYGON_STIPPLE); @@ -1120,7 +1145,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, /* flush buffer if current triangle isn't drawable or it's last triangle... */ flush = (ELEM(draw_option, DM_DRAW_OPTION_SKIP, DM_DRAW_OPTION_STIPPLE)) || (i == tottri - 1); - /* ... or when material setting is dissferent */ + /* ... or when material setting is different. */ flush |= mf[actualFace].mat_nr != mf[next_actualFace].mat_nr; if (!flush && compareDrawOptions) { @@ -1132,6 +1157,8 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, /* Add one to the length if we're drawing at the end of the array */ int count = (i - prevstart + (draw_option != DM_DRAW_OPTION_SKIP ? 1 : 0)) * 3; + printf("flushing!\n"); + if (count) glDrawArrays(GL_TRIANGLES, first, count); @@ -1154,6 +1181,7 @@ static void cdDM_drawMappedFacesTex(DerivedMesh *dm, DMCompareDrawOptions compareDrawOptions, void *userData, DMDrawFlag flag) { + printf("%s\n", __func__); cdDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData, flag); } @@ -1250,6 +1278,8 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, index_mp_to_orig = NULL; } + printf("%s\n", __func__); + /* TODO: same as for solid draw, not entirely correct, but works fine for now, * will skip using textures (dyntopo currently destroys UV anyway) and * works fine for matcap @@ -1560,6 +1590,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, static void cdDM_drawFacesGLSL(DerivedMesh *dm, DMSetMaterial setMaterial) { + printf("%s\n", __func__); dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL); } @@ -1584,6 +1615,8 @@ static void cdDM_drawMappedFacesMat(DerivedMesh *dm, index_mp_to_orig = NULL; } + printf("%s\n", __func__); + /* TODO: same as for solid draw, not entirely correct, but works fine for now, * will skip using textures (dyntopo currently destroys UV anyway) and * works fine for matcap @@ -1782,6 +1815,8 @@ static void cdDM_foreachMappedFaceCenter( MLoop *ml; int i, orig, *index; + printf("%s\n", __func__); + index = CustomData_get_layer(&dm->polyData, CD_ORIGINDEX); mp = cddm->mpoly; for (i = 0; i < dm->numPolyData; i++, mp++) {