Experiment with the compositor border in editor
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 5 Jun 2014 14:05:41 +0000 (20:05 +0600)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 30 Jun 2014 17:01:20 +0000 (23:01 +0600)
Preserve buffer form previous runs so it's possible to make
a compo of full frame, then draw a border and start tweaking
nodes and see updates in that border.

Main idea is to make it able to visually compare difference
between what was changed inside the border and how frame
looked before the tweaks outside of the border.

Also implemented Clear Viewer Border in compositor, shortcut
it Ctrl-Alt-B.

Reviewers: lukastoenne, jbakker

CC: venomgfx, sebastian_k
Differential Revision: https://developer.blender.org/D582

source/blender/editors/include/BIF_glutil.h
source/blender/editors/screen/glutil.c
source/blender/editors/space_image/image_draw.c
source/blender/editors/space_node/drawnode.c
source/blender/editors/space_node/node_edit.c
source/blender/editors/space_node/node_intern.h
source/blender/editors/space_node/node_ops.c
source/blender/makesrna/intern/rna_nodetree.c

index 48440d10ae3636b9e8f817285e5a40c5d859c4c7..b401f06f48486d245f483fd650c3c7664bce2afa 100644 (file)
@@ -222,5 +222,7 @@ void glaDrawImBuf_glsl(struct ImBuf *ibuf, float x, float y, int zoomfilter,
 /* Draw imbuf on a screen, preferably using GLSL display transform */
 void glaDrawImBuf_glsl_ctx(const struct bContext *C, struct ImBuf *ibuf, float x, float y, int zoomfilter);
 
+void glaDrawBorderCorners(const struct rcti *border, float zoomx, float zoomy);
+
 #endif /* __BIF_GLUTIL_H__ */
 
index f31d79ff76b67dc04b35e0c56750bcf3cf102be6..0edde66ffff8e7577e78d602ae13286fca5c1504 100644 (file)
@@ -50,6 +50,8 @@
 #include "IMB_colormanagement.h"
 #include "IMB_imbuf_types.h"
 
+#include "UI_interface.h"
+
 #ifndef GL_CLAMP_TO_EDGE
 #define GL_CLAMP_TO_EDGE                        0x812F
 #endif
@@ -1139,3 +1141,40 @@ void cpack(unsigned int x)
                    (((x) >>  8) & 0xFF),
                    (((x) >> 16) & 0xFF) );
 }
