This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/compositor/nodes/COM_TranslateNode.cpp
Monique Dewanchand c751d40e07 Cleanup hardcoded render percentage to factor conversion
During revision of {D8952} one of the comments was to make a function that converts the render percentage to a factor. This to avoid code duplication. However the duplicated code was already all over the compositor code. So in order to avoid this code duplication for {D8952} I propose to first cleanup the duplicated code and build patch {D8952} based on this clean up.

The method that converts the render percentage to a factor is put in the CompositorContext. Why? The CompositorContext keeps DNA information like the renderdata. DNA, and thus the CompositorContext, keeps the size of the render resolution in percentage (user oriented). The compositor needs the size of the render resolution as a factor. So the CompositorContext seems like the obvious place to have this conversion method.

Why not in de NodeBase? The method could've been added to the nodebase, but I wanted to keep the nodebase as clean as possible and not put simple "conversion" methods into this base class. Also I didn't really like the call flow: you'd always have to get the renderdata size from the context and then convert.
Putting it in the CompositorContext avoids this extra invoke of a call.

Why not in the Converter? See nodebase. And the Converter seems more like a class for "structural" and complex node tree conversions. Not the simple conversions.

Reviewed By: Sergey Sharybin

Differential Revision: https://developer.blender.org/D9566
2020-11-30 08:00:40 +01:00

72 lines
2.7 KiB
C++

/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright 2011, Blender Foundation.
*/
#include "COM_TranslateNode.h"
#include "COM_ExecutionSystem.h"
#include "COM_TranslateOperation.h"
#include "COM_WrapOperation.h"
#include "COM_WriteBufferOperation.h"
TranslateNode::TranslateNode(bNode *editorNode) : Node(editorNode)
{
/* pass */
}
void TranslateNode::convertToOperations(NodeConverter &converter,
const CompositorContext &context) const
{
bNode *bnode = this->getbNode();
NodeTranslateData *data = (NodeTranslateData *)bnode->storage;
NodeInput *inputSocket = this->getInputSocket(0);
NodeInput *inputXSocket = this->getInputSocket(1);
NodeInput *inputYSocket = this->getInputSocket(2);
NodeOutput *outputSocket = this->getOutputSocket(0);
TranslateOperation *operation = new TranslateOperation();
if (data->relative) {
const RenderData *rd = context.getRenderData();
const float render_size_factor = context.getRenderPercentageAsFactor();
float fx = rd->xsch * render_size_factor;
float fy = rd->ysch * render_size_factor;
operation->setFactorXY(fx, fy);
}
converter.addOperation(operation);
converter.mapInputSocket(inputXSocket, operation->getInputSocket(1));
converter.mapInputSocket(inputYSocket, operation->getInputSocket(2));
converter.mapOutputSocket(outputSocket, operation->getOutputSocket(0));
if (data->wrap_axis) {
WriteBufferOperation *writeOperation = new WriteBufferOperation(COM_DT_COLOR);
WrapOperation *wrapOperation = new WrapOperation(COM_DT_COLOR);
wrapOperation->setMemoryProxy(writeOperation->getMemoryProxy());
wrapOperation->setWrapping(data->wrap_axis);
converter.addOperation(writeOperation);
converter.addOperation(wrapOperation);
converter.mapInputSocket(inputSocket, writeOperation->getInputSocket(0));
converter.addLink(wrapOperation->getOutputSocket(), operation->getInputSocket(0));
}
else {
converter.mapInputSocket(inputSocket, operation->getInputSocket(0));
}
}