Commit: 524abadae7844b5678d7f188848a01efb87c4809
Author: Antonio Vazquez
Date:   Sun Apr 9 16:56:52 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB524abadae7844b5678d7f188848a01efb87c4809

Merge branch 'blender2.8' into greasepencil-object

===================================================================



===================================================================

diff --cc source/blender/editors/gpencil/drawgpencil.c
index 38e05315e69,70d97b28202..0c6eeaee129
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@@ -563,124 -501,85 +563,124 @@@ static void gp_triangulate_stroke_fill(
        /* clear memory */
        if (tmp_triangles) MEM_freeN(tmp_triangles);
        if (points2d) MEM_freeN(points2d);
 +      if (uv) MEM_freeN(uv);
  }
  
 -
 -/* draw fills for shapes */
 -static void gp_draw_stroke_fill(
 -        bGPdata *gpd, bGPDstroke *gps,
 -        int offsx, int offsy, int winx, int winy, const float diff_mat[4][4], 
const float color[4])
 +/* add a new fill point and texture coordinates to vertex buffer */
 +static void gp_add_filldata_tobuffer(bGPDspoint *pt, float uv[2], unsigned 
pos, unsigned texcoord, short flag, 
 +      int offsx, int offsy, int winx, int winy, const float diff_mat[4][4])
  {
        float fpt[3];
 +      float co[2];
  
 -      BLI_assert(gps->totpoints >= 3);
 +      mul_v3_m4v3(fpt, diff_mat, &pt->x);
 +      /* if 2d, need conversion */
 +      if (!flag & GP_STROKE_3DSPACE) {
 +              gp_calc_2d_stroke_fxy(fpt, flag, offsx, offsy, winx, winy, co);
 +              copy_v2_v2(fpt, co);
 +              fpt[2] = 0.0f; /* 2d always is z=0.0f */
 +      }
  
 -      bGPDpalettecolor *palcolor = ED_gpencil_stroke_getcolor(gpd, gps);
 +      immAttrib2f(texcoord, uv[0], uv[1]); /* texture coordinates */
 +      immVertex3fv(pos, fpt); /* position */
 +}
  
 -      /* Triangulation fill if high quality flag is enabled */
 -      if (palcolor->flag & PC_COLOR_HQ_FILL) {
 -              /* Calculate triangles cache for filling area (must be done 
only after changes) */
 -              if ((gps->flag & GP_STROKE_RECALC_CACHES) || 
(gps->tot_triangles == 0) || (gps->triangles == NULL)) {
 -                      gp_triangulate_stroke_fill(gps);
 -              }
 -              BLI_assert(gps->tot_triangles >= 1);
 +/* assign image texture for filling stroke */
 +static int gp_set_filling_texture(Image *image, short flag)
 +{
 +      ImBuf *ibuf;
 +      unsigned int *bind = &image->bindcode[TEXTARGET_TEXTURE_2D];
 +      int error = GL_NO_ERROR;
 +      ImageUser iuser = { NULL };
 +      void *lock;
  
 -              unsigned int pos;
 -              if (gps->flag & GP_STROKE_3DSPACE) {
 -                      pos = VertexFormat_add_attrib(immVertexFormat(), "pos", 
COMP_F32, 3, KEEP_FLOAT);
 -                      immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
 -              }
 -              else {
 -                      pos = VertexFormat_add_attrib(immVertexFormat(), "pos", 
COMP_F32, 2, KEEP_FLOAT);
 -                      immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
 -              }
 +      iuser.ok = true;
  
 -              immUniformColor4fv(color);
 +      ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock);
  
 -              /* Draw all triangles for filling the polygon (cache must be 
calculated before) */
 -              immBegin(PRIM_TRIANGLES, gps->tot_triangles * 3);
 -              /* TODO: use batch instead of immediate mode, to share vertices 
*/
 +      if (ibuf == NULL || ibuf->rect == NULL) {
 +              BKE_image_release_ibuf(image, ibuf, NULL);
 +              return (int)GL_INVALID_OPERATION;
 +      }
  
 -              bGPDtriangle *stroke_triangle = gps->triangles;
 -              bGPDspoint *pt;
 +      GPU_create_gl_tex(bind, ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, 
GL_TEXTURE_2D,
 +              false, false, image);
  
 -              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);
 -                      }
 -                      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);
 -                      }
 -              }
 +      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 +      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 +      if (flag & PAC_COLOR_TEX_CLAMP) {
 +              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
 +              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
 +      }
 +      else {
 +              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 +              glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 +      }
 +      BKE_image_release_ibuf(image, ibuf, NULL);
 +      
 +      return error;
 +}
  
 -              immEnd();
 -              immUnbindProgram();
 +/* draw fills for shapes */
 +static void gp_draw_stroke_fill(
 +        bGPdata *gpd, bGPDstroke *gps,
 +        int offsx, int offsy, int winx, int winy, const float diff_mat[4][4], 
const float color[4])
 +{
 +      BLI_assert(gps->totpoints >= 3);
 +      PaletteColor *palcolor = gps->palcolor;
 +
 +      /* Calculate triangles cache for filling area (must be done only after 
changes) */
 +      if ((gps->flag & GP_STROKE_RECALC_CACHES) || (gps->tot_triangles == 0) 
|| (gps->triangles == NULL)) {
 +              gp_triangulate_stroke_fill(gps);
        }
 +      BLI_assert(gps->tot_triangles >= 1);
 +
 +      VertexFormat *format = immVertexFormat();
 +      unsigned pos = VertexFormat_add_attrib(format, "pos", GL_FLOAT, 3, 
KEEP_FLOAT);
 +      unsigned texcoord = VertexFormat_add_attrib(format, "texCoord", 
GL_FLOAT, 2, KEEP_FLOAT);
 +      immBindBuiltinProgram(GPU_SHADER_GPENCIL_FILL);
 +
 +      immUniformColor4fv(color);
 +      immUniform4fv("color2", palcolor->scolor);
 +      immUniform1i("fill_type", palcolor->fill_style);
 +      immUniform1f("mix_factor", palcolor->mix_factor);
 +
 +      immUniform1f("g_angle", palcolor->g_angle);
 +      immUniform1f("g_radius", palcolor->g_radius);
 +      immUniform1f("g_boxsize", palcolor->g_boxsize);
 +      immUniform2fv("g_scale", palcolor->g_scale);
 +      immUniform2fv("g_shift", palcolor->g_shift);
 +
 +      immUniform1f("t_angle", palcolor->t_angle);
 +      immUniform2fv("t_scale", palcolor->t_scale);
 +      immUniform2fv("t_shift", palcolor->t_shift);
 +      immUniform1f("t_opacity", palcolor->t_opacity);
 +      immUniform1i("t_mix", palcolor->flag & PAC_COLOR_TEX_MIX ? 1 : 0);
 +      immUniform1i("t_flip", palcolor->flag & PAC_COLOR_FLIP_FILL ? 1 : 0);
 +      /* image texture */
 +      if ((palcolor->fill_style == FILL_STYLE_TEXTURE) || (palcolor->flag & 
PAC_COLOR_TEX_MIX)) {
 +              gp_set_filling_texture(palcolor->ima, palcolor->flag);
 +      }
 +
 +      /* Draw all triangles for filling the polygon (cache must be calculated 
before) */
-       immBegin(GL_TRIANGLES, gps->tot_triangles * 3);
++      immBegin(PRIM_TRIANGLES, gps->tot_triangles * 3);
 +      /* TODO: use batch instead of immediate mode, to share vertices */
 +
 +      bGPDtriangle *stroke_triangle = gps->triangles;
 +      for (int i = 0; i < gps->tot_triangles; i++, stroke_triangle++) {
 +              gp_add_filldata_tobuffer(&gps->points[stroke_triangle->v1], 
stroke_triangle->uv1,
 +                      pos, texcoord, gps->flag,
 +                      offsx, offsy, winx, winy, diff_mat);
 +              gp_add_filldata_tobuffer(&gps->points[stroke_triangle->v2], 
stroke_triangle->uv2,
 +                      pos, texcoord, gps->flag,
 +                      offsx, offsy, winx, winy, diff_mat);
 +              gp_add_filldata_tobuffer(&gps->points[stroke_triangle->v3], 
stroke_triangle->uv3,
 +                      pos, texcoord, gps->flag,
 +                      offsx, offsy, winx, winy, diff_mat);
 +      }
 +
 +      immEnd();
 +      immUnbindProgram();
  }
  
  /* ----- Existing Strokes Drawing (3D and Point) ------ */

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to