Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/drawgpencil.c
| Context not available. | |||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "BIF_gl.h" | |||||
| #include "BIF_glutil.h" | #include "BIF_glutil.h" | ||||
| #include "GPU_immediate.h" | #include "GPU_immediate.h" | ||||
| Context not available. | |||||
| #define F2UB(x) (unsigned char)(255.0f * x) | #define F2UB(x) (unsigned char)(255.0f * x) | ||||
| /* ----- Tool Buffer Drawing ------ */ | /* ----- Tool Buffer Drawing ------ */ | ||||
| /* helper functions to set color of buffer point */ | /* helper function to set color of buffer point */ | ||||
| static void gp_set_tpoint_color(tGPspoint *pt, float ink[4]) | |||||
| { | |||||
| float alpha = ink[3] * pt->strength; | |||||
| CLAMP(alpha, GPENCIL_STRENGTH_MIN, 1.0f); | |||||
| glColor4f(ink[0], ink[1], ink[2], alpha); | |||||
| } | |||||
| static void gp_set_tpoint_varying_color(const tGPspoint *pt, const float ink[4], unsigned attrib_id) | /* helper functions to set color of point */ | ||||
| static void gp_set_point_color(bGPDspoint *pt, float ink[4]) | |||||
| { | { | ||||
| float alpha = ink[3] * pt->strength; | float alpha = ink[3] * pt->strength; | ||||
| CLAMP(alpha, GPENCIL_STRENGTH_MIN, 1.0f); | CLAMP(alpha, GPENCIL_STRENGTH_MIN, 1.0f); | ||||
| immAttrib4ub(attrib_id, F2UB(ink[0]), F2UB(ink[1]), F2UB(ink[2]), F2UB(alpha)); | glColor4f(ink[0], ink[1], ink[2], alpha); | ||||
| } | } | ||||
| static void gp_set_point_uniform_color(const bGPDspoint *pt, const float ink[4]) | static void gp_set_point_uniform_color(bGPDspoint *pt, const float ink[4]) | ||||
| { | { | ||||
| float alpha = ink[3] * pt->strength; | float alpha = ink[3] * pt->strength; | ||||
| CLAMP(alpha, GPENCIL_STRENGTH_MIN, 1.0f); | CLAMP(alpha, GPENCIL_STRENGTH_MIN, 1.0f); | ||||
| immUniform4f("color", ink[0], ink[1], ink[2], alpha); | immUniform4f("color", ink[0], ink[1], ink[2], alpha); | ||||
| } | } | ||||
| static void gp_set_point_varying_color(const bGPDspoint *pt, const float ink[4], unsigned attrib_id) | static void gp_set_point_varying_color(bGPDspoint *pt, const float ink[4], unsigned attrib_id) | ||||
| { | { | ||||
| float alpha = ink[3] * pt->strength; | float alpha = ink[3] * pt->strength; | ||||
| CLAMP(alpha, GPENCIL_STRENGTH_MIN, 1.0f); | CLAMP(alpha, GPENCIL_STRENGTH_MIN, 1.0f); | ||||
| immAttrib4ub(attrib_id, F2UB(ink[0]), F2UB(ink[1]), F2UB(ink[2]), F2UB(alpha)); | immAttrib4ub(attrib_id, F2UB(ink[0]), F2UB(ink[1]), F2UB(ink[2]), F2UB(alpha)); | ||||
| } | } | ||||
| /* helper function to set color and point */ | |||||
| static void gp_set_color_and_tpoint(tGPspoint *pt, float ink[4]) | |||||
| { | |||||
| gp_set_tpoint_color(pt, ink); | |||||
| glVertex2iv(&pt->x); | |||||
| } | |||||
| /* draw stroke defined in buffer (simple ogl lines/points for now, as dotted lines) */ | /* draw stroke defined in buffer (simple ogl lines/points for now, as dotted lines) */ | ||||
| static void gp_draw_stroke_buffer(const tGPspoint *points, int totpoints, short thickness, | static void gp_draw_stroke_buffer(tGPspoint *points, int totpoints, short thickness, | ||||
| short dflag, short sflag, float ink[4]) | short dflag, short sflag, float ink[4]) | ||||
| { | { | ||||
| tGPspoint *pt; | |||||
| int i; | |||||
| /* error checking */ | /* error checking */ | ||||
| if ((points == NULL) || (totpoints <= 0)) | if ((points == NULL) || (totpoints <= 0)) | ||||
| return; | return; | ||||
| /* check if buffer can be drawn */ | /* check if buffer can be drawn */ | ||||
| if (dflag & (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_ONLYV2D)) | if (dflag & (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_ONLYV2D)) | ||||
| return; | return; | ||||
| if (sflag & GP_STROKE_ERASER) { | |||||
| /* don't draw stroke at all! */ | |||||
| return; | |||||
| } | |||||
| VertexFormat *format = immVertexFormat(); | |||||
| unsigned pos = add_attrib(format, "pos", GL_INT, 2, CONVERT_INT_TO_FLOAT); | |||||
| unsigned color = add_attrib(format, "color", GL_UNSIGNED_BYTE, 4, NORMALIZE_INT_TO_FLOAT); | |||||
| const tGPspoint *pt = points; | |||||
| if (totpoints == 1) { | if (totpoints == 1) { | ||||
| /* if drawing a single point, draw it larger */ | /* if drawing a single point, draw it larger */ | ||||
| glPointSize((float)(thickness + 2) * points->pressure); | glPointSize((float)(thickness + 2) * points->pressure); | ||||
| immBindBuiltinProgram(GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR); | glBegin(GL_POINTS); | ||||
| immBegin(GL_POINTS, 1); | |||||
| gp_set_tpoint_varying_color(pt, ink, color); | gp_set_color_and_tpoint(points, ink); | ||||
| immVertex2iv(pos, &pt->x); | glEnd(); | ||||
| } | |||||
| else if (sflag & GP_STROKE_ERASER) { | |||||
| /* don't draw stroke at all! */ | |||||
| } | } | ||||
| else { | else { | ||||
| float oldpressure = points[0].pressure; | float oldpressure = points[0].pressure; | ||||
| /* draw stroke curve */ | /* draw stroke curve */ | ||||
| if (G.debug & G_DEBUG) setlinestyle(2); | if (G.debug & G_DEBUG) setlinestyle(2); | ||||
| glLineWidth(max_ff(oldpressure * thickness, 1.0)); | glLineWidth(max_ff(oldpressure * thickness, 1.0)); | ||||
| immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR); | glBegin(GL_LINE_STRIP); | ||||
| immBeginAtMost(GL_LINE_STRIP, totpoints); | |||||
| for (i = 0, pt = points; i < totpoints && pt; i++, pt++) { | |||||
| /* TODO: implement this with a geometry shader to draw one continuous tapered stroke */ | |||||
| for (int i = 0; i < totpoints; i++, pt++) { | |||||
| /* if there was a significant pressure change, stop the curve, change the thickness of the stroke, | /* if there was a significant pressure change, stop the curve, change the thickness of the stroke, | ||||
| * and continue drawing again (since line-width cannot change in middle of GL_LINE_STRIP) | * and continue drawing again (since line-width cannot change in middle of GL_LINE_STRIP) | ||||
| */ | */ | ||||
| if (fabsf(pt->pressure - oldpressure) > 0.2f) { | if (fabsf(pt->pressure - oldpressure) > 0.2f) { | ||||
| immEnd(); | glEnd(); | ||||
| glLineWidth(max_ff(pt->pressure * thickness, 1.0f)); | glLineWidth(max_ff(pt->pressure * thickness, 1.0f)); | ||||
| immBeginAtMost(GL_LINE_STRIP, totpoints - i + 1); | glBegin(GL_LINE_STRIP); | ||||
| /* need to roll-back one point to ensure that there are no gaps in the stroke */ | /* need to roll-back one point to ensure that there are no gaps in the stroke */ | ||||
| if (i != 0) { | if (i != 0) { | ||||
| gp_set_tpoint_varying_color(pt - 1, ink, color); | gp_set_color_and_tpoint((pt - 1), ink); | ||||
| immVertex2iv(pos, &(pt - 1)->x); | |||||
| } | } | ||||
| oldpressure = pt->pressure; /* reset our threshold */ | /* now the point we want... */ | ||||
| gp_set_color_and_tpoint(pt, ink); | |||||
| oldpressure = pt->pressure; | |||||
| } | |||||
| else { | |||||
| gp_set_color_and_tpoint(pt, ink); | |||||
| } | } | ||||
| /* now the point we want */ | |||||
| gp_set_tpoint_varying_color(pt, ink, color); | |||||
| immVertex2iv(pos, &pt->x); | |||||
| } | } | ||||
| glEnd(); | |||||
| if (G.debug & G_DEBUG) setlinestyle(0); | if (G.debug & G_DEBUG) setlinestyle(0); | ||||
| } | } | ||||
| immEnd(); | |||||
| immUnbindProgram(); | |||||
| } | } | ||||
| /* --------- 2D Stroke Drawing Helpers --------- */ | /* --------- 2D Stroke Drawing Helpers --------- */ | ||||
| /* change in parameter list */ | /* change in parameter list */ | ||||
| static void gp_calc_2d_stroke_fxy(const float pt[3], short sflag, int offsx, int offsy, int winx, int winy, float r_co[2]) | static void gp_calc_2d_stroke_fxy(float pt[3], short sflag, int offsx, int offsy, int winx, int winy, float r_co[2]) | ||||
| { | { | ||||
| if (sflag & GP_STROKE_2DSPACE) { | if (sflag & GP_STROKE_2DSPACE) { | ||||
| r_co[0] = pt[0]; | r_co[0] = pt[0]; | ||||
| Context not available. | |||||
| /* draw a 2D buffer stroke in "volumetric" style | /* draw a 2D buffer stroke in "volumetric" style | ||||
| * NOTE: the stroke buffer doesn't have any coordinate offsets/transforms | * NOTE: the stroke buffer doesn't have any coordinate offsets/transforms | ||||
| */ | */ | ||||
| static void gp_draw_stroke_volumetric_buffer(const tGPspoint *points, int totpoints, short thickness, | static void gp_draw_stroke_volumetric_buffer(tGPspoint *points, int totpoints, short thickness, | ||||
| short dflag, const float ink[4]) | short dflag, short UNUSED(sflag), float ink[4]) | ||||
| { | { | ||||
| GLUquadricObj *qobj = gluNewQuadric(); | |||||
| float modelview[4][4]; | |||||
| tGPspoint *pt; | |||||
| int i; | |||||
| /* error checking */ | /* error checking */ | ||||
| if ((points == NULL) || (totpoints <= 0)) | if ((points == NULL) || (totpoints <= 0)) | ||||
| return; | return; | ||||
| /* check if buffer can be drawn */ | /* check if buffer can be drawn */ | ||||
| if (dflag & (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_ONLYV2D)) | if (dflag & (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_ONLYV2D)) | ||||
| return; | return; | ||||
| VertexFormat *format = immVertexFormat(); | /* get basic matrix - should be camera space (i.e "identity") */ | ||||
| unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); | glGetFloatv(GL_MODELVIEW_MATRIX, (float *)modelview); | ||||
| unsigned size = add_attrib(format, "size", GL_FLOAT, 1, KEEP_FLOAT); | |||||
| unsigned color = add_attrib(format, "color", GL_UNSIGNED_BYTE, 4, NORMALIZE_INT_TO_FLOAT); | /* draw points */ | ||||
| glPushMatrix(); | |||||
| immBindBuiltinProgram(GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR); | |||||
| GPU_enable_program_point_size(); | for (i = 0, pt = points; i < totpoints; i++, pt++) { | ||||
| immBegin(GL_POINTS, totpoints); | /* set the transformed position */ | ||||
| // TODO: scale should change based on zoom level, which requires proper translation mult too! | |||||
| const tGPspoint *pt = points; | modelview[3][0] = pt->x; | ||||
| for (int i = 0; i < totpoints; i++, pt++) { | modelview[3][1] = pt->y; | ||||
| gp_set_tpoint_varying_color(pt, ink, color); | |||||
| immAttrib1f(size, pt->pressure * thickness); /* TODO: scale based on view transform (zoom level) */ | glLoadMatrixf((float *)modelview); | ||||
| immVertex2f(pos, pt->x, pt->y); | |||||
| /* draw the disk using the current state... */ | |||||
| gp_set_tpoint_color(pt, ink); | |||||
| gluDisk(qobj, 0.0, pt->pressure * thickness, 32, 1); | |||||
| modelview[3][0] = modelview[3][1] = 0.0f; | |||||
| } | } | ||||
| immEnd(); | glPopMatrix(); | ||||
| immUnbindProgram(); | gluDeleteQuadric(qobj); | ||||
| GPU_disable_program_point_size(); | |||||
| } | } | ||||
| /* draw a 2D strokes in "volumetric" style */ | /* draw a 2D strokes in "volumetric" style */ | ||||
| static void gp_draw_stroke_volumetric_2d(const bGPDspoint *points, int totpoints, short thickness, | static void gp_draw_stroke_volumetric_2d(bGPDspoint *points, int totpoints, short thickness, | ||||
| short dflag, short sflag, | short dflag, short sflag, | ||||
| int offsx, int offsy, int winx, int winy, | int offsx, int offsy, int winx, int winy, | ||||
| const float diff_mat[4][4], const float ink[4]) | float diff_mat[4][4], float ink[4]) | ||||
| { | { | ||||
| VertexFormat *format = immVertexFormat(); | VertexFormat *format = immVertexFormat(); | ||||
| unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); | unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); | ||||
| Context not available. | |||||
| GPU_enable_program_point_size(); | GPU_enable_program_point_size(); | ||||
| immBegin(GL_POINTS, totpoints); | immBegin(GL_POINTS, totpoints); | ||||
| const bGPDspoint *pt = points; | bGPDspoint *pt = points; | ||||
| for (int i = 0; i < totpoints; i++, pt++) { | for (int i = 0; i < totpoints; i++, pt++) { | ||||
| /* transform position to 2D */ | /* transform position to 2D */ | ||||
| float co[2]; | float co[2]; | ||||
| Context not available. | |||||
| /* draw a 3D stroke in "volumetric" style */ | /* draw a 3D stroke in "volumetric" style */ | ||||
| static void gp_draw_stroke_volumetric_3d( | static void gp_draw_stroke_volumetric_3d( | ||||
| const bGPDspoint *points, int totpoints, short thickness, | bGPDspoint *points, int totpoints, short thickness, | ||||
| const float ink[4]) | float ink[4]) | ||||
| { | { | ||||
| VertexFormat *format = immVertexFormat(); | VertexFormat *format = immVertexFormat(); | ||||
| unsigned pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT); | unsigned pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT); | ||||
| Context not available. | |||||
| GPU_enable_program_point_size(); | GPU_enable_program_point_size(); | ||||
| immBegin(GL_POINTS, totpoints); | immBegin(GL_POINTS, totpoints); | ||||
| const bGPDspoint *pt = points; | bGPDspoint *pt = points; | ||||
| for (int i = 0; i < totpoints && pt; i++, pt++) { | for (int i = 0; i < totpoints && pt; i++, pt++) { | ||||
| gp_set_point_varying_color(pt, ink, color); | gp_set_point_varying_color(pt, ink, color); | ||||
| immAttrib1f(size, pt->pressure * thickness); /* TODO: scale based on view transform */ | immAttrib1f(size, pt->pressure * thickness); /* TODO: scale based on view transform */ | ||||
| Context not available. | |||||
| /* --------------- Stroke Fills ----------------- */ | /* --------------- Stroke Fills ----------------- */ | ||||
| /* 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(bGPDspoint *points, int totpoints, float(*points2d)[2], int *r_direction) | ||||
| { | { | ||||
| const bGPDspoint *pt0 = &points[0]; | bGPDspoint *pt0 = &points[0]; | ||||
| const bGPDspoint *pt1 = &points[1]; | bGPDspoint *pt1 = &points[1]; | ||||
| const bGPDspoint *pt3 = &points[(int)(totpoints * 0.75)]; | bGPDspoint *pt3 = &points[(int)(totpoints * 0.75)]; | ||||
| float locx[3]; | float locx[3]; | ||||
| float locy[3]; | float locy[3]; | ||||
| float loc3[3]; | float loc3[3]; | ||||
| float normal[3]; | float normal[3]; | ||||
| /* local X axis (p0 -> p1) */ | /* local X axis (p0 -> p1) */ | ||||
| sub_v3_v3v3(locx, &pt1->x, &pt0->x); | sub_v3_v3v3(locx, &pt1->x, &pt0->x); | ||||
| /* point vector at 3/4 */ | /* point vector at 3/4 */ | ||||
| sub_v3_v3v3(loc3, &pt3->x, &pt0->x); | sub_v3_v3v3(loc3, &pt3->x, &pt0->x); | ||||
| /* vector orthogonal to polygon plane */ | /* vector orthogonal to polygon plane */ | ||||
| cross_v3_v3v3(normal, locx, loc3); | cross_v3_v3v3(normal, locx, loc3); | ||||
| /* local Y axis (cross to normal/x axis) */ | /* local Y axis (cross to normal/x axis) */ | ||||
| cross_v3_v3v3(locy, normal, locx); | cross_v3_v3v3(locy, normal, locx); | ||||
| /* Normalize vectors */ | /* Normalize vectors */ | ||||
| normalize_v3(locx); | normalize_v3(locx); | ||||
| normalize_v3(locy); | normalize_v3(locy); | ||||
| /* Get all points in local space */ | /* Get all points in local space */ | ||||
| for (int i = 0; i < totpoints; i++) { | for (int i = 0; i < totpoints; i++) { | ||||
| const bGPDspoint *pt = &points[i]; | bGPDspoint *pt = &points[i]; | ||||
| float loc[3]; | float loc[3]; | ||||
| /* Get local space using first point as origin */ | /* Get local space using first point as origin */ | ||||
| sub_v3_v3v3(loc, &pt->x, &pt0->x); | sub_v3_v3v3(loc, &pt->x, &pt0->x); | ||||
| points2d[i][0] = dot_v3v3(loc, locx); | points2d[i][0] = dot_v3v3(loc, locx); | ||||
| points2d[i][1] = dot_v3v3(loc, locy); | points2d[i][1] = dot_v3v3(loc, locy); | ||||
| } | } | ||||
| /* Concave (-1), Convex (1), or Autodetect (0)? */ | /* Concave (-1), Convex (1), or Autodetect (0)? */ | ||||
| *r_direction = (int)locy[2]; | *r_direction = (int)locy[2]; | ||||
| } | } | ||||
| Context not available. | |||||
| static void gp_triangulate_stroke_fill(bGPDstroke *gps) | static void gp_triangulate_stroke_fill(bGPDstroke *gps) | ||||
| { | { | ||||
| BLI_assert(gps->totpoints >= 3); | BLI_assert(gps->totpoints >= 3); | ||||
| /* allocate memory for temporary areas */ | /* allocate memory for temporary areas */ | ||||
| gps->tot_triangles = gps->totpoints - 2; | gps->tot_triangles = gps->totpoints - 2; | ||||
| unsigned int (*tmp_triangles)[3] = MEM_mallocN(sizeof(*tmp_triangles) * gps->tot_triangles, "GP Stroke temp triangulation"); | unsigned int (*tmp_triangles)[3] = MEM_mallocN(sizeof(*tmp_triangles) * gps->tot_triangles, "GP Stroke temp triangulation"); | ||||
| float (*points2d)[2] = MEM_mallocN(sizeof(*points2d) * gps->totpoints, "GP Stroke temp 2d points"); | float (*points2d)[2] = MEM_mallocN(sizeof(*points2d) * gps->totpoints, "GP Stroke temp 2d points"); | ||||
| 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((const float(*)[2])points2d, (unsigned int)gps->totpoints, direction, (unsigned int(*)[3])tmp_triangles); | BLI_polyfill_calc((const float(*)[2])points2d, (unsigned int)gps->totpoints, direction, (unsigned int(*)[3])tmp_triangles); | ||||
| Context not available. | |||||
| else { | else { | ||||
| gps->triangles = MEM_recallocN(gps->triangles, sizeof(*gps->triangles) * gps->tot_triangles); | gps->triangles = MEM_recallocN(gps->triangles, sizeof(*gps->triangles) * gps->tot_triangles); | ||||
| } | } | ||||
| for (int i = 0; i < gps->tot_triangles; i++) { | for (int i = 0; i < gps->tot_triangles; i++) { | ||||
| bGPDtriangle *stroke_triangle = &gps->triangles[i]; | bGPDtriangle *stroke_triangle = &gps->triangles[i]; | ||||
| stroke_triangle->v1 = tmp_triangles[i][0]; | stroke_triangle->v1 = tmp_triangles[i][0]; | ||||
| Context not available. | |||||
| /* No triangles needed - Free anything allocated previously */ | /* No triangles needed - Free anything allocated previously */ | ||||
| if (gps->triangles) | if (gps->triangles) | ||||
| MEM_freeN(gps->triangles); | MEM_freeN(gps->triangles); | ||||
| gps->triangles = NULL; | gps->triangles = NULL; | ||||
| } | } | ||||
| /* disable recalculation flag */ | /* disable recalculation flag */ | ||||
| if (gps->flag & GP_STROKE_RECALC_CACHES) { | if (gps->flag & GP_STROKE_RECALC_CACHES) { | ||||
| gps->flag &= ~GP_STROKE_RECALC_CACHES; | gps->flag &= ~GP_STROKE_RECALC_CACHES; | ||||
| } | } | ||||
| /* clear memory */ | /* clear memory */ | ||||
| if (tmp_triangles) MEM_freeN(tmp_triangles); | if (tmp_triangles) MEM_freeN(tmp_triangles); | ||||
| if (points2d) MEM_freeN(points2d); | if (points2d) MEM_freeN(points2d); | ||||
| Context not available. | |||||
| /* draw fills for shapes */ | /* draw fills for shapes */ | ||||
| static void gp_draw_stroke_fill( | static void gp_draw_stroke_fill( | ||||
| bGPdata *gpd, bGPDstroke *gps, | bGPdata *gpd, bGPDstroke *gps, | ||||
| int offsx, int offsy, int winx, int winy, const float diff_mat[4][4], const float color[4]) | int offsx, int offsy, int winx, int winy, float diff_mat[4][4]) | ||||
| { | { | ||||
| bGPDpalettecolor *palcolor; | |||||
| int i; | |||||
| float fpt[3]; | float fpt[3]; | ||||
| BLI_assert(gps->totpoints >= 3); | BLI_assert(gps->totpoints >= 3); | ||||
| bGPDpalettecolor *palcolor = ED_gpencil_stroke_getcolor(gpd, gps); | palcolor = ED_gpencil_stroke_getcolor(gpd, gps); | ||||
| /* Triangulation fill if high quality flag is enabled */ | /* Triangulation fill if high quality flag is enabled */ | ||||
| if (palcolor->flag & PC_COLOR_HQ_FILL) { | if (palcolor->flag & PC_COLOR_HQ_FILL) { | ||||
| bGPDtriangle *stroke_triangle; | |||||
| bGPDspoint *pt; | |||||
| /* Calculate triangles cache for filling area (must be done only after changes) */ | /* Calculate triangles cache for filling area (must be done only after changes) */ | ||||
| if ((gps->flag & GP_STROKE_RECALC_CACHES) || (gps->tot_triangles == 0) || (gps->triangles == NULL)) { | if ((gps->flag & GP_STROKE_RECALC_CACHES) || (gps->tot_triangles == 0) || (gps->triangles == NULL)) { | ||||
| gp_triangulate_stroke_fill(gps); | gp_triangulate_stroke_fill(gps); | ||||
| } | } | ||||
| BLI_assert(gps->tot_triangles >= 1); | |||||
| unsigned pos; | |||||
| if (gps->flag & GP_STROKE_3DSPACE) { | |||||
| pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 3, KEEP_FLOAT); | |||||
| immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | |||||
| } | |||||
| else { | |||||
| pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT); | |||||
| immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | |||||
| } | |||||
| immUniformColor4fv(color); | |||||
| /* Draw all triangles for filling the polygon (cache must be calculated before) */ | /* Draw all triangles for filling the polygon (cache must be calculated before) */ | ||||
| immBegin(GL_TRIANGLES, gps->tot_triangles * 3); | BLI_assert(gps->tot_triangles >= 1); | ||||
| /* TODO: use batch instead of immediate mode, to share vertices */ | glBegin(GL_TRIANGLES); | ||||
| for (i = 0, stroke_triangle = gps->triangles; i < gps->tot_triangles; i++, stroke_triangle++) { | |||||
| bGPDtriangle *stroke_triangle = gps->triangles; | |||||
| bGPDspoint *pt; | |||||
| for (int i = 0; i < gps->tot_triangles; i++, stroke_triangle++) { | |||||
| if (gps->flag & GP_STROKE_3DSPACE) { | if (gps->flag & GP_STROKE_3DSPACE) { | ||||
| /* vertex 1 */ | /* vertex 1 */ | ||||
| pt = &gps->points[stroke_triangle->v1]; | pt = &gps->points[stroke_triangle->v1]; | ||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | mul_v3_m4v3(fpt, diff_mat, &pt->x); | ||||
| immVertex3fv(pos, fpt); | glVertex3fv(fpt); | ||||
| /* vertex 2 */ | /* vertex 2 */ | ||||
| pt = &gps->points[stroke_triangle->v2]; | pt = &gps->points[stroke_triangle->v2]; | ||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | mul_v3_m4v3(fpt, diff_mat, &pt->x); | ||||
| immVertex3fv(pos, fpt); | glVertex3fv(fpt); | ||||
| /* vertex 3 */ | /* vertex 3 */ | ||||
| pt = &gps->points[stroke_triangle->v3]; | pt = &gps->points[stroke_triangle->v3]; | ||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | mul_v3_m4v3(fpt, diff_mat, &pt->x); | ||||
| immVertex3fv(pos, fpt); | glVertex3fv(fpt); | ||||
| } | } | ||||
| else { | else { | ||||
| float co[2]; | float co[2]; | ||||
| Context not available. | |||||
| pt = &gps->points[stroke_triangle->v1]; | pt = &gps->points[stroke_triangle->v1]; | ||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | mul_v3_m4v3(fpt, diff_mat, &pt->x); | ||||
| gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co); | gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co); | ||||
| immVertex2fv(pos, co); | glVertex2fv(co); | ||||
| /* vertex 2 */ | /* vertex 2 */ | ||||
| pt = &gps->points[stroke_triangle->v2]; | pt = &gps->points[stroke_triangle->v2]; | ||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | mul_v3_m4v3(fpt, diff_mat, &pt->x); | ||||
| gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co); | gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co); | ||||
| immVertex2fv(pos, co); | glVertex2fv(co); | ||||
| /* vertex 3 */ | /* vertex 3 */ | ||||
| pt = &gps->points[stroke_triangle->v3]; | pt = &gps->points[stroke_triangle->v3]; | ||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | mul_v3_m4v3(fpt, diff_mat, &pt->x); | ||||
| gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co); | gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co); | ||||
| immVertex2fv(pos, co); | glVertex2fv(co); | ||||
| } | } | ||||
| } | } | ||||
| glEnd(); | |||||
| immEnd(); | |||||
| immUnbindProgram(); | |||||
| } | } | ||||
| #if 0 /* convert to modern GL only if needed */ | |||||
| else { | else { | ||||
| /* As an initial implementation, we use the OpenGL filled polygon drawing | /* As an initial implementation, we use the OpenGL filled polygon drawing | ||||
| * here since it's the easiest option to implement for this case. It does | * here since it's the easiest option to implement for this case. It does | ||||
| Context not available. | |||||
| * created using old versions of Blender which may have depended on the artifacts | * created using old versions of Blender which may have depended on the artifacts | ||||
| * the old fills created. | * the old fills created. | ||||
| */ | */ | ||||
| bGPDspoint *pt = gps->points; | bGPDspoint *pt; | ||||
| glBegin(GL_POLYGON); | glBegin(GL_POLYGON); | ||||
| for (int i = 0; i < gps->totpoints; i++, pt++) { | for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { | ||||
| if (gps->flag & GP_STROKE_3DSPACE) { | if (gps->flag & GP_STROKE_3DSPACE) { | ||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | mul_v3_m4v3(fpt, diff_mat, &pt->x); | ||||
| glVertex3fv(fpt); | glVertex3fv(fpt); | ||||
| Context not available. | |||||
| glEnd(); | glEnd(); | ||||
| } | } | ||||
| #endif | |||||
| } | } | ||||
| /* ----- Existing Strokes Drawing (3D and Point) ------ */ | /* ----- Existing Strokes Drawing (3D and Point) ------ */ | ||||
| /* draw a given stroke - just a single dot (only one point) */ | /* draw a given stroke - just a single dot (only one point) */ | ||||
| static void gp_draw_stroke_point( | static void gp_draw_stroke_point( | ||||
| const bGPDspoint *points, short thickness, short dflag, short sflag, | bGPDspoint *points, short thickness, short dflag, short sflag, | ||||
| int offsx, int offsy, int winx, int winy, const float diff_mat[4][4], const float ink[4]) | int offsx, int offsy, int winx, int winy, float diff_mat[4][4], float ink[4]) | ||||
| { | { | ||||
| const bGPDspoint *pt = points; | float fpt[3]; | ||||
| bGPDspoint *pt = &points[0]; | |||||
| /* color of point */ | |||||
| gp_set_point_color(pt, ink); | |||||
| /* set point thickness (since there's only one of these) */ | |||||
| glPointSize((float)(thickness + 2) * points->pressure); | |||||
| /* get final position using parent matrix */ | /* get final position using parent matrix */ | ||||
| float fpt[3]; | |||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | mul_v3_m4v3(fpt, diff_mat, &pt->x); | ||||
| VertexFormat *format = immVertexFormat(); | /* draw point */ | ||||
| unsigned pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT); | |||||
| if (sflag & GP_STROKE_3DSPACE) { | if (sflag & GP_STROKE_3DSPACE) { | ||||
| immBindBuiltinProgram(GPU_SHADER_3D_POINT_FIXED_SIZE_UNIFORM_COLOR); | glBegin(GL_POINTS); | ||||
| glVertex3fv(fpt); | |||||
| glEnd(); | |||||
| } | } | ||||
| else { | else { | ||||
| immBindBuiltinProgram(GPU_SHADER_2D_POINT_FIXED_SIZE_UNIFORM_COLOR); | float co[2]; | ||||
| /* get 2D coordinates of point */ | /* get coordinates of point */ | ||||
| float co[3] = { 0.0f }; | |||||
| gp_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, co); | gp_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, co); | ||||
| copy_v3_v3(fpt, co); | |||||
| /* if thickness is less than GP_DRAWTHICKNESS_SPECIAL, simple dot looks ok | |||||
| * - also mandatory in if Image Editor 'image-based' dot | |||||
| */ | |||||
| if ((thickness < GP_DRAWTHICKNESS_SPECIAL) || | |||||
| ((dflag & GP_DRAWDATA_IEDITHACK) && (sflag & GP_STROKE_2DSPACE))) | |||||
| { | |||||
| glBegin(GL_POINTS); | |||||
| glVertex2fv(co); | |||||
| glEnd(); | |||||
| } | |||||
| else { | |||||
| /* draw filled circle as is done in circf (but without the matrix push/pops which screwed things up) */ | |||||
| GLUquadricObj *qobj = gluNewQuadric(); | |||||
| gluQuadricDrawStyle(qobj, GLU_FILL); | |||||
| /* need to translate drawing position, but must reset after too! */ | |||||
| glTranslate2fv(co); | |||||
| gluDisk(qobj, 0.0, thickness, 32, 1); | |||||
| glTranslatef(-co[0], -co[1], 0.0); | |||||
| gluDeleteQuadric(qobj); | |||||
| } | |||||
| } | } | ||||
| gp_set_point_uniform_color(pt, ink); | |||||
| /* set point thickness (since there's only one of these) */ | |||||
| glPointSize((float)(thickness + 2) * pt->pressure); | |||||
| immBegin(GL_POINTS, 1); | |||||
| immVertex3fv(pos, fpt); | |||||
| immEnd(); | |||||
| 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), using simple ogl lines */ | ||||
| static void gp_draw_stroke_3d(const bGPDspoint *points, int totpoints, short thickness, bool UNUSED(debug), | static void gp_draw_stroke_3d(bGPDspoint *points, int totpoints, short thickness, bool debug, | ||||
| short UNUSED(sflag), const float diff_mat[4][4], const float ink[4], bool cyclic) | short UNUSED(sflag), float diff_mat[4][4], float ink[4], bool cyclic) | ||||
| { | { | ||||
| bGPDspoint *pt, *pt2; | |||||
| float curpressure = points[0].pressure; | float curpressure = points[0].pressure; | ||||
| int i; | |||||
| float fpt[3]; | float fpt[3]; | ||||
| float cyclic_fpt[3]; | float cyclic_fpt[3]; | ||||
| VertexFormat *format = immVertexFormat(); | |||||
| unsigned pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT); | |||||
| unsigned color = add_attrib(format, "color", GL_UNSIGNED_BYTE, 4, NORMALIZE_INT_TO_FLOAT); | |||||
| immBindBuiltinProgram(GPU_SHADER_3D_SMOOTH_COLOR); | |||||
| /* TODO: implement this with a geometry shader to draw one continuous tapered stroke */ | |||||
| /* draw stroke curve */ | /* draw stroke curve */ | ||||
| glLineWidth(max_ff(curpressure * thickness, 1.0f)); | glLineWidth(max_ff(curpressure * thickness, 1.0f)); | ||||
| immBeginAtMost(GL_LINE_STRIP, totpoints); | glBegin(GL_LINE_STRIP); | ||||
| const bGPDspoint *pt = points; | for (i = 0, pt = points; i < totpoints && pt; i++, pt++) { | ||||
| for (int i = 0; i < totpoints; i++, pt++) { | gp_set_point_color(pt, ink); | ||||
| gp_set_point_varying_color(pt, ink, color); | |||||
| /* if there was a significant pressure change, stop the curve, change the thickness of the stroke, | /* if there was a significant pressure change, stop the curve, change the thickness of the stroke, | ||||
| * and continue drawing again (since line-width cannot change in middle of GL_LINE_STRIP) | * and continue drawing again (since line-width cannot change in middle of GL_LINE_STRIP) | ||||
| * Note: we want more visible levels of pressures when thickness is bigger. | * Note: we want more visible levels of pressures when thickness is bigger. | ||||
| */ | */ | ||||
| if (fabsf(pt->pressure - curpressure) > 0.2f / (float)thickness) { | if (fabsf(pt->pressure - curpressure) > 0.2f / (float)thickness) { | ||||
| immEnd(); | glEnd(); | ||||
| curpressure = pt->pressure; | curpressure = pt->pressure; | ||||
| glLineWidth(max_ff(curpressure * thickness, 1.0f)); | glLineWidth(max_ff(curpressure * thickness, 1.0f)); | ||||
| immBeginAtMost(GL_LINE_STRIP, totpoints - i + 1); | glBegin(GL_LINE_STRIP); | ||||
| /* need to roll-back one point to ensure that there are no gaps in the stroke */ | /* need to roll-back one point to ensure that there are no gaps in the stroke */ | ||||
| if (i != 0) { | if (i != 0) { | ||||
| const bGPDspoint *pt2 = pt - 1; | pt2 = pt - 1; | ||||
| mul_v3_m4v3(fpt, diff_mat, &pt2->x); | mul_v3_m4v3(fpt, diff_mat, &pt2->x); | ||||
| immVertex3fv(pos, fpt); | glVertex3fv(fpt); | ||||
| } | } | ||||
| /* now the point we want... */ | |||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | |||||
| glVertex3fv(fpt); | |||||
| } | } | ||||
| else { | |||||
| /* now the point we want */ | mul_v3_m4v3(fpt, diff_mat, &pt->x); | ||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | glVertex3fv(fpt); | ||||
| immVertex3fv(pos, fpt); | } | ||||
| /* saves first point to use in cyclic */ | |||||
| if (cyclic && i == 0) { | if (i == 0) { | ||||
| /* save first point to use in cyclic */ | |||||
| copy_v3_v3(cyclic_fpt, fpt); | copy_v3_v3(cyclic_fpt, fpt); | ||||
| } | } | ||||
| } | } | ||||
| /* if cyclic draw line to first point */ | |||||
| if (cyclic) { | if (cyclic) { | ||||
| /* draw line to first point to complete the cycle */ | glVertex3fv(cyclic_fpt); | ||||
| immVertex3fv(pos, cyclic_fpt); | |||||
| } | } | ||||
| glEnd(); | |||||
| immEnd(); | |||||
| immUnbindProgram(); | |||||
| #if 0 /* convert to modern GL only if needed */ | |||||
| /* draw debug points of curve on top? */ | /* draw debug points of curve on top? */ | ||||
| /* XXX: for now, we represent "selected" strokes in the same way as debug, which isn't used anymore */ | /* XXX: for now, we represent "selected" strokes in the same way as debug, which isn't used anymore */ | ||||
| if (debug) { | if (debug) { | ||||
| glPointSize((float)(thickness + 2)); | glPointSize((float)(thickness + 2)); | ||||
| glBegin(GL_POINTS); | glBegin(GL_POINTS); | ||||
| const bGPDspoint *pt = points; | for (i = 0, pt = points; i < totpoints && pt; i++, pt++) { | ||||
| for (int i = 0; i < totpoints; i++, pt++) { | |||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | mul_v3_m4v3(fpt, diff_mat, &pt->x); | ||||
| glVertex3fv(fpt); | glVertex3fv(fpt); | ||||
| } | } | ||||
| glEnd(); | glEnd(); | ||||
| } | } | ||||
| #endif | |||||
| } | } | ||||
| /* ----- Fancy 2D-Stroke Drawing ------ */ | /* ----- Fancy 2D-Stroke Drawing ------ */ | ||||
| /* draw a given stroke in 2d */ | /* draw a given stroke in 2d */ | ||||
| static void gp_draw_stroke_2d(const bGPDspoint *points, int totpoints, short thickness_s, short dflag, short sflag, | static void gp_draw_stroke_2d(bGPDspoint *points, int totpoints, short thickness_s, short dflag, short sflag, | ||||
| bool debug, int offsx, int offsy, int winx, int winy, const float diff_mat[4][4], const float ink[4]) | bool debug, int offsx, int offsy, int winx, int winy, float diff_mat[4][4], float ink[4]) | ||||
| { | { | ||||
| /* otherwise thickness is twice that of the 3D view */ | /* otherwise thickness is twice that of the 3D view */ | ||||
| float thickness = (float)thickness_s * 0.5f; | float thickness = (float)thickness_s * 0.5f; | ||||
| /* strokes in Image Editor need a scale factor, since units there are not pixels! */ | /* strokes in Image Editor need a scale factor, since units there are not pixels! */ | ||||
| float scalefac = 1.0f; | float scalefac = 1.0f; | ||||
| if ((dflag & GP_DRAWDATA_IEDITHACK) && (dflag & GP_DRAWDATA_ONLYV2D)) { | if ((dflag & GP_DRAWDATA_IEDITHACK) && (dflag & GP_DRAWDATA_ONLYV2D)) { | ||||
| scalefac = 0.001f; | scalefac = 0.001f; | ||||
| } | } | ||||
| /* TODO: fancy++ with the magic of shaders */ | |||||
| /* tessellation code - draw stroke as series of connected quads with connection | /* tessellation code - draw stroke as series of connected quads with connection | ||||
| * edges rotated to minimize shrinking artifacts, and rounded endcaps | * edges rotated to minimize shrinking artifacts, and rounded endcaps | ||||
| */ | */ | ||||
| { | { | ||||
| const bGPDspoint *pt1, *pt2; | bGPDspoint *pt1, *pt2; | ||||
| float pm[2]; | float pm[2]; | ||||
| int i; | int i; | ||||
| float fpt[3]; | float fpt[3]; | ||||
| VertexFormat *format = immVertexFormat(); | glShadeModel(GL_FLAT); | ||||
| unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); | glBegin(GL_QUADS); | ||||
| unsigned color = add_attrib(format, "color", GL_UNSIGNED_BYTE, 4, NORMALIZE_INT_TO_FLOAT); | |||||
| /* this code previously used glShadeModel(GL_FLAT) */ | |||||
| immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR); | |||||
| immBegin(GL_QUADS, (totpoints - 2) * 4 + 12); | |||||
| for (i = 0, pt1 = points, pt2 = points + 1; i < (totpoints - 1); i++, pt1++, pt2++) { | for (i = 0, pt1 = points, pt2 = points + 1; i < (totpoints - 1); i++, pt1++, pt2++) { | ||||
| float s0[2], s1[2]; /* segment 'center' points */ | float s0[2], s1[2]; /* segment 'center' points */ | ||||
| float t0[2], t1[2]; /* tessellated coordinates */ | float t0[2], t1[2]; /* tessellated coordinates */ | ||||
| Context not available. | |||||
| mul_v3_m4v3(fpt, diff_mat, &pt2->x); | mul_v3_m4v3(fpt, diff_mat, &pt2->x); | ||||
| gp_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, s1); | gp_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, s1); | ||||
| /* calculate gradient and normal - 'angle'=(ny/nx) */ | /* calculate gradient and normal - 'angle'=(ny/nx) */ | ||||
| m1[1] = s1[1] - s0[1]; | m1[1] = s1[1] - s0[1]; | ||||
| m1[0] = s1[0] - s0[0]; | m1[0] = s1[0] - s0[0]; | ||||
| normalize_v2(m1); | normalize_v2(m1); | ||||
| m2[1] = -m1[0]; | m2[1] = -m1[0]; | ||||
| m2[0] = m1[1]; | m2[0] = m1[1]; | ||||
| /* always use pressure from first point here */ | /* always use pressure from first point here */ | ||||
| pthick = (pt1->pressure * thickness * scalefac); | pthick = (pt1->pressure * thickness * scalefac); | ||||
| /* color of point */ | /* color of point */ | ||||
| gp_set_point_varying_color(pt1, ink, color); | gp_set_point_color(pt1, ink); | ||||
| /* if the first segment, start of segment is segment's normal */ | /* if the first segment, start of segment is segment's normal */ | ||||
| if (i == 0) { | if (i == 0) { | ||||
| Context not available. | |||||
| mt[1] = m2[1] * pthick * 0.5f; | mt[1] = m2[1] * pthick * 0.5f; | ||||
| sc[0] = s0[0] - (m1[0] * pthick * 0.75f); | sc[0] = s0[0] - (m1[0] * pthick * 0.75f); | ||||
| sc[1] = s0[1] - (m1[1] * pthick * 0.75f); | sc[1] = s0[1] - (m1[1] * pthick * 0.75f); | ||||
| t0[0] = sc[0] - mt[0]; | t0[0] = sc[0] - mt[0]; | ||||
| t0[1] = sc[1] - mt[1]; | t0[1] = sc[1] - mt[1]; | ||||
| t1[0] = sc[0] + mt[0]; | t1[0] = sc[0] + mt[0]; | ||||
| t1[1] = sc[1] + mt[1]; | t1[1] = sc[1] + mt[1]; | ||||
| immVertex2fv(pos, t0); | glVertex2fv(t0); | ||||
| immVertex2fv(pos, t1); | glVertex2fv(t1); | ||||
| /* calculate points for start of segment */ | /* calculate points for start of segment */ | ||||
| mt[0] = m2[0] * pthick; | mt[0] = m2[0] * pthick; | ||||
| mt[1] = m2[1] * pthick; | mt[1] = m2[1] * pthick; | ||||
| t0[0] = s0[0] - mt[0]; | t0[0] = s0[0] - mt[0]; | ||||
| t0[1] = s0[1] - mt[1]; | t0[1] = s0[1] - mt[1]; | ||||
| t1[0] = s0[0] + mt[0]; | t1[0] = s0[0] + mt[0]; | ||||
| t1[1] = s0[1] + mt[1]; | t1[1] = s0[1] + mt[1]; | ||||
| /* draw this line twice (first to finish off start cap, then for stroke) */ | /* draw this line twice (first to finish off start cap, then for stroke) */ | ||||
| immVertex2fv(pos, t1); | glVertex2fv(t1); | ||||
| immVertex2fv(pos, t0); | glVertex2fv(t0); | ||||
| immVertex2fv(pos, t0); | glVertex2fv(t0); | ||||
| immVertex2fv(pos, t1); | glVertex2fv(t1); | ||||
| } | } | ||||
| /* if not the first segment, use bisector of angle between segments */ | /* if not the first segment, use bisector of angle between segments */ | ||||
| else { | else { | ||||
| float mb[2]; /* bisector normal */ | float mb[2]; /* bisector normal */ | ||||
| float athick, dfac; /* actual thickness, difference between thicknesses */ | float athick, dfac; /* actual thickness, difference between thicknesses */ | ||||
| /* calculate gradient of bisector (as average of normals) */ | /* calculate gradient of bisector (as average of normals) */ | ||||
| mb[0] = (pm[0] + m2[0]) / 2; | mb[0] = (pm[0] + m2[0]) / 2; | ||||
| mb[1] = (pm[1] + m2[1]) / 2; | mb[1] = (pm[1] + m2[1]) / 2; | ||||
| normalize_v2(mb); | normalize_v2(mb); | ||||
| /* calculate gradient to apply | /* calculate gradient to apply | ||||
| * - as basis, use just pthick * bisector gradient | * - as basis, use just pthick * bisector gradient | ||||
| * - if cross-section not as thick as it should be, add extra padding to fix it | * - if cross-section not as thick as it should be, add extra padding to fix it | ||||
| Context not available. | |||||
| mt[1] = mb[1] * pthick; | mt[1] = mb[1] * pthick; | ||||
| athick = len_v2(mt); | athick = len_v2(mt); | ||||
| dfac = pthick - (athick * 2); | dfac = pthick - (athick * 2); | ||||
| if (((athick * 2.0f) < pthick) && (IS_EQF(athick, pthick) == 0)) { | if (((athick * 2.0f) < pthick) && (IS_EQF(athick, pthick) == 0)) { | ||||
| mt[0] += (mb[0] * dfac); | mt[0] += (mb[0] * dfac); | ||||
| mt[1] += (mb[1] * dfac); | mt[1] += (mb[1] * dfac); | ||||
| } | } | ||||
| /* calculate points for start of segment */ | /* calculate points for start of segment */ | ||||
| t0[0] = s0[0] - mt[0]; | t0[0] = s0[0] - mt[0]; | ||||
| t0[1] = s0[1] - mt[1]; | t0[1] = s0[1] - mt[1]; | ||||
| t1[0] = s0[0] + mt[0]; | t1[0] = s0[0] + mt[0]; | ||||
| t1[1] = s0[1] + mt[1]; | t1[1] = s0[1] + mt[1]; | ||||
| /* draw this line twice (once for end of current segment, and once for start of next) */ | /* draw this line twice (once for end of current segment, and once for start of next) */ | ||||
| immVertex2fv(pos, t1); | glVertex2fv(t1); | ||||
| immVertex2fv(pos, t0); | glVertex2fv(t0); | ||||
| immVertex2fv(pos, t0); | glVertex2fv(t0); | ||||
| immVertex2fv(pos, t1); | glVertex2fv(t1); | ||||
| } | } | ||||
| /* if last segment, also draw end of segment (defined as segment's normal) */ | /* if last segment, also draw end of segment (defined as segment's normal) */ | ||||
| if (i == totpoints - 2) { | if (i == totpoints - 2) { | ||||
| /* for once, we use second point's pressure (otherwise it won't be drawn) */ | /* for once, we use second point's pressure (otherwise it won't be drawn) */ | ||||
| pthick = (pt2->pressure * thickness * scalefac); | pthick = (pt2->pressure * thickness * scalefac); | ||||
| /* color of point */ | /* color of point */ | ||||
| gp_set_point_varying_color(pt2, ink, color); | gp_set_point_color(pt2, ink); | ||||
| /* calculate points for end of segment */ | /* calculate points for end of segment */ | ||||
| mt[0] = m2[0] * pthick; | mt[0] = m2[0] * pthick; | ||||
| mt[1] = m2[1] * pthick; | mt[1] = m2[1] * pthick; | ||||
| t0[0] = s1[0] - mt[0]; | t0[0] = s1[0] - mt[0]; | ||||
| t0[1] = s1[1] - mt[1]; | t0[1] = s1[1] - mt[1]; | ||||
| t1[0] = s1[0] + mt[0]; | t1[0] = s1[0] + mt[0]; | ||||
| t1[1] = s1[1] + mt[1]; | t1[1] = s1[1] + mt[1]; | ||||
| /* draw this line twice (once for end of stroke, and once for endcap)*/ | /* draw this line twice (once for end of stroke, and once for endcap)*/ | ||||
| immVertex2fv(pos, t1); | glVertex2fv(t1); | ||||
| immVertex2fv(pos, t0); | glVertex2fv(t0); | ||||
| immVertex2fv(pos, t0); | glVertex2fv(t0); | ||||
| immVertex2fv(pos, t1); | glVertex2fv(t1); | ||||
| /* draw end cap as last step | /* draw end cap as last step | ||||
| * - make points slightly closer to center (about halfway across) | * - make points slightly closer to center (about halfway across) | ||||
| */ | */ | ||||
| Context not available. | |||||
| mt[1] = m2[1] * pthick * 0.5f; | mt[1] = m2[1] * pthick * 0.5f; | ||||
| sc[0] = s1[0] + (m1[0] * pthick * 0.75f); | sc[0] = s1[0] + (m1[0] * pthick * 0.75f); | ||||
| sc[1] = s1[1] + (m1[1] * pthick * 0.75f); | sc[1] = s1[1] + (m1[1] * pthick * 0.75f); | ||||
| t0[0] = sc[0] - mt[0]; | t0[0] = sc[0] - mt[0]; | ||||
| t0[1] = sc[1] - mt[1]; | t0[1] = sc[1] - mt[1]; | ||||
| t1[0] = sc[0] + mt[0]; | t1[0] = sc[0] + mt[0]; | ||||
| t1[1] = sc[1] + mt[1]; | t1[1] = sc[1] + mt[1]; | ||||
| immVertex2fv(pos, t1); | glVertex2fv(t1); | ||||
| immVertex2fv(pos, t0); | glVertex2fv(t0); | ||||
| } | } | ||||
| /* store stroke's 'natural' normal for next stroke to use */ | /* store stroke's 'natural' normal for next stroke to use */ | ||||
| copy_v2_v2(pm, m2); | copy_v2_v2(pm, m2); | ||||
| } | } | ||||
| immEnd(); | glEnd(); | ||||
| immUnbindProgram(); | glShadeModel(GL_SMOOTH); | ||||
| } | } | ||||
| #if 0 /* convert to modern GL only if needed */ | |||||
| /* draw debug points of curve on top? (original stroke points) */ | /* draw debug points of curve on top? (original stroke points) */ | ||||
| if (debug) { | if (debug) { | ||||
| glPointSize((float)(thickness_s + 2)); | bGPDspoint *pt; | ||||
| int i; | |||||
| float fpt[3]; | |||||
| glPointSize((float)(thickness_s + 2)); | |||||
| glBegin(GL_POINTS); | glBegin(GL_POINTS); | ||||
| const bGPDspoint *pt = points; | for (i = 0, pt = points; i < totpoints && pt; i++, pt++) { | ||||
| for (int i = 0; i < totpoints && pt; i++, pt++) { | |||||
| float fpt[3]; | |||||
| float co[2]; | float co[2]; | ||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | mul_v3_m4v3(fpt, diff_mat, &pt->x); | ||||
| gp_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, co); | gp_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, co); | ||||
| Context not available. | |||||
| } | } | ||||
| glEnd(); | glEnd(); | ||||
| } | } | ||||
| #endif | |||||
| } | } | ||||
| /* ----- Strokes Drawing ------ */ | /* ----- Strokes Drawing ------ */ | ||||
| Context not available. | |||||
| return false; | return false; | ||||
| if (!(dflag & GP_DRAWDATA_ONLY3D) && (gps->flag & GP_STROKE_3DSPACE)) | if (!(dflag & GP_DRAWDATA_ONLY3D) && (gps->flag & GP_STROKE_3DSPACE)) | ||||
| return false; | return false; | ||||
| /* 2) Screen Space 2D Strokes */ | /* 2) Screen Space 2D Strokes */ | ||||
| if ((dflag & GP_DRAWDATA_ONLYV2D) && !(gps->flag & GP_STROKE_2DSPACE)) | if ((dflag & GP_DRAWDATA_ONLYV2D) && !(gps->flag & GP_STROKE_2DSPACE)) | ||||
| return false; | return false; | ||||
| if (!(dflag & GP_DRAWDATA_ONLYV2D) && (gps->flag & GP_STROKE_2DSPACE)) | if (!(dflag & GP_DRAWDATA_ONLYV2D) && (gps->flag & GP_STROKE_2DSPACE)) | ||||
| return false; | return false; | ||||
| /* 3) Image Space (2D) */ | /* 3) Image Space (2D) */ | ||||
| if ((dflag & GP_DRAWDATA_ONLYI2D) && !(gps->flag & GP_STROKE_2DIMAGE)) | if ((dflag & GP_DRAWDATA_ONLYI2D) && !(gps->flag & GP_STROKE_2DIMAGE)) | ||||
| return false; | return false; | ||||
| if (!(dflag & GP_DRAWDATA_ONLYI2D) && (gps->flag & GP_STROKE_2DIMAGE)) | if (!(dflag & GP_DRAWDATA_ONLYI2D) && (gps->flag & GP_STROKE_2DIMAGE)) | ||||
| return false; | return false; | ||||
| /* skip stroke if it doesn't have any valid data */ | /* skip stroke if it doesn't have any valid data */ | ||||
| if ((gps->points == NULL) || (gps->totpoints < 1)) | if ((gps->points == NULL) || (gps->totpoints < 1)) | ||||
| return false; | return false; | ||||
| /* stroke can be drawn */ | /* stroke can be drawn */ | ||||
| return true; | return true; | ||||
| } | } | ||||
| /* draw a set of strokes */ | /* draw a set of strokes */ | ||||
| static void gp_draw_strokes( | static void gp_draw_strokes( | ||||
| bGPdata *gpd, const bGPDframe *gpf, int offsx, int offsy, int winx, int winy, int dflag, | bGPdata *gpd, bGPDframe *gpf, int offsx, int offsy, int winx, int winy, int dflag, | ||||
| bool debug, short lthick, const float opacity, const float tintcolor[4], | bool debug, short lthick, const float opacity, const float tintcolor[4], | ||||
| const bool onion, const bool custonion, const float diff_mat[4][4]) | const bool onion, const bool custonion, float diff_mat[4][4]) | ||||
| { | { | ||||
| bGPDstroke *gps; | |||||
| float tcolor[4]; | float tcolor[4]; | ||||
| float tfill[4]; | float tfill[4]; | ||||
| short sthickness; | short sthickness; | ||||
| float ink[4]; | float ink[4]; | ||||
| for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { | for (gps = 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, dflag) == false) { | ||||
| continue; | continue; | ||||
| Context not available. | |||||
| 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) { | ||||
| const float *color; | |||||
| if (!onion) { | if (!onion) { | ||||
| color = tfill; | glColor4fv(tfill); | ||||
| } | } | ||||
| else { | else { | ||||
| if (custonion) { | if (custonion) { | ||||
| color = tintcolor; | glColor4fv(tintcolor); | ||||
| } | } | ||||
| else { | else { | ||||
| ARRAY_SET_ITEMS(tfill, UNPACK3(palcolor->fill), tintcolor[3]); | ARRAY_SET_ITEMS(tfill, UNPACK3(palcolor->fill), tintcolor[3]); | ||||
| color = tfill; | glColor4fv(tfill); | ||||
| } | } | ||||
| } | } | ||||
| gp_draw_stroke_fill(gpd, gps, offsx, offsy, winx, winy, diff_mat, color); | gp_draw_stroke_fill(gpd, gps, offsx, offsy, winx, winy, diff_mat); | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| 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) { | ||||
| const float *color; | |||||
| if (!onion) { | if (!onion) { | ||||
| color = tfill; | glColor4fv(tfill); | ||||
| } | } | ||||
| else { | else { | ||||
| if (custonion) { | if (custonion) { | ||||
| color = tintcolor; | glColor4fv(tintcolor); | ||||
| } | } | ||||
| else { | else { | ||||
| ARRAY_SET_ITEMS(tfill, palcolor->fill[0], palcolor->fill[1], palcolor->fill[2], | ARRAY_SET_ITEMS(tfill, palcolor->fill[0], palcolor->fill[1], palcolor->fill[2], | ||||
| tintcolor[3]); | tintcolor[3]); | ||||
| color = tfill; | glColor4fv(tfill); | ||||
| } | } | ||||
| } | } | ||||
| gp_draw_stroke_fill(gpd, gps, offsx, offsy, winx, winy, diff_mat, color); | gp_draw_stroke_fill(gpd, gps, offsx, offsy, winx, winy, diff_mat); | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| /* Draw selected verts for strokes being edited */ | /* Draw selected verts for strokes being edited */ | ||||
| static void gp_draw_strokes_edit( | static void gp_draw_strokes_edit( | ||||
| bGPdata *gpd, const bGPDframe *gpf, int offsx, int offsy, int winx, int winy, short dflag, | bGPdata *gpd, bGPDframe *gpf, int offsx, int offsy, int winx, int winy, short dflag, | ||||
| short lflag, const float diff_mat[4][4], float alpha) | short lflag, float diff_mat[4][4], float alpha) | ||||
| { | { | ||||
| bGPDstroke *gps; | |||||
| /* if alpha 0 do not draw */ | /* if alpha 0 do not draw */ | ||||
| if (alpha == 0.0f) | if (alpha == 0.0f) | ||||
| return; | return; | ||||
| Context not available. | |||||
| glGetIntegerv(GL_DEPTH_WRITEMASK, &mask_orig); | glGetIntegerv(GL_DEPTH_WRITEMASK, &mask_orig); | ||||
| glDepthMask(0); | glDepthMask(0); | ||||
| glEnable(GL_DEPTH_TEST); | glEnable(GL_DEPTH_TEST); | ||||
| /* first arg is normally rv3d->dist, but this isn't | /* first arg is normally rv3d->dist, but this isn't | ||||
| * available here and seems to work quite well without */ | * available here and seems to work quite well without */ | ||||
| bglPolygonOffset(1.0f, 1.0f); | bglPolygonOffset(1.0f, 1.0f); | ||||
| #if 0 | #if 0 | ||||
| glEnable(GL_POLYGON_OFFSET_LINE); /* do we want LINE or POINT here? (merwin) */ | glEnable(GL_POLYGON_OFFSET_LINE); | ||||
| glPolygonOffset(-1.0f, -1.0f); | glPolygonOffset(-1.0f, -1.0f); | ||||
| #endif | #endif | ||||
| } | } | ||||
| } | } | ||||
| GPU_enable_program_point_size(); | |||||
| /* draw stroke verts */ | /* draw stroke verts */ | ||||
| for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { | for (gps = gpf->strokes.first; gps; gps = gps->next) { | ||||
| bGPDspoint *pt; | |||||
| float vsize, bsize; | |||||
| int i; | |||||
| float fpt[3]; | |||||
| /* 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, dflag) == false) | ||||
| continue; | continue; | ||||
| /* Optimisation: only draw points for selected strokes | /* Optimisation: only draw points for selected strokes | ||||
| * We assume that selected points can only occur in | * We assume that selected points can only occur in | ||||
| * strokes that are selected too. | * strokes that are selected too. | ||||
| */ | */ | ||||
| if ((gps->flag & GP_STROKE_SELECT) == 0) | if ((gps->flag & GP_STROKE_SELECT) == 0) | ||||
| continue; | continue; | ||||
| /* verify palette color lock */ | /* verify palette color lock */ | ||||
| { | { | ||||
| bGPDpalettecolor *palcolor = ED_gpencil_stroke_getcolor(gpd, gps); | bGPDpalettecolor *palcolor = ED_gpencil_stroke_getcolor(gpd, gps); | ||||
| Context not available. | |||||
| * they stand out more. | * they stand out more. | ||||
| * - We use the theme setting for size of the unselected verts | * - We use the theme setting for size of the unselected verts | ||||
| */ | */ | ||||
| float bsize = UI_GetThemeValuef(TH_GP_VERTEX_SIZE); | bsize = UI_GetThemeValuef(TH_GP_VERTEX_SIZE); | ||||
| float vsize; | |||||
| if ((int)bsize > 8) { | if ((int)bsize > 8) { | ||||
| vsize = 10.0f; | vsize = 10.0f; | ||||
| bsize = 8.0f; | bsize = 8.0f; | ||||
| Context not available. | |||||
| else { | else { | ||||
| vsize = bsize + 2; | vsize = bsize + 2; | ||||
| } | } | ||||
| /* First Pass: Draw all the verts (i.e. these become the unselected state) */ | |||||
| /* 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); | bGPDpalettecolor *palcolor = ED_gpencil_stroke_getcolor(gpd, gps); | ||||
| glColor3fv(palcolor->color); | |||||
| float selectColor[4]; | glPointSize(bsize); | ||||
| UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, selectColor); | |||||
| selectColor[3] = alpha; | glBegin(GL_POINTS); | ||||
| for (i = 0, pt = gps->points; i < gps->totpoints && pt; i++, pt++) { | |||||
| VertexFormat *format = immVertexFormat(); | |||||
| unsigned pos; /* specified later */ | |||||
| unsigned size = add_attrib(format, "size", GL_FLOAT, 1, KEEP_FLOAT); | |||||
| unsigned color = add_attrib(format, "color", GL_FLOAT, 3, KEEP_FLOAT); | |||||
| if (gps->flag & GP_STROKE_3DSPACE) { | |||||
| pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT); | |||||
| immBindBuiltinProgram(GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR); | |||||
| } | |||||
| else { | |||||
| pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); | |||||
| immBindBuiltinProgram(GPU_SHADER_2D_POINT_VARYING_SIZE_VARYING_COLOR); | |||||
| } | |||||
| immBegin(GL_POINTS, gps->totpoints); | |||||
| /* Draw start and end point differently if enabled stroke direction hint */ | |||||
| bool show_direction_hint = (gpd->flag & GP_DATA_SHOW_DIRECTION) && (gps->totpoints > 1); | |||||
| /* Draw all the stroke points (selected or not) */ | |||||
| bGPDspoint *pt = gps->points; | |||||
| float fpt[3]; | |||||
| for (int i = 0; i < gps->totpoints; i++, pt++) { | |||||
| /* size and color first */ | |||||
| if (show_direction_hint && i == 0) { | |||||
| /* start point in green bigger */ | |||||
| immAttrib3f(color, 0.0f, 1.0f, 0.0f); | |||||
| immAttrib1f(size, vsize + 4); | |||||
| } | |||||
| else if (show_direction_hint && (i == gps->totpoints - 1)) { | |||||
| /* end point in red smaller */ | |||||
| immAttrib3f(color, 1.0f, 0.0f, 0.0f); | |||||
| immAttrib1f(size, vsize + 1); | |||||
| } | |||||
| else if (pt->flag & GP_SPOINT_SELECT) { | |||||
| immAttrib3fv(color, selectColor); | |||||
| immAttrib1f(size, vsize); | |||||
| } | |||||
| else { | |||||
| immAttrib3fv(color, palcolor->color); | |||||
| immAttrib1f(size, bsize); | |||||
| } | |||||
| /* then position */ | |||||
| if (gps->flag & GP_STROKE_3DSPACE) { | if (gps->flag & GP_STROKE_3DSPACE) { | ||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | mul_v3_m4v3(fpt, diff_mat, &pt->x); | ||||
| immVertex3fv(pos, fpt); | glVertex3fv(fpt); | ||||
| } | } | ||||
| else { | else { | ||||
| float co[2]; | float co[2]; | ||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | mul_v3_m4v3(fpt, diff_mat, &pt->x); | ||||
| gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co); | gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co); | ||||
| immVertex2fv(pos, co); | glVertex2fv(co); | ||||
| } | } | ||||
| } | } | ||||
| glEnd(); | |||||
| /* Second Pass: Draw only verts which are selected */ | |||||
| float curColor[4]; | |||||
| UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, curColor); | |||||
| glColor4f(curColor[0], curColor[1], curColor[2], alpha); | |||||
| immEnd(); | glPointSize(vsize); | ||||
| immUnbindProgram(); | |||||
| } | glBegin(GL_POINTS); | ||||
| for (i = 0, pt = gps->points; i < gps->totpoints && pt; i++, pt++) { | |||||
| if (pt->flag & GP_SPOINT_SELECT) { | |||||
| if (gps->flag & GP_STROKE_3DSPACE) { | |||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | |||||
| glVertex3fv(fpt); | |||||
| } | |||||
| else { | |||||
| float co[2]; | |||||
| mul_v3_m4v3(fpt, diff_mat, &pt->x); | |||||
| gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co); | |||||
| glVertex2fv(co); | |||||
| } | |||||
| } | |||||
| } | |||||
| glEnd(); | |||||
| GPU_disable_program_point_size(); | /* Draw start and end point if enabled stroke direction hint */ | ||||
| if ((gpd->flag & GP_DATA_SHOW_DIRECTION) && (gps->totpoints > 1)) { | |||||
| bGPDspoint *p; | |||||
| glPointSize(vsize + 4); | |||||
| glBegin(GL_POINTS); | |||||
| /* start point in green bigger */ | |||||
| glColor3f(0.0f, 1.0f, 0.0f); | |||||
| p = &gps->points[0]; | |||||
| mul_v3_m4v3(fpt, diff_mat, &p->x); | |||||
| glVertex3fv(fpt); | |||||
| glEnd(); | |||||
| /* end point in red smaller */ | |||||
| glPointSize(vsize + 1); | |||||
| glBegin(GL_POINTS); | |||||
| glColor3f(1.0f, 0.0f, 0.0f); | |||||
| p = &gps->points[gps->totpoints - 1]; | |||||
| mul_v3_m4v3(fpt, diff_mat, &p->x); | |||||
| glVertex3fv(fpt); | |||||
| glEnd(); | |||||
| } | |||||
| } | |||||
| /* clear depth mask */ | /* clear depth mask */ | ||||
| if (dflag & GP_DRAWDATA_ONLY3D) { | if (dflag & GP_DRAWDATA_ONLY3D) { | ||||
| if (no_xray) { | if (no_xray) { | ||||
| glDepthMask(mask_orig); | glDepthMask(mask_orig); | ||||
| glDisable(GL_DEPTH_TEST); | glDisable(GL_DEPTH_TEST); | ||||
| bglPolygonOffset(0.0, 0.0); | bglPolygonOffset(0.0, 0.0); | ||||
| #if 0 | #if 0 | ||||
| glDisable(GL_POLYGON_OFFSET_LINE); | glDisable(GL_POLYGON_OFFSET_LINE); | ||||
| Context not available. | |||||
| /* draw onion-skinning for a layer */ | /* draw onion-skinning for a layer */ | ||||
| static void gp_draw_onionskins( | static void gp_draw_onionskins( | ||||
| bGPdata *gpd, const bGPDlayer *gpl, const bGPDframe *gpf, int offsx, int offsy, int winx, int winy, | bGPdata *gpd, bGPDlayer *gpl, bGPDframe *gpf, int offsx, int offsy, int winx, int winy, | ||||
| int UNUSED(cfra), int dflag, bool debug, const float diff_mat[4][4]) | int UNUSED(cfra), int dflag, bool debug, 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; | ||||
| Context not available. | |||||
| else { | else { | ||||
| copy_v3_v3(color, default_color); | copy_v3_v3(color, default_color); | ||||
| } | } | ||||
| if (gpl->gstep > 0) { | if (gpl->gstep > 0) { | ||||
| bGPDframe *gf; | |||||
| float fac; | |||||
| /* draw previous frames first */ | /* draw previous frames first */ | ||||
| for (bGPDframe *gf = gpf->prev; gf; gf = gf->prev) { | for (gf = gpf->prev; gf; gf = gf->prev) { | ||||
| /* check if frame is drawable */ | /* check if frame is drawable */ | ||||
| if ((gpf->framenum - gf->framenum) <= gpl->gstep) { | if ((gpf->framenum - gf->framenum) <= 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)); | 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, gpl->flag & GP_LAYER_GHOST_PREVCOL, diff_mat); | ||||
| Context not available. | |||||
| else { | else { | ||||
| /* don't draw - disabled */ | /* don't draw - disabled */ | ||||
| } | } | ||||
| /* 2) Now draw next frames */ | /* 2) Now draw next frames */ | ||||
| if (gpl->flag & GP_LAYER_GHOST_NEXTCOL) { | if (gpl->flag & GP_LAYER_GHOST_NEXTCOL) { | ||||
| copy_v3_v3(color, gpl->gcolor_next); | copy_v3_v3(color, gpl->gcolor_next); | ||||
| Context not available. | |||||
| else { | else { | ||||
| copy_v3_v3(color, default_color); | copy_v3_v3(color, default_color); | ||||
| } | } | ||||
| if (gpl->gstep_next > 0) { | if (gpl->gstep_next > 0) { | ||||
| bGPDframe *gf; | |||||
| float fac; | |||||
| /* now draw next frames */ | /* now draw next frames */ | ||||
| for (bGPDframe *gf = gpf->next; gf; gf = gf->next) { | for (gf = 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 - gpf->framenum) <= 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)); | 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, gpl->flag & GP_LAYER_GHOST_NEXTCOL, diff_mat); | ||||
| Context not available. | |||||
| else { | else { | ||||
| /* don't draw - disabled */ | /* don't draw - disabled */ | ||||
| } | } | ||||
| } | } | ||||
| /* draw interpolate strokes (used only while operator is running) */ | /* draw interpolate strokes (used only while operator is running) */ | ||||
| Context not available. | |||||
| /* 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, | bGPDbrush *brush, float alpha, 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) | ||||
| { | { | ||||
| bGPDlayer *gpl; | |||||
| float diff_mat[4][4]; | float diff_mat[4][4]; | ||||
| for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { | ||||
| bGPDframe *gpf; | |||||
| /* calculate parent position */ | /* calculate parent position */ | ||||
| ED_gpencil_parent_location(gpl, diff_mat); | ED_gpencil_parent_location(gpl, diff_mat); | ||||
| bool debug = (gpl->flag & GP_LAYER_DRAWDEBUG); | bool debug = (gpl->flag & GP_LAYER_DRAWDEBUG) ? true : false; | ||||
| short lthick = brush->thickness + gpl->thickness; | short lthick = brush->thickness + gpl->thickness; | ||||
| /* don't draw layer if hidden */ | /* don't draw layer if hidden */ | ||||
| if (gpl->flag & GP_LAYER_HIDE) | if (gpl->flag & GP_LAYER_HIDE) | ||||
| continue; | continue; | ||||
| /* get frame to draw */ | /* get frame to draw */ | ||||
| bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra, 0); | gpf = BKE_gpencil_layer_getframe(gpl, cfra, 0); | ||||
| if (gpf == NULL) | if (gpf == NULL) | ||||
| continue; | continue; | ||||
| /* set basic stroke thickness */ | /* set basic stroke thickness */ | ||||
| glLineWidth(lthick); | glLineWidth(lthick); | ||||
| Context not available. | |||||
| if (condition) dflag |= (draw_flag_value); \ | if (condition) dflag |= (draw_flag_value); \ | ||||
| else dflag &= ~(draw_flag_value); \ | else dflag &= ~(draw_flag_value); \ | ||||
| } (void)0 | } (void)0 | ||||
| /* xray... */ | /* xray... */ | ||||
| GP_DRAWFLAG_APPLY((gpl->flag & GP_LAYER_NO_XRAY), GP_DRAWDATA_NO_XRAY); | GP_DRAWFLAG_APPLY((gpl->flag & GP_LAYER_NO_XRAY), GP_DRAWDATA_NO_XRAY); | ||||
| /* volumetric strokes... */ | /* volumetric strokes... */ | ||||
| GP_DRAWFLAG_APPLY((gpl->flag & GP_LAYER_VOLUMETRIC), GP_DRAWDATA_VOLUMETRIC); | GP_DRAWFLAG_APPLY((gpl->flag & GP_LAYER_VOLUMETRIC), GP_DRAWDATA_VOLUMETRIC); | ||||
| Context not available. | |||||
| GP_DRAWFLAG_APPLY((gpl->flag & GP_LAYER_HQ_FILL), GP_DRAWDATA_HQ_FILL); | 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) */ | ||||
| if ((gpl->flag & GP_LAYER_ONIONSKIN) && !(dflag & GP_DRAWDATA_NO_ONIONS)) { | if ((gpl->flag & GP_LAYER_ONIONSKIN) && !(dflag & GP_DRAWDATA_NO_ONIONS)) { | ||||
| /* Drawing method - only immediately surrounding (gstep = 0), | /* Drawing method - only immediately surrounding (gstep = 0), | ||||
| Context not available. | |||||
| */ | */ | ||||
| gp_draw_onionskins(gpd, gpl, gpf, offsx, offsy, winx, winy, cfra, dflag, debug, diff_mat); | gp_draw_onionskins(gpd, gpl, gpf, offsx, offsy, winx, winy, cfra, dflag, debug, diff_mat); | ||||
| } | } | ||||
| /* 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(gpd, gpf, offsx, offsy, winx, winy, dflag, debug, gpl->thickness, | ||||
| gpl->opacity, gpl->tintcolor, false, false, diff_mat); | gpl->opacity, gpl->tintcolor, false, false, diff_mat); | ||||
| /* Draw verts of selected strokes | /* Draw verts of selected strokes | ||||
| * - when doing OpenGL renders, we don't want to be showing these, as that ends up flickering | * - when doing OpenGL renders, we don't want to be showing these, as that ends up flickering | ||||
| * - locked layers can't be edited, so there's no point showing these verts | * - locked layers can't be edited, so there's no point showing these verts | ||||
| Context not available. | |||||
| { | { | ||||
| gp_draw_strokes_edit(gpd, gpf, offsx, offsy, winx, winy, dflag, gpl->flag, diff_mat, alpha); | gp_draw_strokes_edit(gpd, gpf, offsx, offsy, winx, winy, dflag, gpl->flag, diff_mat, alpha); | ||||
| } | } | ||||
| /* Check if may need to draw the active stroke cache, only if this layer is the active layer | /* Check if may need to draw the active stroke cache, only if this layer is the active layer | ||||
| * that is being edited. (Stroke buffer is currently stored in gp-data) | * that is being edited. (Stroke buffer is currently stored in gp-data) | ||||
| */ | */ | ||||
| if (ED_gpencil_session_active() && (gpl->flag & GP_LAYER_ACTIVE) && | if (ED_gpencil_session_active() && (gpl->flag & GP_LAYER_ACTIVE) && | ||||
| (gpf->flag & GP_FRAME_PAINT)) | (gpf->flag & GP_FRAME_PAINT)) | ||||
| { | { | ||||
| /* Set color for drawing buffer stroke - since this may not be set yet */ | |||||
| // glColor4fv(gpl->color); | |||||
| /* Buffer stroke needs to be drawn with a different linestyle | /* Buffer stroke needs to be drawn with a different linestyle | ||||
| * to help differentiate them from normal strokes. | * to help differentiate them from normal strokes. | ||||
| * | * | ||||
| Context not available. | |||||
| */ | */ | ||||
| if (gpd->sflag & PC_COLOR_VOLUMETRIC) { | if (gpd->sflag & PC_COLOR_VOLUMETRIC) { | ||||
| 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->sbuffer_sflag, gpd->scolor); | ||||
| } | } | ||||
| else { | else { | ||||
| gp_draw_stroke_buffer(gpd->sbuffer, gpd->sbuffer_size, lthick, dflag, gpd->sbuffer_sflag, gpd->scolor); | gp_draw_stroke_buffer(gpd->sbuffer, gpd->sbuffer_size, lthick, dflag, gpd->sbuffer_sflag, gpd->scolor); | ||||
| Context not available. | |||||
| } | } | ||||
| /* draw a short status message in the top-right corner */ | /* draw a short status message in the top-right corner */ | ||||
| static void gp_draw_status_text(const bGPdata *gpd, ARegion *ar) | static void gp_draw_status_text(bGPdata *gpd, ARegion *ar) | ||||
| { | { | ||||
| rcti rect; | rcti rect; | ||||
| /* Cannot draw any status text when drawing OpenGL Renders */ | /* Cannot draw any status text when drawing OpenGL Renders */ | ||||
| if (G.f & G_RENDER_OGL) | if (G.f & G_RENDER_OGL) | ||||
| return; | return; | ||||
| /* Get bounds of region - Necessary to avoid problems with region overlap */ | /* Get bounds of region - Necessary to avoid problems with region overlap */ | ||||
| ED_region_visible_rect(ar, &rect); | ED_region_visible_rect(ar, &rect); | ||||
| /* for now, this should only be used to indicate when we are in stroke editmode */ | /* for now, this should only be used to indicate when we are in stroke editmode */ | ||||
| if (gpd->flag & GP_DATA_STROKE_EDITMODE) { | if (gpd->flag & GP_DATA_STROKE_EDITMODE) { | ||||
| const char *printable = IFACE_("GPencil Stroke Editing"); | const char *printable = IFACE_("GPencil Stroke Editing"); | ||||
| float printable_size[2]; | float printable_size[2]; | ||||
| int xco, yco; | |||||
| BLF_width_and_height_default(printable, BLF_DRAW_STR_DUMMY_MAX, &printable_size[0], &printable_size[1]); | BLF_width_and_height_default(printable, BLF_DRAW_STR_DUMMY_MAX, &printable_size[0], &printable_size[1]); | ||||
| int xco = (rect.xmax - U.widget_unit) - (int)printable_size[0]; | xco = (rect.xmax - U.widget_unit) - (int)printable_size[0]; | ||||
| int yco = (rect.ymax - U.widget_unit); | yco = (rect.ymax - U.widget_unit); | ||||
| /* text label */ | /* text label */ | ||||
| UI_ThemeColor(TH_TEXT_HI); | UI_ThemeColor(TH_TEXT_HI); | ||||
| #ifdef WITH_INTERNATIONAL | #ifdef WITH_INTERNATIONAL | ||||
| Context not available. | |||||
| #else | #else | ||||
| BLF_draw_default_ascii(xco, yco, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX); | BLF_draw_default_ascii(xco, yco, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX); | ||||
| #endif | #endif | ||||
| /* grease pencil icon... */ | /* grease pencil icon... */ | ||||
| // XXX: is this too intrusive? | // XXX: is this too intrusive? | ||||
| glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||||
| glEnable(GL_BLEND); | glEnable(GL_BLEND); | ||||
| xco -= U.widget_unit; | xco -= U.widget_unit; | ||||
| yco -= (int)printable_size[1] / 2; | yco -= (int)printable_size[1] / 2; | ||||
| UI_icon_draw(xco, yco, ICON_GREASEPENCIL); | UI_icon_draw(xco, yco, ICON_GREASEPENCIL); | ||||
| glDisable(GL_BLEND); | glDisable(GL_BLEND); | ||||
| } | } | ||||
| } | } | ||||
| /* draw grease-pencil datablock */ | /* draw grease-pencil datablock */ | ||||
| static void gp_draw_data( | static void gp_draw_data( | ||||
| const bGPDbrush *brush, float alpha, bGPdata *gpd, | bGPDbrush *brush, float alpha, 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) | ||||
| { | { | ||||
| #if 0 /* disable to see if really needed. re-enable or delete by Dec 2016 */ | |||||
| /* reset line drawing style (in case previous user didn't reset) */ | /* reset line drawing style (in case previous user didn't reset) */ | ||||
| setlinestyle(0); | setlinestyle(0); | ||||
| #endif | |||||
| /* turn on smooth lines (i.e. anti-aliasing) */ | /* turn on smooth lines (i.e. anti-aliasing) */ | ||||
| glEnable(GL_LINE_SMOOTH); | glEnable(GL_LINE_SMOOTH); | ||||
| /* XXX: turn on some way of ensuring that the polygon edges get smoothed | /* XXX: turn on some way of ensuring that the polygon edges get smoothed | ||||
| * GL_POLYGON_SMOOTH is nasty and shouldn't be used, as it ends up | * GL_POLYGON_SMOOTH is nasty and shouldn't be used, as it ends up | ||||
| * creating internal white rays due to the ways it accumulates stuff | * creating internal white rays due to the ways it accumulates stuff | ||||
| */ | */ | ||||
| /* turn on alpha-blending */ | /* turn on alpha-blending */ | ||||
| glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | ||||
| glEnable(GL_BLEND); | glEnable(GL_BLEND); | ||||
| /* draw! */ | /* draw! */ | ||||
| gp_draw_data_layers(brush, alpha, gpd, offsx, offsy, winx, winy, cfra, dflag); | gp_draw_data_layers(brush, alpha, gpd, offsx, offsy, winx, winy, cfra, dflag); | ||||
| /* turn off alpha blending, then smooth lines */ | /* turn off alpha blending, then smooth lines */ | ||||
| glDisable(GL_BLEND); // alpha blending | glDisable(GL_BLEND); // alpha blending | ||||
| glDisable(GL_LINE_SMOOTH); // smooth lines | glDisable(GL_LINE_SMOOTH); // smooth lines | ||||
| #if 0 /* disable to see if really needed. re-enable or delete by Dec 2016 */ | |||||
| /* restore initial gl conditions */ | /* restore initial gl conditions */ | ||||
| glColor4f(0, 0, 0, 1); | glColor4f(0, 0, 0, 1); | ||||
| #endif | |||||
| } | } | ||||
| /* if we have strokes for scenes (3d view)/clips (movie clip editor) | /* if we have strokes for scenes (3d view)/clips (movie clip editor) | ||||
| 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; | ||||
| if (scene) { | if (scene) { | ||||
| 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. | |||||
| /* currently drawing only gpencil data from either clip or track, but not both - XXX fix logic behind */ | /* currently drawing only gpencil data from either clip or track, but not both - XXX fix logic behind */ | ||||
| gpd_source = (scene->clip->gpd ? scene->clip->gpd : NULL); | gpd_source = (scene->clip->gpd ? scene->clip->gpd : NULL); | ||||
| } | } | ||||
| if (gpd_source) { | if (gpd_source) { | ||||
| ToolSettings *ts = scene->toolsettings; | ToolSettings *ts = scene->toolsettings; | ||||
| bGPDbrush *brush = BKE_gpencil_brush_getactive(ts); | bGPDbrush *brush = BKE_gpencil_brush_getactive(ts); | ||||
| Context not available. | |||||
| gp_draw_data(brush, ts->gp_sculpt.alpha, gpd_source, | gp_draw_data(brush, ts->gp_sculpt.alpha, gpd_source, | ||||
| offsx, offsy, winx, winy, cfra, dflag); | offsx, offsy, winx, winy, cfra, dflag); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* scene/clip data has already been drawn, only object/track data is drawn here | /* scene/clip data has already been drawn, only object/track data is drawn here | ||||
| * if gpd_source == gpd, we don't have any object/track data and we can skip */ | * if gpd_source == gpd, we don't have any object/track data and we can skip */ | ||||
| if (gpd_source == NULL || (gpd_source && gpd_source != gpd)) { | if (gpd_source == NULL || (gpd_source && gpd_source != gpd)) { | ||||
| Context not available. | |||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| bGPdata *gpd; | |||||
| int offsx, offsy, sizex, sizey; | int offsx, offsy, sizex, sizey; | ||||
| int dflag = GP_DRAWDATA_NOSTATUS; | int dflag = GP_DRAWDATA_NOSTATUS; | ||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); // XXX | gpd = ED_gpencil_data_get_active(C); // XXX | ||||
| if (gpd == NULL) return; | if (gpd == NULL) return; | ||||
| /* calculate rect */ | /* calculate rect */ | ||||
| switch (sa->spacetype) { | switch (sa->spacetype) { | ||||
| case SPACE_IMAGE: /* image */ | case SPACE_IMAGE: /* image */ | ||||
| case SPACE_CLIP: /* clip */ | case SPACE_CLIP: /* clip */ | ||||
| { | { | ||||
| /* just draw using standard scaling (settings here are currently ignored anyways) */ | /* just draw using standard scaling (settings here are currently ignored anyways) */ | ||||
| /* FIXME: the opengl poly-strokes don't draw at right thickness when done this way, so disabled */ | /* FIXME: the opengl poly-strokes don't draw at right thickness when done this way, so disabled */ | ||||
| offsx = 0; | offsx = 0; | ||||
| offsy = 0; | offsy = 0; | ||||
| sizex = ar->winx; | sizex = ar->winx; | ||||
| sizey = ar->winy; | sizey = ar->winy; | ||||
| wmOrtho2(ar->v2d.cur.xmin, ar->v2d.cur.xmax, ar->v2d.cur.ymin, ar->v2d.cur.ymax); | wmOrtho2(ar->v2d.cur.xmin, ar->v2d.cur.xmax, ar->v2d.cur.ymin, ar->v2d.cur.ymax); | ||||
| dflag |= GP_DRAWDATA_ONLYV2D | GP_DRAWDATA_IEDITHACK; | dflag |= GP_DRAWDATA_ONLYV2D | GP_DRAWDATA_IEDITHACK; | ||||
| break; | break; | ||||
| } | } | ||||
| Context not available. | |||||
| offsy = 0; | offsy = 0; | ||||
| sizex = ar->winx; | sizex = ar->winx; | ||||
| sizey = ar->winy; | sizey = ar->winy; | ||||
| /* NOTE: I2D was used in 2.4x, but the old settings for that have been deprecated | /* NOTE: I2D was used in 2.4x, but the old settings for that have been deprecated | ||||
| * and everything moved to standard View2d | * and everything moved to standard View2d | ||||
| */ | */ | ||||
| Context not available. | |||||
| offsy = 0; | offsy = 0; | ||||
| sizex = ar->winx; | sizex = ar->winx; | ||||
| sizey = ar->winy; | sizey = ar->winy; | ||||
| dflag |= GP_DRAWDATA_ONLYI2D; | dflag |= GP_DRAWDATA_ONLYI2D; | ||||
| break; | break; | ||||
| } | } | ||||
| if (ED_screen_animation_playing(wm)) { | if (ED_screen_animation_playing(wm)) { | ||||
| /* don't show onionskins during animation playback/scrub (i.e. it obscures the poses) | /* don't show onionskins during animation playback/scrub (i.e. it obscures the poses) | ||||
| * OpenGL Renders (i.e. final output), or depth buffer (i.e. not real strokes) | * OpenGL Renders (i.e. final output), or depth buffer (i.e. not real strokes) | ||||
| */ | */ | ||||
| dflag |= GP_DRAWDATA_NO_ONIONS; | dflag |= GP_DRAWDATA_NO_ONIONS; | ||||
| } | } | ||||
| /* draw it! */ | /* draw it! */ | ||||
| gp_draw_data_all(scene, gpd, offsx, offsy, sizex, sizey, CFRA, dflag, sa->spacetype); | gp_draw_data_all(scene, gpd, offsx, offsy, sizex, sizey, CFRA, dflag, sa->spacetype); | ||||
| } | } | ||||
| /* draw grease-pencil sketches to specified 2d-view assuming that matrices are already set correctly | /* draw grease-pencil sketches to specified 2d-view assuming that matrices are already set correctly | ||||
| * Note: this gets called twice - first time with onlyv2d=true to draw 'canvas' strokes, | * Note: this gets called twice - first time with onlyv2d=1 to draw 'canvas' strokes, | ||||
| * second time with onlyv2d=false for screen-aligned strokes */ | * second time with onlyv2d=0 for screen-aligned strokes */ | ||||
| void ED_gpencil_draw_view2d(const bContext *C, bool onlyv2d) | void ED_gpencil_draw_view2d(const bContext *C, bool onlyv2d) | ||||
| { | { | ||||
| wmWindowManager *wm = CTX_wm_manager(C); | wmWindowManager *wm = CTX_wm_manager(C); | ||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| bGPdata *gpd; | |||||
| int dflag = 0; | int dflag = 0; | ||||
| /* check that we have grease-pencil stuff to draw */ | /* check that we have grease-pencil stuff to draw */ | ||||
| if (sa == NULL) return; | if (sa == NULL) return; | ||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); // XXX | gpd = ED_gpencil_data_get_active(C); // XXX | ||||
| if (gpd == NULL) return; | if (gpd == NULL) return; | ||||
| /* special hack for Image Editor */ | /* special hack for Image Editor */ | ||||
| /* FIXME: the opengl poly-strokes don't draw at right thickness when done this way, so disabled */ | /* FIXME: the opengl poly-strokes don't draw at right thickness when done this way, so disabled */ | ||||
| if (ELEM(sa->spacetype, SPACE_IMAGE, SPACE_CLIP)) | if (ELEM(sa->spacetype, SPACE_IMAGE, SPACE_CLIP)) | ||||
| dflag |= GP_DRAWDATA_IEDITHACK; | dflag |= GP_DRAWDATA_IEDITHACK; | ||||
| /* draw it! */ | /* draw it! */ | ||||
| if (onlyv2d) dflag |= (GP_DRAWDATA_ONLYV2D | GP_DRAWDATA_NOSTATUS); | if (onlyv2d) dflag |= (GP_DRAWDATA_ONLYV2D | GP_DRAWDATA_NOSTATUS); | ||||
| if (ED_screen_animation_playing(wm)) dflag |= GP_DRAWDATA_NO_ONIONS; | if (ED_screen_animation_playing(wm)) dflag |= GP_DRAWDATA_NO_ONIONS; | ||||
| gp_draw_data_all(scene, gpd, 0, 0, ar->winx, ar->winy, CFRA, dflag, sa->spacetype); | gp_draw_data_all(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 == false) { | ||||
| gp_draw_status_text(gpd, ar); | gp_draw_status_text(gpd, ar); | ||||
| } | } | ||||
| } | } | ||||
| /* draw grease-pencil sketches to specified 3d-view assuming that matrices are already set correctly | /* draw grease-pencil sketches to specified 3d-view assuming that matrices are already set correctly | ||||
| * Note: this gets called twice - first time with only3d=true to draw 3d-strokes, | * Note: this gets called twice - first time with only3d=1 to draw 3d-strokes, | ||||
| * second time with only3d=false for screen-aligned strokes */ | * second time with only3d=0 for screen-aligned strokes */ | ||||
| void ED_gpencil_draw_view3d(wmWindowManager *wm, Scene *scene, View3D *v3d, ARegion *ar, bool only3d) | void ED_gpencil_draw_view3d(wmWindowManager *wm, Scene *scene, View3D *v3d, ARegion *ar, bool only3d) | ||||
| { | { | ||||
| bGPdata *gpd; | |||||
| int dflag = 0; | int dflag = 0; | ||||
| RegionView3D *rv3d = ar->regiondata; | RegionView3D *rv3d = ar->regiondata; | ||||
| int offsx, offsy, winx, winy; | int offsx, offsy, winx, winy; | ||||
| /* check that we have grease-pencil stuff to draw */ | /* check that we have grease-pencil stuff to draw */ | ||||
| bGPdata *gpd = ED_gpencil_data_get_active_v3d(scene, v3d); | gpd = ED_gpencil_data_get_active_v3d(scene, v3d); | ||||
| if (gpd == NULL) return; | if (gpd == NULL) return; | ||||
| /* when rendering to the offscreen buffer we don't want to | /* when rendering to the offscreen buffer we don't want to | ||||
| * deal with the camera border, otherwise map the coords to the camera border. */ | * deal with the camera border, otherwise map the coords to the camera border. */ | ||||
| if ((rv3d->persp == RV3D_CAMOB) && !(G.f & G_RENDER_OGL)) { | if ((rv3d->persp == RV3D_CAMOB) && !(G.f & G_RENDER_OGL)) { | ||||
| rctf rectf; | rctf rectf; | ||||
| ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &rectf, true); /* no shift */ | ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &rectf, true); /* no shift */ | ||||
| offsx = iroundf(rectf.xmin); | offsx = iroundf(rectf.xmin); | ||||
| offsy = iroundf(rectf.ymin); | offsy = iroundf(rectf.ymin); | ||||
| winx = iroundf(rectf.xmax - rectf.xmin); | winx = iroundf(rectf.xmax - rectf.xmin); | ||||
| Context not available. | |||||
| winx = ar->winx; | winx = ar->winx; | ||||
| winy = ar->winy; | winy = ar->winy; | ||||
| } | } | ||||
| /* set flags */ | /* set flags */ | ||||
| if (only3d) { | if (only3d) { | ||||
| /* 3D strokes/3D space: | /* 3D strokes/3D space: | ||||
| Context not available. | |||||
| */ | */ | ||||
| dflag |= (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_NOSTATUS); | dflag |= (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_NOSTATUS); | ||||
| } | } | ||||
| if (v3d->flag2 & V3D_RENDER_OVERRIDE) { | if (v3d->flag2 & V3D_RENDER_OVERRIDE) { | ||||
| /* don't draw status text when "only render" flag is set */ | /* don't draw status text when "only render" flag is set */ | ||||
| dflag |= GP_DRAWDATA_NOSTATUS; | dflag |= GP_DRAWDATA_NOSTATUS; | ||||
| } | } | ||||
| if ((wm == NULL) || ED_screen_animation_playing(wm)) { | if ((wm == NULL) || ED_screen_animation_playing(wm)) { | ||||
| /* don't show onionskins during animation playback/scrub (i.e. it obscures the poses) | /* don't show onionskins during animation playback/scrub (i.e. it obscures the poses) | ||||
| * OpenGL Renders (i.e. final output), or depth buffer (i.e. not real strokes) | * OpenGL Renders (i.e. final output), or depth buffer (i.e. not real strokes) | ||||
| */ | */ | ||||
| dflag |= GP_DRAWDATA_NO_ONIONS; | dflag |= GP_DRAWDATA_NO_ONIONS; | ||||
| } | } | ||||
| /* draw it! */ | /* draw it! */ | ||||
| gp_draw_data_all(scene, gpd, offsx, offsy, winx, winy, CFRA, dflag, v3d->spacetype); | gp_draw_data_all(scene, gpd, offsx, offsy, winx, winy, CFRA, dflag, v3d->spacetype); | ||||
| } | } | ||||
| 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; | ||||
| gp_draw_data_all(scene, gpd, 0, 0, winx, winy, cfra, dflag, spacetype); | gp_draw_data_all(scene, gpd, 0, 0, winx, winy, cfra, dflag, spacetype); | ||||
| } | } | ||||
| Context not available. | |||||