Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/drawnode.cc
| Show First 20 Lines • Show All 3,938 Lines • ▼ Show 20 Lines | |||||
| static float mute_expand_axis[3][2] = {{1.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, -0.0f}}; | static float mute_expand_axis[3][2] = {{1.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, -0.0f}}; | ||||
| /* Is zero initialized because it is static data. */ | /* Is zero initialized because it is static data. */ | ||||
| static struct { | static struct { | ||||
| GPUBatch *batch; /* for batching line together */ | GPUBatch *batch; /* for batching line together */ | ||||
| GPUBatch *batch_single; /* for single line */ | GPUBatch *batch_single; /* for single line */ | ||||
| GPUVertBuf *inst_vbo; | GPUVertBuf *inst_vbo; | ||||
| uint p0_id, p1_id, p2_id, p3_id; | uint p0_id, p1_id, p2_id, p3_id; | ||||
| uint colid_id, muted_id; | uint colid_id, muted_id, start_color_id, end_color_id; | ||||
| uint dim_factor_id; | uint dim_factor_id; | ||||
| uint thickness_id; | uint thickness_id; | ||||
| uint dash_factor_id; | uint dash_factor_id; | ||||
| uint dash_alpha_id; | |||||
| GPUVertBufRaw p0_step, p1_step, p2_step, p3_step; | GPUVertBufRaw p0_step, p1_step, p2_step, p3_step; | ||||
| GPUVertBufRaw colid_step, muted_step; | GPUVertBufRaw colid_step, muted_step, start_color_step, end_color_step; | ||||
| GPUVertBufRaw dim_factor_step; | GPUVertBufRaw dim_factor_step; | ||||
| GPUVertBufRaw thickness_step; | GPUVertBufRaw thickness_step; | ||||
| GPUVertBufRaw dash_factor_step; | GPUVertBufRaw dash_factor_step; | ||||
| GPUVertBufRaw dash_alpha_step; | |||||
| uint count; | uint count; | ||||
| bool enabled; | bool enabled; | ||||
| } g_batch_link; | } g_batch_link; | ||||
| static void nodelink_batch_reset() | static void nodelink_batch_reset() | ||||
| { | { | ||||
| GPU_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p0_id, &g_batch_link.p0_step); | GPU_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p0_id, &g_batch_link.p0_step); | ||||
| GPU_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p1_id, &g_batch_link.p1_step); | GPU_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p1_id, &g_batch_link.p1_step); | ||||
| GPU_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p2_id, &g_batch_link.p2_step); | GPU_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p2_id, &g_batch_link.p2_step); | ||||
| GPU_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p3_id, &g_batch_link.p3_step); | GPU_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p3_id, &g_batch_link.p3_step); | ||||
| GPU_vertbuf_attr_get_raw_data( | GPU_vertbuf_attr_get_raw_data( | ||||
| g_batch_link.inst_vbo, g_batch_link.colid_id, &g_batch_link.colid_step); | g_batch_link.inst_vbo, g_batch_link.colid_id, &g_batch_link.colid_step); | ||||
| GPU_vertbuf_attr_get_raw_data( | GPU_vertbuf_attr_get_raw_data( | ||||
| g_batch_link.inst_vbo, g_batch_link.muted_id, &g_batch_link.muted_step); | g_batch_link.inst_vbo, g_batch_link.muted_id, &g_batch_link.muted_step); | ||||
| GPU_vertbuf_attr_get_raw_data( | GPU_vertbuf_attr_get_raw_data( | ||||
| g_batch_link.inst_vbo, g_batch_link.dim_factor_id, &g_batch_link.dim_factor_step); | g_batch_link.inst_vbo, g_batch_link.dim_factor_id, &g_batch_link.dim_factor_step); | ||||
| GPU_vertbuf_attr_get_raw_data( | GPU_vertbuf_attr_get_raw_data( | ||||
| g_batch_link.inst_vbo, g_batch_link.thickness_id, &g_batch_link.thickness_step); | g_batch_link.inst_vbo, g_batch_link.thickness_id, &g_batch_link.thickness_step); | ||||
| GPU_vertbuf_attr_get_raw_data( | GPU_vertbuf_attr_get_raw_data( | ||||
| g_batch_link.inst_vbo, g_batch_link.dash_factor_id, &g_batch_link.dash_factor_step); | g_batch_link.inst_vbo, g_batch_link.dash_factor_id, &g_batch_link.dash_factor_step); | ||||
| GPU_vertbuf_attr_get_raw_data( | |||||
| g_batch_link.inst_vbo, g_batch_link.dash_alpha_id, &g_batch_link.dash_alpha_step); | |||||
| GPU_vertbuf_attr_get_raw_data( | |||||
| g_batch_link.inst_vbo, g_batch_link.start_color_id, &g_batch_link.start_color_step); | |||||
| GPU_vertbuf_attr_get_raw_data( | |||||
| g_batch_link.inst_vbo, g_batch_link.end_color_id, &g_batch_link.end_color_step); | |||||
| g_batch_link.count = 0; | g_batch_link.count = 0; | ||||
| } | } | ||||
| static void set_nodelink_vertex(GPUVertBuf *vbo, | static void set_nodelink_vertex(GPUVertBuf *vbo, | ||||
| uint uv_id, | uint uv_id, | ||||
| uint pos_id, | uint pos_id, | ||||
| uint exp_id, | uint exp_id, | ||||
| uint v, | uint v, | ||||
| ▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | static void nodelink_batch_init() | ||||
| g_batch_link.p1_id = GPU_vertformat_attr_add( | g_batch_link.p1_id = GPU_vertformat_attr_add( | ||||
| &format_inst, "P1", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | &format_inst, "P1", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| g_batch_link.p2_id = GPU_vertformat_attr_add( | g_batch_link.p2_id = GPU_vertformat_attr_add( | ||||
| &format_inst, "P2", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | &format_inst, "P2", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| g_batch_link.p3_id = GPU_vertformat_attr_add( | g_batch_link.p3_id = GPU_vertformat_attr_add( | ||||
| &format_inst, "P3", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | &format_inst, "P3", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| g_batch_link.colid_id = GPU_vertformat_attr_add( | g_batch_link.colid_id = GPU_vertformat_attr_add( | ||||
| &format_inst, "colid_doarrow", GPU_COMP_U8, 4, GPU_FETCH_INT); | &format_inst, "colid_doarrow", GPU_COMP_U8, 4, GPU_FETCH_INT); | ||||
| g_batch_link.start_color_id = GPU_vertformat_attr_add( | |||||
| &format_inst, "start_color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | |||||
| g_batch_link.end_color_id = GPU_vertformat_attr_add( | |||||
| &format_inst, "end_color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | |||||
| g_batch_link.muted_id = GPU_vertformat_attr_add( | g_batch_link.muted_id = GPU_vertformat_attr_add( | ||||
| &format_inst, "domuted", GPU_COMP_U8, 2, GPU_FETCH_INT); | &format_inst, "domuted", GPU_COMP_U8, 2, GPU_FETCH_INT); | ||||
| g_batch_link.dim_factor_id = GPU_vertformat_attr_add( | g_batch_link.dim_factor_id = GPU_vertformat_attr_add( | ||||
| &format_inst, "dim_factor", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); | &format_inst, "dim_factor", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); | ||||
| g_batch_link.thickness_id = GPU_vertformat_attr_add( | g_batch_link.thickness_id = GPU_vertformat_attr_add( | ||||
| &format_inst, "thickness", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); | &format_inst, "thickness", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); | ||||
| g_batch_link.dash_factor_id = GPU_vertformat_attr_add( | g_batch_link.dash_factor_id = GPU_vertformat_attr_add( | ||||
| &format_inst, "dash_factor", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); | &format_inst, "dash_factor", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); | ||||
| g_batch_link.dash_alpha_id = GPU_vertformat_attr_add( | |||||
| &format_inst, "dash_alpha", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); | |||||
| g_batch_link.inst_vbo = GPU_vertbuf_create_with_format_ex(&format_inst, GPU_USAGE_STREAM); | g_batch_link.inst_vbo = GPU_vertbuf_create_with_format_ex(&format_inst, GPU_USAGE_STREAM); | ||||
| /* Alloc max count but only draw the range we need. */ | /* Alloc max count but only draw the range we need. */ | ||||
| GPU_vertbuf_data_alloc(g_batch_link.inst_vbo, NODELINK_GROUP_SIZE); | GPU_vertbuf_data_alloc(g_batch_link.inst_vbo, NODELINK_GROUP_SIZE); | ||||
| GPU_batch_instbuf_set(g_batch_link.batch, g_batch_link.inst_vbo, true); | GPU_batch_instbuf_set(g_batch_link.batch, g_batch_link.inst_vbo, true); | ||||
| nodelink_batch_reset(); | nodelink_batch_reset(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
| static void nodelink_batch_add_link(const SpaceNode *snode, | static void nodelink_batch_add_link(const SpaceNode *snode, | ||||
| const float p0[2], | const float p0[2], | ||||
| const float p1[2], | const float p1[2], | ||||
| const float p2[2], | const float p2[2], | ||||
| const float p3[2], | const float p3[2], | ||||
| int th_col1, | int th_col1, | ||||
| int th_col2, | int th_col2, | ||||
| int th_col3, | int th_col3, | ||||
| const float start_color[4], | |||||
| const float end_color[4], | |||||
| bool drawarrow, | bool drawarrow, | ||||
| bool drawmuted, | bool drawmuted, | ||||
| float dim_factor, | float dim_factor, | ||||
| float thickness, | float thickness, | ||||
| float dash_factor) | float dash_factor, | ||||
| float dash_alpha) | |||||
| { | { | ||||
| /* Only allow these colors. If more is needed, you need to modify the shader accordingly. */ | /* Only allow these colors. If more is needed, you need to modify the shader accordingly. */ | ||||
| BLI_assert(ELEM(th_col1, TH_WIRE_INNER, TH_WIRE, TH_ACTIVE, TH_EDGE_SELECT, TH_REDALERT)); | BLI_assert(ELEM(th_col1, TH_WIRE_INNER, TH_WIRE, TH_ACTIVE, TH_EDGE_SELECT, TH_REDALERT)); | ||||
| BLI_assert(ELEM(th_col2, TH_WIRE_INNER, TH_WIRE, TH_ACTIVE, TH_EDGE_SELECT, TH_REDALERT)); | BLI_assert(ELEM(th_col2, TH_WIRE_INNER, TH_WIRE, TH_ACTIVE, TH_EDGE_SELECT, TH_REDALERT)); | ||||
| BLI_assert(ELEM(th_col3, TH_WIRE, TH_REDALERT, -1)); | BLI_assert(ELEM(th_col3, TH_WIRE, TH_REDALERT, -1)); | ||||
| g_batch_link.count++; | g_batch_link.count++; | ||||
| copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p0_step), p0); | copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p0_step), p0); | ||||
| copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p1_step), p1); | copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p1_step), p1); | ||||
| copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p2_step), p2); | copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p2_step), p2); | ||||
| copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p3_step), p3); | copy_v2_v2((float *)GPU_vertbuf_raw_step(&g_batch_link.p3_step), p3); | ||||
| char *colid = (char *)GPU_vertbuf_raw_step(&g_batch_link.colid_step); | char *colid = (char *)GPU_vertbuf_raw_step(&g_batch_link.colid_step); | ||||
| colid[0] = nodelink_get_color_id(th_col1); | colid[0] = nodelink_get_color_id(th_col1); | ||||
| colid[1] = nodelink_get_color_id(th_col2); | colid[1] = nodelink_get_color_id(th_col2); | ||||
| colid[2] = nodelink_get_color_id(th_col3); | colid[2] = nodelink_get_color_id(th_col3); | ||||
| colid[3] = drawarrow; | colid[3] = drawarrow; | ||||
| copy_v4_v4((float *)GPU_vertbuf_raw_step(&g_batch_link.start_color_step), start_color); | |||||
| copy_v4_v4((float *)GPU_vertbuf_raw_step(&g_batch_link.end_color_step), end_color); | |||||
| char *muted = (char *)GPU_vertbuf_raw_step(&g_batch_link.muted_step); | char *muted = (char *)GPU_vertbuf_raw_step(&g_batch_link.muted_step); | ||||
| muted[0] = drawmuted; | muted[0] = drawmuted; | ||||
| *(float *)GPU_vertbuf_raw_step(&g_batch_link.dim_factor_step) = dim_factor; | *(float *)GPU_vertbuf_raw_step(&g_batch_link.dim_factor_step) = dim_factor; | ||||
| *(float *)GPU_vertbuf_raw_step(&g_batch_link.thickness_step) = thickness; | *(float *)GPU_vertbuf_raw_step(&g_batch_link.thickness_step) = thickness; | ||||
| *(float *)GPU_vertbuf_raw_step(&g_batch_link.dash_factor_step) = dash_factor; | *(float *)GPU_vertbuf_raw_step(&g_batch_link.dash_factor_step) = dash_factor; | ||||
| *(float *)GPU_vertbuf_raw_step(&g_batch_link.dash_alpha_step) = dash_alpha; | |||||
| if (g_batch_link.count == NODELINK_GROUP_SIZE) { | if (g_batch_link.count == NODELINK_GROUP_SIZE) { | ||||
| nodelink_batch_draw(snode); | nodelink_batch_draw(snode); | ||||
| } | } | ||||
| } | } | ||||
| /* don't do shadows if th_col3 is -1. */ | /* don't do shadows if th_col3 is -1. */ | ||||
| void node_draw_link_bezier(const View2D *v2d, | void node_draw_link_bezier(const View2D *v2d, | ||||
| const SpaceNode *snode, | const SpaceNode *snode, | ||||
| const bNodeLink *link, | const bNodeLink *link, | ||||
| int th_col1, | int th_col1, | ||||
| int th_col2, | int th_col2, | ||||
| int th_col3) | int th_col3) | ||||
| { | { | ||||
| const float dim_factor = node_link_dim_factor(v2d, link); | const float dim_factor = node_link_dim_factor(v2d, link); | ||||
| float thickness = 1.5f; | float thickness = 1.5f; | ||||
| float dash_factor = 1.0f; | float dash_factor = 1.0f; | ||||
| bTheme *btheme = UI_GetTheme(); | |||||
| const float dash_alpha = btheme->space_node.dash_alpha; | |||||
HooglyBoogly: `const` ;) | |||||
| if (snode->edittree->type == NTREE_GEOMETRY) { | if (snode->edittree->type == NTREE_GEOMETRY) { | ||||
| if (link->fromsock && link->fromsock->display_shape == SOCK_DISPLAY_SHAPE_DIAMOND) { | if (link->fromsock && link->fromsock->display_shape == SOCK_DISPLAY_SHAPE_DIAMOND) { | ||||
| /* Make field links a bit thinner. */ | /* Make field links a bit thinner. */ | ||||
| thickness = 1.0f; | thickness = 1.0f; | ||||
| /* Draw field as dashes. */ | /* Draw field as dashes. */ | ||||
| dash_factor = 0.75f; | dash_factor = 0.75f; | ||||
| } | } | ||||
| } | } | ||||
| float vec[4][2]; | float vec[4][2]; | ||||
| const bool highlighted = link->flag & NODE_LINK_TEMP_HIGHLIGHT; | const bool highlighted = link->flag & NODE_LINK_TEMP_HIGHLIGHT; | ||||
| if (node_link_bezier_handles(v2d, snode, link, vec)) { | if (node_link_bezier_handles(v2d, snode, link, vec)) { | ||||
| int drawarrow = ((link->tonode && (link->tonode->type == NODE_REROUTE)) && | int drawarrow = ((link->tonode && (link->tonode->type == NODE_REROUTE)) && | ||||
| (link->fromnode && (link->fromnode->type == NODE_REROUTE))); | (link->fromnode && (link->fromnode->type == NODE_REROUTE))); | ||||
| int drawmuted = (link->flag & NODE_LINK_MUTED); | int drawmuted = (link->flag & NODE_LINK_MUTED); | ||||
| if (g_batch_link.batch == nullptr) { | if (g_batch_link.batch == nullptr) { | ||||
| nodelink_batch_init(); | nodelink_batch_init(); | ||||
| } | } | ||||
| /* Draw single link. */ | |||||
| float colors[3][4] = {{0.0f}}; | |||||
| if (th_col3 != -1) { | |||||
| UI_GetThemeColor4fv(th_col3, colors[0]); | |||||
| } | |||||
| if (snode->overlay.flag & SN_OVERLAY_SHOW_OVERLAYS && | |||||
| snode->overlay.flag & SN_OVERLAY_SHOW_WIRE_COLORS) { | |||||
| if (link->fromsock) { | |||||
| copy_v4_v4(colors[1], std_node_socket_colors[link->fromsock->typeinfo->type]); | |||||
| } | |||||
| else { | |||||
| copy_v4_v4(colors[1], std_node_socket_colors[link->tosock->typeinfo->type]); | |||||
| } | |||||
| if (link->tosock) { | |||||
| copy_v4_v4(colors[2], std_node_socket_colors[link->tosock->typeinfo->type]); | |||||
| } | |||||
| else { | |||||
| copy_v4_v4(colors[2], std_node_socket_colors[link->fromsock->typeinfo->type]); | |||||
| } | |||||
| } | |||||
| else { | |||||
| UI_GetThemeColor4fv(th_col1, colors[1]); | |||||
| UI_GetThemeColor4fv(th_col2, colors[2]); | |||||
| } | |||||
| if (g_batch_link.enabled && !highlighted) { | if (g_batch_link.enabled && !highlighted) { | ||||
| /* Add link to batch. */ | /* Add link to batch. */ | ||||
| nodelink_batch_add_link(snode, | nodelink_batch_add_link(snode, | ||||
| vec[0], | vec[0], | ||||
| vec[1], | vec[1], | ||||
| vec[2], | vec[2], | ||||
| vec[3], | vec[3], | ||||
| th_col1, | th_col1, | ||||
| th_col2, | th_col2, | ||||
| th_col3, | th_col3, | ||||
| colors[1], | |||||
| colors[2], | |||||
| drawarrow, | drawarrow, | ||||
| drawmuted, | drawmuted, | ||||
| dim_factor, | dim_factor, | ||||
| thickness, | thickness, | ||||
| dash_factor); | dash_factor, | ||||
| dash_alpha); | |||||
| } | } | ||||
| else { | else { | ||||
| /* Draw single link. */ | |||||
| float colors[3][4] = {{0.0f}}; | |||||
| if (th_col3 != -1) { | |||||
| UI_GetThemeColor4fv(th_col3, colors[0]); | |||||
| } | |||||
| UI_GetThemeColor4fv(th_col1, colors[1]); | |||||
| UI_GetThemeColor4fv(th_col2, colors[2]); | |||||
| if (highlighted) { | if (highlighted) { | ||||
| float link_preselection_highlight_color[4]; | float link_preselection_highlight_color[4]; | ||||
| UI_GetThemeColor4fv(TH_SELECT, link_preselection_highlight_color); | UI_GetThemeColor4fv(TH_SELECT, link_preselection_highlight_color); | ||||
| copy_v4_v4(colors[2], link_preselection_highlight_color); | copy_v4_v4(colors[2], link_preselection_highlight_color); | ||||
| } | } | ||||
| GPUBatch *batch = g_batch_link.batch_single; | GPUBatch *batch = g_batch_link.batch_single; | ||||
| GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_NODELINK); | GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_NODELINK); | ||||
| GPU_batch_uniform_2fv_array(batch, "bezierPts", 4, vec); | GPU_batch_uniform_2fv_array(batch, "bezierPts", 4, vec); | ||||
| GPU_batch_uniform_4fv_array(batch, "colors", 3, colors); | GPU_batch_uniform_4fv_array(batch, "colors", 3, colors); | ||||
| GPU_batch_uniform_1f(batch, "expandSize", snode->runtime->aspect * LINK_WIDTH); | GPU_batch_uniform_1f(batch, "expandSize", snode->runtime->aspect * LINK_WIDTH); | ||||
| GPU_batch_uniform_1f(batch, "arrowSize", ARROW_SIZE); | GPU_batch_uniform_1f(batch, "arrowSize", ARROW_SIZE); | ||||
| GPU_batch_uniform_1i(batch, "doArrow", drawarrow); | GPU_batch_uniform_1i(batch, "doArrow", drawarrow); | ||||
| GPU_batch_uniform_1i(batch, "doMuted", drawmuted); | GPU_batch_uniform_1i(batch, "doMuted", drawmuted); | ||||
| GPU_batch_uniform_1f(batch, "dim_factor", dim_factor); | GPU_batch_uniform_1f(batch, "dim_factor", dim_factor); | ||||
| GPU_batch_uniform_1f(batch, "thickness", thickness); | GPU_batch_uniform_1f(batch, "thickness", thickness); | ||||
| GPU_batch_uniform_1f(batch, "dash_factor", dash_factor); | GPU_batch_uniform_1f(batch, "dash_factor", dash_factor); | ||||
| GPU_batch_uniform_1f(batch, "dash_alpha", dash_alpha); | |||||
| GPU_batch_draw(batch); | GPU_batch_draw(batch); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* NOTE: this is used for fake links in groups too. */ | /* NOTE: this is used for fake links in groups too. */ | ||||
| void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link) | void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines | |||||
const ;)