Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/drawgpencil.c
| Show First 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | if (tot_triangles > 0) { | ||||
| immBegin(GPU_PRIM_TRIS, tot_triangles * 3); | immBegin(GPU_PRIM_TRIS, tot_triangles * 3); | ||||
| /* TODO: use batch instead of immediate mode, to share vertices */ | /* TODO: use batch instead of immediate mode, to share vertices */ | ||||
| const tGPspoint *pt; | const tGPspoint *pt; | ||||
| for (int i = 0; i < tot_triangles; i++) { | for (int i = 0; i < tot_triangles; i++) { | ||||
| /* vertex 1 */ | /* vertex 1 */ | ||||
| pt = &points[tmp_triangles[i][0]]; | pt = &points[tmp_triangles[i][0]]; | ||||
| gp_set_tpoint_varying_color(pt, ink, color); | gp_set_tpoint_varying_color(pt, ink, color); | ||||
| immVertex2iv(pos, &pt->x); | immVertex2fv(pos, &pt->x); | ||||
| /* vertex 2 */ | /* vertex 2 */ | ||||
| pt = &points[tmp_triangles[i][1]]; | pt = &points[tmp_triangles[i][1]]; | ||||
| gp_set_tpoint_varying_color(pt, ink, color); | gp_set_tpoint_varying_color(pt, ink, color); | ||||
| immVertex2iv(pos, &pt->x); | immVertex2fv(pos, &pt->x); | ||||
| /* vertex 3 */ | /* vertex 3 */ | ||||
| pt = &points[tmp_triangles[i][2]]; | pt = &points[tmp_triangles[i][2]]; | ||||
| gp_set_tpoint_varying_color(pt, ink, color); | gp_set_tpoint_varying_color(pt, ink, color); | ||||
| immVertex2iv(pos, &pt->x); | immVertex2fv(pos, &pt->x); | ||||
| } | } | ||||
| immEnd(); | immEnd(); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| } | } | ||||
| /* clear memory */ | /* clear memory */ | ||||
| if (tmp_triangles) { | if (tmp_triangles) { | ||||
| Show All 31 Lines | static void gp_draw_stroke_buffer( | ||||
| const tGPspoint *pt = points; | 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 */ | ||||
| GPU_point_size((float)(thickness + 2) * points->pressure); | GPU_point_size((float)(thickness + 2) * points->pressure); | ||||
| immBindBuiltinProgram(GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR); | immBindBuiltinProgram(GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR); | ||||
| immBegin(GPU_PRIM_POINTS, 1); | immBegin(GPU_PRIM_POINTS, 1); | ||||
| gp_set_tpoint_varying_color(pt, ink, color); | gp_set_tpoint_varying_color(pt, ink, color); | ||||
| immVertex2iv(pos, &pt->x); | immVertex2fv(pos, &pt->x); | ||||
| } | } | ||||
| else { | else { | ||||
| float oldpressure = points[0].pressure; | float oldpressure = points[0].pressure; | ||||
| /* draw stroke curve */ | /* draw stroke curve */ | ||||
| GPU_line_width(max_ff(oldpressure * thickness, 1.0)); | GPU_line_width(max_ff(oldpressure * thickness, 1.0)); | ||||
| immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR); | immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR); | ||||
| immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints); | immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints); | ||||
| /* TODO: implement this with a geometry shader to draw one continuous tapered stroke */ | /* TODO: implement this with a geometry shader to draw one continuous tapered stroke */ | ||||
| for (int i = 0; i < totpoints; i++, pt++) { | 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) { | ||||
| /* need to have 2 points to avoid immEnd assert error */ | /* need to have 2 points to avoid immEnd assert error */ | ||||
| if (draw_points < 2) { | if (draw_points < 2) { | ||||
| gp_set_tpoint_varying_color(pt - 1, ink, color); | gp_set_tpoint_varying_color(pt - 1, ink, color); | ||||
| immVertex2iv(pos, &(pt - 1)->x); | immVertex2fv(pos, &(pt - 1)->x); | ||||
| } | } | ||||
| immEnd(); | immEnd(); | ||||
| draw_points = 0; | draw_points = 0; | ||||
| GPU_line_width(max_ff(pt->pressure * thickness, 1.0f)); | GPU_line_width(max_ff(pt->pressure * thickness, 1.0f)); | ||||
| immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints - i + 1); | immBeginAtMost(GPU_PRIM_LINE_STRIP, totpoints - i + 1); | ||||
| /* need to roll-back one point to ensure that there are no gaps in the stroke */ | /* need to roll-back one point to ensure that there are no gaps in the stroke */ | ||||
| if (i != 0) { | if (i != 0) { | ||||
| gp_set_tpoint_varying_color(pt - 1, ink, color); | gp_set_tpoint_varying_color(pt - 1, ink, color); | ||||
| immVertex2iv(pos, &(pt - 1)->x); | immVertex2fv(pos, &(pt - 1)->x); | ||||
| draw_points++; | draw_points++; | ||||
| } | } | ||||
| oldpressure = pt->pressure; /* reset our threshold */ | oldpressure = pt->pressure; /* reset our threshold */ | ||||
| } | } | ||||
| /* now the point we want */ | /* now the point we want */ | ||||
| gp_set_tpoint_varying_color(pt, ink, color); | gp_set_tpoint_varying_color(pt, ink, color); | ||||
| immVertex2iv(pos, &pt->x); | immVertex2fv(pos, &pt->x); | ||||
| draw_points++; | draw_points++; | ||||
| } | } | ||||
| /* need to have 2 points to avoid immEnd assert error */ | /* need to have 2 points to avoid immEnd assert error */ | ||||
| if (draw_points < 2) { | if (draw_points < 2) { | ||||
| gp_set_tpoint_varying_color(pt - 1, ink, color); | gp_set_tpoint_varying_color(pt - 1, ink, color); | ||||
| immVertex2iv(pos, &(pt - 1)->x); | immVertex2fv(pos, &(pt - 1)->x); | ||||
| } | } | ||||
| } | } | ||||
| immEnd(); | immEnd(); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| // draw fill | // draw fill | ||||
| if (fill_ink[3] > GPENCIL_ALPHA_OPACITY_THRESH) { | if (fill_ink[3] > GPENCIL_ALPHA_OPACITY_THRESH) { | ||||
| ▲ Show 20 Lines • Show All 1,555 Lines • Show Last 20 Lines | |||||