svn merge ^/trunk/blender -r44213:44235 --- fixes bmesh shading bug [#30125]
authorCampbell Barton <ideasman42@gmail.com>
Sun, 19 Feb 2012 03:19:58 +0000 (03:19 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 19 Feb 2012 03:19:58 +0000 (03:19 +0000)
1  2 
source/blender/blenkernel/intern/editderivedmesh.c

@@@ -833,134 -482,130 +833,124 @@@ static void emDM_drawFacesTex_common
  
                        if (flag != 0) { /* flag 0 == the face is hidden or invisible */
  
--                              /* we always want smooth here since otherwise vertex colors dont interpolate */
-                               if (!has_vcol) {
-                                       glShadeModel(drawSmooth?GL_SMOOTH:GL_FLAT);
 -                              if (mcol) {
 -                                      if (flag==1) {
 -                                              cp= (unsigned char*)mcol;
 -                                      }
--                              }
--
 -                              glBegin(efa->v4?GL_QUADS:GL_TRIANGLES);
                                if (!drawSmooth) {
 -                                      glNormal3fv(emdm->faceNos[i]);
 +                                      glNormal3fv(bmdm->polyNos[BM_elem_index_get(efa)]);
  
 -                                      if (tf) glTexCoord2fv(tf->uv[0]);
 -                                      if (cp) glColor3ub(cp[3], cp[2], cp[1]);
 -                                      glVertex3fv(vertexCos[(int) efa->v1->tmp.l]);
 +                                      bmdm_get_tri_tex(bm, ls, luv, lcol, has_uv, has_vcol);
  
 -                                      if (tf) glTexCoord2fv(tf->uv[1]);
 -                                      if (cp) glColor3ub(cp[7], cp[6], cp[5]);
 -                                      glVertex3fv(vertexCos[(int) efa->v2->tmp.l]);
 +                                      glTexCoord2fv(luv[0]->uv);
 +                                      glColor3ub(lcol[0]->b, lcol[0]->g, lcol[0]->r);
 +                                      glVertex3fv(vertexCos[BM_elem_index_get(ls[0]->v)]);
  
 -                                      if (tf) glTexCoord2fv(tf->uv[2]);
 -                                      if (cp) glColor3ub(cp[11], cp[10], cp[9]);
 -                                      glVertex3fv(vertexCos[(int) efa->v3->tmp.l]);
 +                                      glTexCoord2fv(luv[1]->uv);
 +                                      glColor3ub(lcol[1]->b, lcol[1]->g, lcol[1]->r);
 +                                      glVertex3fv(vertexCos[BM_elem_index_get(ls[1]->v)]);
  
 -                                      if (efa->v4) {
 -                                              if (tf) glTexCoord2fv(tf->uv[3]);
 -                                              if (cp) glColor3ub(cp[15], cp[14], cp[13]);
 -                                              glVertex3fv(vertexCos[(int) efa->v4->tmp.l]);
 -                                      }
 +                                      glTexCoord2fv(luv[2]->uv);
 +                                      glColor3ub(lcol[2]->b, lcol[2]->g, lcol[2]->r);
 +                                      glVertex3fv(vertexCos[BM_elem_index_get(ls[2]->v)]);
                                }
                                else {
 -                                      if (tf) glTexCoord2fv(tf->uv[0]);
 -                                      if (cp) glColor3ub(cp[3], cp[2], cp[1]);
 -                                      glNormal3fv(vertexNos[(int) efa->v1->tmp.l]);
 -                                      glVertex3fv(vertexCos[(int) efa->v1->tmp.l]);
 -
 -                                      if (tf) glTexCoord2fv(tf->uv[1]);
 -                                      if (cp) glColor3ub(cp[7], cp[6], cp[5]);
 -                                      glNormal3fv(vertexNos[(int) efa->v2->tmp.l]);
 -                                      glVertex3fv(vertexCos[(int) efa->v2->tmp.l]);
 -
 -                                      if (tf) glTexCoord2fv(tf->uv[2]);
 -                                      if (cp) glColor3ub(cp[11], cp[10], cp[9]);
 -                                      glNormal3fv(vertexNos[(int) efa->v3->tmp.l]);
 -                                      glVertex3fv(vertexCos[(int) efa->v3->tmp.l]);
 -
 -                                      if (efa->v4) {
 -                                              if (tf) glTexCoord2fv(tf->uv[3]);
 -                                              if (cp) glColor3ub(cp[15], cp[14], cp[13]);
 -                                              glNormal3fv(vertexNos[(int) efa->v4->tmp.l]);
 -                                              glVertex3fv(vertexCos[(int) efa->v4->tmp.l]);
 -                                      }
 +                                      bmdm_get_tri_tex(bm, ls, luv, lcol, has_uv, has_vcol);
 +
 +                                      glTexCoord2fv(luv[0]->uv);
 +                                      glColor3ub(lcol[0]->b, lcol[0]->g, lcol[0]->r);
 +                                      glNormal3fv(vertexNos[BM_elem_index_get(ls[0]->v)]);
 +                                      glVertex3fv(vertexCos[BM_elem_index_get(ls[0]->v)]);
 +
 +                                      glTexCoord2fv(luv[1]->uv);
 +                                      glColor3ub(lcol[1]->b, lcol[1]->g, lcol[1]->r);
 +                                      glNormal3fv(vertexNos[BM_elem_index_get(ls[1]->v)]);
 +                                      glVertex3fv(vertexCos[BM_elem_index_get(ls[1]->v)]);
 +
 +                                      glTexCoord2fv(luv[2]->uv);
 +                                      glColor3ub(lcol[2]->b, lcol[2]->g, lcol[2]->r);
 +                                      glNormal3fv(vertexNos[BM_elem_index_get(ls[2]->v)]);
 +                                      glVertex3fv(vertexCos[BM_elem_index_get(ls[2]->v)]);
                                }
 -                              glEnd();
                        }
                }
 +              glEnd();
        }
        else {
 -              for (i=0,efa= em->faces.first; efa; i++,efa= efa->next) {
 -                      MTFace *tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
 -                      MCol *mcol= CustomData_em_get(&em->fdata, efa->data, CD_MCOL);
 -                      unsigned char *cp= NULL;
 -                      int drawSmooth= (efa->flag & ME_SMOOTH);
 +              BM_mesh_elem_index_ensure(bm, BM_VERT);
 +
 +              for (i=0; i<em->tottri; i++) {
 +                      BMLoop **ls = em->looptris[i];
 +                      MTexPoly *tp= has_uv ? CustomData_bmesh_get(&bm->pdata, ls[0]->f->head.data, CD_MTEXPOLY) : NULL;
 +                      MTFace mtf = {{{0}}};
 +                      /*unsigned char *cp= NULL;*/ /*UNUSED*/
 +                      int drawSmooth= BM_elem_flag_test(ls[0]->f, BM_ELEM_SMOOTH);
                        int flag;
  
 +                      efa = ls[0]->f;
 +
 +                      if (has_uv) {
 +                              ME_MTEXFACE_CPY(&mtf, tp);
 +                      }
 +
                        if (drawParams)
 -                              flag= drawParams(tf, (mcol != NULL), efa->mat_nr);
 +                              flag= drawParams(&mtf, has_vcol, efa->mat_nr);
                        else if (drawParamsMapped)
 -                              flag= drawParamsMapped(userData, i);
 +                              flag= drawParamsMapped(userData, BM_elem_index_get(efa));
                        else
                                flag= 1;
  
                        if (flag != 0) { /* flag 0 == the face is hidden or invisible */
  
--                              /* we always want smooth here since otherwise vertex colors dont interpolate */
-                               if (!has_vcol) {
-                                       glShadeModel(drawSmooth?GL_SMOOTH:GL_FLAT);
 -                              if (mcol) {
 -                                      if (flag==1) {
 -                                              cp= (unsigned char*)mcol;
 -                                      }
--                              }
--
 -                              glBegin(efa->v4?GL_QUADS:GL_TRIANGLES);
 +                              glBegin(GL_TRIANGLES);
                                if (!drawSmooth) {
 -                                      glNormal3fv(efa->n);
 -
 -                                      if (tf) glTexCoord2fv(tf->uv[0]);
 -                                      if (cp) glColor3ub(cp[3], cp[2], cp[1]);
 -                                      glVertex3fv(efa->v1->co);
 -
 -                                      if (tf) glTexCoord2fv(tf->uv[1]);
 -                                      if (cp) glColor3ub(cp[7], cp[6], cp[5]);
 -                                      glVertex3fv(efa->v2->co);
 -
 -                                      if (tf) glTexCoord2fv(tf->uv[2]);
 -                                      if (cp) glColor3ub(cp[11], cp[10], cp[9]);
 -                                      glVertex3fv(efa->v3->co);
 -
 -                                      if (efa->v4) {
 -                                              if (tf) glTexCoord2fv(tf->uv[3]);
 -                                              if (cp) glColor3ub(cp[15], cp[14], cp[13]);
 -                                              glVertex3fv(efa->v4->co);
 -                                      }
 +                                      glNormal3fv(efa->no);
 +
 +                                      bmdm_get_tri_tex(bm, ls, luv, lcol, has_uv, has_vcol);
 +
 +                                      if (luv[0])
 +                                              glTexCoord2fv(luv[0]->uv);
 +                                      if (lcol[0])
 +                                              glColor3ub(lcol[0]->b, lcol[0]->g, lcol[0]->r);
 +                                      else glColor3ub(0, 0, 0);
 +                                      glVertex3fv(ls[0]->v->co);
 +
 +                                      if (luv[1])
 +                                              glTexCoord2fv(luv[1]->uv);
 +                                      if (lcol[1])
 +                                              glColor3ub(lcol[1]->b, lcol[1]->g, lcol[1]->r);
 +                                      else glColor3ub(0, 0, 0);
 +                                      glVertex3fv(ls[1]->v->co);
 +
 +                                      if (luv[2])
 +                                              glTexCoord2fv(luv[2]->uv);
 +                                      if (lcol[2])
 +                                              glColor3ub(lcol[2]->b, lcol[2]->g, lcol[2]->r);
 +                                      else glColor3ub(0, 0, 0);
 +                                      glVertex3fv(ls[2]->v->co);
                                }
                                else {
 -                                      if (tf) glTexCoord2fv(tf->uv[0]);
 -                                      if (cp) glColor3ub(cp[3], cp[2], cp[1]);
 -                                      glNormal3fv(efa->v1->no);
 -                                      glVertex3fv(efa->v1->co);
 -
 -                                      if (tf) glTexCoord2fv(tf->uv[1]);
 -                                      if (cp) glColor3ub(cp[7], cp[6], cp[5]);
 -                                      glNormal3fv(efa->v2->no);
 -                                      glVertex3fv(efa->v2->co);
 -
 -                                      if (tf) glTexCoord2fv(tf->uv[2]);
 -                                      if (cp) glColor3ub(cp[11], cp[10], cp[9]);
 -                                      glNormal3fv(efa->v3->no);
 -                                      glVertex3fv(efa->v3->co);
 -
 -                                      if (efa->v4) {
 -                                              if (tf) glTexCoord2fv(tf->uv[3]);
 -                                              if (cp) glColor3ub(cp[15], cp[14], cp[13]);
 -                                              glNormal3fv(efa->v4->no);
 -                                              glVertex3fv(efa->v4->co);
 -                                      }
 +                                      bmdm_get_tri_tex(bm, ls, luv, lcol, has_uv, has_vcol);
 +
 +                                      if (luv[0])
 +                                              glTexCoord2fv(luv[0]->uv);
 +                                      if (lcol[0])
 +                                              glColor3ub(lcol[0]->b, lcol[0]->g, lcol[0]->r);
 +                                      else glColor3ub(0, 0, 0);
 +                                      glNormal3fv(ls[0]->v->no);
 +                                      glVertex3fv(ls[0]->v->co);
 +
 +                                      if (luv[1])
 +                                              glTexCoord2fv(luv[1]->uv);
 +                                      if (lcol[1])
 +                                              glColor3ub(lcol[1]->b, lcol[1]->g, lcol[1]->r);
 +                                      else glColor3ub(0, 0, 0);
 +                                      glNormal3fv(ls[1]->v->no);
 +                                      glVertex3fv(ls[1]->v->co);
 +
 +                                      if (luv[2])
 +                                              glTexCoord2fv(luv[2]->uv);
 +                                      if (lcol[2])
 +                                              glColor3ub(lcol[2]->b, lcol[2]->g, lcol[2]->r);
 +                                      else glColor3ub(0, 0, 0);
 +                                      glNormal3fv(ls[2]->v->no);
 +                                      glVertex3fv(ls[2]->v->co);
                                }
                                glEnd();
                        }