Fix for #35349, multiple viewers nodes crashing during render. The condition for...
[blender.git] / source / blender / compositor / nodes / COM_ViewerNode.cpp
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor: 
19  *              Jeroen Bakker 
20  *              Monique Dewanchand
21  */
22
23 #include "COM_ViewerNode.h"
24 #include "BKE_global.h"
25
26 #include "COM_ViewerOperation.h"
27 #include "COM_ExecutionSystem.h"
28
29 ViewerNode::ViewerNode(bNode *editorNode) : Node(editorNode)
30 {
31         /* pass */
32 }
33
34 void ViewerNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
35 {
36         bNode *editorNode = this->getbNode();
37         bool is_active = (editorNode->flag & NODE_DO_OUTPUT_RECALC || context->isRendering()) &&
38                          ((editorNode->flag & NODE_DO_OUTPUT) && this->isInActiveGroup());
39
40         InputSocket *imageSocket = this->getInputSocket(0);
41         InputSocket *alphaSocket = this->getInputSocket(1);
42         InputSocket *depthSocket = this->getInputSocket(2);
43         Image *image = (Image *)this->getbNode()->id;
44         ImageUser *imageUser = (ImageUser *) this->getbNode()->storage;
45         ViewerOperation *viewerOperation = new ViewerOperation();
46         viewerOperation->setbNodeTree(context->getbNodeTree());
47         viewerOperation->setImage(image);
48         viewerOperation->setImageUser(imageUser);
49         viewerOperation->setActive(is_active);
50         viewerOperation->setChunkOrder((OrderOfChunks)editorNode->custom1);
51         viewerOperation->setCenterX(editorNode->custom3);
52         viewerOperation->setCenterY(editorNode->custom4);
53         viewerOperation->setIgnoreAlpha(editorNode->custom2 & CMP_NODE_OUTPUT_IGNORE_ALPHA);
54
55         viewerOperation->setViewSettings(context->getViewSettings());
56         viewerOperation->setDisplaySettings(context->getDisplaySettings());
57
58         viewerOperation->setResolutionInputSocketIndex(0);
59         if (!imageSocket->isConnected()) {
60                 if (alphaSocket->isConnected()) {
61                         viewerOperation->setResolutionInputSocketIndex(1);
62                 }
63         }
64
65         imageSocket->relinkConnections(viewerOperation->getInputSocket(0), 0, graph);
66         alphaSocket->relinkConnections(viewerOperation->getInputSocket(1));
67         depthSocket->relinkConnections(viewerOperation->getInputSocket(2));
68         graph->addOperation(viewerOperation);
69
70         addPreviewOperation(graph, context, viewerOperation->getInputSocket(0));
71 }