Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/drawnode.c
| Context not available. | |||||
| #include "BLF_api.h" | #include "BLF_api.h" | ||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "GPU_draw.h" | |||||
| #include "GPU_basic_shader.h" | |||||
| #include "GPU_immediate.h" | |||||
| #include "BIF_gl.h" | #include "BIF_gl.h" | ||||
| #include "BIF_glutil.h" | #include "BIF_glutil.h" | ||||
merwin: I recently added Batch_Uniform1b for booleans. Will add same thing for immediate mode so you… | |||||
Not Done Inline ActionsReturn true or false. merwin: Return true or false. | |||||
| Context not available. | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| /* if v2d not NULL, it clips and returns 0 if not visible */ | |||||
| bool node_link_bezier_points_glsl(View2D *v2d, SpaceNode *snode, bNodeLink *link, float vec[4][2]) | |||||
| { | |||||
| float dist; | |||||
| float deltax, deltay; | |||||
| float cursor[2] = {0.0f, 0.0f}; | |||||
| int toreroute, fromreroute; | |||||
| /* this function can be called with snode null (via cut_links_intersect) */ | |||||
| /* XXX map snode->cursor back to view space */ | |||||
| if (snode) { | |||||
| cursor[0] = snode->cursor[0] * UI_DPI_FAC; | |||||
| cursor[1] = snode->cursor[1] * UI_DPI_FAC; | |||||
| } | |||||
| /* in v0 and v3 we put begin/end points */ | |||||
| if (link->fromsock) { | |||||
| vec[0][0] = link->fromsock->locx; | |||||
| vec[0][1] = link->fromsock->locy; | |||||
| fromreroute = (link->fromnode && link->fromnode->type == NODE_REROUTE); | |||||
| } | |||||
| else { | |||||
| if (snode == NULL) return 0; | |||||
| copy_v2_v2(vec[0], cursor); | |||||
| fromreroute = 0; | |||||
| } | |||||
| if (link->tosock) { | |||||
| vec[3][0] = link->tosock->locx; | |||||
| vec[3][1] = link->tosock->locy; | |||||
| toreroute = (link->tonode && link->tonode->type == NODE_REROUTE); | |||||
| } | |||||
| else { | |||||
| if (snode == NULL) return 0; | |||||
| copy_v2_v2(vec[3], cursor); | |||||
| toreroute = 0; | |||||
| } | |||||
| /* may be called outside of drawing (so pass spacetype) */ | |||||
| dist = UI_GetThemeValueType(TH_NODE_CURVING, SPACE_NODE) * 0.10f * fabsf(vec[0][0] - vec[3][0]); | |||||
| deltax = vec[3][0] - vec[0][0]; | |||||
| deltay = vec[3][1] - vec[0][1]; | |||||
| /* check direction later, for top sockets */ | |||||
| if (fromreroute) { | |||||
| if (ABS(deltax) > ABS(deltay)) { | |||||
| vec[1][1] = vec[0][1]; | |||||
| vec[1][0] = vec[0][0] + (deltax > 0 ? dist : -dist); | |||||
| } | |||||
| else { | |||||
| vec[1][0] = vec[0][0]; | |||||
| vec[1][1] = vec[0][1] + (deltay > 0 ? dist : -dist); | |||||
| } | |||||
| } | |||||
| else { | |||||
| vec[1][0] = vec[0][0] + dist; | |||||
| vec[1][1] = vec[0][1]; | |||||
| } | |||||
| if (toreroute) { | |||||
| if (ABS(deltax) > ABS(deltay)) { | |||||
| vec[2][1] = vec[3][1]; | |||||
| vec[2][0] = vec[3][0] + (deltax > 0 ? -dist : dist); | |||||
| } | |||||
| else { | |||||
| vec[2][0] = vec[3][0]; | |||||
| vec[2][1] = vec[3][1] + (deltay > 0 ? -dist : dist); | |||||
| } | |||||
| } | |||||
| else { | |||||
| vec[2][0] = vec[3][0] - dist; | |||||
| vec[2][1] = vec[3][1]; | |||||
| } | |||||
| if (v2d && min_ffff(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) > v2d->cur.xmax) { | |||||
| /* clipped */ | |||||
| } | |||||
| else if (v2d && max_ffff(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) < v2d->cur.xmin) { | |||||
| /* clipped */ | |||||
| } | |||||
| else { | |||||
| /* always do all three, to prevent data hanging around */ | |||||
| return 1; | |||||
| } | |||||
| return 0; | |||||
| } | |||||
| void node_draw_link_bezier_glsl(View2D *v2d, SpaceNode *snode, bNodeLink *link, | |||||
| int th_col1, bool do_shaded, int th_col2, bool do_triple, int UNUSED(th_col3)) | |||||
| { | |||||
| float coord_array[4][2], linew; | |||||
| bool drawarrow; | |||||
| glGetFloatv(GL_LINE_WIDTH, &linew); | |||||
| if (node_link_bezier_points_glsl(v2d, snode, link, coord_array)) { | |||||
Not Done Inline ActionsSame here, return true or false. merwin: Same here, return true or false. | |||||
| if (!do_triple) | |||||
| glLineWidth(1.5f * UI_DPI_WINDOW_FAC); | |||||
| else | |||||
| glLineWidth(4.0f * UI_DPI_WINDOW_FAC); | |||||
| VertexFormat* format = immVertexFormat(); | |||||
| unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT); | |||||
| unsigned color = add_attrib(format, "color", GL_FLOAT, 3, KEEP_FLOAT); | |||||
| immBindBuiltinProgram(GPU_SHADER_2D_BEZIER_CURVE); | |||||
| drawarrow = ((link->tonode && (link->tonode->type == NODE_REROUTE)) && | |||||
| (link->fromnode && (link->fromnode->type == NODE_REROUTE))); | |||||
| if (drawarrow) | |||||
| immUniform1i("drawarrow", 1); | |||||
| else | |||||
| immUniform1i("drawarrow", 0); | |||||
| immUniform2fv("h1", coord_array[1]); | |||||
| immUniform2fv("h2", coord_array[2]); | |||||
| immBegin(GL_LINES, 2); | |||||
| float col[3]; | |||||
| UI_GetThemeColor3fv(th_col1, col); | |||||
| immAttrib3fv(color, col); | |||||
| immVertex2fv(pos, coord_array[0]); | |||||
| if (do_shaded) | |||||
| UI_GetThemeColor3fv(th_col2, col); | |||||
| immAttrib3fv(color, col); | |||||
| immVertex2fv(pos, coord_array[3]); | |||||
| immEnd(); | |||||
| glLineWidth(linew); | |||||
| immUnbindProgram(); | |||||
| } | |||||
| } | |||||
| #define LINK_RESOL 24 | #define LINK_RESOL 24 | ||||
| #define LINK_ARROW 12 /* position of arrow on the link, LINK_RESOL/2 */ | #define LINK_ARROW 12 /* position of arrow on the link, LINK_RESOL/2 */ | ||||
| #define ARROW_SIZE (7 * UI_DPI_FAC) | #define ARROW_SIZE (7 * UI_DPI_FAC) | ||||
| void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link, | void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link, | ||||
| int th_col1, bool do_shaded, int th_col2, bool do_triple, int th_col3) | int th_col1, bool do_shaded, int th_col2, bool do_triple, int th_col3) | ||||
| { | { | ||||
| Context not available. | |||||
| void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link) | void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link) | ||||
| { | { | ||||
| bool do_shaded = false; | bool do_shaded = false; | ||||
| bool do_triple = false; | //bool do_triple = false; | ||||
| int th_col1 = TH_WIRE_INNER, th_col2 = TH_WIRE_INNER, th_col3 = TH_WIRE; | int th_col1 = TH_WIRE_INNER, th_col2 = TH_WIRE_INNER, th_col3 = TH_WIRE; | ||||
| if (link->fromsock == NULL && link->tosock == NULL) | if (link->fromsock == NULL && link->tosock == NULL) | ||||
| Context not available. | |||||
| /* new connection */ | /* new connection */ | ||||
| if (!link->fromsock || !link->tosock) { | if (!link->fromsock || !link->tosock) { | ||||
| th_col1 = TH_ACTIVE; | th_col1 = TH_ACTIVE; | ||||
| do_triple = true; | //do_triple = true; | ||||
| } | } | ||||
| else { | else { | ||||
| /* going to give issues once... */ | /* going to give issues once... */ | ||||
| Context not available. | |||||
| th_col2 = TH_EDGE_SELECT; | th_col2 = TH_EDGE_SELECT; | ||||
| } | } | ||||
| do_shaded = true; | do_shaded = true; | ||||
| do_triple = true; | //do_triple = true; | ||||
| } | } | ||||
| else { | else { | ||||
| th_col1 = TH_REDALERT; | th_col1 = TH_REDALERT; | ||||
| } | } | ||||
| } | } | ||||
| node_draw_link_bezier(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3); | node_draw_link_bezier_glsl(v2d, snode, link, th_col3, 0, 0, true, 0); | ||||
| node_draw_link_bezier_glsl(v2d, snode, link, th_col1, do_shaded, th_col2, false, th_col3); | |||||
| // node_draw_link_straight(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3); | // node_draw_link_straight(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3); | ||||
| } | } | ||||
| Context not available. | |||||
I recently added Batch_Uniform1b for booleans. Will add same thing for immediate mode so you can say this:
immUniform1b("drawarrow", drawarrow);