diff options
Diffstat (limited to 'source/blender/windowmanager/intern/wm_gesture.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_gesture.c | 328 |
1 files changed, 232 insertions, 96 deletions
diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c index 46203333eb5..d49c83fa729 100644 --- a/source/blender/windowmanager/intern/wm_gesture.c +++ b/source/blender/windowmanager/intern/wm_gesture.c @@ -45,15 +45,14 @@ #include "BKE_context.h" - #include "WM_api.h" #include "WM_types.h" #include "wm.h" #include "wm_subwindow.h" #include "wm_draw.h" -#include "GPU_basic_shader.h" +#include "GPU_immediate.h" #include "BIF_glutil.h" @@ -168,69 +167,156 @@ int wm_gesture_evaluate(wmGesture *gesture) /* ******************* gesture draw ******************* */ +static void wm_gesture_draw_line(wmGesture *gt) +{ + rcti *rect = (rcti *)gt->customdata; + + VertexFormat *format = immVertexFormat(); + unsigned pos = add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); + unsigned line_origin = add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); + + immUniform4f("color1", 0.4f, 0.4f, 0.4f, 1.0f); + immUniform4f("color2", 1.0f, 1.0f, 1.0f, 1.0f); + immUniform1f("dash_width", 8.0f); + immUniform1f("dash_width_on", 4.0f); + + float xmin = (float)rect->xmin; + float ymin = (float)rect->ymin; + + immBegin(PRIM_LINES, 2); + + immAttrib2f(line_origin, xmin, ymin); + immVertex2f(pos, xmin, ymin); + immAttrib2f(line_origin, xmin, ymin); + immVertex2f(pos, (float)rect->xmax, (float)rect->ymax); + + immEnd(); + + immUnbindProgram(); +} + +static void imm_draw_line_box_dashed(unsigned pos, unsigned line_origin, float x1, float y1, float x2, float y2) +{ + immBegin(PRIM_LINES, 8); + immAttrib2f(line_origin, x1, y1); + immVertex2f(pos, x1, y1); + immVertex2f(pos, x1, y2); + immAttrib2f(line_origin, x1, y2); + immVertex2f(pos, x1, y2); + immVertex2f(pos, x2, y2); + immAttrib2f(line_origin, x2, y1); + immVertex2f(pos, x2, y2); + immVertex2f(pos, x2, y1); + immAttrib2f(line_origin, x1, y1); + immVertex2f(pos, x2, y1); + immVertex2f(pos, x1, y1); + immEnd(); +} + static void wm_gesture_draw_rect(wmGesture *gt) { rcti *rect = (rcti *)gt->customdata; + + VertexFormat *format = immVertexFormat(); + unsigned pos = add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); glEnable(GL_BLEND); - glColor4f(1.0, 1.0, 1.0, 0.05); - glBegin(GL_QUADS); - glVertex2s(rect->xmax, rect->ymin); - glVertex2s(rect->xmax, rect->ymax); - glVertex2s(rect->xmin, rect->ymax); - glVertex2s(rect->xmin, rect->ymin); - glEnd(); + + immUniform4f("color", 1.0f, 1.0f, 1.0f, 0.05f); + + immBegin(GL_QUADS, 4); + + immVertex2f(pos, (float)rect->xmax, (float)rect->ymin); + immVertex2f(pos, (float)rect->xmax, (float)rect->ymax); + immVertex2f(pos, (float)rect->xmin, (float)rect->ymax); + immVertex2f(pos, (float)rect->xmin, (float)rect->ymin); + + immEnd(); + + immUnbindProgram(); + glDisable(GL_BLEND); + + format = immVertexFormat(); + pos = add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); + unsigned line_origin = add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); + + immUniform4f("color1", 0.4f, 0.4f, 0.4f, 1.0f); + immUniform4f("color2", 1.0f, 1.0f, 1.0f, 1.0f); + immUniform1f("dash_width", 8.0f); + immUniform1f("dash_width_on", 4.0f); - GPU_basic_shader_bind(GPU_SHADER_LINE | GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR); - glColor3ub(96, 96, 96); - GPU_basic_shader_line_stipple(1, 0xCCCC); - sdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax); - glColor3ub(255, 255, 255); - GPU_basic_shader_line_stipple(1, 0x3333); - sdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax); - GPU_basic_shader_bind(GPU_SHADER_USE_COLOR); + imm_draw_line_box_dashed(pos, line_origin, + (float)rect->xmin, (float)rect->ymin, (float)rect->xmax, (float)rect->ymax); + + immUnbindProgram(); + + // wm_gesture_draw_line(gt); // draws a diagonal line in the lined box to test wm_gesture_draw_line } -static void wm_gesture_draw_line(wmGesture *gt) +static void imm_draw_lined_dashed_circle(unsigned pos, unsigned line_origin, float x, float y, float rad, int nsegments) { - rcti *rect = (rcti *)gt->customdata; - - GPU_basic_shader_bind(GPU_SHADER_LINE | GPU_SHADER_STIPPLE); - glColor3ub(96, 96, 96); - GPU_basic_shader_line_stipple(1, 0xAAAA); - sdrawline(rect->xmin, rect->ymin, rect->xmax, rect->ymax); - glColor3ub(255, 255, 255); - GPU_basic_shader_line_stipple(1, 0x5555); - sdrawline(rect->xmin, rect->ymin, rect->xmax, rect->ymax); - - GPU_basic_shader_bind(GPU_SHADER_USE_COLOR); - + float xpos, ypos; + + xpos = x + rad; + ypos = y; + + immBegin(PRIM_LINES, nsegments * 2); + + for (int i = 1; i <= nsegments; ++i) { + float angle = 2 * M_PI * ((float)i / (float)nsegments); + + immAttrib2f(line_origin, xpos, ypos); + immVertex2f(pos, xpos, ypos); + + xpos = x + rad * cosf(angle); + ypos = y + rad * sinf(angle); + + immVertex2f(pos, xpos, ypos); + } + + immEnd(); } static void wm_gesture_draw_circle(wmGesture *gt) { rcti *rect = (rcti *)gt->customdata; - glTranslatef((float)rect->xmin, (float)rect->ymin, 0.0f); - glEnable(GL_BLEND); - glColor4f(1.0, 1.0, 1.0, 0.05); - glutil_draw_filled_arc(0.0, M_PI * 2.0, rect->xmax, 40); + + VertexFormat *format = immVertexFormat(); + unsigned pos = add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + + immUniformColor4f(1.0, 1.0, 1.0, 0.05); + imm_draw_filled_circle(pos, (float)rect->xmin, (float)rect->ymin, (float)rect->xmax, 40); + + immUnbindProgram(); + glDisable(GL_BLEND); - // for USE_GLSL works bad because of no relation between lines - GPU_basic_shader_bind(GPU_SHADER_LINE | GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR); - glColor3ub(96, 96, 96); - GPU_basic_shader_line_stipple(1, 0xAAAA); - glutil_draw_lined_arc(0.0, M_PI * 2.0, rect->xmax, 40); - glColor3ub(255, 255, 255); - GPU_basic_shader_line_stipple(1, 0x5555); - glutil_draw_lined_arc(0.0, M_PI * 2.0, rect->xmax, 40); - - GPU_basic_shader_bind(GPU_SHADER_USE_COLOR); - glTranslatef(-rect->xmin, -rect->ymin, 0.0f); + format = immVertexFormat(); + pos = add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); + unsigned line_origin = add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); + + immUniform4f("color1", 0.4f, 0.4f, 0.4f, 1.0f); + immUniform4f("color2", 1.0f, 1.0f, 1.0f, 1.0f); + immUniform1f("dash_width", 4.0f); + immUniform1f("dash_width_on", 2.0f); + imm_draw_lined_dashed_circle(pos, line_origin, + (float)rect->xmin, (float)rect->ymin, (float)rect->xmax, 40); + + immUnbindProgram(); } struct LassoFillData { @@ -253,6 +339,7 @@ static void draw_filled_lasso(wmWindow *win, wmGesture *gt) int i; rcti rect; rcti rect_win; + float red[4] = {1.0f, 0.0f, 0.0f, 0.0f}; for (i = 0; i < tot; i++, lasso += 2) { moves[i][0] = lasso[0]; @@ -278,28 +365,28 @@ static void draw_filled_lasso(wmWindow *win, wmGesture *gt) (const int (*)[2])moves, tot, draw_filled_lasso_px_cb, &lasso_fill_data); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + /* Additive Blending */ + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE); - glColor4f(1, 1, 1, 1); - glPixelTransferf(GL_RED_BIAS, 1); - glPixelTransferf(GL_GREEN_BIAS, 1); - glPixelTransferf(GL_BLUE_BIAS, 1); + GLint unpack_alignment; + glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpack_alignment); - GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glEnable(GL_BLEND); - glaDrawPixelsTex(rect.xmin, rect.ymin, w, h, GL_ALPHA, GL_UNSIGNED_BYTE, GL_NEAREST, pixel_buf); - glDisable(GL_BLEND); + GPUShader *shader = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR); + GPU_shader_bind(shader); + GPU_shader_uniform_vector(shader, GPU_shader_get_uniform(shader, "shuffle"), 4, 1, red); - GPU_basic_shader_bind(GPU_SHADER_USE_COLOR); + immDrawPixelsTex(rect.xmin, rect.ymin, w, h, GL_RED, GL_UNSIGNED_BYTE, GL_NEAREST, pixel_buf, 1.0f, 1.0f, NULL); - glPixelTransferf(GL_RED_BIAS, 0); - glPixelTransferf(GL_GREEN_BIAS, 0); - glPixelTransferf(GL_BLUE_BIAS, 0); + GPU_shader_unbind(); - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_alignment); MEM_freeN(pixel_buf); + + glDisable(GL_BLEND); } MEM_freeN(moves); @@ -309,35 +396,57 @@ static void draw_filled_lasso(wmWindow *win, wmGesture *gt) static void wm_gesture_draw_lasso(wmWindow *win, wmGesture *gt, bool filled) { const short *lasso = (short *)gt->customdata; - int i; + int i, numverts; + float x, y; if (filled) { draw_filled_lasso(win, gt); } - // for USE_GLSL can't check this yet - GPU_basic_shader_bind(GPU_SHADER_LINE | GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR); - glColor3ub(96, 96, 96); - GPU_basic_shader_line_stipple(1, 0xAAAA); - glBegin(GL_LINE_STRIP); - for (i = 0; i < gt->points; i++, lasso += 2) - glVertex2sv(lasso); - if (gt->type == WM_GESTURE_LASSO) - glVertex2sv((short *)gt->customdata); - glEnd(); - - glColor3ub(255, 255, 255); - GPU_basic_shader_line_stipple(1, 0x5555); - glBegin(GL_LINE_STRIP); - lasso = (short *)gt->customdata; - for (i = 0; i < gt->points; i++, lasso += 2) - glVertex2sv(lasso); - if (gt->type == WM_GESTURE_LASSO) - glVertex2sv((short *)gt->customdata); - glEnd(); - - GPU_basic_shader_bind(GPU_SHADER_USE_COLOR); - + numverts = gt->points; + if (gt->type == WM_GESTURE_LASSO) { + numverts++; + } + + /* Nothing to drawe, do early output. */ + if (numverts < 2) { + return; + } + + VertexFormat *format = immVertexFormat(); + unsigned pos = add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); + unsigned line_origin = add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); + + immUniform4f("color1", 0.4f, 0.4f, 0.4f, 1.0f); + immUniform4f("color2", 1.0f, 1.0f, 1.0f, 1.0f); + immUniform1f("dash_width", 2.0f); + immUniform1f("dash_width_on", 1.0f); + + immBegin(PRIM_LINE_STRIP, numverts); + + for (i = 0; i < gt->points; i++, lasso += 2) { + + /* get line_origin coordinates only from the first vertex of each line */ + if (!(i % 2)) { + x = (float)lasso[0]; + y = (float)lasso[1]; + } + + immAttrib2f(line_origin, x, y); + immVertex2f(pos, (float)lasso[0], (float)lasso[1]); + } + + if (gt->type == WM_GESTURE_LASSO) { + immAttrib2f(line_origin, x, y); + lasso = (short *)gt->customdata; + immVertex2f(pos, (float)lasso[0], (float)lasso[1]); + } + + immEnd(); + + immUnbindProgram(); } static void wm_gesture_draw_cross(wmWindow *win, wmGesture *gt) @@ -346,25 +455,52 @@ static void wm_gesture_draw_cross(wmWindow *win, wmGesture *gt) const int winsize_x = WM_window_pixels_x(win); const int winsize_y = WM_window_pixels_y(win); - GPU_basic_shader_bind(GPU_SHADER_LINE | GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR); - glColor3ub(96, 96, 96); - GPU_basic_shader_line_stipple(1, 0xCCCC); - sdrawline(rect->xmin - winsize_x, rect->ymin, rect->xmin + winsize_x, rect->ymin); - sdrawline(rect->xmin, rect->ymin - winsize_y, rect->xmin, rect->ymin + winsize_y); - - glColor3ub(255, 255, 255); - GPU_basic_shader_line_stipple(1, 0x3333); - sdrawline(rect->xmin - winsize_x, rect->ymin, rect->xmin + winsize_x, rect->ymin); - sdrawline(rect->xmin, rect->ymin - winsize_y, rect->xmin, rect->ymin + winsize_y); - GPU_basic_shader_bind(GPU_SHADER_USE_COLOR); + float x1, x2, y1, y2; + + VertexFormat *format = immVertexFormat(); + unsigned pos = add_attrib(format, "pos", COMP_F32, 2, KEEP_FLOAT); + unsigned line_origin = add_attrib(format, "line_origin", COMP_F32, 2, KEEP_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_COLOR); + + immUniform4f("color1", 0.4f, 0.4f, 0.4f, 1.0f); + immUniform4f("color2", 1.0f, 1.0f, 1.0f, 1.0f); + immUniform1f("dash_width", 8.0f); + immUniform1f("dash_width_on", 4.0f); + + immBegin(PRIM_LINES, 4); + + x1 = (float)(rect->xmin - winsize_x); + y1 = (float)rect->ymin; + x2 = (float)(rect->xmin + winsize_x); + y2 = y1; + + immAttrib2f(line_origin, x1, y1); + immVertex2f(pos, x1, y1); + immAttrib2f(line_origin, x1, y1); + immVertex2f(pos, x2, y2); + + x1 = (float)rect->xmin; + y1 = (float)(rect->ymin - winsize_y); + x2 = x1; + y2 = (float)(rect->ymin + winsize_y); + + immAttrib2f(line_origin, x1, y1); + immVertex2f(pos, x1, y1); + immAttrib2f(line_origin, x1, y1); + immVertex2f(pos, x2, y2); + + immEnd(); + + immUnbindProgram(); } /* called in wm_draw.c */ void wm_gesture_draw(wmWindow *win) { wmGesture *gt = (wmGesture *)win->gesture.first; - - GPU_basic_shader_line_width(1); + + glLineWidth(1.0f); for (; gt; gt = gt->next) { /* all in subwindow space */ wmSubWindowSet(win, gt->swinid); |