Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/drawgpencil.c
| Show All 40 Lines | |||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_polyfill_2d.h" | #include "BLI_polyfill_2d.h" | ||||
| #include "BLF_api.h" | #include "BLF_api.h" | ||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "DNA_brush_types.h" | |||||
| #include "DNA_gpencil_types.h" | #include "DNA_gpencil_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_screen_types.h" | #include "DNA_screen_types.h" | ||||
| #include "DNA_space_types.h" | #include "DNA_space_types.h" | ||||
| #include "DNA_view3d_types.h" | #include "DNA_view3d_types.h" | ||||
| #include "DNA_userdef_types.h" | #include "DNA_userdef_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_brush.h" | |||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_paint.h" | |||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| #include "BKE_image.h" | |||||
| #include "DEG_depsgraph.h" | |||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "BIF_glutil.h" | #include "BIF_glutil.h" | ||||
| #include "GPU_immediate.h" | #include "GPU_immediate.h" | ||||
| #include "GPU_draw.h" | #include "GPU_draw.h" | ||||
| #include "ED_gpencil.h" | #include "ED_gpencil.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_view3d.h" | #include "ED_view3d.h" | ||||
| #include "ED_space_api.h" | #include "ED_space_api.h" | ||||
| #include "UI_interface_icons.h" | #include "UI_interface_icons.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "IMB_imbuf_types.h" | |||||
| #include "gpencil_intern.h" | |||||
| /* ************************************************** */ | /* ************************************************** */ | ||||
| /* GREASE PENCIL DRAWING */ | /* GREASE PENCIL DRAWING */ | ||||
| /* ----- General Defines ------ */ | /* ----- General Defines ------ */ | ||||
| /* flags for sflag */ | /* flags for sflag */ | ||||
| typedef enum eDrawStrokeFlags { | typedef enum eDrawStrokeFlags { | ||||
| GP_DRAWDATA_NOSTATUS = (1 << 0), /* don't draw status info */ | GP_DRAWDATA_NOSTATUS = (1 << 0), /* don't draw status info */ | ||||
| GP_DRAWDATA_ONLY3D = (1 << 1), /* only draw 3d-strokes */ | GP_DRAWDATA_ONLY3D = (1 << 1), /* only draw 3d-strokes */ | ||||
| GP_DRAWDATA_ONLYV2D = (1 << 2), /* only draw 'canvas' strokes */ | GP_DRAWDATA_ONLYV2D = (1 << 2), /* only draw 'canvas' strokes */ | ||||
| GP_DRAWDATA_ONLYI2D = (1 << 3), /* only draw 'image' strokes */ | GP_DRAWDATA_ONLYI2D = (1 << 3), /* only draw 'image' strokes */ | ||||
| GP_DRAWDATA_IEDITHACK = (1 << 4), /* special hack for drawing strokes in Image Editor (weird coordinates) */ | GP_DRAWDATA_IEDITHACK = (1 << 4), /* special hack for drawing strokes in Image Editor (weird coordinates) */ | ||||
| GP_DRAWDATA_NO_XRAY = (1 << 5), /* don't draw xray in 3D view (which is default) */ | GP_DRAWDATA_NO_XRAY = (1 << 5), /* don't draw xray in 3D view (which is default) */ | ||||
| GP_DRAWDATA_NO_ONIONS = (1 << 6), /* no onionskins should be drawn (for animation playback) */ | GP_DRAWDATA_NO_ONIONS = (1 << 6), /* no onionskins should be drawn (for animation playback) */ | ||||
| GP_DRAWDATA_VOLUMETRIC = (1 << 7), /* draw strokes as "volumetric" circular billboards */ | GP_DRAWDATA_VOLUMETRIC = (1 << 7), /* draw strokes as "volumetric" circular billboards */ | ||||
| GP_DRAWDATA_FILL = (1 << 8), /* fill insides/bounded-regions of strokes */ | GP_DRAWDATA_FILL = (1 << 8) /* fill insides/bounded-regions of strokes */ | ||||
| GP_DRAWDATA_HQ_FILL = (1 << 9) /* Use high quality fill */ | |||||
| } eDrawStrokeFlags; | } eDrawStrokeFlags; | ||||
| /* thickness above which we should use special drawing */ | /* thickness above which we should use special drawing */ | ||||
| #if 0 | #if 0 | ||||
| #define GP_DRAWTHICKNESS_SPECIAL 3 | #define GP_DRAWTHICKNESS_SPECIAL 3 | ||||
| #endif | #endif | ||||
| ▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | for (int i = 0; i < totpoints; i++, pt++) { | ||||
| glLineWidth(max_ff(pt->pressure * thickness, 1.0f)); | glLineWidth(max_ff(pt->pressure * thickness, 1.0f)); | ||||
| immBeginAtMost(GWN_PRIM_LINE_STRIP, totpoints - i + 1); | immBeginAtMost(GWN_PRIM_LINE_STRIP, totpoints - i + 1); | ||||
| /* need to roll-back one point to ensure that there are no gaps in the stroke */ | /* need to roll-back one point to ensure that there are no gaps in the stroke */ | ||||
| if (i != 0) { | if (i != 0) { | ||||
| gp_set_tpoint_varying_color(pt - 1, ink, color); | gp_set_tpoint_varying_color(pt - 1, ink, color); | ||||
| immVertex2iv(pos, &(pt - 1)->x); | immVertex2iv(pos, &(pt - 1)->x); | ||||
| ++draw_points; | draw_points++; | ||||
| } | } | ||||
| oldpressure = pt->pressure; /* reset our threshold */ | oldpressure = pt->pressure; /* reset our threshold */ | ||||
| } | } | ||||
| /* now the point we want */ | /* now the point we want */ | ||||
| gp_set_tpoint_varying_color(pt, ink, color); | gp_set_tpoint_varying_color(pt, ink, color); | ||||
| immVertex2iv(pos, &pt->x); | immVertex2iv(pos, &pt->x); | ||||
| ++draw_points; | draw_points++; | ||||
| } | } | ||||
| /* need to have 2 points to avoid immEnd assert error */ | /* need to have 2 points to avoid immEnd assert error */ | ||||
| if (draw_points < 2) { | if (draw_points < 2) { | ||||
| gp_set_tpoint_varying_color(pt - 1, ink, color); | gp_set_tpoint_varying_color(pt - 1, ink, color); | ||||
| immVertex2iv(pos, &(pt - 1)->x); | immVertex2iv(pos, &(pt - 1)->x); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | static void gp_draw_stroke_volumetric_3d( | ||||
| immEnd(); | immEnd(); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| GPU_disable_program_point_size(); | GPU_disable_program_point_size(); | ||||
| } | } | ||||
| /* --------------- Stroke Fills ----------------- */ | /* --------------- Stroke Fills ----------------- */ | ||||
| /* calc bounding box in 2d using flat projection data */ | |||||
| static void gp_calc_2d_bounding_box(const float(*points2d)[2], int totpoints, float minv[2], float maxv[2], bool expand) | |||||
| { | |||||
| copy_v2_v2(minv, points2d[0]); | |||||
| copy_v2_v2(maxv, points2d[0]); | |||||
| for (int i = 1; i < totpoints; i++) { | |||||
| /* min */ | |||||
| if (points2d[i][0] < minv[0]) { | |||||
| minv[0] = points2d[i][0]; | |||||
| } | |||||
| if (points2d[i][1] < minv[1]) { | |||||
| minv[1] = points2d[i][1]; | |||||
| } | |||||
| /* max */ | |||||
| if (points2d[i][0] > maxv[0]) { | |||||
| maxv[0] = points2d[i][0]; | |||||
| } | |||||
| if (points2d[i][1] > maxv[1]) { | |||||
| maxv[1] = points2d[i][1]; | |||||
| } | |||||
| } | |||||
| /* If not expanded, use a perfect square */ | |||||
| if (expand == false) { | |||||
| if (maxv[0] > maxv[1]) { | |||||
| maxv[1] = maxv[0]; | |||||
| } | |||||
| else { | |||||
| maxv[0] = maxv[1]; | |||||
| } | |||||
| } | |||||
| } | |||||
| /* calc texture coordinates using flat projected points */ | |||||
| static void gp_calc_stroke_text_coordinates(const float(*points2d)[2], int totpoints, float minv[2], float maxv[2], float(*r_uv)[2]) | |||||
| { | |||||
| float d[2]; | |||||
| d[0] = maxv[0] - minv[0]; | |||||
| d[1] = maxv[1] - minv[1]; | |||||
| for (int i = 0; i < totpoints; i++) { | |||||
| r_uv[i][0] = (points2d[i][0] - minv[0]) / d[0]; | |||||
| r_uv[i][1] = (points2d[i][1] - minv[1]) / d[1]; | |||||
| } | |||||
| } | |||||
| /* Get points of stroke always flat to view not affected by camera view or view position */ | /* Get points of stroke always flat to view not affected by camera view or view position */ | ||||
| static void gp_stroke_2d_flat(const bGPDspoint *points, int totpoints, float(*points2d)[2], int *r_direction) | static void gp_stroke_2d_flat(const bGPDspoint *points, int totpoints, float(*points2d)[2], int *r_direction) | ||||
| { | { | ||||
| const bGPDspoint *pt0 = &points[0]; | const bGPDspoint *pt0 = &points[0]; | ||||
| const bGPDspoint *pt1 = &points[1]; | const bGPDspoint *pt1 = &points[1]; | ||||
| const bGPDspoint *pt3 = &points[(int)(totpoints * 0.75)]; | const bGPDspoint *pt3 = &points[(int)(totpoints * 0.75)]; | ||||
| Show All 29 Lines | for (int i = 0; i < totpoints; i++) { | ||||
| points2d[i][0] = dot_v3v3(loc, locx); | points2d[i][0] = dot_v3v3(loc, locx); | ||||
| points2d[i][1] = dot_v3v3(loc, locy); | points2d[i][1] = dot_v3v3(loc, locy); | ||||
| } | } | ||||
| /* Concave (-1), Convex (1), or Autodetect (0)? */ | /* Concave (-1), Convex (1), or Autodetect (0)? */ | ||||
| *r_direction = (int)locy[2]; | *r_direction = (int)locy[2]; | ||||
| } | } | ||||
| /* Triangulate stroke for high quality fill (this is done only if cache is null or stroke was modified) */ | /* Triangulate stroke for high quality fill (this is done only if cache is null or stroke was modified) */ | ||||
| static void gp_triangulate_stroke_fill(bGPDstroke *gps) | static void gp_triangulate_stroke_fill(bGPDstroke *gps) | ||||
| { | { | ||||
| BLI_assert(gps->totpoints >= 3); | BLI_assert(gps->totpoints >= 3); | ||||
| /* allocate memory for temporary areas */ | /* allocate memory for temporary areas */ | ||||
| gps->tot_triangles = gps->totpoints - 2; | gps->tot_triangles = gps->totpoints - 2; | ||||
| unsigned int (*tmp_triangles)[3] = MEM_mallocN(sizeof(*tmp_triangles) * gps->tot_triangles, "GP Stroke temp triangulation"); | unsigned int (*tmp_triangles)[3] = MEM_mallocN(sizeof(*tmp_triangles) * gps->tot_triangles, "GP Stroke temp triangulation"); | ||||
| float (*points2d)[2] = MEM_mallocN(sizeof(*points2d) * gps->totpoints, "GP Stroke temp 2d points"); | float (*points2d)[2] = MEM_mallocN(sizeof(*points2d) * gps->totpoints, "GP Stroke temp 2d points"); | ||||
| float(*uv)[2] = MEM_mallocN(sizeof(*uv) * gps->totpoints, "GP Stroke temp 2d uv data"); | |||||
| int direction = 0; | int direction = 0; | ||||
| /* convert to 2d and triangulate */ | /* convert to 2d and triangulate */ | ||||
| gp_stroke_2d_flat(gps->points, gps->totpoints, points2d, &direction); | gp_stroke_2d_flat(gps->points, gps->totpoints, points2d, &direction); | ||||
| BLI_polyfill_calc(points2d, (unsigned int)gps->totpoints, direction, tmp_triangles); | BLI_polyfill_calc(points2d, (unsigned int)gps->totpoints, direction, tmp_triangles); | ||||
| /* calc texture coordinates automatically */ | |||||
| float minv[2]; | |||||
| float maxv[2]; | |||||
| /* first needs bounding box data */ | |||||
| gp_calc_2d_bounding_box((const float(*)[2])points2d, gps->totpoints, minv, maxv, false); | |||||
| /* calc uv data */ | |||||
| gp_calc_stroke_text_coordinates((const float(*)[2])points2d, gps->totpoints, minv, maxv, uv); | |||||
| /* Number of triangles */ | /* Number of triangles */ | ||||
| gps->tot_triangles = gps->totpoints - 2; | gps->tot_triangles = gps->totpoints - 2; | ||||
| /* save triangulation data in stroke cache */ | /* save triangulation data in stroke cache */ | ||||
| if (gps->tot_triangles > 0) { | if (gps->tot_triangles > 0) { | ||||
| if (gps->triangles == NULL) { | if (gps->triangles == NULL) { | ||||
| gps->triangles = MEM_callocN(sizeof(*gps->triangles) * gps->tot_triangles, "GP Stroke triangulation"); | gps->triangles = MEM_callocN(sizeof(*gps->triangles) * gps->tot_triangles, "GP Stroke triangulation"); | ||||
| } | } | ||||
| else { | else { | ||||
| gps->triangles = MEM_recallocN(gps->triangles, sizeof(*gps->triangles) * gps->tot_triangles); | gps->triangles = MEM_recallocN(gps->triangles, sizeof(*gps->triangles) * gps->tot_triangles); | ||||
| } | } | ||||
| for (int i = 0; i < gps->tot_triangles; i++) { | for (int i = 0; i < gps->tot_triangles; i++) { | ||||
| memcpy(gps->triangles[i].verts, tmp_triangles[i], sizeof(uint[3])); | bGPDtriangle *stroke_triangle = &gps->triangles[i]; | ||||
| memcpy(stroke_triangle->verts, tmp_triangles[i], sizeof(uint[3])); | |||||
| /* copy texture coordinates */ | |||||
| copy_v2_v2(stroke_triangle->uv[0], uv[tmp_triangles[i][0]]); | |||||
| copy_v2_v2(stroke_triangle->uv[1], uv[tmp_triangles[i][1]]); | |||||
| copy_v2_v2(stroke_triangle->uv[2], uv[tmp_triangles[i][2]]); | |||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* No triangles needed - Free anything allocated previously */ | /* No triangles needed - Free anything allocated previously */ | ||||
| if (gps->triangles) | if (gps->triangles) | ||||
| MEM_freeN(gps->triangles); | MEM_freeN(gps->triangles); | ||||
| gps->triangles = NULL; | gps->triangles = NULL; | ||||
| } | } | ||||
| /* disable recalculation flag */ | /* disable recalculation flag */ | ||||
| if (gps->flag & GP_STROKE_RECALC_CACHES) { | if (gps->flag & GP_STROKE_RECALC_CACHES) { | ||||
| gps->flag &= ~GP_STROKE_RECALC_CACHES; | gps->flag &= ~GP_STROKE_RECALC_CACHES; | ||||
| } | } | ||||
| /* clear memory */ | /* clear memory */ | ||||
| if (tmp_triangles) MEM_freeN(tmp_triangles); | MEM_SAFE_FREE(tmp_triangles); | ||||
| if (points2d) MEM_freeN(points2d); | MEM_SAFE_FREE(points2d); | ||||
| MEM_SAFE_FREE(uv); | |||||
| } | } | ||||
| /* add a new fill point and texture coordinates to vertex buffer */ | |||||
| static void gp_add_filldata_tobuffer( | |||||
| const bGPDspoint *pt, const float uv[2], uint 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]; | |||||
| 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 */ | |||||
| } | |||||
| immAttrib2f(texcoord, uv[0], uv[1]); /* texture coordinates */ | |||||
| immVertex3fv(pos, fpt); /* position */ | |||||
| } | |||||
| /* 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; | |||||
| iuser.ok = true; | |||||
| ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock); | |||||
| if (ibuf == NULL || ibuf->rect == NULL) { | |||||
| BKE_image_release_ibuf(image, ibuf, NULL); | |||||
| return (int)GL_INVALID_OPERATION; | |||||
| } | |||||
| GPU_create_gl_tex(bind, ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, GL_TEXTURE_2D, | |||||
| false, false, image); | |||||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |||||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |||||
| if (flag & GP_STYLE_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; | |||||
| } | |||||
| /* draw fills for shapes */ | /* draw fills for shapes */ | ||||
| static void gp_draw_stroke_fill( | static void gp_draw_stroke_fill( | ||||
| bGPdata *gpd, bGPDstroke *gps, | bGPdata *gpd, bGPDstroke *gps, | ||||
| int offsx, int offsy, int winx, int winy, const float diff_mat[4][4], const float color[4]) | int offsx, int offsy, int winx, int winy, const float diff_mat[4][4], const float color[4]) | ||||
| { | { | ||||
| float fpt[3]; | |||||
| BLI_assert(gps->totpoints >= 3); | BLI_assert(gps->totpoints >= 3); | ||||
| Material *ma = gpd->mat[gps->mat_nr]; | |||||
| MaterialGPencilStyle *gp_style = ma->gp_style; | |||||
| bGPDpalettecolor *palcolor = ED_gpencil_stroke_getcolor(gpd, gps); | |||||
| /* 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) */ | /* 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)) { | if ((gps->flag & GP_STROKE_RECALC_CACHES) || (gps->tot_triangles == 0) || (gps->triangles == NULL)) { | ||||
| gp_triangulate_stroke_fill(gps); | gp_triangulate_stroke_fill(gps); | ||||
| } | } | ||||
| BLI_assert(gps->tot_triangles >= 1); | BLI_assert(gps->tot_triangles >= 1); | ||||
| unsigned int pos; | Gwn_VertFormat *format = immVertexFormat(); | ||||
| if (gps->flag & GP_STROKE_3DSPACE) { | unsigned pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT); | ||||
| pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT); | unsigned texcoord = GWN_vertformat_attr_add(format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); | ||||
| immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | immBindBuiltinProgram(GPU_SHADER_GPENCIL_FILL); | ||||
| } | |||||
| else { | |||||
| pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); | |||||
| immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | |||||
| } | |||||
| immUniformColor4fv(color); | immUniformColor4fv(color); | ||||
| immUniform4fv("color2", gp_style->mix_rgba); | |||||
| immUniform1i("fill_type", gp_style->fill_style); | |||||
| immUniform1f("mix_factor", gp_style->mix_factor); | |||||
| immUniform1f("gradient_angle", gp_style->gradient_angle); | |||||
| immUniform1f("gradient_radius", gp_style->gradient_radius); | |||||
| immUniform1f("gradient_boxsize", gp_style->gradient_boxsize); | |||||
| immUniform2fv("gradient_scale", gp_style->gradient_scale); | |||||
| immUniform2fv("gradient_shift", gp_style->gradient_shift); | |||||
| immUniform1f("texture_angle", gp_style->texture_angle); | |||||
| immUniform2fv("texture_scale", gp_style->texture_scale); | |||||
| immUniform2fv("texture_offset", gp_style->texture_offset); | |||||
| immUniform1f("texture_opacity", gp_style->texture_opacity); | |||||
| immUniform1i("t_mix", gp_style->flag & GP_STYLE_COLOR_TEX_MIX ? 1 : 0); | |||||
| immUniform1i("t_flip", gp_style->flag & GP_STYLE_COLOR_FLIP_FILL ? 1 : 0); | |||||
| /* image texture */ | |||||
| if ((gp_style->fill_style == GP_STYLE_FILL_STYLE_TEXTURE) || (gp_style->flag & GP_STYLE_COLOR_TEX_MIX)) { | |||||
| gp_set_filling_texture(gp_style->ima, gp_style->flag); | |||||
| } | |||||
| /* Draw all triangles for filling the polygon (cache must be calculated before) */ | /* Draw all triangles for filling the polygon (cache must be calculated before) */ | ||||
| immBegin(GWN_PRIM_TRIS, gps->tot_triangles * 3); | immBegin(GWN_PRIM_TRIS, gps->tot_triangles * 3); | ||||
| /* TODO: use batch instead of immediate mode, to share vertices */ | /* TODO: use batch instead of immediate mode, to share vertices */ | ||||
| bGPDtriangle *stroke_triangle = gps->triangles; | const bGPDtriangle *stroke_triangle = gps->triangles; | ||||
| bGPDspoint *pt; | |||||
| 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); | |||||
| immVertex3fv(pos, fpt); | |||||
| } | |||||
| } | |||||
| } | |||||
| else { | |||||
| for (int i = 0; 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++) { | for (int j = 0; j < 3; j++) { | ||||
| float co[2]; | gp_add_filldata_tobuffer( | ||||
| pt = &gps->points[stroke_triangle->verts[j]]; | &gps->points[stroke_triangle->verts[j]], stroke_triangle->uv[j], | ||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | pos, texcoord, gps->flag, | ||||
| gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co); | offsx, offsy, winx, winy, diff_mat); | ||||
| immVertex3fv(pos, fpt); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| immEnd(); | immEnd(); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| } | } | ||||
| } | |||||
| /* ----- Existing Strokes Drawing (3D and Point) ------ */ | /* ----- Existing Strokes Drawing (3D and Point) ------ */ | ||||
| /* draw a given stroke - just a single dot (only one point) */ | /* draw a given stroke - just a single dot (only one point) */ | ||||
| static void gp_draw_stroke_point( | static void gp_draw_stroke_point( | ||||
| const bGPDspoint *points, short thickness, short UNUSED(dflag), short sflag, | const bGPDspoint *points, short thickness, short UNUSED(dflag), short sflag, | ||||
| int offsx, int offsy, int winx, int winy, const float diff_mat[4][4], const float ink[4]) | int offsx, int offsy, int winx, int winy, const float diff_mat[4][4], const float ink[4]) | ||||
| { | { | ||||
| Show All 24 Lines | static void gp_draw_stroke_point( | ||||
| immBegin(GWN_PRIM_POINTS, 1); | immBegin(GWN_PRIM_POINTS, 1); | ||||
| immVertex3fv(pos, fpt); | immVertex3fv(pos, fpt); | ||||
| immEnd(); | immEnd(); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| } | } | ||||
| /* draw a given stroke in 3d (i.e. in 3d-space), using simple ogl lines */ | /* draw a given stroke in 3d (i.e. in 3d-space) */ | ||||
| static void gp_draw_stroke_3d(const bGPDspoint *points, int totpoints, short thickness, bool UNUSED(debug), | static void gp_draw_stroke_3d(tGPDdraw *tgpw, short thickness, const float ink[4], bool cyclic) | ||||
| short UNUSED(sflag), const float diff_mat[4][4], const float ink[4], bool cyclic) | |||||
| { | { | ||||
| bGPDspoint *points = tgpw->gps->points; | |||||
| int totpoints = tgpw->gps->totpoints; | |||||
| const float viewport[2] = { (float)tgpw->winx, (float)tgpw->winy }; | |||||
| float curpressure = points[0].pressure; | float curpressure = points[0].pressure; | ||||
| float fpt[3]; | float fpt[3]; | ||||
| float cyclic_fpt[3]; | |||||
| int draw_points = 0; | |||||
| /* if cyclic needs one vertex more */ | |||||
| int cyclic_add = 0; | |||||
| if (cyclic) { | |||||
| ++cyclic_add; | |||||
| } | |||||
| /* if cyclic needs more vertex */ | |||||
| int cyclic_add = (cyclic) ? 1 : 0; | |||||
| Gwn_VertFormat *format = immVertexFormat(); | Gwn_VertFormat *format = immVertexFormat(); | ||||
| unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT); | unsigned pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT); | ||||
| unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT); | unsigned color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT); | ||||
| unsigned thickattrib = GWN_vertformat_attr_add(format, "thickness", GWN_COMP_F32, 1, GWN_FETCH_FLOAT); | |||||
| immBindBuiltinProgram(GPU_SHADER_3D_SMOOTH_COLOR); | |||||
| immBindBuiltinProgram(GPU_SHADER_GPENCIL_STROKE); | |||||
| /* TODO: implement this with a geometry shader to draw one continuous tapered stroke */ | immUniform2fv("Viewport", viewport); | ||||
| immUniform1f("pixsize", tgpw->rv3d->pixsize); | |||||
| immUniform1f("pixelsize", U.pixelsize); | |||||
| float obj_scale = (tgpw->ob->size[0] + tgpw->ob->size[1] + tgpw->ob->size[2]) / 3.0f; | |||||
| immUniform1f("objscale", obj_scale); | |||||
| int keep_size = (int)((tgpw->gpd) && (tgpw->gpd->flag & GP_DATA_STROKE_KEEPTHICKNESS)); | |||||
| immUniform1i("keep_size", keep_size); | |||||
| immUniform1i("pixfactor", tgpw->gpd->pixfactor); | |||||
| immUniform1i("xraymode", tgpw->gpd->xray_mode); | |||||
| /* draw stroke curve */ | /* draw stroke curve */ | ||||
| glLineWidth(max_ff(curpressure * thickness, 1.0f)); | glLineWidth(max_ff(curpressure * thickness, 1.0f)); | ||||
| immBeginAtMost(GWN_PRIM_LINE_STRIP, totpoints + cyclic_add); | immBeginAtMost(GWN_PRIM_LINE_STRIP_ADJ, totpoints + cyclic_add + 2); | ||||
| const bGPDspoint *pt = points; | const bGPDspoint *pt = points; | ||||
| for (int i = 0; i < totpoints; i++, pt++) { | |||||
| gp_set_point_varying_color(pt, ink, color); | |||||
| /* if there was a significant pressure change, stop the curve, change the thickness of the stroke, | for (int i = 0; i < totpoints; i++, pt++) { | ||||
| * and continue drawing again (since line-width cannot change in middle of GL_LINE_STRIP) | /* first point for adjacency (not drawn) */ | ||||
| * Note: we want more visible levels of pressures when thickness is bigger. | if (i == 0) { | ||||
| */ | gp_set_point_varying_color(points, ink, color); | ||||
| if (fabsf(pt->pressure - curpressure) > 0.2f / (float)thickness) { | immAttrib1f(thickattrib, max_ff(curpressure * thickness, 1.0f)); | ||||
| /* if the pressure changes before get at least 2 vertices, need to repeat last point to avoid assert in immEnd() */ | if ((cyclic) && (totpoints > 2)) { | ||||
| if (draw_points < 2) { | mul_v3_m4v3(fpt, tgpw->diff_mat, &(points + totpoints - 1)->x); | ||||
| const bGPDspoint *pt2 = pt - 1; | |||||
| mul_v3_m4v3(fpt, diff_mat, &pt2->x); | |||||
| immVertex3fv(pos, fpt); | |||||
| } | } | ||||
| immEnd(); | else { | ||||
| draw_points = 0; | mul_v3_m4v3(fpt, tgpw->diff_mat, &(points + 1)->x); | ||||
| curpressure = pt->pressure; | |||||
| glLineWidth(max_ff(curpressure * thickness, 1.0f)); | |||||
| immBeginAtMost(GWN_PRIM_LINE_STRIP, totpoints - i + 1 + cyclic_add); | |||||
| /* need to roll-back one point to ensure that there are no gaps in the stroke */ | |||||
| if (i != 0) { | |||||
| const bGPDspoint *pt2 = pt - 1; | |||||
| mul_v3_m4v3(fpt, diff_mat, &pt2->x); | |||||
| gp_set_point_varying_color(pt2, ink, color); | |||||
| immVertex3fv(pos, fpt); | |||||
| ++draw_points; | |||||
| } | } | ||||
| mul_v3_fl(fpt, -1.0f); | |||||
| immVertex3fv(pos, fpt); | |||||
| } | } | ||||
| /* set point */ | |||||
| /* now the point we want */ | gp_set_point_varying_color(pt, ink, color); | ||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | immAttrib1f(thickattrib, max_ff(curpressure * thickness, 1.0f)); | ||||
| mul_v3_m4v3(fpt, tgpw->diff_mat, &pt->x); | |||||
| immVertex3fv(pos, fpt); | immVertex3fv(pos, fpt); | ||||
| ++draw_points; | |||||
| if (cyclic && i == 0) { | curpressure = pt->pressure; | ||||
| /* save first point to use in cyclic */ | |||||
| copy_v3_v3(cyclic_fpt, fpt); | |||||
| } | |||||
| } | } | ||||
| if (cyclic) { | if (cyclic && totpoints > 2) { | ||||
| /* draw line to first point to complete the cycle */ | /* draw line to first point to complete the cycle */ | ||||
| immVertex3fv(pos, cyclic_fpt); | immAttrib1f(thickattrib, max_ff(points->pressure * thickness, 1.0f)); | ||||
| ++draw_points; | mul_v3_m4v3(fpt, tgpw->diff_mat, &points->x); | ||||
| } | immVertex3fv(pos, fpt); | ||||
| /* if less of two points, need to repeat last point to avoid assert in immEnd() */ | /* now add adjacency point (not drawn) */ | ||||
| if (draw_points < 2) { | immAttrib1f(thickattrib, max_ff((points + 1)->pressure * thickness, 1.0f)); | ||||
| const bGPDspoint *pt2 = pt - 1; | mul_v3_m4v3(fpt, tgpw->diff_mat, &(points + 1)->x); | ||||
| mul_v3_m4v3(fpt, diff_mat, &pt2->x); | immVertex3fv(pos, fpt); | ||||
| gp_set_point_varying_color(pt2, ink, color); | } | ||||
| /* last adjacency point (not drawn) */ | |||||
| else { | |||||
| gp_set_point_varying_color(points + totpoints - 1, ink, color); | |||||
| immAttrib1f(thickattrib, max_ff(curpressure * thickness, 1.0f)); | |||||
| mul_v3_m4v3(fpt, tgpw->diff_mat, &(points + totpoints - 2)->x); | |||||
| mul_v3_fl(fpt, -1.0f); | |||||
| immVertex3fv(pos, fpt); | immVertex3fv(pos, fpt); | ||||
| } | } | ||||
| immEnd(); | immEnd(); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| } | } | ||||
| /* ----- Fancy 2D-Stroke Drawing ------ */ | /* ----- Fancy 2D-Stroke Drawing ------ */ | ||||
| ▲ Show 20 Lines • Show All 202 Lines • ▼ Show 20 Lines | static bool gp_can_draw_stroke(const bGPDstroke *gps, const int dflag) | ||||
| if ((gps->points == NULL) || (gps->totpoints < 1)) | if ((gps->points == NULL) || (gps->totpoints < 1)) | ||||
| return false; | return false; | ||||
| /* stroke can be drawn */ | /* stroke can be drawn */ | ||||
| return true; | return true; | ||||
| } | } | ||||
| /* draw a set of strokes */ | /* draw a set of strokes */ | ||||
| static void gp_draw_strokes( | static void gp_draw_strokes(tGPDdraw *tgpw) | ||||
| bGPdata *gpd, const bGPDframe *gpf, int offsx, int offsy, int winx, int winy, int dflag, | |||||
| bool debug, short lthick, const float opacity, const float tintcolor[4], | |||||
| const bool onion, const bool custonion, const float diff_mat[4][4]) | |||||
| { | { | ||||
| float tcolor[4]; | float tcolor[4]; | ||||
| float tfill[4]; | float tfill[4]; | ||||
| short sthickness; | short sthickness; | ||||
| float ink[4]; | float ink[4]; | ||||
| GPU_enable_program_point_size(); | GPU_enable_program_point_size(); | ||||
| for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { | for (bGPDstroke *gps = tgpw->t_gpf->strokes.first; gps; gps = gps->next) { | ||||
| /* check if stroke can be drawn */ | /* check if stroke can be drawn */ | ||||
| if (gp_can_draw_stroke(gps, dflag) == false) { | if (gp_can_draw_stroke(gps, tgpw->dflag) == false) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* check if the color is visible */ | /* check if the color is visible */ | ||||
| bGPDpalettecolor *palcolor = ED_gpencil_stroke_getcolor(gpd, gps); | Material *ma = tgpw->gpd->mat[gps->mat_nr]; | ||||
| if ((palcolor == NULL) || | MaterialGPencilStyle *gp_style = ma->gp_style; | ||||
| (palcolor->flag & PC_COLOR_HIDE) || | |||||
| if ((gp_style == NULL) || | |||||
| (gp_style->flag & GP_STYLE_COLOR_HIDE) || | |||||
| /* if onion and ghost flag do not draw*/ | /* if onion and ghost flag do not draw*/ | ||||
| (onion && (palcolor->flag & PC_COLOR_ONIONSKIN))) | (tgpw->onion && (gp_style->flag & GP_STYLE_COLOR_ONIONSKIN))) | ||||
| { | |||||
| continue; | |||||
| } | |||||
| /* if disable fill, the colors with fill must be omitted too except fill boundary strokes */ | |||||
| if ((tgpw->disable_fill == 1) && | |||||
| (gp_style->fill_rgba[3] > 0.0f) && | |||||
| ((gps->flag & GP_STROKE_NOFILL) == 0)) | |||||
| { | { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* calculate thickness */ | /* calculate thickness */ | ||||
| sthickness = gps->thickness + lthick; | sthickness = gps->thickness + tgpw->lthick; | ||||
| if (sthickness <= 0) { | if (sthickness <= 0) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* check which stroke-drawer to use */ | /* check which stroke-drawer to use */ | ||||
| if (dflag & GP_DRAWDATA_ONLY3D) { | if (tgpw->dflag & GP_DRAWDATA_ONLY3D) { | ||||
| const int no_xray = (dflag & GP_DRAWDATA_NO_XRAY); | const int no_xray = (tgpw->dflag & GP_DRAWDATA_NO_XRAY); | ||||
| int mask_orig = 0; | int mask_orig = 0; | ||||
| if (no_xray) { | if (no_xray) { | ||||
| glGetIntegerv(GL_DEPTH_WRITEMASK, &mask_orig); | glGetIntegerv(GL_DEPTH_WRITEMASK, &mask_orig); | ||||
| glDepthMask(0); | glDepthMask(0); | ||||
| glEnable(GL_DEPTH_TEST); | glEnable(GL_DEPTH_TEST); | ||||
| /* first arg is normally rv3d->dist, but this isn't | /* first arg is normally rv3d->dist, but this isn't | ||||
| * available here and seems to work quite well without */ | * available here and seems to work quite well without */ | ||||
| bglPolygonOffset(1.0f, 1.0f); | bglPolygonOffset(1.0f, 1.0f); | ||||
| } | } | ||||
| /* 3D Fill */ | /* 3D Fill */ | ||||
| //if ((dflag & GP_DRAWDATA_FILL) && (gps->totpoints >= 3)) { | //if ((dflag & GP_DRAWDATA_FILL) && (gps->totpoints >= 3)) { | ||||
| if (gps->totpoints >= 3) { | if ((gps->totpoints >= 3) && (tgpw->disable_fill != 1)) { | ||||
| /* set color using palette, tint color and opacity */ | /* set color using material, tint color and opacity */ | ||||
| interp_v3_v3v3(tfill, palcolor->fill, tintcolor, tintcolor[3]); | interp_v3_v3v3(tfill, gp_style->fill_rgba, tgpw->tintcolor, tgpw->tintcolor[3]); | ||||
| tfill[3] = palcolor->fill[3] * opacity; | tfill[3] = gp_style->fill_rgba[3] * tgpw->opacity; | ||||
| if (tfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) { | if ((tfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) || (gp_style->fill_style > 0)) { | ||||
| const float *color; | const float *color; | ||||
| if (!onion) { | if (!tgpw->onion) { | ||||
| color = tfill; | color = tfill; | ||||
| } | } | ||||
| else { | else { | ||||
| if (custonion) { | if (tgpw->custonion) { | ||||
| color = tintcolor; | color = tgpw->tintcolor; | ||||
| } | } | ||||
| else { | else { | ||||
| ARRAY_SET_ITEMS(tfill, UNPACK3(palcolor->fill), tintcolor[3]); | ARRAY_SET_ITEMS(tfill, UNPACK3(gp_style->fill_rgba), tgpw->tintcolor[3]); | ||||
| color = tfill; | color = tfill; | ||||
| } | } | ||||
| } | } | ||||
| gp_draw_stroke_fill(gpd, gps, offsx, offsy, winx, winy, diff_mat, color); | gp_draw_stroke_fill(tgpw->gpd, gps, tgpw->offsx, tgpw->offsy, tgpw->winx, tgpw->winy, tgpw->diff_mat, color); | ||||
| } | } | ||||
| } | } | ||||
| /* 3D Stroke */ | /* 3D Stroke */ | ||||
| /* set color using palette, tint color and opacity */ | /* set color using material tint color and opacity */ | ||||
| if (!onion) { | if (!tgpw->onion) { | ||||
| interp_v3_v3v3(tcolor, palcolor->color, tintcolor, tintcolor[3]); | interp_v3_v3v3(tcolor, gp_style->stroke_rgba, tgpw->tintcolor, tgpw->tintcolor[3]); | ||||
| tcolor[3] = palcolor->color[3] * opacity; | tcolor[3] = gp_style->stroke_rgba[3] * tgpw->opacity; | ||||
| copy_v4_v4(ink, tcolor); | copy_v4_v4(ink, tcolor); | ||||
| } | } | ||||
| else { | else { | ||||
| if (custonion) { | if (tgpw->custonion) { | ||||
| copy_v4_v4(ink, tintcolor); | copy_v4_v4(ink, tgpw->tintcolor); | ||||
| } | } | ||||
| else { | else { | ||||
| ARRAY_SET_ITEMS(tcolor, palcolor->color[0], palcolor->color[1], palcolor->color[2], opacity); | ARRAY_SET_ITEMS(tcolor, UNPACK3(gp_style->stroke_rgba), tgpw->opacity); | ||||
| copy_v4_v4(ink, tcolor); | copy_v4_v4(ink, tcolor); | ||||
| } | } | ||||
| } | } | ||||
| if (palcolor->flag & PC_COLOR_VOLUMETRIC) { | if (gp_style->mode == GP_STYLE_MODE_DOTS) { | ||||
| /* volumetric stroke drawing */ | /* volumetric stroke drawing */ | ||||
| if (tgpw->disable_fill != 1) { | |||||
| gp_draw_stroke_volumetric_3d(gps->points, gps->totpoints, sthickness, ink); | gp_draw_stroke_volumetric_3d(gps->points, gps->totpoints, sthickness, ink); | ||||
| } | } | ||||
| } | |||||
| else { | else { | ||||
| /* 3D Lines - OpenGL primitives-based */ | /* 3D Lines - OpenGL primitives-based */ | ||||
| if (gps->totpoints == 1) { | if (gps->totpoints == 1) { | ||||
| gp_draw_stroke_point(gps->points, sthickness, dflag, gps->flag, offsx, offsy, winx, winy, | if (tgpw->disable_fill != 1) { | ||||
| diff_mat, ink); | gp_draw_stroke_point(gps->points, sthickness, tgpw->dflag, gps->flag, | ||||
| tgpw->offsx, tgpw->offsy, tgpw->winx, tgpw->winy, | |||||
| tgpw->diff_mat, ink); | |||||
| } | |||||
| } | } | ||||
| else { | else { | ||||
| gp_draw_stroke_3d(gps->points, gps->totpoints, sthickness, debug, gps->flag, | tgpw->gps = gps; | ||||
| diff_mat, ink, gps->flag & GP_STROKE_CYCLIC); | gp_draw_stroke_3d(tgpw, sthickness, ink, gps->flag & GP_STROKE_CYCLIC); | ||||
| } | } | ||||
| } | } | ||||
| if (no_xray) { | if (no_xray) { | ||||
| glDepthMask(mask_orig); | glDepthMask(mask_orig); | ||||
| glDisable(GL_DEPTH_TEST); | glDisable(GL_DEPTH_TEST); | ||||
| bglPolygonOffset(0.0, 0.0); | bglPolygonOffset(0.0, 0.0); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* 2D - Fill */ | /* 2D - Fill */ | ||||
| if (gps->totpoints >= 3) { | if (gps->totpoints >= 3) { | ||||
| /* set color using palette, tint color and opacity */ | /* set color using material, tint color and opacity */ | ||||
| interp_v3_v3v3(tfill, palcolor->fill, tintcolor, tintcolor[3]); | interp_v3_v3v3(tfill, gp_style->fill_rgba, tgpw->tintcolor, tgpw->tintcolor[3]); | ||||
| tfill[3] = palcolor->fill[3] * opacity; | tfill[3] = gp_style->fill_rgba[3] * tgpw->opacity; | ||||
| if (tfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) { | if ((tfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) || (gp_style->fill_style > 0)) { | ||||
| const float *color; | const float *color; | ||||
| if (!onion) { | if (!tgpw->onion) { | ||||
| color = tfill; | color = tfill; | ||||
| } | } | ||||
| else { | else { | ||||
| if (custonion) { | if (tgpw->custonion) { | ||||
| color = tintcolor; | color = tgpw->tintcolor; | ||||
| } | } | ||||
| else { | else { | ||||
| ARRAY_SET_ITEMS(tfill, palcolor->fill[0], palcolor->fill[1], palcolor->fill[2], | ARRAY_SET_ITEMS(tfill, UNPACK3(gp_style->fill_rgba), tgpw->tintcolor[3]); | ||||
| tintcolor[3]); | |||||
| color = tfill; | color = tfill; | ||||
| } | } | ||||
| } | } | ||||
| gp_draw_stroke_fill(gpd, gps, offsx, offsy, winx, winy, diff_mat, color); | gp_draw_stroke_fill(tgpw->gpd, gps, tgpw->offsx, tgpw->offsy, tgpw->winx, tgpw->winy, tgpw->diff_mat, color); | ||||
| } | } | ||||
| } | } | ||||
| /* 2D Strokes... */ | /* 2D Strokes... */ | ||||
| /* set color using palette, tint color and opacity */ | /* set color using material, tint color and opacity */ | ||||
| if (!onion) { | if (!tgpw->onion) { | ||||
| interp_v3_v3v3(tcolor, palcolor->color, tintcolor, tintcolor[3]); | interp_v3_v3v3(tcolor, gp_style->stroke_rgba, tgpw->tintcolor, tgpw->tintcolor[3]); | ||||
| tcolor[3] = palcolor->color[3] * opacity; | tcolor[3] = gp_style->stroke_rgba[3] * tgpw->opacity; | ||||
| copy_v4_v4(ink, tcolor); | copy_v4_v4(ink, tcolor); | ||||
| } | } | ||||
| else { | else { | ||||
| if (custonion) { | if (tgpw->custonion) { | ||||
| copy_v4_v4(ink, tintcolor); | copy_v4_v4(ink, tgpw->tintcolor); | ||||
| } | } | ||||
| else { | else { | ||||
| ARRAY_SET_ITEMS(tcolor, palcolor->color[0], palcolor->color[1], palcolor->color[2], opacity); | ARRAY_SET_ITEMS(tcolor, UNPACK3(gp_style->stroke_rgba), tgpw->opacity); | ||||
| copy_v4_v4(ink, tcolor); | copy_v4_v4(ink, tcolor); | ||||
| } | } | ||||
| } | } | ||||
| if (palcolor->flag & PC_COLOR_VOLUMETRIC) { | if (gp_style->mode == GP_STYLE_MODE_DOTS) { | ||||
| /* blob/disk-based "volumetric" drawing */ | /* blob/disk-based "volumetric" drawing */ | ||||
| gp_draw_stroke_volumetric_2d(gps->points, gps->totpoints, sthickness, dflag, gps->flag, | gp_draw_stroke_volumetric_2d(gps->points, gps->totpoints, sthickness, tgpw->dflag, gps->flag, | ||||
| offsx, offsy, winx, winy, diff_mat, ink); | tgpw->offsx, tgpw->offsy, tgpw->winx, tgpw->winy, tgpw->diff_mat, ink); | ||||
| } | } | ||||
| else { | else { | ||||
| /* normal 2D strokes */ | /* normal 2D strokes */ | ||||
| if (gps->totpoints == 1) { | if (gps->totpoints == 1) { | ||||
| gp_draw_stroke_point(gps->points, sthickness, dflag, gps->flag, offsx, offsy, winx, winy, | gp_draw_stroke_point(gps->points, sthickness, tgpw->dflag, gps->flag, tgpw->offsx, tgpw->offsy, tgpw->winx, tgpw->winy, | ||||
| diff_mat, ink); | tgpw->diff_mat, ink); | ||||
| } | } | ||||
| else { | else { | ||||
| gp_draw_stroke_2d(gps->points, gps->totpoints, sthickness, dflag, gps->flag, debug, | gp_draw_stroke_2d(gps->points, gps->totpoints, sthickness, tgpw->dflag, gps->flag, false, | ||||
| offsx, offsy, winx, winy, diff_mat, ink); | tgpw->offsx, tgpw->offsy, tgpw->winx, tgpw->winy, tgpw->diff_mat, ink); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| GPU_disable_program_point_size(); | GPU_disable_program_point_size(); | ||||
| } | } | ||||
| Show All 32 Lines | for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { | ||||
| /* Optimisation: only draw points for selected strokes | /* Optimisation: only draw points for selected strokes | ||||
| * We assume that selected points can only occur in | * We assume that selected points can only occur in | ||||
| * strokes that are selected too. | * strokes that are selected too. | ||||
| */ | */ | ||||
| if ((gps->flag & GP_STROKE_SELECT) == 0) | if ((gps->flag & GP_STROKE_SELECT) == 0) | ||||
| continue; | continue; | ||||
| /* verify palette color lock */ | /* verify color lock */ | ||||
| { | { | ||||
| bGPDpalettecolor *palcolor = ED_gpencil_stroke_getcolor(gpd, gps); | Material *ma = gpd->mat[gps->mat_nr]; | ||||
| if (palcolor != NULL) { | MaterialGPencilStyle *gp_style = ma->gp_style; | ||||
| if (palcolor->flag & PC_COLOR_HIDE) { | |||||
| if (gp_style != NULL) { | |||||
| if (gp_style->flag & GP_STYLE_COLOR_HIDE) { | |||||
| continue; | continue; | ||||
| } | } | ||||
| if (((lflag & GP_LAYER_UNLOCK_COLOR) == 0) && (palcolor->flag & PC_COLOR_LOCKED)) { | if (((lflag & GP_LAYER_UNLOCK_COLOR) == 0) && (gp_style->flag & GP_STYLE_COLOR_LOCKED)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Get size of verts: | /* Get size of verts: | ||||
| * - The selected state needs to be larger than the unselected state so that | * - The selected state needs to be larger than the unselected state so that | ||||
| * they stand out more. | * they stand out more. | ||||
| * - We use the theme setting for size of the unselected verts | * - We use the theme setting for size of the unselected verts | ||||
| */ | */ | ||||
| float bsize = UI_GetThemeValuef(TH_GP_VERTEX_SIZE); | float bsize = UI_GetThemeValuef(TH_GP_VERTEX_SIZE); | ||||
| float vsize; | float vsize; | ||||
| if ((int)bsize > 8) { | if ((int)bsize > 8) { | ||||
| vsize = 10.0f; | vsize = 10.0f; | ||||
| bsize = 8.0f; | bsize = 8.0f; | ||||
| } | } | ||||
| else { | else { | ||||
| vsize = bsize + 2; | vsize = bsize + 2; | ||||
| } | } | ||||
| /* for now, we assume that the base color of the points is not too close to the real color */ | /* for now, we assume that the base color of the points is not too close to the real color */ | ||||
| /* set color using palette */ | /* set color using material */ | ||||
| bGPDpalettecolor *palcolor = ED_gpencil_stroke_getcolor(gpd, gps); | Material *ma = gpd->mat[gps->mat_nr]; | ||||
| MaterialGPencilStyle *gp_style = ma->gp_style; | |||||
| float selectColor[4]; | float selectColor[4]; | ||||
| UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, selectColor); | UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, selectColor); | ||||
| selectColor[3] = alpha; | selectColor[3] = alpha; | ||||
| Gwn_VertFormat *format = immVertexFormat(); | Gwn_VertFormat *format = immVertexFormat(); | ||||
| unsigned int pos; /* specified later */ | unsigned int pos; /* specified later */ | ||||
| unsigned int size = GWN_vertformat_attr_add(format, "size", GWN_COMP_F32, 1, GWN_FETCH_FLOAT); | unsigned int size = GWN_vertformat_attr_add(format, "size", GWN_COMP_F32, 1, GWN_FETCH_FLOAT); | ||||
| unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 3, GWN_FETCH_FLOAT); | unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT); | ||||
| if (gps->flag & GP_STROKE_3DSPACE) { | if (gps->flag & GP_STROKE_3DSPACE) { | ||||
| pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT); | pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT); | ||||
| immBindBuiltinProgram(GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR); | immBindBuiltinProgram(GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR); | ||||
| } | } | ||||
| else { | else { | ||||
| pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); | pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); | ||||
| immBindBuiltinProgram(GPU_SHADER_2D_POINT_VARYING_SIZE_VARYING_COLOR); | immBindBuiltinProgram(GPU_SHADER_2D_POINT_VARYING_SIZE_VARYING_COLOR); | ||||
| Show All 19 Lines | for (int i = 0; i < gps->totpoints; i++, pt++) { | ||||
| immAttrib3f(color, 1.0f, 0.0f, 0.0f); | immAttrib3f(color, 1.0f, 0.0f, 0.0f); | ||||
| immAttrib1f(size, vsize + 1); | immAttrib1f(size, vsize + 1); | ||||
| } | } | ||||
| else if (pt->flag & GP_SPOINT_SELECT) { | else if (pt->flag & GP_SPOINT_SELECT) { | ||||
| immAttrib3fv(color, selectColor); | immAttrib3fv(color, selectColor); | ||||
| immAttrib1f(size, vsize); | immAttrib1f(size, vsize); | ||||
| } | } | ||||
| else { | else { | ||||
| immAttrib3fv(color, palcolor->color); | immAttrib3fv(color, gp_style->stroke_rgba); | ||||
| immAttrib1f(size, bsize); | immAttrib1f(size, bsize); | ||||
| } | } | ||||
| /* then position */ | /* then position */ | ||||
| if (gps->flag & GP_STROKE_3DSPACE) { | if (gps->flag & GP_STROKE_3DSPACE) { | ||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | mul_v3_m4v3(fpt, diff_mat, &pt->x); | ||||
| immVertex3fv(pos, fpt); | immVertex3fv(pos, fpt); | ||||
| } | } | ||||
| Show All 24 Lines | |||||
| #endif | #endif | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* ----- General Drawing ------ */ | /* ----- General Drawing ------ */ | ||||
| /* draw onion-skinning for a layer */ | /* draw onion-skinning for a layer */ | ||||
| static void gp_draw_onionskins( | static void gp_draw_onionskins(tGPDdraw *tgpw) | ||||
| bGPdata *gpd, const bGPDlayer *gpl, const bGPDframe *gpf, int offsx, int offsy, int winx, int winy, | |||||
| int UNUSED(cfra), int dflag, bool debug, const float diff_mat[4][4]) | |||||
| { | { | ||||
| const float default_color[3] = {UNPACK3(U.gpencil_new_layer_col)}; | const float default_color[3] = {UNPACK3(U.gpencil_new_layer_col)}; | ||||
| const float alpha = 1.0f; | const float alpha = 1.0f; | ||||
| float color[4]; | float color[4]; | ||||
| /* 1) Draw Previous Frames First */ | /* 1) Draw Previous Frames First */ | ||||
| if (gpl->flag & GP_LAYER_GHOST_PREVCOL) { | if (tgpw->gpd->onion_flag & GP_ONION_GHOST_PREVCOL) { | ||||
| copy_v3_v3(color, gpl->gcolor_prev); | copy_v3_v3(color, tgpw->gpl->gcolor_prev); | ||||
| } | } | ||||
| else { | else { | ||||
| copy_v3_v3(color, default_color); | copy_v3_v3(color, default_color); | ||||
| } | } | ||||
| if (gpl->gstep > 0) { | if (tgpw->gpl->gstep > 0) { | ||||
| /* draw previous frames first */ | /* draw previous frames first */ | ||||
| for (bGPDframe *gf = gpf->prev; gf; gf = gf->prev) { | for (bGPDframe *gf = tgpw->gpf->prev; gf; gf = gf->prev) { | ||||
| /* check if frame is drawable */ | /* check if frame is drawable */ | ||||
| if ((gpf->framenum - gf->framenum) <= gpl->gstep) { | if ((tgpw->gpf->framenum - gf->framenum) <= tgpw->gpl->gstep) { | ||||
| /* alpha decreases with distance from curframe index */ | /* alpha decreases with distance from curframe index */ | ||||
| float fac = 1.0f - ((float)(gpf->framenum - gf->framenum) / (float)(gpl->gstep + 1)); | float fac = 1.0f - ((float)(tgpw->gpf->framenum - gf->framenum) / (float)(tgpw->gpl->gstep + 1)); | ||||
| color[3] = alpha * fac * 0.66f; | color[3] = alpha * fac * 0.66f; | ||||
| gp_draw_strokes(gpd, gf, offsx, offsy, winx, winy, dflag, debug, gpl->thickness, 1.0f, color, | |||||
| true, gpl->flag & GP_LAYER_GHOST_PREVCOL, diff_mat); | tgpw->t_gpf = gf; | ||||
| tgpw->opacity = 1.0f; | |||||
| copy_v4_v4(tgpw->tintcolor, color); | |||||
| tgpw->onion = true; | |||||
| tgpw->custonion = tgpw->gpd->onion_flag & GP_ONION_GHOST_PREVCOL; | |||||
| gp_draw_strokes(tgpw); | |||||
| } | } | ||||
| else | else | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| else if (gpl->gstep == 0) { | else if (tgpw->gpl->gstep == 0) { | ||||
| /* draw the strokes for the ghost frames (at half of the alpha set by user) */ | /* draw the strokes for the ghost frames (at half of the alpha set by user) */ | ||||
| if (gpf->prev) { | if (tgpw->gpf->prev) { | ||||
| color[3] = (alpha / 7); | color[3] = (alpha / 7); | ||||
| gp_draw_strokes(gpd, gpf->prev, offsx, offsy, winx, winy, dflag, debug, gpl->thickness, 1.0f, color, | |||||
| true, gpl->flag & GP_LAYER_GHOST_PREVCOL, diff_mat); | tgpw->t_gpf = tgpw->gpf->prev; | ||||
| tgpw->opacity = 1.0f; | |||||
| copy_v4_v4(tgpw->tintcolor, color); | |||||
| tgpw->onion = true; | |||||
| tgpw->custonion = tgpw->gpd->onion_flag & GP_ONION_GHOST_PREVCOL; | |||||
| gp_draw_strokes(tgpw); | |||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* don't draw - disabled */ | /* don't draw - disabled */ | ||||
| } | } | ||||
| /* 2) Now draw next frames */ | /* 2) Now draw next frames */ | ||||
| if (gpl->flag & GP_LAYER_GHOST_NEXTCOL) { | if (tgpw->gpd->onion_flag & GP_ONION_GHOST_NEXTCOL) { | ||||
| copy_v3_v3(color, gpl->gcolor_next); | copy_v3_v3(color, tgpw->gpl->gcolor_next); | ||||
| } | } | ||||
| else { | else { | ||||
| copy_v3_v3(color, default_color); | copy_v3_v3(color, default_color); | ||||
| } | } | ||||
| if (gpl->gstep_next > 0) { | if (tgpw->gpl->gstep_next > 0) { | ||||
| /* now draw next frames */ | /* now draw next frames */ | ||||
| for (bGPDframe *gf = gpf->next; gf; gf = gf->next) { | for (bGPDframe *gf = tgpw->gpf->next; gf; gf = gf->next) { | ||||
| /* check if frame is drawable */ | /* check if frame is drawable */ | ||||
| if ((gf->framenum - gpf->framenum) <= gpl->gstep_next) { | if ((gf->framenum - tgpw->gpf->framenum) <= tgpw->gpl->gstep_next) { | ||||
| /* alpha decreases with distance from curframe index */ | /* alpha decreases with distance from curframe index */ | ||||
| float fac = 1.0f - ((float)(gf->framenum - gpf->framenum) / (float)(gpl->gstep_next + 1)); | float fac = 1.0f - ((float)(gf->framenum - tgpw->gpf->framenum) / (float)(tgpw->gpl->gstep_next + 1)); | ||||
| color[3] = alpha * fac * 0.66f; | color[3] = alpha * fac * 0.66f; | ||||
| gp_draw_strokes(gpd, gf, offsx, offsy, winx, winy, dflag, debug, gpl->thickness, 1.0f, color, | |||||
| true, gpl->flag & GP_LAYER_GHOST_NEXTCOL, diff_mat); | tgpw->t_gpf = gf; | ||||
| tgpw->opacity = 1.0f; | |||||
| copy_v4_v4(tgpw->tintcolor, color); | |||||
| tgpw->onion = true; | |||||
| tgpw->custonion = tgpw->gpd->onion_flag & GP_ONION_GHOST_PREVCOL; | |||||
| gp_draw_strokes(tgpw); | |||||
| } | } | ||||
| else | else | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| else if (gpl->gstep_next == 0) { | else if (tgpw->gpl->gstep_next == 0) { | ||||
| /* draw the strokes for the ghost frames (at half of the alpha set by user) */ | /* draw the strokes for the ghost frames (at half of the alpha set by user) */ | ||||
| if (gpf->next) { | if (tgpw->gpf->next) { | ||||
| color[3] = (alpha / 4); | color[3] = (alpha / 4); | ||||
| gp_draw_strokes(gpd, gpf->next, offsx, offsy, winx, winy, dflag, debug, gpl->thickness, 1.0f, color, | |||||
| true, gpl->flag & GP_LAYER_GHOST_NEXTCOL, diff_mat); | tgpw->t_gpf = tgpw->gpf->next; | ||||
| tgpw->opacity = 1.0f; | |||||
| copy_v4_v4(tgpw->tintcolor, color); | |||||
| tgpw->onion = true; | |||||
| tgpw->custonion = tgpw->gpd->onion_flag & GP_ONION_GHOST_PREVCOL; | |||||
| gp_draw_strokes(tgpw); | |||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* don't draw - disabled */ | /* don't draw - disabled */ | ||||
| } | } | ||||
| } | } | ||||
| /* draw interpolate strokes (used only while operator is running) */ | /* draw interpolate strokes (used only while operator is running) */ | ||||
| void ED_gp_draw_interpolation(tGPDinterpolate *tgpi, const int type) | void ED_gp_draw_interpolation(const bContext *C, tGPDinterpolate *tgpi, const int type) | ||||
| { | { | ||||
| tGPDdraw tgpw; | |||||
| ARegion *ar = CTX_wm_region(C); | |||||
| RegionView3D *rv3d = ar->regiondata; | |||||
| tGPDinterpolate_layer *tgpil; | tGPDinterpolate_layer *tgpil; | ||||
| float diff_mat[4][4]; | Object *obact = CTX_data_active_object(C); | ||||
| float color[4]; | Depsgraph *depsgraph = CTX_data_depsgraph(C); \ | ||||
| int offsx = 0; | float color[4]; | ||||
| int offsy = 0; | |||||
| int winx = tgpi->ar->winx; | |||||
| int winy = tgpi->ar->winy; | |||||
| UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, color); | UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, color); | ||||
| color[3] = 0.6f; | color[3] = 0.6f; | ||||
| int dflag = 0; | int dflag = 0; | ||||
| /* if 3d stuff, enable flags */ | /* if 3d stuff, enable flags */ | ||||
| if (type == REGION_DRAW_POST_VIEW) { | if (type == REGION_DRAW_POST_VIEW) { | ||||
| dflag |= (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_NOSTATUS); | dflag |= (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_NOSTATUS); | ||||
| } | } | ||||
| tgpw.rv3d = rv3d; | |||||
| tgpw.depsgraph = depsgraph; | |||||
| tgpw.ob = obact; | |||||
| tgpw.gpd = tgpi->gpd; | |||||
| tgpw.offsx = 0; | |||||
| tgpw.offsy = 0; | |||||
| tgpw.winx = tgpi->ar->winx; | |||||
| tgpw.winy = tgpi->ar->winy; | |||||
| tgpw.dflag = dflag; | |||||
| /* turn on alpha-blending */ | /* turn on alpha-blending */ | ||||
| glEnable(GL_BLEND); | glEnable(GL_BLEND); | ||||
| for (tgpil = tgpi->ilayers.first; tgpil; tgpil = tgpil->next) { | for (tgpil = tgpi->ilayers.first; tgpil; tgpil = tgpil->next) { | ||||
| /* calculate parent position */ | /* calculate parent position */ | ||||
| ED_gpencil_parent_location(tgpil->gpl, diff_mat); | ED_gpencil_parent_location(depsgraph, obact, tgpi->gpd, tgpil->gpl, tgpw.diff_mat); | ||||
| if (tgpil->interFrame) { | if (tgpil->interFrame) { | ||||
| gp_draw_strokes(tgpi->gpd, tgpil->interFrame, offsx, offsy, winx, winy, dflag, false, | tgpw.gpl = tgpil->gpl; | ||||
| tgpil->gpl->thickness, 1.0f, color, true, true, diff_mat); | tgpw.gpf = tgpil->interFrame; | ||||
| tgpw.t_gpf = tgpil->interFrame; | |||||
| tgpw.lthick = tgpil->gpl->thickness; | |||||
| tgpw.opacity = 1.0; | |||||
| copy_v4_v4(tgpw.tintcolor, color); | |||||
| tgpw.onion = true; | |||||
| tgpw.custonion = true; | |||||
| gp_draw_strokes(&tgpw); | |||||
| } | } | ||||
| } | } | ||||
| glDisable(GL_BLEND); | glDisable(GL_BLEND); | ||||
| } | } | ||||
| /* draw interpolate strokes (used only while operator is running) */ | |||||
| void ED_gp_draw_primitives(const bContext *C, tGPDprimitive *tgpi, const int type) | |||||
| { | |||||
| tGPDdraw tgpw; | |||||
| ARegion *ar = CTX_wm_region(C); | |||||
| RegionView3D *rv3d = ar->regiondata; | |||||
| /* if idle, do not draw */ | |||||
| if (tgpi->flag == 0) { | |||||
| return; | |||||
| } | |||||
| Object *obact = CTX_data_active_object(C); | |||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); \ | |||||
| float color[4]; | |||||
| UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, color); | |||||
| color[3] = 0.6f; | |||||
| int dflag = 0; | |||||
| /* if 3d stuff, enable flags */ | |||||
| if (type == REGION_DRAW_POST_VIEW) { | |||||
| dflag |= (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_NOSTATUS); | |||||
| } | |||||
| tgpw.rv3d = rv3d; | |||||
| tgpw.depsgraph = depsgraph; | |||||
| tgpw.ob = obact; | |||||
| tgpw.gpd = tgpi->gpd; | |||||
| tgpw.offsx = 0; | |||||
| tgpw.offsy = 0; | |||||
| tgpw.winx = tgpi->ar->winx; | |||||
| tgpw.winy = tgpi->ar->winy; | |||||
| tgpw.dflag = dflag; | |||||
| /* turn on alpha-blending */ | |||||
| glEnable(GL_BLEND); | |||||
| /* calculate parent position */ | |||||
| ED_gpencil_parent_location(depsgraph, obact, tgpi->gpd, tgpi->gpl, tgpw.diff_mat); | |||||
| if (tgpi->gpf) { | |||||
| tgpw.gps = tgpi->gpf->strokes.first; | |||||
| if (tgpw.gps->totpoints > 0) { | |||||
| tgpw.gpl = tgpi->gpl; | |||||
| tgpw.gpf = tgpi->gpf; | |||||
| tgpw.t_gpf = tgpi->gpf; | |||||
| tgpw.lthick = tgpi->gpl->thickness; | |||||
| tgpw.opacity = 1.0; | |||||
| copy_v4_v4(tgpw.tintcolor, color); | |||||
| tgpw.onion = true; | |||||
| tgpw.custonion = true; | |||||
| gp_draw_strokes(&tgpw); | |||||
| } | |||||
| } | |||||
| glDisable(GL_BLEND); | |||||
| } | |||||
| /* wrapper to draw strokes for filling operator */ | |||||
| void ED_gp_draw_fill(tGPDdraw *tgpw) | |||||
| { | |||||
| gp_draw_strokes(tgpw); | |||||
| } | |||||
| /* loop over gpencil data layers, drawing them */ | /* loop over gpencil data layers, drawing them */ | ||||
| static void gp_draw_data_layers( | static void gp_draw_data_layers(RegionView3D *rv3d, | ||||
| const bGPDbrush *brush, float alpha, bGPdata *gpd, | const Brush *brush, float alpha, Object *ob, bGPdata *gpd, | ||||
| int offsx, int offsy, int winx, int winy, int cfra, int dflag) | int offsx, int offsy, int winx, int winy, int cfra, int dflag) | ||||
| { | { | ||||
| float diff_mat[4][4]; | float diff_mat[4][4]; | ||||
| tGPDdraw tgpw; | |||||
| tgpw.rv3d = rv3d; | |||||
| tgpw.depsgraph = NULL; /* XXX: This is not used here */ | |||||
| tgpw.ob = ob; | |||||
| tgpw.gpd = gpd; | |||||
| tgpw.gpl = NULL; | |||||
| tgpw.gpf = NULL; | |||||
| tgpw.t_gpf = NULL; | |||||
| tgpw.offsx = offsx; | |||||
| tgpw.offsy = offsy; | |||||
| tgpw.winx = winx; | |||||
| tgpw.winy = winy; | |||||
| tgpw.dflag = dflag; | |||||
| for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | ||||
| /* calculate parent position */ | /* calculate parent position */ | ||||
| ED_gpencil_parent_location(gpl, diff_mat); | ED_gpencil_parent_location(tgpw.depsgraph, ob, gpd, gpl, diff_mat); | ||||
| bool debug = (gpl->flag & GP_LAYER_DRAWDEBUG); | short lthick = brush->size + gpl->thickness; | ||||
| short lthick = brush->thickness + gpl->thickness; | |||||
| /* don't draw layer if hidden */ | /* don't draw layer if hidden */ | ||||
| if (gpl->flag & GP_LAYER_HIDE) | if (gpl->flag & GP_LAYER_HIDE) | ||||
| continue; | continue; | ||||
| /* get frame to draw */ | /* get frame to draw */ | ||||
| bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra, 0); | bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra, 0); | ||||
| if (gpf == NULL) | if (gpf == NULL) | ||||
| Show All 12 Lines | #define GP_DRAWFLAG_APPLY(condition, draw_flag_value) { \ | ||||
| } (void)0 | } (void)0 | ||||
| /* xray... */ | /* xray... */ | ||||
| GP_DRAWFLAG_APPLY((gpl->flag & GP_LAYER_NO_XRAY), GP_DRAWDATA_NO_XRAY); | GP_DRAWFLAG_APPLY((gpl->flag & GP_LAYER_NO_XRAY), GP_DRAWDATA_NO_XRAY); | ||||
| /* volumetric strokes... */ | /* volumetric strokes... */ | ||||
| GP_DRAWFLAG_APPLY((gpl->flag & GP_LAYER_VOLUMETRIC), GP_DRAWDATA_VOLUMETRIC); | GP_DRAWFLAG_APPLY((gpl->flag & GP_LAYER_VOLUMETRIC), GP_DRAWDATA_VOLUMETRIC); | ||||
| /* HQ fills... */ | |||||
| GP_DRAWFLAG_APPLY((gpl->flag & GP_LAYER_HQ_FILL), GP_DRAWDATA_HQ_FILL); | |||||
| #undef GP_DRAWFLAG_APPLY | #undef GP_DRAWFLAG_APPLY | ||||
| tgpw.gpl = gpl; | |||||
| tgpw.gpf = gpf; | |||||
| tgpw.t_gpf = gpf; // XXX? | |||||
| tgpw.lthick = gpl->thickness; | |||||
| tgpw.opacity = gpl->opacity; | |||||
| copy_v4_v4(tgpw.tintcolor, gpl->tintcolor); | |||||
| tgpw.onion = false; | |||||
| tgpw.custonion = false; | |||||
| copy_m4_m4(tgpw.diff_mat, diff_mat); | |||||
| /* Draw 'onionskins' (frame left + right) | /* Draw 'onionskins' (frame left + right) | ||||
| * - It is only possible to show these if the option is enabled | * - It is only possible to show these if the option is enabled | ||||
| * - The "no onions" flag prevents ghosts from appearing during animation playback/scrubbing | * - The "no onions" flag prevents ghosts from appearing during animation playback/scrubbing | ||||
| * and in renders | * and in renders | ||||
| * - The per-layer "always show" flag however overrides the playback/render restriction, | * - The per-layer "always show" flag however overrides the playback/render restriction, | ||||
| * allowing artists to selectively turn onionskins on/off during playback | * allowing artists to selectively turn onionskins on/off during playback | ||||
| */ | */ | ||||
| if ((gpl->flag & GP_LAYER_ONIONSKIN) && | if ((gpl->onion_flag & GP_LAYER_ONIONSKIN) && | ||||
| ((dflag & GP_DRAWDATA_NO_ONIONS) == 0 || (gpl->flag & GP_LAYER_GHOST_ALWAYS))) | ((dflag & GP_DRAWDATA_NO_ONIONS) == 0 || (gpd->onion_flag & GP_ONION_GHOST_ALWAYS))) | ||||
| { | { | ||||
| /* Drawing method - only immediately surrounding (gstep = 0), | /* Drawing method - only immediately surrounding (gstep = 0), | ||||
| * or within a frame range on either side (gstep > 0) | * or within a frame range on either side (gstep > 0) | ||||
| */ | */ | ||||
| gp_draw_onionskins(gpd, gpl, gpf, offsx, offsy, winx, winy, cfra, dflag, debug, diff_mat); | gp_draw_onionskins(&tgpw); | ||||
| } | } | ||||
| /* draw the strokes already in active frame */ | /* draw the strokes already in active frame */ | ||||
| gp_draw_strokes(gpd, gpf, offsx, offsy, winx, winy, dflag, debug, gpl->thickness, | gp_draw_strokes(&tgpw); | ||||
| gpl->opacity, gpl->tintcolor, false, false, diff_mat); | |||||
| /* Draw verts of selected strokes | /* Draw verts of selected strokes | ||||
| * - when doing OpenGL renders, we don't want to be showing these, as that ends up flickering | * - when doing OpenGL renders, we don't want to be showing these, as that ends up flickering | ||||
| * - locked layers can't be edited, so there's no point showing these verts | * - locked layers can't be edited, so there's no point showing these verts | ||||
| * as they will have no bearings on what gets edited | * as they will have no bearings on what gets edited | ||||
| * - only show when in editmode, since operators shouldn't work otherwise | * - only show when in editmode, since operators shouldn't work otherwise | ||||
| * (NOTE: doing it this way means that the toggling editmode shows visible change immediately) | * (NOTE: doing it this way means that the toggling editmode shows visible change immediately) | ||||
| */ | */ | ||||
| Show All 12 Lines | if (ED_gpencil_session_active() && (gpl->flag & GP_LAYER_ACTIVE) && | ||||
| (gpf->flag & GP_FRAME_PAINT)) | (gpf->flag & GP_FRAME_PAINT)) | ||||
| { | { | ||||
| /* Buffer stroke needs to be drawn with a different linestyle | /* Buffer stroke needs to be drawn with a different linestyle | ||||
| * to help differentiate them from normal strokes. | * to help differentiate them from normal strokes. | ||||
| * | * | ||||
| * It should also be noted that sbuffer contains temporary point types | * It should also be noted that sbuffer contains temporary point types | ||||
| * i.e. tGPspoints NOT bGPDspoints | * i.e. tGPspoints NOT bGPDspoints | ||||
| */ | */ | ||||
| if (gpd->sflag & PC_COLOR_VOLUMETRIC) { | if (gpd->mode == GP_STYLE_MODE_DOTS) { | ||||
| gp_draw_stroke_volumetric_buffer(gpd->sbuffer, gpd->sbuffer_size, lthick, | gp_draw_stroke_volumetric_buffer(gpd->sbuffer, gpd->sbuffer_size, lthick, | ||||
| dflag, gpd->scolor); | dflag, gpd->scolor); | ||||
| } | } | ||||
| else { | else { | ||||
| gp_draw_stroke_buffer(gpd->sbuffer, gpd->sbuffer_size, lthick, dflag, gpd->sbuffer_sflag, gpd->scolor, gpd->sfill); | gp_draw_stroke_buffer(gpd->sbuffer, gpd->sbuffer_size, lthick, dflag, gpd->sbuffer_sflag, gpd->scolor, gpd->sfill); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | #endif | ||||
| UI_icon_draw(xco, yco, ICON_GREASEPENCIL); | UI_icon_draw(xco, yco, ICON_GREASEPENCIL); | ||||
| glDisable(GL_BLEND); | glDisable(GL_BLEND); | ||||
| } | } | ||||
| } | } | ||||
| /* draw grease-pencil datablock */ | /* draw grease-pencil datablock */ | ||||
| static void gp_draw_data( | static void gp_draw_data(RegionView3D *rv3d, | ||||
| const bGPDbrush *brush, float alpha, bGPdata *gpd, | const Brush *brush, float alpha, Object *ob, bGPdata *gpd, | ||||
| int offsx, int offsy, int winx, int winy, int cfra, int dflag) | int offsx, int offsy, int winx, int winy, int cfra, int dflag) | ||||
| { | { | ||||
| /* turn on smooth lines (i.e. anti-aliasing) */ | /* turn on smooth lines (i.e. anti-aliasing) */ | ||||
| glEnable(GL_LINE_SMOOTH); | glEnable(GL_LINE_SMOOTH); | ||||
| /* XXX: turn on some way of ensuring that the polygon edges get smoothed | /* XXX: turn on some way of ensuring that the polygon edges get smoothed | ||||
| * GL_POLYGON_SMOOTH is nasty and shouldn't be used, as it ends up | * GL_POLYGON_SMOOTH is nasty and shouldn't be used, as it ends up | ||||
| * creating internal white rays due to the ways it accumulates stuff | * creating internal white rays due to the ways it accumulates stuff | ||||
| */ | */ | ||||
| /* turn on alpha-blending */ | /* turn on alpha-blending */ | ||||
| glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | ||||
| glEnable(GL_BLEND); | glEnable(GL_BLEND); | ||||
| /* draw! */ | /* draw! */ | ||||
| gp_draw_data_layers(brush, alpha, gpd, offsx, offsy, winx, winy, cfra, dflag); | gp_draw_data_layers(rv3d, brush, alpha, ob, gpd, offsx, offsy, winx, winy, cfra, dflag); | ||||
| /* turn off alpha blending, then smooth lines */ | /* turn off alpha blending, then smooth lines */ | ||||
| glDisable(GL_BLEND); // alpha blending | glDisable(GL_BLEND); // alpha blending | ||||
| glDisable(GL_LINE_SMOOTH); // smooth lines | glDisable(GL_LINE_SMOOTH); // smooth lines | ||||
| } | } | ||||
| /* if we have strokes for scenes (3d view)/clips (movie clip editor) | /* if we have strokes for scenes (3d view)/clips (movie clip editor) | ||||
| * and objects/tracks, multiple data blocks have to be drawn */ | * and objects/tracks, multiple data blocks have to be drawn */ | ||||
| static void gp_draw_data_all(Scene *scene, bGPdata *gpd, int offsx, int offsy, int winx, int winy, | static void gp_draw_data_all(RegionView3D *rv3d, Scene *scene, bGPdata *gpd, int offsx, int offsy, int winx, int winy, | ||||
| int cfra, int dflag, const char spacetype) | int cfra, int dflag, const char spacetype) | ||||
| { | { | ||||
| bGPdata *gpd_source = NULL; | bGPdata *gpd_source = NULL; | ||||
| ToolSettings *ts; | ToolSettings *ts = NULL; | ||||
| bGPDbrush *brush = NULL; | Brush *brush = NULL; | ||||
| if (scene) { | if (scene) { | ||||
| ts = scene->toolsettings; | ts = scene->toolsettings; | ||||
| brush = BKE_gpencil_brush_getactive(ts); | brush = BKE_brush_getactive_gpencil(ts); | ||||
| /* if no brushes, create default set */ | |||||
| if (brush == NULL) { | |||||
| BKE_gpencil_brush_init_presets(ts); | |||||
| brush = BKE_gpencil_brush_getactive(ts); | |||||
| } | |||||
| if (spacetype == SPACE_VIEW3D) { | if (spacetype == SPACE_CLIP && scene->clip) { | ||||
| gpd_source = (scene->gpd ? scene->gpd : NULL); | |||||
| } | |||||
| else if (spacetype == SPACE_CLIP && scene->clip) { | |||||
| /* currently drawing only gpencil data from either clip or track, but not both - XXX fix logic behind */ | /* currently drawing only gpencil data from either clip or track, but not both - XXX fix logic behind */ | ||||
| gpd_source = (scene->clip->gpd ? scene->clip->gpd : NULL); | gpd_source = (scene->clip->gpd ? scene->clip->gpd : NULL); | ||||
| } | } | ||||
| if (gpd_source) { | if (gpd_source) { | ||||
| if (brush != NULL) { | if (brush != NULL) { | ||||
| gp_draw_data(brush, ts->gp_sculpt.alpha, gpd_source, | gp_draw_data(rv3d, brush, ts->gp_sculpt.alpha, NULL, gpd_source, | ||||
| offsx, offsy, winx, winy, cfra, dflag); | offsx, offsy, winx, winy, cfra, dflag); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* scene/clip data has already been drawn, only object/track data is drawn here | /* scene/clip data has already been drawn, only object/track data is drawn here | ||||
| * if gpd_source == gpd, we don't have any object/track data and we can skip */ | * if gpd_source == gpd, we don't have any object/track data and we can skip */ | ||||
| if (gpd_source == NULL || (gpd_source && gpd_source != gpd)) { | if (gpd_source == NULL || (gpd_source && gpd_source != gpd)) { | ||||
| if (brush != NULL) { | if (brush != NULL) { | ||||
| gp_draw_data(brush, ts->gp_sculpt.alpha, gpd, | gp_draw_data(rv3d, brush, ts->gp_sculpt.alpha, NULL, gpd, | ||||
| offsx, offsy, winx, winy, cfra, dflag); | offsx, offsy, winx, winy, cfra, dflag); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* ----- Grease Pencil Sketches Drawing API ------ */ | /* ----- Grease Pencil Sketches Drawing API ------ */ | ||||
| /* ............................ | /* ............................ | ||||
| * XXX | * XXX | ||||
| * We need to review the calls below, since they may be/are not that suitable for | * We need to review the calls below, since they may be/are not that suitable for | ||||
| * the new ways that we intend to be drawing data... | * the new ways that we intend to be drawing data... | ||||
| * ............................ */ | * ............................ */ | ||||
| /* draw grease-pencil sketches to specified 2d-view that uses ibuf corrections */ | /* draw grease-pencil sketches to specified 2d-view that uses ibuf corrections */ | ||||
| void ED_gpencil_draw_2dimage(const bContext *C) | void ED_gpencil_draw_2dimage(const bContext *C) | ||||
| { | { | ||||
| wmWindowManager *wm = CTX_wm_manager(C); | wmWindowManager *wm = CTX_wm_manager(C); | ||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| RegionView3D *rv3d = ar->regiondata; | |||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| int offsx, offsy, sizex, sizey; | int offsx, offsy, sizex, sizey; | ||||
| int dflag = GP_DRAWDATA_NOSTATUS; | int dflag = GP_DRAWDATA_NOSTATUS; | ||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); // XXX | bGPdata *gpd = ED_gpencil_data_get_active(C); // XXX | ||||
| if (gpd == NULL) return; | if (gpd == NULL) return; | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | void ED_gpencil_draw_2dimage(const bContext *C) | ||||
| if (ED_screen_animation_playing(wm)) { | if (ED_screen_animation_playing(wm)) { | ||||
| /* don't show onionskins during animation playback/scrub (i.e. it obscures the poses) | /* don't show onionskins during animation playback/scrub (i.e. it obscures the poses) | ||||
| * OpenGL Renders (i.e. final output), or depth buffer (i.e. not real strokes) | * OpenGL Renders (i.e. final output), or depth buffer (i.e. not real strokes) | ||||
| */ | */ | ||||
| dflag |= GP_DRAWDATA_NO_ONIONS; | dflag |= GP_DRAWDATA_NO_ONIONS; | ||||
| } | } | ||||
| /* draw it! */ | /* draw it! */ | ||||
| gp_draw_data_all(scene, gpd, offsx, offsy, sizex, sizey, CFRA, dflag, sa->spacetype); | gp_draw_data_all(rv3d, scene, gpd, offsx, offsy, sizex, sizey, CFRA, dflag, sa->spacetype); | ||||
| } | } | ||||
| /* draw grease-pencil sketches to specified 2d-view assuming that matrices are already set correctly | /* draw grease-pencil sketches to specified 2d-view assuming that matrices are already set correctly | ||||
| * Note: this gets called twice - first time with onlyv2d=true to draw 'canvas' strokes, | * Note: this gets called twice - first time with onlyv2d=true to draw 'canvas' strokes, | ||||
| * second time with onlyv2d=false for screen-aligned strokes */ | * second time with onlyv2d=false for screen-aligned strokes */ | ||||
| void ED_gpencil_draw_view2d(const bContext *C, bool onlyv2d) | void ED_gpencil_draw_view2d(const bContext *C, bool onlyv2d) | ||||
| { | { | ||||
| wmWindowManager *wm = CTX_wm_manager(C); | wmWindowManager *wm = CTX_wm_manager(C); | ||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| RegionView3D *rv3d = ar->regiondata; | |||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| int dflag = 0; | int dflag = 0; | ||||
| /* check that we have grease-pencil stuff to draw */ | /* check that we have grease-pencil stuff to draw */ | ||||
| if (sa == NULL) return; | if (sa == NULL) return; | ||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); // XXX | bGPdata *gpd = ED_gpencil_data_get_active(C); // XXX | ||||
| if (gpd == NULL) return; | if (gpd == NULL) return; | ||||
| /* special hack for Image Editor */ | /* special hack for Image Editor */ | ||||
| /* FIXME: the opengl poly-strokes don't draw at right thickness when done this way, so disabled */ | /* FIXME: the opengl poly-strokes don't draw at right thickness when done this way, so disabled */ | ||||
| if (ELEM(sa->spacetype, SPACE_IMAGE, SPACE_CLIP)) | if (ELEM(sa->spacetype, SPACE_IMAGE, SPACE_CLIP)) | ||||
| dflag |= GP_DRAWDATA_IEDITHACK; | dflag |= GP_DRAWDATA_IEDITHACK; | ||||
| /* draw it! */ | /* draw it! */ | ||||
| if (onlyv2d) dflag |= (GP_DRAWDATA_ONLYV2D | GP_DRAWDATA_NOSTATUS); | if (onlyv2d) dflag |= (GP_DRAWDATA_ONLYV2D | GP_DRAWDATA_NOSTATUS); | ||||
| if (ED_screen_animation_playing(wm)) dflag |= GP_DRAWDATA_NO_ONIONS; | if (ED_screen_animation_playing(wm)) dflag |= GP_DRAWDATA_NO_ONIONS; | ||||
| gp_draw_data_all(scene, gpd, 0, 0, ar->winx, ar->winy, CFRA, dflag, sa->spacetype); | gp_draw_data_all(rv3d, scene, gpd, 0, 0, ar->winx, ar->winy, CFRA, dflag, sa->spacetype); | ||||
| /* draw status text (if in screen/pixel-space) */ | /* draw status text (if in screen/pixel-space) */ | ||||
| if (!onlyv2d) { | if (!onlyv2d) { | ||||
| gp_draw_status_text(gpd, ar); | gp_draw_status_text(gpd, ar); | ||||
| } | } | ||||
| } | } | ||||
| /* draw grease-pencil sketches to specified 3d-view assuming that matrices are already set correctly | /* draw grease-pencil sketches to specified 3d-view assuming that matrices are already set correctly | ||||
| * Note: this gets called twice - first time with only3d=true to draw 3d-strokes, | * Note: this gets called twice - first time with only3d=true to draw 3d-strokes, | ||||
| * second time with only3d=false for screen-aligned strokes */ | * second time with only3d=false for screen-aligned strokes */ | ||||
| void ED_gpencil_draw_view3d(wmWindowManager *wm, | void ED_gpencil_draw_view3d(wmWindowManager *wm, | ||||
| Scene *scene, | Scene *scene, | ||||
| ViewLayer *view_layer, | ViewLayer *view_layer, | ||||
| struct Depsgraph *depsgraph, | struct Depsgraph *depsgraph, | ||||
| View3D *v3d, | View3D *v3d, | ||||
| ARegion *ar, | ARegion *ar, | ||||
| bool only3d) | bool only3d) | ||||
| { | { | ||||
| int dflag = 0; | int dflag = 0; | ||||
| RegionView3D *rv3d = ar->regiondata; | RegionView3D *rv3d = ar->regiondata; | ||||
| int offsx, offsy, winx, winy; | int offsx, offsy, winx, winy; | ||||
| /* check that we have grease-pencil stuff to draw */ | /* check that we have grease-pencil stuff to draw */ | ||||
| bGPdata *gpd = ED_gpencil_data_get_active_v3d(scene, view_layer); | // XXX: This is the only place that still uses this function | ||||
| bGPdata *gpd = ED_gpencil_data_get_active_v3d(view_layer); | |||||
| if (gpd == NULL) return; | |||||
| /* when rendering to the offscreen buffer we don't want to | |||||
| * deal with the camera border, otherwise map the coords to the camera border. */ | |||||
| if ((rv3d->persp == RV3D_CAMOB) && !(G.f & G_RENDER_OGL)) { | |||||
| rctf rectf; | |||||
| ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &rectf, true); /* no shift */ | |||||
| offsx = round_fl_to_int(rectf.xmin); | |||||
| offsy = round_fl_to_int(rectf.ymin); | |||||
| winx = round_fl_to_int(rectf.xmax - rectf.xmin); | |||||
| winy = round_fl_to_int(rectf.ymax - rectf.ymin); | |||||
| } | |||||
| else { | |||||
| offsx = 0; | |||||
| offsy = 0; | |||||
| winx = ar->winx; | |||||
| winy = ar->winy; | |||||
| } | |||||
| /* set flags */ | |||||
| if (only3d) { | |||||
| /* 3D strokes/3D space: | |||||
| * - only 3D space points | |||||
| * - don't status text either (as it's the wrong space) | |||||
| */ | |||||
| dflag |= (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_NOSTATUS); | |||||
| } | |||||
| if (v3d->flag2 & V3D_RENDER_OVERRIDE) { | |||||
| /* don't draw status text when "only render" flag is set */ | |||||
| dflag |= GP_DRAWDATA_NOSTATUS; | |||||
| } | |||||
| if ((wm == NULL) || ED_screen_animation_playing(wm)) { | |||||
| /* don't show onionskins during animation playback/scrub (i.e. it obscures the poses) | |||||
| * OpenGL Renders (i.e. final output), or depth buffer (i.e. not real strokes) | |||||
| */ | |||||
| dflag |= GP_DRAWDATA_NO_ONIONS; | |||||
| } | |||||
| /* draw it! */ | |||||
| gp_draw_data_all(rv3d, scene, gpd, offsx, offsy, winx, winy, CFRA, dflag, v3d->spacetype); | |||||
| } | |||||
| /* draw grease-pencil sketches to specified 3d-view for gp object | |||||
| * assuming that matrices are already set correctly | |||||
| */ | |||||
| void ED_gpencil_draw_view3d_object(wmWindowManager *wm, Scene *scene, Depsgraph *depsgraph, Object *ob, View3D *v3d, ARegion *ar, bool only3d) | |||||
| { | |||||
| int dflag = 0; | |||||
| RegionView3D *rv3d = ar->regiondata; | |||||
| int offsx, offsy, winx, winy; | |||||
| /* check that we have grease-pencil stuff to draw */ | |||||
| bGPdata *gpd = ob->data; | |||||
| if (gpd == NULL) return; | if (gpd == NULL) return; | ||||
| /* when rendering to the offscreen buffer we don't want to | /* when rendering to the offscreen buffer we don't want to | ||||
| * deal with the camera border, otherwise map the coords to the camera border. */ | * deal with the camera border, otherwise map the coords to the camera border. */ | ||||
| if ((rv3d->persp == RV3D_CAMOB) && !(G.f & G_RENDER_OGL)) { | if ((rv3d->persp == RV3D_CAMOB) && !(G.f & G_RENDER_OGL)) { | ||||
| rctf rectf; | rctf rectf; | ||||
| ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &rectf, true); /* no shift */ | ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &rectf, true); /* no shift */ | ||||
| offsx = round_fl_to_int(rectf.xmin); | offsx = round_fl_to_int(rectf.xmin); | ||||
| offsy = round_fl_to_int(rectf.ymin); | offsy = round_fl_to_int(rectf.ymin); | ||||
| winx = round_fl_to_int(rectf.xmax - rectf.xmin); | winx = round_fl_to_int(rectf.xmax - rectf.xmin); | ||||
| winy = round_fl_to_int(rectf.ymax - rectf.ymin); | winy = round_fl_to_int(rectf.ymax - rectf.ymin); | ||||
| } | } | ||||
| else { | else { | ||||
| offsx = 0; | offsx = 0; | ||||
| offsy = 0; | offsy = 0; | ||||
| winx = ar->winx; | winx = ar->winx; | ||||
| winy = ar->winy; | winy = ar->winy; | ||||
| } | } | ||||
| /* set flags */ | /* set flags */ | ||||
| if (only3d) { | if (only3d) { | ||||
| /* 3D strokes/3D space: | /* 3D strokes/3D space: | ||||
| * - only 3D space points | * - only 3D space points | ||||
| * - don't status text either (as it's the wrong space) | * - don't status text either (as it's the wrong space) | ||||
| */ | */ | ||||
| dflag |= (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_NOSTATUS); | dflag |= (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_NOSTATUS); | ||||
| } | } | ||||
| if (v3d->flag2 & V3D_RENDER_OVERRIDE) { | if (v3d->flag2 & V3D_RENDER_OVERRIDE) { | ||||
| /* don't draw status text when "only render" flag is set */ | /* don't draw status text when "only render" flag is set */ | ||||
| dflag |= GP_DRAWDATA_NOSTATUS; | dflag |= GP_DRAWDATA_NOSTATUS; | ||||
| } | } | ||||
| if ((wm == NULL) || ED_screen_animation_playing(wm)) { | if ((wm == NULL) || ED_screen_animation_playing(wm)) { | ||||
| /* don't show onionskins during animation playback/scrub (i.e. it obscures the poses) | /* don't show onionskins during animation playback/scrub (i.e. it obscures the poses) | ||||
| * OpenGL Renders (i.e. final output), or depth buffer (i.e. not real strokes) | * OpenGL Renders (i.e. final output), or depth buffer (i.e. not real strokes) | ||||
| */ | */ | ||||
| dflag |= GP_DRAWDATA_NO_ONIONS; | dflag |= GP_DRAWDATA_NO_ONIONS; | ||||
| } | } | ||||
| /* draw it! */ | /* draw it! */ | ||||
| gp_draw_data_all(scene, gpd, offsx, offsy, winx, winy, CFRA, dflag, v3d->spacetype); | ToolSettings *ts = scene->toolsettings; | ||||
| Brush *brush = BKE_brush_getactive_gpencil(ts); | |||||
| if (brush != NULL) { | |||||
| gp_draw_data(rv3d, brush, ts->gp_sculpt.alpha, ob, gpd, | |||||
| offsx, offsy, winx, winy, CFRA, dflag); | |||||
| } | |||||
| } | } | ||||
| void ED_gpencil_draw_ex(Scene *scene, bGPdata *gpd, int winx, int winy, const int cfra, const char spacetype) | void ED_gpencil_draw_ex(RegionView3D *rv3d, Scene *scene, bGPdata *gpd, int winx, int winy, const int cfra, const char spacetype) | ||||
| { | { | ||||
| int dflag = GP_DRAWDATA_NOSTATUS | GP_DRAWDATA_ONLYV2D; | int dflag = GP_DRAWDATA_NOSTATUS | GP_DRAWDATA_ONLYV2D; | ||||
| gp_draw_data_all(scene, gpd, 0, 0, winx, winy, cfra, dflag, spacetype); | gp_draw_data_all(rv3d, scene, gpd, 0, 0, winx, winy, cfra, dflag, spacetype); | ||||
| } | } | ||||
| /* ************************************************** */ | /* ************************************************** */ | ||||