~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/compositor/nodes/COM_SocketProxyNode.cpp

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_SocketProxyNode.h"
 
24
#include "COM_SocketConnection.h"
 
25
#include "COM_SocketProxyOperation.h"
 
26
#include "COM_ExecutionSystem.h"
 
27
#include "COM_SetValueOperation.h"
 
28
#include "COM_SetVectorOperation.h"
 
29
#include "COM_SetColorOperation.h"
 
30
#include "COM_WriteBufferOperation.h"
 
31
#include "COM_ReadBufferOperation.h"
 
32
 
 
33
SocketProxyNode::SocketProxyNode(bNode *editorNode, bNodeSocket *editorInput, bNodeSocket *editorOutput, bool buffer) : Node(editorNode, false)
 
34
{
 
35
        DataType dt;
 
36
        this->m_buffer = buffer;
 
37
 
 
38
        dt = COM_DT_VALUE;
 
39
        if (editorInput->type == SOCK_RGBA) dt = COM_DT_COLOR;
 
40
        if (editorInput->type == SOCK_VECTOR) dt = COM_DT_VECTOR;
 
41
        this->addInputSocket(dt, (InputSocketResizeMode)editorInput->resizemode, editorInput);
 
42
 
 
43
        dt = COM_DT_VALUE;
 
44
        if (editorOutput->type == SOCK_RGBA) dt = COM_DT_COLOR;
 
45
        if (editorOutput->type == SOCK_VECTOR) dt = COM_DT_VECTOR;
 
46
        this->addOutputSocket(dt, editorOutput);
 
47
}
 
48
 
 
49
void SocketProxyNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
 
50
{
 
51
        OutputSocket *outputsocket = this->getOutputSocket(0);
 
52
        InputSocket *inputsocket = this->getInputSocket(0);
 
53
        if (outputsocket->isConnected()) {
 
54
                if (inputsocket->isConnected()) {
 
55
                        SocketProxyOperation *operation = new SocketProxyOperation(this->getOutputSocket()->getDataType());
 
56
                        inputsocket->relinkConnections(operation->getInputSocket(0));
 
57
                        outputsocket->relinkConnections(operation->getOutputSocket(0));
 
58
                        graph->addOperation(operation);
 
59
                        if (m_buffer) {
 
60
                                WriteBufferOperation *writeOperation = new WriteBufferOperation();
 
61
                                ReadBufferOperation *readOperation = new ReadBufferOperation();
 
62
                                readOperation->setMemoryProxy(writeOperation->getMemoryProxy());
 
63
 
 
64
                                operation->getOutputSocket()->relinkConnections(readOperation->getOutputSocket());
 
65
                                addLink(graph, operation->getOutputSocket(), writeOperation->getInputSocket(0));
 
66
 
 
67
                                graph->addOperation(writeOperation);
 
68
                                graph->addOperation(readOperation);
 
69
                        }
 
70
                }
 
71
                else {
 
72
                        /* If input is not connected, add a constant value operation instead */
 
73
                        switch (outputsocket->getDataType()) {
 
74
                                case COM_DT_VALUE:
 
75
                                {
 
76
                                        SetValueOperation *operation = new SetValueOperation();
 
77
                                        bNodeSocketValueFloat *dval = (bNodeSocketValueFloat *)inputsocket->getbNodeSocket()->default_value;
 
78
                                        operation->setValue(dval->value);
 
79
                                        outputsocket->relinkConnections(operation->getOutputSocket(0));
 
80
                                        graph->addOperation(operation);
 
81
                                        break;
 
82
                                }
 
83
                                case COM_DT_COLOR:
 
84
                                {
 
85
                                        SetColorOperation *operation = new SetColorOperation();
 
86
                                        bNodeSocketValueRGBA *dval = (bNodeSocketValueRGBA *)inputsocket->getbNodeSocket()->default_value;
 
87
                                        operation->setChannels(dval->value);
 
88
                                        outputsocket->relinkConnections(operation->getOutputSocket(0));
 
89
                                        graph->addOperation(operation);
 
90
                                        break;
 
91
                                }
 
92
                                case COM_DT_VECTOR:
 
93
                                {
 
94
                                        SetVectorOperation *operation = new SetVectorOperation();
 
95
                                        bNodeSocketValueVector *dval = (bNodeSocketValueVector *)inputsocket->getbNodeSocket()->default_value;
 
96
                                        operation->setVector(dval->value);
 
97
                                        outputsocket->relinkConnections(operation->getOutputSocket(0));
 
98
                                        graph->addOperation(operation);
 
99
                                        break;
 
100
                                }
 
101
                        }
 
102
                }
 
103
        }
 
104
}