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. | |||||
| BKE_mask_coord_from_movieclip(sc->clip, &sc->user, r_co, r_co); | BKE_mask_coord_from_movieclip(sc->clip, &sc->user, r_co, r_co); | ||||
| } | } | ||||
| static void draw_circle(const float x, const float y, | static void draw_circle(const unsigned pos, const float x, const float y, | ||||
| const float size, const bool fill, | const float size, const bool fill, | ||||
| const float xscale, const float yscale) | const float xscale, const float yscale) | ||||
| { | { | ||||
| static GLuint wire_displist = 0; | if (fill) { | ||||
| static GLuint fill_displist = 0; | imm_draw_filled_circle(pos, x, y, 0.7 * 1.0f / xscale * size, 8); | ||||
| GLuint displist = fill ? fill_displist : wire_displist; | } | ||||
| else { | |||||
| /* Initialize round circle shape. */ | imm_draw_lined_circle(pos, x, y, 0.7 * 1.0f / xscale * size, 8); | ||||
| if (displist == 0) { | |||||
| GLUquadricObj *qobj; | |||||
| displist = glGenLists(1); | |||||
| glNewList(displist, GL_COMPILE); | |||||
| qobj = gluNewQuadric(); | |||||
| gluQuadricDrawStyle(qobj, fill ? GLU_FILL : GLU_SILHOUETTE); | |||||
| gluDisk(qobj, 0, 0.7, 8, 1); | |||||
| gluDeleteQuadric(qobj); | |||||
| glEndList(); | |||||
| if (fill) { | |||||
| fill_displist = displist; | |||||
| } | |||||
| else { | |||||
| wire_displist = displist; | |||||
| } | |||||
| } | } | ||||
| glPushMatrix(); | |||||
| glTranslatef(x, y, 0.0f); | |||||
| glScalef(1.0f / xscale * size, 1.0f / yscale * size, 1.0f); | |||||
| glCallList(displist); | |||||
| glPopMatrix(); | |||||
| } | } | ||||
| static void draw_single_handle(const MaskLayer *mask_layer, const MaskSplinePoint *point, | static void draw_single_handle(const MaskLayer *mask_layer, const MaskSplinePoint *point, | ||||
| Context not available. | |||||
| return; | return; | ||||
| } | } | ||||
| VertexFormat *format = immVertexFormat(); | |||||
| unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); | |||||
| const unsigned char rgb_gray[4] = {0x60, 0x60, 0x60, 0xff}; | |||||
| immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | |||||
| immUniformColor3ubv(rgb_gray); | |||||
| /* 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}; | |||||
| glLineWidth(3); | glLineWidth(3); | ||||
| glColor4ubv(rgb_gray); | immBegin(GL_LINES, 2); | ||||
| glBegin(GL_LINES); | immVertex2fv(pos, point_pos); | ||||
| glVertex2fv(point_pos); | immVertex2fv(pos, handle_pos); | ||||
| glVertex2fv(handle_pos); | immEnd(); | ||||
| glEnd(); | |||||
| } | } | ||||
| 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(); | ||||
| /* draw handle points */ | /* draw handle points */ | ||||
| if (MASKPOINT_ISSEL_HANDLE(point, which_handle)) { | if (MASKPOINT_ISSEL_HANDLE(point, which_handle)) { | ||||
merwin: Must use immUniformColor here, to match the UNIFORM_COLOR shader. The 3ub or 3ubv version is… | |||||
| if (point == mask_layer->act_point) | if (point == mask_layer->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); | ||||
| } | } | ||||
| draw_circle(handle_pos[0], handle_pos[1], handle_size, false, xscale, yscale); | draw_circle(pos, handle_pos[0], handle_pos[1], handle_size, false, xscale, yscale); | ||||
| immUnbindProgram(); | |||||
| } | } | ||||
| /* return non-zero if spline is selected */ | /* return non-zero if spline is selected */ | ||||
| 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); | ||||
| } | } | ||||
| immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | |||||
| if (is_spline_sel) { | if (is_spline_sel) { | ||||
| float x = (min[0] + max[0]) / 2.0f; | float x = (min[0] + max[0]) / 2.0f; | ||||
| float y = (min[1] + max[1]) / 2.0f; | float y = (min[1] + max[1]) / 2.0f; | ||||
| /* TODO(sergey): Remove hardcoded colors. */ | const unsigned char active_spline_color[3] = { 255, 255, 255 }; | ||||
| const unsigned char inactive_spline_color[3] = { 255, 255, 0 }; | |||||
| if (masklay->act_spline == spline) { | if (masklay->act_spline == spline) { | ||||
| glColor3ub(255, 255, 255); | immUniformColor3ubv(active_spline_color); | ||||
| } | } | ||||
| else { | else { | ||||
| glColor3ub(255, 255, 0); | immUniformColor3ubv(inactive_spline_color); | ||||
| } | } | ||||
| draw_circle(x, y, 6.0f, true, xscale, yscale); | draw_circle(pos, x, y, 6.0f, true, xscale, yscale); | ||||
| glColor3ub(0, 0, 0); | immUniformColor3ub(0, 0, 0); | ||||
| draw_circle(x, y, 6.0f, false, xscale, yscale); | draw_circle(pos, x, y, 6.0f, false, xscale, yscale); | ||||
| } | } | ||||
| immUnbindProgram(); | |||||
| if (is_smooth) { | if (is_smooth) { | ||||
| glDisable(GL_LINE_SMOOTH); | glDisable(GL_LINE_SMOOTH); | ||||
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; | ||||
| 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. | |||||
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… | |||||
Must use immUniformColor here, to match the UNIFORM_COLOR shader. The 3ub or 3ubv version is good since alpha = 0xff.