Changeset View
Standalone View
source/blender/editors/mask/mask_draw.c
| Context not available. | |||||
| #include "UI_view2d.h" | #include "UI_view2d.h" | ||||
| #include "mask_intern.h" /* own include */ | #include "mask_intern.h" /* own include */ | ||||
| #include "GPU_immediate.h" | |||||
| static void mask_spline_color_get(MaskLayer *masklay, MaskSpline *spline, const bool is_sel, | static void mask_spline_color_get(MaskLayer *masklay, MaskSpline *spline, const bool is_sel, | ||||
| unsigned char r_rgb[4]) | unsigned char r_rgb[4]) | ||||
| Context not available. | |||||
| return; | return; | ||||
| } | } | ||||
| VertexFormat *format = immVertexFormat(); | |||||
| unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); | |||||
| unsigned color = add_attrib(format, "color", GL_UNSIGNED_BYTE, 4, NORMALIZE_INT_TO_FLOAT); | |||||
| immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | |||||
| /* this could be split into its own loop */ | /* this could be split into its own loop */ | ||||
| if (draw_type == MASK_DT_OUTLINE) { | if (draw_type == MASK_DT_OUTLINE) { | ||||
| const unsigned char rgb_gray[4] = {0x60, 0x60, 0x60, 0xff}; | const unsigned char rgb_gray[4] = {0x60, 0x60, 0x60, 0xff}; | ||||
| glLineWidth(3); | glLineWidth(3); | ||||
| glColor4ubv(rgb_gray); | immBegin(GL_LINES, 2); | ||||
| glBegin(GL_LINES); | immAttrib4ubv(color, rgb_gray); | ||||
merwin: Must use immUniformColor here, to match the UNIFORM_COLOR shader. The 3ub or 3ubv version is… | |||||
| glVertex2fv(point_pos); | immVertex2fv(pos, point_pos); | ||||
| glVertex2fv(handle_pos); | immVertex2fv(pos, handle_pos); | ||||
| glEnd(); | immEnd(); | ||||
| } | } | ||||
| switch (handle_type) { | switch (handle_type) { | ||||
| case HD_FREE: | case HD_FREE: | ||||
| UI_ThemeColor(TH_HANDLE_FREE); | immUniformThemeColor(TH_HANDLE_FREE); | ||||
| break; | break; | ||||
| case HD_AUTO: | case HD_AUTO: | ||||
| UI_ThemeColor(TH_HANDLE_AUTO); | immUniformThemeColor(TH_HANDLE_AUTO); | ||||
| break; | break; | ||||
| case HD_ALIGN: | case HD_ALIGN: | ||||
| case HD_ALIGN_DOUBLESIDE: | case HD_ALIGN_DOUBLESIDE: | ||||
| UI_ThemeColor(TH_HANDLE_ALIGN); | immUniformThemeColor(TH_HANDLE_ALIGN); | ||||
| break; | break; | ||||
| } | } | ||||
| glLineWidth(1); | glLineWidth(1); | ||||
| glBegin(GL_LINES); | immBegin(GL_LINES, 2); | ||||
| glVertex2fv(point_pos); | immVertex2fv(pos, point_pos); | ||||
| glVertex2fv(handle_pos); | immVertex2fv(pos, handle_pos); | ||||
| glEnd(); | immEnd(); | ||||
| immUnbindProgram(); | |||||
| /* draw handle points */ | /* draw handle points */ | ||||
| if (MASKPOINT_ISSEL_HANDLE(point, which_handle)) { | if (MASKPOINT_ISSEL_HANDLE(point, which_handle)) { | ||||
| Context not available. | |||||
| mask_spline_color_get(masklay, spline, is_spline_sel, rgb_spline); | mask_spline_color_get(masklay, spline, is_spline_sel, rgb_spline); | ||||
| VertexFormat *format = immVertexFormat(); | |||||
| unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); | |||||
| immBindBuiltinProgram(GPU_SHADER_2D_POINT_FIXED_SIZE_UNIFORM_COLOR); | |||||
| /* feather points */ | /* feather points */ | ||||
| feather_points = fp = BKE_mask_spline_feather_points(spline, &tot_feather_point); | feather_points = fp = BKE_mask_spline_feather_points(spline, &tot_feather_point); | ||||
| for (i = 0; i < spline->tot_point; i++) { | for (i = 0; i < spline->tot_point; i++) { | ||||
| Context not available. | |||||
| if (sel) { | if (sel) { | ||||
| if (point == masklay->act_point) | if (point == masklay->act_point) | ||||
| glColor3f(1.0f, 1.0f, 1.0f); | immUniformColor3f(1.0f, 1.0f, 1.0f); | ||||
| else | else | ||||
| UI_ThemeColor(TH_HANDLE_VERTEX_SELECT); | immUniformThemeColor(TH_HANDLE_VERTEX_SELECT); | ||||
| } | } | ||||
| else { | else { | ||||
| UI_ThemeColor(TH_HANDLE_VERTEX); | immUniformThemeColor(TH_HANDLE_VERTEX); | ||||
| } | } | ||||
| glBegin(GL_POINTS); | immBegin(GL_POINTS, 1); | ||||
| glVertex2fv(feather_point); | immVertex2fv(pos, feather_point); | ||||
| glEnd(); | immEnd(); | ||||
| fp++; | fp++; | ||||
| } | } | ||||
| } | } | ||||
| MEM_freeN(feather_points); | MEM_freeN(feather_points); | ||||
| immUnbindProgram(); | |||||
| if (is_smooth) { | if (is_smooth) { | ||||
| glEnable(GL_LINE_SMOOTH); | glEnable(GL_LINE_SMOOTH); | ||||
| glEnable(GL_BLEND); | glEnable(GL_BLEND); | ||||
| Context not available. | |||||
| draw_type, handle_size, xscale, yscale, vert, handle_right); | draw_type, handle_size, xscale, yscale, vert, handle_right); | ||||
| } | } | ||||
| /* bind program in loop so it does not interfere with draw_single_handle */ | |||||
| immBindBuiltinProgram(GPU_SHADER_2D_POINT_FIXED_SIZE_UNIFORM_COLOR); | |||||
| /* draw CV point */ | /* draw CV point */ | ||||
| if (MASKPOINT_ISSEL_KNOT(point)) { | if (MASKPOINT_ISSEL_KNOT(point)) { | ||||
| if (point == masklay->act_point) | if (point == masklay->act_point) | ||||
| glColor3f(1.0f, 1.0f, 1.0f); | immUniformColor3f(1.0f, 1.0f, 1.0f); | ||||
| else | else | ||||
| UI_ThemeColor(TH_HANDLE_VERTEX_SELECT); | immUniformThemeColor(TH_HANDLE_VERTEX_SELECT); | ||||
| } | } | ||||
| else | else | ||||
| UI_ThemeColor(TH_HANDLE_VERTEX); | immUniformThemeColor(TH_HANDLE_VERTEX); | ||||
| glBegin(GL_POINTS); | immBegin(GL_POINTS, 1); | ||||
| glVertex2fv(vert); | immVertex2fv(pos, vert); | ||||
| glEnd(); | immEnd(); | ||||
| immUnbindProgram(); | |||||
| minmax_v2v2_v2(min, max, vert); | minmax_v2v2_v2(min, max, vert); | ||||
| } | } | ||||
Done Inline ActionsIt's ok to name these spline_VAO, spline_VBO. Quicker to read at a glance. merwin: It's ok to name these spline_VAO, spline_VBO. Quicker to read at a glance. | |||||
Done Inline ActionsSince the whole VAO will be deleted, I think this can be removed. merwin: Since the whole VAO will be deleted, I think this can be removed. | |||||
Done Inline ActionsEach point is 2 * float, so total size should be tot_point * 2 * sizeof(GL_FLOAT) merwin: Each point is 2 * float, so total size should be
```
tot_point * 2 * sizeof(GL_FLOAT)
``` | |||||
Done Inline ActionsCould use immUniformColor4ub & get rid of color_loc, color_scale. Here and in other nearby places. merwin: Could use immUniformColor4ub & get rid of color_loc, color_scale. Here and in other nearby… | |||||
Done Inline ActionsDelete this & the matching glEnableClientState; they're part of the old pre-VBO API. merwin: Delete this & the matching glEnableClientState; they're part of the old pre-VBO API. | |||||
Done Inline ActionsFor now we only "get" attribute locations for builtin shaders, never "bind" them. Should be good without this line. merwin: For now we only "get" attribute locations for builtin shaders, never "bind" them. Should be… | |||||
Not Done Inline ActionsOh okay! Right now, though, it still can't draw the spline to the screen, and I thought that being unable to bind the array was preventing that. Am I missing something else? ryry: Oh okay! Right now, though, it still can't draw the spline to the screen, and I thought that… | |||||
| Context not available. | |||||
| MaskLayer *masklay = BKE_mask_layer_active(mask); | MaskLayer *masklay = BKE_mask_layer_active(mask); | ||||
| glBegin(GL_LINES); | |||||
| glColor4ub(255, 175, 0, 255); | VertexFormat *format = immVertexFormat(); | ||||
| unsigned pos = add_attrib(format, "pos", GL_INT, 2, KEEP_INT); | |||||
| immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | |||||
| immUniformColor4ub(255, 175, 0, 255); | |||||
| immBegin(GL_LINES, 2); | |||||
| if (masklay) { | if (masklay) { | ||||
| MaskLayerShape *masklay_shape; | MaskLayerShape *masklay_shape; | ||||
Done Inline ActionsThis function only draws if masklay != NULL. One line (2 vertices) per MaskLayerShape. Put all this setup code inside the if (masklay) block & count the number of lines needed. merwin: This function only draws if masklay != NULL. One line (2 vertices) per MaskLayerShape.
Put all… | |||||
Not Done Inline ActionsIs it better to iterate over the whole linked list to get the number of lines, or could I put the immBegin/End within the for loop? ryry: Is it better to iterate over the whole linked list to get the number of lines, or could I put… | |||||
Not Done Inline Actionsint num_lines = BLI_listbase_count(masklay->splines_shapes); It does the same thing as your loop, but keeps things readable here. merwin: ```lang=c
int num_lines = BLI_listbase_count(masklay->splines_shapes);
```
It does the same… | |||||
| Context not available. | |||||
| /* draw_keyframe(i, CFRA, sfra, framelen, 1); */ | /* draw_keyframe(i, CFRA, sfra, framelen, 1); */ | ||||
| int height = (frame == cfra) ? 22 : 10; | int height = (frame == cfra) ? 22 : 10; | ||||
| int x = (frame - sfra) * framelen; | int x = (frame - sfra) * framelen; | ||||
| glVertex2i(x, 0); | immVertex2i(pos, x, 0); | ||||
| glVertex2i(x, height); | immVertex2i(pos, x, height); | ||||
| } | } | ||||
| } | } | ||||
| glEnd(); | immEnd(); | ||||
| immUnbindProgram(); | |||||
| } | } | ||||
| Context not available. | |||||
Must use immUniformColor here, to match the UNIFORM_COLOR shader. The 3ub or 3ubv version is good since alpha = 0xff.