Fixed bug #23922, Sculpting - Textured display draws incorrectly
[blender.git] / source / blender / blenkernel / intern / cdderivedmesh.c
index b820ad0030593a8225523ce151c0d41886519318..cd0872807a0e7feaabb3735b1044df4c3d19f8fc 100644 (file)
@@ -226,6 +226,21 @@ static struct PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm)
        return cddm->pbvh;
 }
 
+/* update vertex normals so that drawing smooth faces works during sculpt
+   TODO: proper fix is to support the pbvh in all drawing modes */
+static void cdDM_update_normals_from_pbvh(DerivedMesh *dm)
+{
+       CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
+       float (*face_nors)[3];
+
+       if(!cddm->pbvh || !cddm->pbvh_draw || !dm->numFaceData)
+               return;
+
+       face_nors = CustomData_get_layer(&dm->faceData, CD_NORMAL);
+
+       BLI_pbvh_update(cddm->pbvh, PBVH_UpdateNormals, face_nors);
+}
+
 static void cdDM_drawVerts(DerivedMesh *dm)
 {
        CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
@@ -538,6 +553,8 @@ static void cdDM_drawFacesColored(DerivedMesh *dm, int useTwoSided, unsigned cha
        if(col1 && col2)
                glEnable(GL_CULL_FACE);
 
+       cdDM_update_normals_from_pbvh(dm);
+
        if( GPU_buffer_legacy(dm) ) {
                DEBUG_VBO( "Using legacy code. cdDM_drawFacesColored\n" );
                glShadeModel(GL_SMOOTH);
@@ -617,6 +634,8 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
        if(!mcol)
                mcol = dm->getFaceDataArray(dm, CD_MCOL);
 
+       cdDM_update_normals_from_pbvh(dm);
+
        if( GPU_buffer_legacy(dm) ) {
                DEBUG_VBO( "Using legacy code. cdDM_drawFacesTex_common\n" );
                for(i = 0; i < dm->numFaceData; i++, mf++) {
@@ -792,6 +811,8 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *us
        if(!mc)
                mc = DM_get_face_data_layer(dm, CD_MCOL);
 
+       cdDM_update_normals_from_pbvh(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) {
@@ -938,6 +959,8 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo
        int transp, new_transp, orig_transp;
        int orig, *index = dm->getFaceDataArray(dm, CD_ORIGINDEX);
 
+       cdDM_update_normals_from_pbvh(dm);
+
        matnr = -1;
        smoothnormal = 0;
        dodraw = 0;