Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/drawgpencil.c
| Context not available. | |||||
| #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" | ||||
| Context not available. | |||||
| #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" | ||||
| Context not available. | |||||
| #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 */ | ||||
| Context not available. | |||||
| 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; | ||||
| Context not available. | |||||
| 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 */ | ||||
| Context not available. | |||||
| /* 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) { | ||||
| Context not available. | |||||
| /* --------------- 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) | ||||
| Context not available. | |||||
| *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) | ||||
| { | { | ||||
| Context not available. | |||||
| 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; | ||||
| Context not available. | |||||
| } | } | ||||
| 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 { | ||||
| Context not available. | |||||
| } | } | ||||
| /* 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 */ | |||||
| /* draw fills for shapes */ | static void gp_add_filldata_tobuffer( | ||||
| static void gp_draw_stroke_fill( | const bGPDspoint *pt, const float uv[2], uint pos, unsigned texcoord, short flag, | ||||
| bGPdata *gpd, bGPDstroke *gps, | int offsx, int offsy, int winx, int winy, const float diff_mat[4][4]) | ||||
| int offsx, int offsy, int winx, int winy, const float diff_mat[4][4], const float color[4]) | |||||
| { | { | ||||
| float fpt[3]; | 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 */ | /* assign image texture for filling stroke */ | ||||
| if (palcolor->flag & PC_COLOR_HQ_FILL) { | static int gp_set_filling_texture(Image *image, short flag) | ||||
| /* 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)) { | ImBuf *ibuf; | ||||
| gp_triangulate_stroke_fill(gps); | unsigned int *bind = &image->bindcode[TEXTARGET_TEXTURE_2D]; | ||||
| } | int error = GL_NO_ERROR; | ||||
| BLI_assert(gps->tot_triangles >= 1); | ImageUser iuser = { NULL }; | ||||
| void *lock; | |||||
| unsigned int pos; | iuser.ok = true; | ||||
| if (gps->flag & GP_STROKE_3DSPACE) { | |||||
| 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); | ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock); | ||||
| /* Draw all triangles for filling the polygon (cache must be calculated before) */ | if (ibuf == NULL || ibuf->rect == NULL) { | ||||
| immBegin(GWN_PRIM_TRIS, gps->tot_triangles * 3); | BKE_image_release_ibuf(image, ibuf, NULL); | ||||
| /* TODO: use batch instead of immediate mode, to share vertices */ | return (int)GL_INVALID_OPERATION; | ||||
| } | |||||
| bGPDtriangle *stroke_triangle = gps->triangles; | GPU_create_gl_tex(bind, ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, GL_TEXTURE_2D, | ||||
| bGPDspoint *pt; | false, false, image); | ||||
| if (gps->flag & GP_STROKE_3DSPACE) { | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||||
| for (int i = 0; i < gps->tot_triangles; i++, stroke_triangle++) { | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||||
| for (int j = 0; j < 3; j++) { | if (flag & GPC_COLOR_TEX_CLAMP) { | ||||
| pt = &gps->points[stroke_triangle->verts[j]]; | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); | ||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); | ||||
| immVertex3fv(pos, fpt); | } | ||||
| } | else { | ||||
| } | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | ||||
| } | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | ||||
| else { | } | ||||
| for (int i = 0; i < gps->tot_triangles; i++, stroke_triangle++) { | BKE_image_release_ibuf(image, ibuf, NULL); | ||||
| for (int j = 0; j < 3; j++) { | |||||
| float co[2]; | return error; | ||||
| 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); | |||||
| immVertex3fv(pos, fpt); | |||||
| } | |||||
| } | |||||
| } | |||||
| immEnd(); | /* draw fills for shapes */ | ||||
| immUnbindProgram(); | 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); | |||||
| Material *ma = gpd->mat[gps->mat_nr]; | |||||
| GpencilColorData *gpcolor = ma->gpcolor; | |||||
| /* 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); | |||||
| Gwn_VertFormat *format = immVertexFormat(); | |||||
| unsigned pos = GWN_vertformat_attr_add(format, "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_GPENCIL_FILL); | |||||
| immUniformColor4fv(color); | |||||
| immUniform4fv("color2", gpcolor->scolor); | |||||
| immUniform1i("fill_type", gpcolor->fill_style); | |||||
| immUniform1f("mix_factor", gpcolor->mix_factor); | |||||
| immUniform1f("g_angle", gpcolor->g_angle); | |||||
| immUniform1f("g_radius", gpcolor->g_radius); | |||||
| immUniform1f("g_boxsize", gpcolor->g_boxsize); | |||||
| immUniform2fv("g_scale", gpcolor->g_scale); | |||||
| immUniform2fv("g_shift", gpcolor->g_shift); | |||||
| immUniform1f("t_angle", gpcolor->t_angle); | |||||
| immUniform2fv("t_scale", gpcolor->t_scale); | |||||
| immUniform2fv("t_offset", gpcolor->t_offset); | |||||
| immUniform1f("t_opacity", gpcolor->t_opacity); | |||||
| immUniform1i("t_mix", gpcolor->flag & GPC_COLOR_TEX_MIX ? 1 : 0); | |||||
| immUniform1i("t_flip", gpcolor->flag & GPC_COLOR_FLIP_FILL ? 1 : 0); | |||||
| /* image texture */ | |||||
| if ((gpcolor->fill_style == GPC_FILL_STYLE_TEXTURE) || (gpcolor->flag & GPC_COLOR_TEX_MIX)) { | |||||
| gp_set_filling_texture(gpcolor->ima, gpcolor->flag); | |||||
| } | |||||
| /* 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 */ | |||||
| const bGPDtriangle *stroke_triangle = gps->triangles; | |||||
| for (int i = 0; i < gps->tot_triangles; i++, stroke_triangle++) { | |||||
| for (int j = 0; j < 3; j++) { | |||||
| gp_add_filldata_tobuffer( | |||||
| &gps->points[stroke_triangle->verts[j]], stroke_triangle->uv[j], | |||||
| pos, texcoord, gps->flag, | |||||
| offsx, offsy, winx, winy, diff_mat); | |||||
| } | |||||
| } | } | ||||
| immEnd(); | |||||
| immUnbindProgram(); | |||||
| } | } | ||||
| /* ----- Existing Strokes Drawing (3D and Point) ------ */ | /* ----- Existing Strokes Drawing (3D and Point) ------ */ | ||||
| Context not available. | |||||
| 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); | ||||
| } | } | ||||
| Context not available. | |||||
| } | } | ||||
| /* 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]; | ||||
| Context not available. | |||||
| 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) || | GpencilColorData *gpcolor = ma->gpcolor; | ||||
| (palcolor->flag & PC_COLOR_HIDE) || | |||||
| if ((gpcolor == NULL) || | |||||
| (gpcolor->flag & GPC_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 && (gpcolor->flag & GPC_COLOR_ONIONSKIN))) | ||||
| { | { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* if disable fill, the colors with fill must be omitted too except fill boundary strokes */ | |||||
| if ((tgpw->disable_fill == 1) && | |||||
| (gpcolor->fill[3] > 0.0f) && | |||||
| ((gps->flag & GP_STROKE_NOFILL) == 0)) | |||||
| { | |||||
| 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) { | ||||
| Context not available. | |||||
| /* 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, gpcolor->fill, tgpw->tintcolor, tgpw->tintcolor[3]); | ||||
| tfill[3] = palcolor->fill[3] * opacity; | tfill[3] = gpcolor->fill[3] * tgpw->opacity; | ||||
| if (tfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) { | if ((tfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) || (gpcolor->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(gpcolor->fill), 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, gpcolor->rgb, tgpw->tintcolor, tgpw->tintcolor[3]); | ||||
| tcolor[3] = palcolor->color[3] * opacity; | tcolor[3] = gpcolor->rgb[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, gpcolor->rgb[0], gpcolor->rgb[1], gpcolor->rgb[2], tgpw->opacity); | ||||
| copy_v4_v4(ink, tcolor); | copy_v4_v4(ink, tcolor); | ||||
| } | } | ||||
| } | } | ||||
| if (palcolor->flag & PC_COLOR_VOLUMETRIC) { | if (gpcolor->mode == GPC_MODE_DOTS) { | ||||
| /* volumetric stroke drawing */ | /* volumetric stroke drawing */ | ||||
| gp_draw_stroke_volumetric_3d(gps->points, gps->totpoints, sthickness, ink); | if (tgpw->disable_fill != 1) { | ||||
| 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) { | ||||
| Context not available. | |||||
| 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, gpcolor->fill, tgpw->tintcolor, tgpw->tintcolor[3]); | ||||
| tfill[3] = palcolor->fill[3] * opacity; | tfill[3] = gpcolor->fill[3] * tgpw->opacity; | ||||
| if (tfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) { | if ((tfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) || (gpcolor->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, gpcolor->fill[0], gpcolor->fill[1], gpcolor->fill[2], | ||||
| tintcolor[3]); | 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); | ||||
| } | } | ||||
| } | } | ||||
| /* 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, gpcolor->rgb, tgpw->tintcolor, tgpw->tintcolor[3]); | ||||
| tcolor[3] = palcolor->color[3] * opacity; | tcolor[3] = gpcolor->rgb[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, gpcolor->rgb[0], gpcolor->rgb[1], gpcolor->rgb[2], tgpw->opacity); | ||||
| copy_v4_v4(ink, tcolor); | copy_v4_v4(ink, tcolor); | ||||
| } | } | ||||
| } | } | ||||
| if (palcolor->flag & PC_COLOR_VOLUMETRIC) { | if (gpcolor->mode == GPC_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); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| 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) { | GpencilColorData *gpcolor = ma->gpcolor; | ||||
| if (palcolor->flag & PC_COLOR_HIDE) { | |||||
| if (gpcolor != NULL) { | |||||
| if (gpcolor->flag & GPC_COLOR_HIDE) { | |||||
| continue; | continue; | ||||
| } | } | ||||
| if (((lflag & GP_LAYER_UNLOCK_COLOR) == 0) && (palcolor->flag & PC_COLOR_LOCKED)) { | if (((lflag & GP_LAYER_UNLOCK_COLOR) == 0) && (gpcolor->flag & GPC_COLOR_LOCKED)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| } | } | ||||
| /* 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]; | ||||
| GpencilColorData *gpcolor = ma->gpcolor; | |||||
| float selectColor[4]; | float selectColor[4]; | ||||
| UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, selectColor); | UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, selectColor); | ||||
| Context not available. | |||||
| 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); | ||||
| Context not available. | |||||
| immAttrib1f(size, vsize); | immAttrib1f(size, vsize); | ||||
| } | } | ||||
| else { | else { | ||||
| immAttrib3fv(color, palcolor->color); | immAttrib3fv(color, gpcolor->rgb); | ||||
| immAttrib1f(size, bsize); | immAttrib1f(size, bsize); | ||||
| } | } | ||||
| Context not available. | |||||
| /* ----- 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 { | ||||
| Context not available. | |||||
| } | } | ||||
| /* 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 { | ||||
| Context not available. | |||||
| } | } | ||||
| /* 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]; | float color[4]; | ||||
| int offsx = 0; | |||||
| 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; | ||||
| Context not available. | |||||
| dflag |= (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_NOSTATUS); | dflag |= (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_NOSTATUS); | ||||
| } | } | ||||
| tgpw.rv3d = rv3d; | |||||
| 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(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); | |||||
| } | |||||
| /* 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); | |||||
| 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.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(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); | 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.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(ob, gpd, gpl, diff_mat); | ||||
| bool debug = (gpl->flag & GP_LAYER_DRAWDEBUG); | |||||
| short lthick = brush->thickness + gpl->thickness; | short lthick = brush->thickness + gpl->thickness; | ||||
| /* don't draw layer if hidden */ | /* don't draw layer if hidden */ | ||||
| Context not available. | |||||
| /* 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 | ||||
| Context not available. | |||||
| * - 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 | ||||
| Context not available. | |||||
| * 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 == GPC_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); | ||||
| } | } | ||||
| Context not available. | |||||
| } | } | ||||
| /* 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) */ | ||||
| Context not available. | |||||
| 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 | ||||
| Context not available. | |||||
| /* 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_VIEW3D) { | ||||
| gpd_source = (scene->gpd ? scene->gpd : NULL); | gpd_source = (scene->gpd ? scene->gpd : NULL); | ||||
| Context not available. | |||||
| 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); | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| * 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); | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| 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; | ||||
| Context not available. | |||||
| } | } | ||||
| /* 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 | ||||
| Context not available. | |||||
| 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; | ||||
| Context not available. | |||||
| 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) { | ||||
| Context not available. | |||||
| 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 */ | ||||
| // XXX: This is the only place that still uses this function | |||||
| bGPdata *gpd = ED_gpencil_data_get_active_v3d(scene, view_layer); | bGPdata *gpd = ED_gpencil_data_get_active_v3d(scene, view_layer); | ||||
| if (gpd == NULL) return; | if (gpd == NULL) return; | ||||
| Context not available. | |||||
| } | } | ||||
| /* draw it! */ | /* draw it! */ | ||||
| gp_draw_data_all(scene, gpd, offsx, offsy, winx, winy, CFRA, dflag, v3d->spacetype); | 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; | |||||
| /* 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! */ | |||||
| 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); | ||||
| } | } | ||||
| /* ************************************************** */ | /* ************************************************** */ | ||||
| Context not available. | |||||