+
+void glaDrawBorderCorners(const rcti *border, float zoomx, float zoomy)
+{
+       float delta_x = 4.0f * UI_DPI_FAC / zoomx;
+       float delta_y = 4.0f * UI_DPI_FAC / zoomy;
+
+       delta_x = min_ff(delta_x, border->xmax - border->xmin);
+       delta_y = min_ff(delta_y, border->ymax - border->ymin);
+
+       /* left bottom corner */
+       glBegin(GL_LINE_STRIP);
+       glVertex2f(border->xmin, border->ymin + delta_y);
+       glVertex2f(border->xmin, border->ymin);
+       glVertex2f(border->xmin + delta_x, border->ymin);
+       glEnd();
+
+       /* left top corner */
+       glBegin(GL_LINE_STRIP);
+       glVertex2f(border->xmin, border->ymax - delta_y);
+       glVertex2f(border->xmin, border->ymax);
+       glVertex2f(border->xmin + delta_x, border->ymax);
+       glEnd();
+
+       /* right bottom corner */
+       glBegin(GL_LINE_STRIP);
+       glVertex2f(border->xmax - delta_x, border->ymin);
+       glVertex2f(border->xmax, border->ymin);
+       glVertex2f(border->xmax, border->ymin + delta_y);
+       glEnd();
+
+       /* right top corner */
+       glBegin(GL_LINE_STRIP);
+       glVertex2f(border->xmax - delta_x, border->ymax);
+       glVertex2f(border->xmax, border->ymax);
+       glVertex2f(border->xmax, border->ymax - delta_y);
+       glEnd();
+}
index 5f996f94a81a1c00dc7561c9d08d0e5d92209c89..79c21bab01ceaddfd47b21dbc8ddbe297f5ad4f7 100644 (file)
@@ -119,39 +119,7 @@ static void draw_render_info(Scene *scene, Image *ima, ARegion *ar, float zoomx,
                        UI_ThemeColor(TH_FACE_SELECT);
 
                        for (i = 0, tile = tiles; i < total_tiles; i++, tile++) {
-                               float delta_x = 4.0f * UI_DPI_FAC / zoomx;
-                               float delta_y = 4.0f * UI_DPI_FAC / zoomy;
-
-                               delta_x = min_ff(delta_x, tile->xmax - tile->xmin);
-                               delta_y = min_ff(delta_y, tile->ymax - tile->ymin);
-
-                               /* left bottom corner */
-                               glBegin(GL_LINE_STRIP);
-                               glVertex2f(tile->xmin, tile->ymin + delta_y);
-                               glVertex2f(tile->xmin, tile->ymin);
-                               glVertex2f(tile->xmin + delta_x, tile->ymin);
-                               glEnd();
-
-                               /* left top corner */
-                               glBegin(GL_LINE_STRIP);
-                               glVertex2f(tile->xmin, tile->ymax - delta_y);
-                               glVertex2f(tile->xmin, tile->ymax);
-                               glVertex2f(tile->xmin + delta_x, tile->ymax);
-                               glEnd();
-
-                               /* right bottom corner */
-                               glBegin(GL_LINE_STRIP);
-                               glVertex2f(tile->xmax - delta_x, tile->ymin);
-                               glVertex2f(tile->xmax, tile->ymin);
-                               glVertex2f(tile->xmax, tile->ymin + delta_y);
-                               glEnd();
-
-                               /* right top corner */
-                               glBegin(GL_LINE_STRIP);
-                               glVertex2f(tile->xmax - delta_x, tile->ymax);
-                               glVertex2f(tile->xmax, tile->ymax);
-                               glVertex2f(tile->xmax, tile->ymax - delta_y);
-                               glEnd();
+                               glaDrawBorderCorners(tile, zoomx, zoomy);
                        }
 
                        MEM_freeN(tiles);
index 2f265d21a38c78f757bc9a6a176948b48f8d1932..ef23fc2419417a1bcb77d4e3a0d1ac76a7271a9e 100644 (file)
@@ -3122,20 +3122,17 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, b
                        }
                        
                        if ((snode->nodetree->flag & NTREE_VIEWER_BORDER) &&
-                               viewer_border->xmin < viewer_border->xmax &&
-                               viewer_border->ymin < viewer_border->ymax)
+                           viewer_border->xmin < viewer_border->xmax &&
+                           viewer_border->ymin < viewer_border->ymax)
                        {
-                               glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-                               setlinestyle(3);
-                               cpack(0x4040FF);
-                               
-                               glRectf(x + snode->zoom * viewer_border->xmin * ibuf->x,
-                                       y + snode->zoom * viewer_border->ymin * ibuf->y,
-                                       x + snode->zoom * viewer_border->xmax * ibuf->x,
-                                       y + snode->zoom * viewer_border->ymax * ibuf->y);
-                               
-                               setlinestyle(0);
-                               glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+                               rcti pixel_border;
+                               UI_ThemeColor(TH_ACTIVE);
+                               BLI_rcti_init(&pixel_border,
+                                             x + snode->zoom * viewer_border->xmin * ibuf->x,
+                                             x + snode->zoom * viewer_border->xmax * ibuf->x,
+                                             y + snode->zoom * viewer_border->ymin * ibuf->y,
+                                             y + snode->zoom * viewer_border->ymax * ibuf->y);
+                               glaDrawBorderCorners(&pixel_border, 1.0f, 1.0f);
                        }
                }
                
index 5bbe0c1c229f1de8dafe974d72bcebf3f406be39..1c41ce9d86d87cc4ba796a34fcfb233327593789 100644 (file)
@@ -2482,14 +2482,6 @@ static int viewer_border_exec(bContext *C, wmOperator *op)
                                btree->flag &= ~NTREE_VIEWER_BORDER;
                        }
                        else {
-                               if (ibuf->rect)
-                                       memset(ibuf->rect, 0, 4 * ibuf->x * ibuf->y);
-
-                               if (ibuf->rect_float)
-                                       memset(ibuf->rect_float, 0, 4 * ibuf->x * ibuf->y * sizeof(float));
-
-                               ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
-
                                btree->flag |= NTREE_VIEWER_BORDER;
                        }
 
