| 880 | } |
| 881 | |
| 882 | void ShaderGraph::finalize(GenContext& context) |
| 883 | { |
| 884 | // Allow node implementations to update the classification |
| 885 | // on its node instances |
| 886 | for (ShaderNode* node : getNodes()) |
| 887 | { |
| 888 | node->getImplementation().addClassification(*node); |
| 889 | } |
| 890 | |
| 891 | // Add classification according to root node |
| 892 | ShaderGraphOutputSocket* outputSocket = getOutputSocket(); |
| 893 | if (outputSocket->getConnection()) |
| 894 | { |
| 895 | addClassification(outputSocket->getConnection()->getNode()->getClassification()); |
| 896 | } |
| 897 | |
| 898 | // Insert color transformation nodes where needed |
| 899 | if (context.getOptions().emitColorTransforms) |
| 900 | { |
| 901 | for (const auto& it : _inputColorTransformMap) |
| 902 | { |
| 903 | addColorTransformNode(it.first, it.second, context); |
| 904 | } |
| 905 | for (const auto& it : _outputColorTransformMap) |
| 906 | { |
| 907 | addColorTransformNode(it.first, it.second, context); |
| 908 | } |
| 909 | } |
| 910 | _inputColorTransformMap.clear(); |
| 911 | _outputColorTransformMap.clear(); |
| 912 | |
| 913 | // Insert unit transformation nodes where needed |
| 914 | for (const auto& it : _inputUnitTransformMap) |
| 915 | { |
| 916 | addUnitTransformNode(it.first, it.second, context); |
| 917 | } |
| 918 | for (const auto& it : _outputUnitTransformMap) |
| 919 | { |
| 920 | addUnitTransformNode(it.first, it.second, context); |
| 921 | } |
| 922 | _inputUnitTransformMap.clear(); |
| 923 | _outputUnitTransformMap.clear(); |
| 924 | |
| 925 | // Run registered graph refactoring passes. |
| 926 | size_t totalEdits = 0; |
| 927 | for (auto& refactor : context.getShaderGenerator().getRefactors()) |
| 928 | { |
| 929 | totalEdits += refactor->execute(*this, context); |
| 930 | } |
| 931 | |
| 932 | // Remove unused nodes if any refactoring pass made edits. |
| 933 | if (totalEdits > 0) |
| 934 | { |
| 935 | removeUnusedNodes(); |
| 936 | } |
| 937 | |
| 938 | // Sort the nodes in topological order. |
| 939 | topologicalSort(); |
no test coverage detected