Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Thu, 19 Oct 2017 22:40:08 +0000 (09:40 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 19 Oct 2017 22:40:08 +0000 (09:40 +1100)
1  2 
source/blender/editors/gpencil/drawgpencil.c
source/blender/makesdna/DNA_gpencil_types.h

index 63c1574438815dead83e03aa347de771484f62a6,bba7137c3eee89052d26cae18a7030f1970a6ac3..659c0c99fcbe0fbb91153701197491af898d6c11
@@@ -473,12 -438,10 +473,9 @@@ static void gp_triangulate_stroke_fill(
                else {
                        gps->triangles = MEM_recallocN(gps->triangles, sizeof(*gps->triangles) * gps->tot_triangles);
                }
 -              
 +
                for (int i = 0; i < gps->tot_triangles; i++) {
--                      bGPDtriangle *stroke_triangle = &gps->triangles[i];
-                       stroke_triangle->v1 = tmp_triangles[i][0];
-                       stroke_triangle->v2 = tmp_triangles[i][1];
-                       stroke_triangle->v3 = tmp_triangles[i][2];
 -                      memcpy(stroke_triangle->verts, tmp_triangles[i], sizeof(uint[3]));
++                      memcpy(gps->triangles[i].verts, tmp_triangles[i], sizeof(uint[3]));
                }
        }
        else {
@@@ -517,64 -485,59 +514,50 @@@ static void gp_draw_stroke_fill
                if ((gps->flag & GP_STROKE_RECALC_CACHES) || (gps->tot_triangles == 0) || (gps->triangles == NULL)) {
                        gp_triangulate_stroke_fill(gps);
                }
 -              /* Draw all triangles for filling the polygon (cache must be calculated before) */
                BLI_assert(gps->tot_triangles >= 1);
 -              glBegin(GL_TRIANGLES);
 +
 +              unsigned int pos;
                if (gps->flag & GP_STROKE_3DSPACE) {
 -                      for (i = 0, stroke_triangle = gps->triangles; i < gps->tot_triangles; i++, stroke_triangle++) {
 +                      pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
 +                      immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
 +              }
 +              else {
 +                      pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
 +                      immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
 +              }
 +
 +              immUniformColor4fv(color);
 +
 +              /* Draw all triangles for filling the polygon (cache must be calculated before) */
 +              immBegin(GWN_PRIM_TRIS, gps->tot_triangles * 3);
 +              /* TODO: use batch instead of immediate mode, to share vertices */
 +
 +              bGPDtriangle *stroke_triangle = gps->triangles;
 +              bGPDspoint *pt;
 +
-               for (int i = 0; i < gps->tot_triangles; i++, stroke_triangle++) {
-                       if (gps->flag & GP_STROKE_3DSPACE) {
-                               /* vertex 1 */
-                               pt = &gps->points[stroke_triangle->v1];
-                               mul_v3_m4v3(fpt, diff_mat, &pt->x);
-                               immVertex3fv(pos, fpt);
-                               /* vertex 2 */
-                               pt = &gps->points[stroke_triangle->v2];
-                               mul_v3_m4v3(fpt, diff_mat, &pt->x);
-                               immVertex3fv(pos, fpt);
-                               /* vertex 3 */
-                               pt = &gps->points[stroke_triangle->v3];
-                               mul_v3_m4v3(fpt, diff_mat, &pt->x);
-                               immVertex3fv(pos, fpt);
++              if (gps->flag & GP_STROKE_3DSPACE) {
++                      for (int i = 0; i < gps->tot_triangles; i++, stroke_triangle++) {
+                               for (int j = 0; j < 3; j++) {
+                                       pt = &gps->points[stroke_triangle->verts[j]];
+                                       mul_v3_m4v3(fpt, diff_mat, &pt->x);
 -                                      glVertex3fv(fpt);
++                                      immVertex3fv(pos, fpt);
+                               }
                        }
-                       else {
-                               float co[2];
-                               /* vertex 1 */
-                               pt = &gps->points[stroke_triangle->v1];
-                               mul_v3_m4v3(fpt, diff_mat, &pt->x);
-                               gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co);
-                               immVertex2fv(pos, co);
-                               /* vertex 2 */
-                               pt = &gps->points[stroke_triangle->v2];
-                               mul_v3_m4v3(fpt, diff_mat, &pt->x);
-                               gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co);
-                               immVertex2fv(pos, co);
-                               /* vertex 3 */
-                               pt = &gps->points[stroke_triangle->v3];
-                               mul_v3_m4v3(fpt, diff_mat, &pt->x);
-                               gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co);
-                               immVertex2fv(pos, co);
+               }
+               else {
 -                      for (i = 0, stroke_triangle = gps->triangles; i < gps->tot_triangles; i++, stroke_triangle++) {
++                      for (int i = 0; i < gps->tot_triangles; i++, stroke_triangle++) {
+                               for (int j = 0; j < 3; j++) {
+                                       float co[2];
+                                       pt = &gps->points[stroke_triangle->verts[j]];
+                                       mul_v3_m4v3(fpt, diff_mat, &pt->x);
+                                       gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co);
 -                                      glVertex2fv(co);
++                                      immVertex3fv(pos, fpt);
+                               }
                        }
                }
 -              glEnd();
 -      }
 -      else {
 -              /* As an initial implementation, we use the OpenGL filled polygon drawing
 -               * here since it's the easiest option to implement for this case. It does
 -               * come with limitations (notably for concave shapes), though it shouldn't
 -               * be much of an issue in most cases.
 -               *
 -               * We keep this legacy implementation around despite now having the high quality
 -               * fills, as this is necessary for keeping everything working nicely for files
 -               * created using old versions of Blender which may have depended on the artifacts
 -               * the old fills created.
 -               */
 -              bGPDspoint *pt;
 -
 -              glBegin(GL_POLYGON);
 -              for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
 -                      if (gps->flag & GP_STROKE_3DSPACE) {
 -                              mul_v3_m4v3(fpt, diff_mat, &pt->x);
 -                              glVertex3fv(fpt);
 -                      }
 -                      else {
 -                              float co[2];
 -                              mul_v3_m4v3(fpt, diff_mat, &pt->x);
 -                              gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co);
 -                              glVertex2fv(co);
 -                      }
 -              }
  
 -              glEnd();
 +              immEnd();
 +              immUnbindProgram();
        }
  }