@@ -2526,3 +2518,30 @@ void NODE_OT_viewer_border(wmOperatorType *ot)
        /* properties */
        WM_operator_properties_gesture_border(ot, true);
 }
+
+static int clear_viewer_border_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       SpaceNode *snode = CTX_wm_space_node(C);
+       bNodeTree *btree = snode->nodetree;
+
+       btree->flag &= ~NTREE_VIEWER_BORDER;
+       snode_notify(C, snode);
+       WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
+
+       return OPERATOR_FINISHED;
+}
+
+void NODE_OT_clear_viewer_border(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Clear Viewer Border";
+       ot->description = "Clear the boundaries for viewer operations";
+       ot->idname = "NODE_OT_clear_viewer_border";
+
+       /* api callbacks */
+       ot->exec = clear_viewer_border_exec;
+       ot->poll = composite_node_active;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
index fa20aeb8624c190cb53d45e62484168afe91e6c2..86c8e80a2285a24a432d21ba8f278bd11df81372 100644 (file)
@@ -217,6 +217,7 @@ void NODE_OT_tree_socket_move(struct wmOperatorType *ot);
 void NODE_OT_shader_script_update(struct wmOperatorType *ot);
 
 void NODE_OT_viewer_border(struct wmOperatorType *ot);
+void NODE_OT_clear_viewer_border(struct wmOperatorType *ot);
 
 extern const char *node_context_dir[];
 
index ac541ef6a28b22f41282e42b9a388f225c49b1b2..807ed756c776b462bc91ad90a60f5898f4520074 100644 (file)
@@ -122,6 +122,7 @@ void node_operatortypes(void)
        WM_operatortype_append(NODE_OT_shader_script_update);
 
        WM_operatortype_append(NODE_OT_viewer_border);
+       WM_operatortype_append(NODE_OT_clear_viewer_border);
 
        WM_operatortype_append(NODE_OT_tree_socket_add);
        WM_operatortype_append(NODE_OT_tree_socket_remove);
@@ -321,6 +322,7 @@ void node_keymap(struct wmKeyConfig *keyconf)
        WM_keymap_add_item(keymap, "NODE_OT_clipboard_paste", VKEY, KM_PRESS, KM_OSKEY, 0);
 #endif
        WM_keymap_add_item(keymap, "NODE_OT_viewer_border", BKEY, KM_PRESS, KM_CTRL, 0);
+       WM_keymap_add_item(keymap, "NODE_OT_clear_viewer_border", BKEY, KM_PRESS, KM_ALT | KM_CTRL, 0);
 
        transform_keymap_for_space(keyconf, keymap, SPACE_NODE);
 }
index e550c4e85fbd5bfe27d69aa66c300aa3e8b3ba9f..065b6f787b6de40902d91e2c5b3a53b30fc7afef 100644 (file)
@@ -658,30 +658,6 @@ static void rna_NodeTree_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *p
 {
        bNodeTree *ntree = (bNodeTree *)ptr->id.data;
 
-       /* when using border, make it so no old data from outside of
-        * border is hanging around
-        * ideally shouldn't be in RNA callback, but how to teach
-        * compo to only clear frame when border usage is actually
-        * toggling
-        */
-       if (ntree->flag & NTREE_VIEWER_BORDER) {
-               Image *ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
-               void *lock;
-               ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
-
-               if (ibuf) {
-                       if (ibuf->rect)
-                               memset(ibuf->rect, 0, 4 * ibuf->x * ibuf->y);
-
-                       if (ibuf->rect_float)
-                               memset(ibuf->rect_float, 0, 4 * ibuf->x * ibuf->y * sizeof(float));
-
-                       ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
-               }
-
-               BKE_image_release_ibuf(ima, ibuf, lock);
-       }
-
        WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
        WM_main_add_notifier(NC_SCENE | ND_NODES, &ntree->id);