Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/drawnode.c
| Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| #include "BLF_api.h" | #include "BLF_api.h" | ||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "BIF_glutil.h" | #include "BIF_glutil.h" | ||||
| #include "GPU_batch.h" | #include "GPU_batch.h" | ||||
| #include "GPU_batch_presets.h" | #include "GPU_batch_presets.h" | ||||
| #include "GPU_framebuffer.h" | |||||
| #include "GPU_immediate.h" | #include "GPU_immediate.h" | ||||
| #include "GPU_matrix.h" | #include "GPU_matrix.h" | ||||
| #include "GPU_platform.h" | #include "GPU_platform.h" | ||||
| #include "GPU_state.h" | #include "GPU_state.h" | ||||
| #include "DRW_engine.h" | |||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "RNA_define.h" | #include "RNA_define.h" | ||||
| #include "ED_node.h" | #include "ED_node.h" | ||||
| #include "ED_space_api.h" | #include "ED_space_api.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| ▲ Show 20 Lines • Show All 3,466 Lines • ▼ Show 20 Lines | |||||
| void draw_nodespace_back_pix(const bContext *C, | void draw_nodespace_back_pix(const bContext *C, | ||||
| ARegion *region, | ARegion *region, | ||||
| SpaceNode *snode, | SpaceNode *snode, | ||||
| bNodeInstanceKey parent_key) | bNodeInstanceKey parent_key) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| bNodeInstanceKey active_viewer_key = (snode->nodetree ? snode->nodetree->active_viewer_key : | bNodeInstanceKey active_viewer_key = (snode->nodetree ? snode->nodetree->active_viewer_key : | ||||
| NODE_INSTANCE_KEY_NONE); | NODE_INSTANCE_KEY_NONE); | ||||
| float shuffle[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | |||||
| GPU_matrix_push_projection(); | GPU_matrix_push_projection(); | ||||
| GPU_matrix_push(); | GPU_matrix_push(); | ||||
| wmOrtho2_region_pixelspace(region); | wmOrtho2_region_pixelspace(region); | ||||
| GPU_matrix_identity_set(); | GPU_matrix_identity_set(); | ||||
| ED_region_draw_cb_draw(C, region, REGION_DRAW_BACKDROP); | ED_region_draw_cb_draw(C, region, REGION_DRAW_BACKDROP); | ||||
| GPU_matrix_pop_projection(); | GPU_matrix_pop_projection(); | ||||
| GPU_matrix_pop(); | GPU_matrix_pop(); | ||||
| if (!(snode->flag & SNODE_BACKDRAW) || !ED_node_is_compositor(snode)) { | if (!(snode->flag & SNODE_BACKDRAW) || !ED_node_is_compositor(snode)) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (parent_key.value != active_viewer_key.value) { | if (parent_key.value != active_viewer_key.value) { | ||||
| return; | return; | ||||
| } | } | ||||
| GPU_matrix_push_projection(); | |||||
| GPU_matrix_push(); | |||||
| /* The draw manager is used to draw the backdrop image. */ | |||||
| GPUFrameBuffer *old_fb = GPU_framebuffer_active_get(); | |||||
| GPU_framebuffer_restore(); | |||||
fclem: Make a comment to indicate that this is drawing the render preview. | |||||
| DRW_draw_view(C); | |||||
| GPU_framebuffer_bind_no_srgb(old_fb); | |||||
| /* Draw manager changes the depth state. Set it back to NONE. Without this the node preview | |||||
| * images aren't drawn correctly. */ | |||||
| GPU_depth_test(GPU_DEPTH_NONE); | |||||
| void *lock; | void *lock; | ||||
| Image *ima = BKE_image_ensure_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); | Image *ima = BKE_image_ensure_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); | ||||
| ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); | ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); | ||||
| if (ibuf) { | if (ibuf) { | ||||
| GPU_matrix_push_projection(); | |||||
| GPU_matrix_push(); | |||||
| /* somehow the offset has to be calculated inverse */ | /* somehow the offset has to be calculated inverse */ | ||||
| wmOrtho2_region_pixelspace(region); | wmOrtho2_region_pixelspace(region); | ||||
| const float x = (region->winx - snode->zoom * ibuf->x) / 2 + snode->xof; | const float x = (region->winx - snode->zoom * ibuf->x) / 2 + snode->xof; | ||||
| const float y = (region->winy - snode->zoom * ibuf->y) / 2 + snode->yof; | const float y = (region->winy - snode->zoom * ibuf->y) / 2 + snode->yof; | ||||
| if (ibuf->rect || ibuf->rect_float) { | |||||
| uchar *display_buffer = NULL; | |||||
| void *cache_handle = NULL; | |||||
| if (snode->flag & (SNODE_SHOW_R | SNODE_SHOW_G | SNODE_SHOW_B | SNODE_SHOW_ALPHA)) { | |||||
| display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle); | |||||
| if (snode->flag & SNODE_SHOW_R) { | |||||
| shuffle[0] = 1.0f; | |||||
| } | |||||
| else if (snode->flag & SNODE_SHOW_G) { | |||||
| shuffle[1] = 1.0f; | |||||
| } | |||||
| else if (snode->flag & SNODE_SHOW_B) { | |||||
| shuffle[2] = 1.0f; | |||||
| } | |||||
| else { | |||||
| shuffle[3] = 1.0f; | |||||
| } | |||||
| IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR); | |||||
| GPU_shader_uniform_vector( | |||||
| state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, shuffle); | |||||
| immDrawPixelsTex(&state, | |||||
| x, | |||||
| y, | |||||
| ibuf->x, | |||||
| ibuf->y, | |||||
| GPU_RGBA8, | |||||
| false, | |||||
| display_buffer, | |||||
| snode->zoom, | |||||
| snode->zoom, | |||||
| NULL); | |||||
| GPU_shader_unbind(); | |||||
| } | |||||
| else if (snode->flag & SNODE_USE_ALPHA) { | |||||
| GPU_blend(GPU_BLEND_ALPHA); | |||||
| ED_draw_imbuf_ctx(C, ibuf, x, y, false, snode->zoom, snode->zoom); | |||||
| GPU_blend(GPU_BLEND_NONE); | |||||
| } | |||||
| else { | |||||
| ED_draw_imbuf_ctx(C, ibuf, x, y, false, snode->zoom, snode->zoom); | |||||
| } | |||||
| if (cache_handle) { | |||||
| IMB_display_buffer_release(cache_handle); | |||||
| } | |||||
| } | |||||
| /** \note draw selected info on backdrop */ | /** \note draw selected info on backdrop */ | ||||
| if (snode->edittree) { | if (snode->edittree) { | ||||
| bNode *node = snode->edittree->nodes.first; | bNode *node = snode->edittree->nodes.first; | ||||
| rctf *viewer_border = &snode->nodetree->viewer_border; | rctf *viewer_border = &snode->nodetree->viewer_border; | ||||
| while (node) { | while (node) { | ||||
| if (node->flag & NODE_SELECT) { | if (node->flag & NODE_SELECT) { | ||||
| if (node->typeinfo->draw_backdrop) { | if (node->typeinfo->draw_backdrop) { | ||||
| node->typeinfo->draw_backdrop(snode, ibuf, node, x, y); | node->typeinfo->draw_backdrop(snode, ibuf, node, x, y); | ||||
| Show All 16 Lines | if (snode->edittree) { | ||||
| immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | ||||
| immUniformThemeColor(TH_ACTIVE); | immUniformThemeColor(TH_ACTIVE); | ||||
| immDrawBorderCorners(pos, &pixel_border, 1.0f, 1.0f); | immDrawBorderCorners(pos, &pixel_border, 1.0f, 1.0f); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| } | } | ||||
| } | } | ||||
| GPU_matrix_pop_projection(); | |||||
| GPU_matrix_pop(); | |||||
| } | } | ||||
| BKE_image_release_ibuf(ima, ibuf, lock); | BKE_image_release_ibuf(ima, ibuf, lock); | ||||
| GPU_matrix_pop_projection(); | |||||
| GPU_matrix_pop(); | |||||
| } | } | ||||
Done Inline ActionsIs this needed? fclem: Is this needed? | |||||
| /* return quadratic beziers points for a given nodelink and clip if v2d is not NULL. */ | /* return quadratic beziers points for a given nodelink and clip if v2d is not NULL. */ | ||||
| static bool node_link_bezier_handles(View2D *v2d, | static bool node_link_bezier_handles(View2D *v2d, | ||||
| SpaceNode *snode, | SpaceNode *snode, | ||||
| bNodeLink *link, | bNodeLink *link, | ||||
| float vec[4][2]) | float vec[4][2]) | ||||
| { | { | ||||
| float cursor[2] = {0.0f, 0.0f}; | float cursor[2] = {0.0f, 0.0f}; | ||||
| ▲ Show 20 Lines • Show All 434 Lines • Show Last 20 Lines | |||||
Make a comment to indicate that this is drawing the render preview.