Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/drawgpencil.c
| Context not available. | |||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| #include "BKE_image.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" | |||||
| /* ************************************************** */ | /* ************************************************** */ | ||||
| /* 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. | |||||
| /* --------------- 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) | |||||
| { | |||||
| minv[0] = points2d[0][0]; | |||||
| minv[1] = points2d[0][1]; | |||||
| maxv[0] = points2d[0][0]; | |||||
| maxv[1] = points2d[0][1]; | |||||
| 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); | if (tmp_triangles) MEM_freeN(tmp_triangles); | ||||
| if (points2d) MEM_freeN(points2d); | if (points2d) MEM_freeN(points2d); | ||||
| if (uv) MEM_freeN(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 & PAC_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 *UNUSED(gpd), bGPDstroke *gps, | |||||
| int offsx, int offsy, int winx, int winy, const float diff_mat[4][4], const float color[4]) | |||||
| { | |||||
| BLI_assert(gps->totpoints >= 3); | |||||
| PaletteColor *palcolor = gps->palcolor; | |||||
| /* Calculate triangles cache for filling area (must be done only after changes) */ | |||||
| if ((gps->flag & GP_STROKE_RECALC_CACHES) || (gps->tot_triangles == 0) || (gps->triangles == NULL)) { | |||||
| gp_triangulate_stroke_fill(gps); | |||||
| } | |||||
| BLI_assert(gps->tot_triangles >= 1); | |||||
| 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", palcolor->scolor); | |||||
| immUniform1i("fill_type", palcolor->fill_style); | |||||
| immUniform1f("mix_factor", palcolor->mix_factor); | |||||
| immUniform1f("g_angle", palcolor->g_angle); | |||||
| immUniform1f("g_radius", palcolor->g_radius); | |||||
| immUniform1f("g_boxsize", palcolor->g_boxsize); | |||||
| immUniform2fv("g_scale", palcolor->g_scale); | |||||
| immUniform2fv("g_shift", palcolor->g_shift); | |||||
| immUniform1f("t_angle", palcolor->t_angle); | |||||
| immUniform2fv("t_scale", palcolor->t_scale); | |||||
| immUniform2fv("t_offset", palcolor->t_offset); | |||||
| immUniform1f("t_opacity", palcolor->t_opacity); | |||||
| immUniform1i("t_mix", palcolor->flag & PAC_COLOR_TEX_MIX ? 1 : 0); | |||||
| immUniform1i("t_flip", palcolor->flag & PAC_COLOR_FLIP_FILL ? 1 : 0); | |||||
| /* image texture */ | |||||
| if ((palcolor->fill_style == FILL_STYLE_TEXTURE) || (palcolor->flag & PAC_COLOR_TEX_MIX)) { | |||||
| gp_set_filling_texture(palcolor->ima, palcolor->flag); | |||||
| } | |||||
| /* Draw all triangles for filling the polygon (cache must be calculated before) */ | |||||
| immBegin(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( | ||||
| short UNUSED(sflag), const float diff_mat[4][4], const float ink[4], bool cyclic) | const bGPDspoint *points, int totpoints, short thickness, bool UNUSED(debug), | ||||
| short UNUSED(sflag), const float diff_mat[4][4], const float ink[4], bool cyclic, | |||||
| int winx, int winy, int offsx, int offsy) | |||||
| { | { | ||||
| float viewport[2] = { winx, winy }; | |||||
| float offset[2] = { offsx, offsy }; | |||||
| float curpressure = points[0].pressure; | float curpressure = points[0].pressure; | ||||
| float fpt[3]; | float fpt[3]; | ||||
| float cyclic_fpt[3]; | UNUSED_VARS(offset); | ||||
| 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); | ||||
| immUniform2fv("Viewport", viewport); | |||||
| /* TODO: implement this with a geometry shader to draw one continuous tapered stroke */ | //immUniform2fv("Offset", offset); | ||||
| /* 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, 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, 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); | ||||
| immAttrib1f(thickattrib, max_ff(curpressure * thickness, 1.0f)); | |||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | mul_v3_m4v3(fpt, 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, 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, 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, diff_mat, &(points + totpoints - 2)->x); | |||||
| mul_v3_fl(fpt, -1.0f); | |||||
| immVertex3fv(pos, fpt); | immVertex3fv(pos, fpt); | ||||
| } | } | ||||
| Context not available. | |||||
| continue; | continue; | ||||
| } | } | ||||
| /* check if the color is visible */ | /* check if the color is visible */ | ||||
| bGPDpalettecolor *palcolor = ED_gpencil_stroke_getcolor(gpd, gps); | PaletteColor *palcolor = gps->palcolor; | ||||
| if ((palcolor == NULL) || | if ((palcolor == NULL) || | ||||
| (palcolor->flag & PC_COLOR_HIDE) || | (palcolor->flag & PC_COLOR_HIDE) || | ||||
| /* if onion and ghost flag do not draw*/ | /* if onion and ghost flag do not draw*/ | ||||
| Context not available. | |||||
| /* set color using palette, tint color and opacity */ | /* set color using palette, tint color and opacity */ | ||||
| interp_v3_v3v3(tfill, palcolor->fill, tintcolor, tintcolor[3]); | interp_v3_v3v3(tfill, palcolor->fill, tintcolor, tintcolor[3]); | ||||
| tfill[3] = palcolor->fill[3] * opacity; | tfill[3] = palcolor->fill[3] * opacity; | ||||
| if (tfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) { | if ((tfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) || (palcolor->fill_style > 0)) { | ||||
| const float *color; | const float *color; | ||||
| if (!onion) { | if (!onion) { | ||||
| color = tfill; | color = tfill; | ||||
| Context not available. | |||||
| /* 3D Stroke */ | /* 3D Stroke */ | ||||
| /* set color using palette, tint color and opacity */ | /* set color using palette, tint color and opacity */ | ||||
| if (!onion) { | if (!onion) { | ||||
| interp_v3_v3v3(tcolor, palcolor->color, tintcolor, tintcolor[3]); | interp_v3_v3v3(tcolor, palcolor->rgb, tintcolor, tintcolor[3]); | ||||
| tcolor[3] = palcolor->color[3] * opacity; | tcolor[3] = palcolor->rgb[3] * opacity; | ||||
| copy_v4_v4(ink, tcolor); | copy_v4_v4(ink, tcolor); | ||||
| } | } | ||||
| else { | else { | ||||
| Context not available. | |||||
| copy_v4_v4(ink, tintcolor); | copy_v4_v4(ink, tintcolor); | ||||
| } | } | ||||
| else { | else { | ||||
| ARRAY_SET_ITEMS(tcolor, palcolor->color[0], palcolor->color[1], palcolor->color[2], opacity); | ARRAY_SET_ITEMS(tcolor, palcolor->rgb[0], palcolor->rgb[1], palcolor->rgb[2], opacity); | ||||
| copy_v4_v4(ink, tcolor); | copy_v4_v4(ink, tcolor); | ||||
| } | } | ||||
| } | } | ||||
| if (palcolor->flag & PC_COLOR_VOLUMETRIC) { | if (palcolor->flag & PAC_COLOR_DOT) { | ||||
| /* volumetric stroke drawing */ | /* volumetric stroke drawing */ | ||||
| gp_draw_stroke_volumetric_3d(gps->points, gps->totpoints, sthickness, ink); | gp_draw_stroke_volumetric_3d(gps->points, gps->totpoints, sthickness, ink); | ||||
| } | } | ||||
| Context not available. | |||||
| } | } | ||||
| else { | else { | ||||
| gp_draw_stroke_3d(gps->points, gps->totpoints, sthickness, debug, gps->flag, | gp_draw_stroke_3d(gps->points, gps->totpoints, sthickness, debug, gps->flag, | ||||
| diff_mat, ink, gps->flag & GP_STROKE_CYCLIC); | diff_mat, ink, gps->flag & GP_STROKE_CYCLIC, | ||||
| winx, winy, offsx, offsy); | |||||
| } | } | ||||
| } | } | ||||
| if (no_xray) { | if (no_xray) { | ||||
| Context not available. | |||||
| /* set color using palette, tint color and opacity */ | /* set color using palette, tint color and opacity */ | ||||
| interp_v3_v3v3(tfill, palcolor->fill, tintcolor, tintcolor[3]); | interp_v3_v3v3(tfill, palcolor->fill, tintcolor, tintcolor[3]); | ||||
| tfill[3] = palcolor->fill[3] * opacity; | tfill[3] = palcolor->fill[3] * opacity; | ||||
| if (tfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) { | if ((tfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) || (palcolor->fill_style > 0)) { | ||||
| const float *color; | const float *color; | ||||
| if (!onion) { | if (!onion) { | ||||
| color = tfill; | color = tfill; | ||||
| Context not available. | |||||
| /* 2D Strokes... */ | /* 2D Strokes... */ | ||||
| /* set color using palette, tint color and opacity */ | /* set color using palette, tint color and opacity */ | ||||
| if (!onion) { | if (!onion) { | ||||
| interp_v3_v3v3(tcolor, palcolor->color, tintcolor, tintcolor[3]); | interp_v3_v3v3(tcolor, palcolor->rgb, tintcolor, tintcolor[3]); | ||||
| tcolor[3] = palcolor->color[3] * opacity; | tcolor[3] = palcolor->rgb[3] * opacity; | ||||
| copy_v4_v4(ink, tcolor); | copy_v4_v4(ink, tcolor); | ||||
| } | } | ||||
| else { | else { | ||||
| Context not available. | |||||
| copy_v4_v4(ink, tintcolor); | copy_v4_v4(ink, tintcolor); | ||||
| } | } | ||||
| else { | else { | ||||
| ARRAY_SET_ITEMS(tcolor, palcolor->color[0], palcolor->color[1], palcolor->color[2], opacity); | ARRAY_SET_ITEMS(tcolor, palcolor->rgb[0], palcolor->rgb[1], palcolor->rgb[2], opacity); | ||||
| copy_v4_v4(ink, tcolor); | copy_v4_v4(ink, tcolor); | ||||
| } | } | ||||
| } | } | ||||
| if (palcolor->flag & PC_COLOR_VOLUMETRIC) { | if (palcolor->flag & PAC_COLOR_DOT) { | ||||
| /* 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, dflag, gps->flag, | ||||
| offsx, offsy, winx, winy, diff_mat, ink); | offsx, offsy, winx, winy, diff_mat, ink); | ||||
| Context not available. | |||||
| /* verify palette color lock */ | /* verify palette color lock */ | ||||
| { | { | ||||
| bGPDpalettecolor *palcolor = ED_gpencil_stroke_getcolor(gpd, gps); | PaletteColor *palcolor = gps->palcolor; | ||||
| if (palcolor != NULL) { | if (palcolor != NULL) { | ||||
| if (palcolor->flag & PC_COLOR_HIDE) { | if (palcolor->flag & PC_COLOR_HIDE) { | ||||
| 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 palette */ | ||||
| bGPDpalettecolor *palcolor = ED_gpencil_stroke_getcolor(gpd, gps); | PaletteColor *palcolor = gps->palcolor; | ||||
| 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, palcolor->rgb); | ||||
| immAttrib1f(size, bsize); | immAttrib1f(size, bsize); | ||||
| } | } | ||||
| Context not available. | |||||
| float color[4]; | float color[4]; | ||||
| /* 1) Draw Previous Frames First */ | /* 1) Draw Previous Frames First */ | ||||
| if (gpl->flag & GP_LAYER_GHOST_PREVCOL) { | if (gpd->onion_flag & GP_ONION_GHOST_PREVCOL) { | ||||
| copy_v3_v3(color, gpl->gcolor_prev); | copy_v3_v3(color, gpl->gcolor_prev); | ||||
| } | } | ||||
| else { | else { | ||||
| Context not available. | |||||
| float fac = 1.0f - ((float)(gpf->framenum - gf->framenum) / (float)(gpl->gstep + 1)); | float fac = 1.0f - ((float)(gpf->framenum - gf->framenum) / (float)(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, | 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); | true, gpd->onion_flag & GP_ONION_GHOST_PREVCOL, diff_mat); | ||||
| } | } | ||||
| else | else | ||||
| break; | break; | ||||
| Context not available. | |||||
| if (gpf->prev) { | if (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, | 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); | true, gpd->onion_flag & GP_ONION_GHOST_PREVCOL, diff_mat); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| Context not available. | |||||
| } | } | ||||
| /* 2) Now draw next frames */ | /* 2) Now draw next frames */ | ||||
| if (gpl->flag & GP_LAYER_GHOST_NEXTCOL) { | if (gpd->onion_flag & GP_ONION_GHOST_NEXTCOL) { | ||||
| copy_v3_v3(color, gpl->gcolor_next); | copy_v3_v3(color, gpl->gcolor_next); | ||||
| } | } | ||||
| else { | else { | ||||
| Context not available. | |||||
| float fac = 1.0f - ((float)(gf->framenum - gpf->framenum) / (float)(gpl->gstep_next + 1)); | float fac = 1.0f - ((float)(gf->framenum - gpf->framenum) / (float)(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, | 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); | true, gpd->onion_flag & GP_ONION_GHOST_NEXTCOL, diff_mat); | ||||
| } | } | ||||
| else | else | ||||
| break; | break; | ||||
| Context not available. | |||||
| if (gpf->next) { | if (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, | 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); | true, gpd->onion_flag & GP_ONION_GHOST_NEXTCOL, diff_mat); | ||||
| } | } | ||||
| } | } | ||||
| 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) | ||||
| { | { | ||||
| tGPDinterpolate_layer *tgpil; | tGPDinterpolate_layer *tgpil; | ||||
| Object *obact = CTX_data_active_object(C); | |||||
| float diff_mat[4][4]; | float diff_mat[4][4]; | ||||
| float color[4]; | float color[4]; | ||||
| Context not available. | |||||
| 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, diff_mat); | ||||
| if (tgpil->interFrame) { | if (tgpil->interFrame) { | ||||
| gp_draw_strokes(tgpi->gpd, tgpil->interFrame, offsx, offsy, winx, winy, dflag, false, | gp_draw_strokes(tgpi->gpd, tgpil->interFrame, offsx, offsy, winx, winy, dflag, false, | ||||
| tgpil->gpl->thickness, 1.0f, color, true, true, diff_mat); | tgpil->gpl->thickness, 1.0f, color, true, true, diff_mat); | ||||
| Context not available. | |||||
| 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) | |||||
| { | |||||
| /* if idle, do not draw */ | |||||
| if (tgpi->flag == 0) { | |||||
| return; | |||||
| } | |||||
| Object *obact = CTX_data_active_object(C); | |||||
| float diff_mat[4][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); | |||||
| 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); | |||||
| } | |||||
| /* turn on alpha-blending */ | |||||
| glEnable(GL_BLEND); | |||||
| /* calculate parent position */ | |||||
| ED_gpencil_parent_location(obact, tgpi->gpd, tgpi->gpl, diff_mat); | |||||
| if (tgpi->gpf) { | |||||
| bGPDstroke *gps = tgpi->gpf->strokes.first; | |||||
| if (gps->totpoints > 0) { | |||||
| gp_draw_strokes(tgpi->gpd, tgpi->gpf, offsx, offsy, winx, winy, dflag, false, | |||||
| tgpi->gpl->thickness, 1.0f, color, true, true, diff_mat); | |||||
| } | |||||
| } | |||||
| glDisable(GL_BLEND); | |||||
| } | |||||
| /* 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( | ||||
| const bGPDbrush *brush, float alpha, bGPdata *gpd, | const bGPDbrush *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]; | ||||
| 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); | bool debug = (gpl->flag & GP_LAYER_DRAWDEBUG); | ||||
| short lthick = brush->thickness + gpl->thickness; | short lthick = brush->thickness + gpl->thickness; | ||||
| 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 | ||||
| /* Draw 'onionskins' (frame left + right) | /* Draw 'onionskins' (frame left + right) | ||||
| 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) | ||||
| 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->sflag & PAC_COLOR_DOT) { | ||||
| 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( | ||||
| const bGPDbrush *brush, float alpha, bGPdata *gpd, | const bGPDbrush *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(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. | |||||
| 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; | bGPDbrush *brush = NULL; | ||||
| if (scene) { | if (scene) { | ||||
| ts = scene->toolsettings; | ts = scene->toolsettings; | ||||
| 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(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(brush, ts->gp_sculpt.alpha, NULL, gpd, | ||||
| offsx, offsy, winx, winy, cfra, dflag); | offsx, offsy, winx, winy, cfra, dflag); | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| gp_draw_data_all(scene, gpd, offsx, offsy, winx, winy, CFRA, dflag, v3d->spacetype); | gp_draw_data_all(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, 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, 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; | |||||
| bGPDbrush *brush = BKE_gpencil_brush_getactive(ts); | |||||
| if (brush != NULL) { | |||||
| gp_draw_data(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(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; | ||||
| Context not available. | |||||