Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
| Show First 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| if (be->vbo->vertex_alloc <= be->vbo_len + totvertex) { | if (be->vbo->vertex_alloc <= be->vbo_len + totvertex) { | ||||
| uint newsize = be->vbo->vertex_alloc + | uint newsize = be->vbo->vertex_alloc + | ||||
| (((totvertex / GPENCIL_VBO_BLOCK_SIZE) + 1) * GPENCIL_VBO_BLOCK_SIZE); | (((totvertex / GPENCIL_VBO_BLOCK_SIZE) + 1) * GPENCIL_VBO_BLOCK_SIZE); | ||||
| GPU_vertbuf_data_resize(be->vbo, newsize); | GPU_vertbuf_data_resize(be->vbo, newsize); | ||||
| } | } | ||||
| } | } | ||||
| static void gpencil_elem_format_ensure(GpencilBatchCacheElem *be) | |||||
| { | |||||
| if (be->format == NULL) { | |||||
| be->format = MEM_callocN(sizeof(GPUVertFormat), __func__); | |||||
| } | |||||
| } | |||||
| /* create batch geometry data for points stroke shader */ | /* create batch geometry data for points stroke shader */ | ||||
| void gpencil_get_point_geom(GpencilBatchCacheElem *be, | void gpencil_get_point_geom(GpencilBatchCacheElem *be, | ||||
| bGPDstroke *gps, | bGPDstroke *gps, | ||||
| short thickness, | short thickness, | ||||
| const float ink[4], | const float ink[4], | ||||
| const int alignment_mode) | const int alignment_mode) | ||||
| { | { | ||||
| int totvertex = gps->totpoints; | int totvertex = gps->totpoints; | ||||
| if (be->vbo == NULL) { | if (be->vbo == NULL) { | ||||
| be->pos_id = GPU_vertformat_attr_add(&be->format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | gpencil_elem_format_ensure(be); | ||||
| be->color_id = GPU_vertformat_attr_add(&be->format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | be->pos_id = GPU_vertformat_attr_add(be->format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | ||||
| be->color_id = GPU_vertformat_attr_add(be->format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | |||||
| be->thickness_id = GPU_vertformat_attr_add( | be->thickness_id = GPU_vertformat_attr_add( | ||||
| &be->format, "thickness", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); | be->format, "thickness", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); | ||||
| be->uvdata_id = GPU_vertformat_attr_add( | be->uvdata_id = GPU_vertformat_attr_add( | ||||
| &be->format, "uvdata", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | be->format, "uvdata", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| be->prev_pos_id = GPU_vertformat_attr_add( | be->prev_pos_id = GPU_vertformat_attr_add( | ||||
| &be->format, "prev_pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | be->format, "prev_pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | ||||
| be->vbo = GPU_vertbuf_create_with_format(&be->format); | be->vbo = GPU_vertbuf_create_with_format(be->format); | ||||
| GPU_vertbuf_data_alloc(be->vbo, be->tot_vertex); | GPU_vertbuf_data_alloc(be->vbo, be->tot_vertex); | ||||
| be->vbo_len = 0; | be->vbo_len = 0; | ||||
| } | } | ||||
| gpencil_vbo_ensure_size(be, totvertex); | gpencil_vbo_ensure_size(be, totvertex); | ||||
| /* draw stroke curve */ | /* draw stroke curve */ | ||||
| const bGPDspoint *pt = gps->points; | const bGPDspoint *pt = gps->points; | ||||
| float alpha; | float alpha; | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| bGPDspoint *points = gps->points; | bGPDspoint *points = gps->points; | ||||
| int totpoints = gps->totpoints; | int totpoints = gps->totpoints; | ||||
| /* if cyclic needs more vertex */ | /* if cyclic needs more vertex */ | ||||
| int cyclic_add = (gps->flag & GP_STROKE_CYCLIC) ? 1 : 0; | int cyclic_add = (gps->flag & GP_STROKE_CYCLIC) ? 1 : 0; | ||||
| int totvertex = totpoints + cyclic_add + 2; | int totvertex = totpoints + cyclic_add + 2; | ||||
| if (be->vbo == NULL) { | if (be->vbo == NULL) { | ||||
| be->pos_id = GPU_vertformat_attr_add(&be->format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | gpencil_elem_format_ensure(be); | ||||
| be->color_id = GPU_vertformat_attr_add(&be->format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | be->pos_id = GPU_vertformat_attr_add(be->format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | ||||
| be->color_id = GPU_vertformat_attr_add(be->format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | |||||
| be->thickness_id = GPU_vertformat_attr_add( | be->thickness_id = GPU_vertformat_attr_add( | ||||
| &be->format, "thickness", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); | be->format, "thickness", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); | ||||
| be->uvdata_id = GPU_vertformat_attr_add( | be->uvdata_id = GPU_vertformat_attr_add( | ||||
| &be->format, "uvdata", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | be->format, "uvdata", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| be->vbo = GPU_vertbuf_create_with_format(&be->format); | be->vbo = GPU_vertbuf_create_with_format(be->format); | ||||
| GPU_vertbuf_data_alloc(be->vbo, be->tot_vertex); | GPU_vertbuf_data_alloc(be->vbo, be->tot_vertex); | ||||
| be->vbo_len = 0; | be->vbo_len = 0; | ||||
| } | } | ||||
| gpencil_vbo_ensure_size(be, totvertex); | gpencil_vbo_ensure_size(be, totvertex); | ||||
| /* draw stroke curve */ | /* draw stroke curve */ | ||||
| const bGPDspoint *pt = points; | const bGPDspoint *pt = points; | ||||
| for (int i = 0; i < totpoints; i++, pt++) { | for (int i = 0; i < totpoints; i++, pt++) { | ||||
| ▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | if ((gps->flag & GP_STROKE_RECALC_GEOMETRY) || (gps->tot_triangles == 0) || | ||||
| (gps->triangles == NULL)) { | (gps->triangles == NULL)) { | ||||
| gpencil_triangulate_stroke_fill(ob, gps); | gpencil_triangulate_stroke_fill(ob, gps); | ||||
| } | } | ||||
| BLI_assert(gps->tot_triangles >= 1); | BLI_assert(gps->tot_triangles >= 1); | ||||
| int totvertex = gps->tot_triangles * 3; | int totvertex = gps->tot_triangles * 3; | ||||
| if (be->vbo == NULL) { | if (be->vbo == NULL) { | ||||
| be->pos_id = GPU_vertformat_attr_add(&be->format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | gpencil_elem_format_ensure(be); | ||||
| be->color_id = GPU_vertformat_attr_add(&be->format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | be->pos_id = GPU_vertformat_attr_add(be->format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | ||||
| be->color_id = GPU_vertformat_attr_add(be->format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | |||||
| be->uvdata_id = GPU_vertformat_attr_add( | be->uvdata_id = GPU_vertformat_attr_add( | ||||
| &be->format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | be->format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| be->vbo = GPU_vertbuf_create_with_format(&be->format); | be->vbo = GPU_vertbuf_create_with_format(be->format); | ||||
| GPU_vertbuf_data_alloc(be->vbo, be->tot_vertex); | GPU_vertbuf_data_alloc(be->vbo, be->tot_vertex); | ||||
| be->vbo_len = 0; | be->vbo_len = 0; | ||||
| } | } | ||||
| gpencil_vbo_ensure_size(be, totvertex); | gpencil_vbo_ensure_size(be, totvertex); | ||||
| /* Draw all triangles for filling the polygon (cache must be calculated before) */ | /* Draw all triangles for filling the polygon (cache must be calculated before) */ | ||||
| bGPDtriangle *stroke_triangle = gps->triangles; | bGPDtriangle *stroke_triangle = gps->triangles; | ||||
| for (int i = 0; i < gps->tot_triangles; i++, stroke_triangle++) { | for (int i = 0; i < gps->tot_triangles; i++, stroke_triangle++) { | ||||
| ▲ Show 20 Lines • Show All 345 Lines • ▼ Show 20 Lines | void gpencil_get_edit_geom(struct GpencilBatchCacheElem *be, | ||||
| bGPDstroke *gps, | bGPDstroke *gps, | ||||
| float alpha, | float alpha, | ||||
| short dflag) | short dflag) | ||||
| { | { | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| Object *ob = draw_ctx->obact; | Object *ob = draw_ctx->obact; | ||||
| bGPdata *gpd = ob->data; | bGPdata *gpd = ob->data; | ||||
| const bool is_weight_paint = (gpd) && (gpd->flag & GP_DATA_STROKE_WEIGHTMODE); | const bool is_weight_paint = (gpd) && (gpd->flag & GP_DATA_STROKE_WEIGHTMODE); | ||||
| const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd); | |||||
| int vgindex = ob->actdef - 1; | int vgindex = ob->actdef - 1; | ||||
| if (!BLI_findlink(&ob->defbase, vgindex)) { | if (!BLI_findlink(&ob->defbase, vgindex)) { | ||||
| vgindex = -1; | vgindex = -1; | ||||
| } | } | ||||
| /* Get size of verts: | /* Get size of verts: | ||||
| * - The selected state needs to be larger than the unselected state so that | * - The selected state needs to be larger than the unselected state so that | ||||
| Show All 14 Lines | void gpencil_get_edit_geom(struct GpencilBatchCacheElem *be, | ||||
| float selectColor[4]; | float selectColor[4]; | ||||
| UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, selectColor); | UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, selectColor); | ||||
| selectColor[3] = alpha; | selectColor[3] = alpha; | ||||
| float unselectColor[4]; | float unselectColor[4]; | ||||
| UI_GetThemeColor3fv(TH_GP_VERTEX, unselectColor); | UI_GetThemeColor3fv(TH_GP_VERTEX, unselectColor); | ||||
| unselectColor[3] = alpha; | unselectColor[3] = alpha; | ||||
| float linecolor[4]; | |||||
| copy_v4_v4(linecolor, gpd->line_color); | |||||
| if (be->vbo == NULL) { | if (be->vbo == NULL) { | ||||
| be->pos_id = GPU_vertformat_attr_add(&be->format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | gpencil_elem_format_ensure(be); | ||||
| be->color_id = GPU_vertformat_attr_add(&be->format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | be->pos_id = GPU_vertformat_attr_add(be->format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | ||||
| be->color_id = GPU_vertformat_attr_add(be->format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | |||||
| be->thickness_id = GPU_vertformat_attr_add( | be->thickness_id = GPU_vertformat_attr_add( | ||||
| &be->format, "size", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); | be->format, "size", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); | ||||
| be->vbo = GPU_vertbuf_create_with_format(&be->format); | be->vbo = GPU_vertbuf_create_with_format(be->format); | ||||
| GPU_vertbuf_data_alloc(be->vbo, be->tot_vertex); | GPU_vertbuf_data_alloc(be->vbo, be->tot_vertex); | ||||
| be->vbo_len = 0; | be->vbo_len = 0; | ||||
| } | } | ||||
| gpencil_vbo_ensure_size(be, gps->totpoints); | gpencil_vbo_ensure_size(be, gps->totpoints); | ||||
| /* Draw start and end point differently if enabled stroke direction hint */ | /* Draw start and end point differently if enabled stroke direction hint */ | ||||
| bool show_direction_hint = (dflag & GP_DATA_SHOW_DIRECTION) && (gps->totpoints > 1); | bool show_direction_hint = (dflag & GP_DATA_SHOW_DIRECTION) && (gps->totpoints > 1); | ||||
| Show All 20 Lines | else { | ||||
| ARRAY_SET_ITEMS(fcolor, 0.0f, 1.0f, 0.0f, 1.0f); | ARRAY_SET_ITEMS(fcolor, 0.0f, 1.0f, 0.0f, 1.0f); | ||||
| fsize = vsize + 4; | fsize = vsize + 4; | ||||
| } | } | ||||
| else if (show_direction_hint && (i == gps->totpoints - 1)) { | else if (show_direction_hint && (i == gps->totpoints - 1)) { | ||||
| /* end point in red smaller */ | /* end point in red smaller */ | ||||
| ARRAY_SET_ITEMS(fcolor, 1.0f, 0.0f, 0.0f, 1.0f); | ARRAY_SET_ITEMS(fcolor, 1.0f, 0.0f, 0.0f, 1.0f); | ||||
| fsize = vsize + 1; | fsize = vsize + 1; | ||||
| } | } | ||||
| else if ((!is_multiedit) && (pt->runtime.pt_orig == NULL)) { | |||||
| ARRAY_SET_ITEMS(fcolor, linecolor[0], linecolor[1], linecolor[2], selectColor[3]); | |||||
| mul_v4_fl(fcolor, 0.9f); | |||||
| copy_v4_v4(fcolor, fcolor); | |||||
| fsize = vsize * 0.8f; | |||||
| } | |||||
| else if (pt->flag & GP_SPOINT_SELECT) { | else if (pt->flag & GP_SPOINT_SELECT) { | ||||
| copy_v4_v4(fcolor, selectColor); | copy_v4_v4(fcolor, selectColor); | ||||
| fsize = vsize; | fsize = vsize; | ||||
| } | } | ||||
| else { | else { | ||||
| copy_v4_v4(fcolor, unselectColor); | copy_v4_v4(fcolor, unselectColor); | ||||
| fsize = bsize; | fsize = bsize; | ||||
| } | } | ||||
| Show All 27 Lines | void gpencil_get_edlin_geom(struct GpencilBatchCacheElem *be, | ||||
| float selectColor[4]; | float selectColor[4]; | ||||
| UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, selectColor); | UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, selectColor); | ||||
| selectColor[3] = alpha; | selectColor[3] = alpha; | ||||
| float linecolor[4]; | float linecolor[4]; | ||||
| copy_v4_v4(linecolor, gpd->line_color); | copy_v4_v4(linecolor, gpd->line_color); | ||||
| if (be->vbo == NULL) { | if (be->vbo == NULL) { | ||||
| be->pos_id = GPU_vertformat_attr_add(&be->format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | gpencil_elem_format_ensure(be); | ||||
| be->color_id = GPU_vertformat_attr_add(&be->format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | be->pos_id = GPU_vertformat_attr_add(be->format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | ||||
| be->color_id = GPU_vertformat_attr_add(be->format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | |||||
| be->vbo = GPU_vertbuf_create_with_format(&be->format); | be->vbo = GPU_vertbuf_create_with_format(be->format); | ||||
| GPU_vertbuf_data_alloc(be->vbo, be->tot_vertex); | GPU_vertbuf_data_alloc(be->vbo, be->tot_vertex); | ||||
| be->vbo_len = 0; | be->vbo_len = 0; | ||||
| } | } | ||||
| gpencil_vbo_ensure_size(be, gps->totpoints); | gpencil_vbo_ensure_size(be, gps->totpoints); | ||||
| /* Draw all the stroke lines (selected or not) */ | /* Draw all the stroke lines (selected or not) */ | ||||
| bGPDspoint *pt = gps->points; | bGPDspoint *pt = gps->points; | ||||
| MDeformVert *dvert = gps->dvert; | MDeformVert *dvert = gps->dvert; | ||||
| ▲ Show 20 Lines • Show All 164 Lines • Show Last 20 Lines | |||||