code cleanup: quiet some warnings and style
[blender.git] / source / blender / compositor / nodes / COM_ZCombineNode.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_ZCombineNode.h"
24
25 #include "COM_ZCombineOperation.h"
26
27 #include "COM_ExecutionSystem.h"
28 #include "COM_SetValueOperation.h"
29 #include "COM_MathBaseOperation.h"
30 #include "COM_AntiAliasOperation.h"
31 #include "COM_MixBlendOperation.h"
32
33 #include "DNA_material_types.h" // the ramp types
34
35 void ZCombineNode::convertToOperations(ExecutionSystem *system, CompositorContext *context)
36 {
37         if (context->getRenderData()->scemode & R_FULL_SAMPLE) {
38                 if (this->getOutputSocket(0)->isConnected()) {
39                         ZCombineOperation *operation = NULL;
40                         if (this->getbNode()->custom1) {
41                                 operation = new ZCombineAlphaOperation();
42                         }
43                         else {
44                                 operation = new ZCombineOperation();
45                         }
46
47                         this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, system);
48                         this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, system);
49                         this->getInputSocket(2)->relinkConnections(operation->getInputSocket(2), 2, system);
50                         this->getInputSocket(3)->relinkConnections(operation->getInputSocket(3), 3, system);
51                         this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket());
52                         system->addOperation(operation);
53                         if (this->getOutputSocket(1)->isConnected()) {
54                                 MathMinimumOperation *zoperation = new MathMinimumOperation();
55                                 addLink(system, operation->getInputSocket(1)->getConnection()->getFromSocket(), zoperation->getInputSocket(0));
56                                 addLink(system, operation->getInputSocket(3)->getConnection()->getFromSocket(), zoperation->getInputSocket(1));
57                                 this->getOutputSocket(1)->relinkConnections(zoperation->getOutputSocket());
58                                 system->addOperation(zoperation);
59                         }
60                 }
61                 else {
62                         if (this->getOutputSocket(1)->isConnected()) {
63                                 MathMinimumOperation *zoperation = new MathMinimumOperation();
64                                 this->getInputSocket(1)->relinkConnections(zoperation->getInputSocket(0), 1, system);
65                                 this->getInputSocket(3)->relinkConnections(zoperation->getInputSocket(1), 3, system);
66                                 this->getOutputSocket(1)->relinkConnections(zoperation->getOutputSocket());
67                                 system->addOperation(zoperation);
68                         }
69                 }
70         }
71         else {
72                 // not full anti alias, use masking for Z combine. be aware it uses anti aliasing.
73                 // step 1 create mask
74                 MathGreaterThanOperation *maskoperation = new MathGreaterThanOperation();
75                 this->getInputSocket(1)->relinkConnections(maskoperation->getInputSocket(0), 1, system);
76                 this->getInputSocket(3)->relinkConnections(maskoperation->getInputSocket(1), 3, system);
77
78                 // step 2 anti alias mask bit of an expensive operation, but does the trick
79                 AntiAliasOperation *antialiasoperation = new AntiAliasOperation();
80                 addLink(system, maskoperation->getOutputSocket(), antialiasoperation->getInputSocket(0));
81
82                 // use mask to blend between the input colors.
83                 ZCombineMaskOperation *zcombineoperation = this->getbNode()->custom1?new ZCombineMaskAlphaOperation():new ZCombineMaskOperation();
84                 addLink(system, antialiasoperation->getOutputSocket(), zcombineoperation->getInputSocket(0));
85                 this->getInputSocket(0)->relinkConnections(zcombineoperation->getInputSocket(1), 0, system);
86                 this->getInputSocket(2)->relinkConnections(zcombineoperation->getInputSocket(2), 2, system);
87                 this->getOutputSocket(0)->relinkConnections(zcombineoperation->getOutputSocket());
88
89                 system->addOperation(maskoperation);
90                 system->addOperation(antialiasoperation);
91                 system->addOperation(zcombineoperation);
92
93                 if (this->getOutputSocket(1)->isConnected()) {
94                         MathMinimumOperation *zoperation = new MathMinimumOperation();
95                         addLink(system, maskoperation->getInputSocket(0)->getConnection()->getFromSocket(), zoperation->getInputSocket(0));
96                         addLink(system, maskoperation->getInputSocket(1)->getConnection()->getFromSocket(), zoperation->getInputSocket(1));
97                         this->getOutputSocket(1)->relinkConnections(zoperation->getOutputSocket());
98                         system->addOperation(zoperation);
99                 }
100         }
101 }