Commit: e0c1dc44880add2fb64b0e0efc2f174576ba2cd1 Author: Brecht Van Lommel Date: Sat May 7 19:47:37 2016 +0200 Branches: compositor-2016 https://developer.blender.org/rBe0c1dc44880add2fb64b0e0efc2f174576ba2cd1
Code refactor: add generic Cycles node infrastructure. Differential Revision: https://developer.blender.org/D2016 =================================================================== M build_files/cmake/macros.cmake M intern/cycles/CMakeLists.txt M intern/cycles/app/CMakeLists.txt M intern/cycles/blender/CMakeLists.txt M intern/cycles/bvh/CMakeLists.txt M intern/cycles/device/CMakeLists.txt A intern/cycles/graph/CMakeLists.txt A intern/cycles/graph/node.cpp A intern/cycles/graph/node.h A intern/cycles/graph/node_enum.h A intern/cycles/graph/node_type.cpp A intern/cycles/graph/node_type.h M intern/cycles/kernel/osl/CMakeLists.txt M intern/cycles/kernel/svm/svm_types.h M intern/cycles/render/CMakeLists.txt M intern/cycles/render/nodes.cpp M intern/cycles/render/svm.cpp M intern/cycles/render/svm.h M intern/cycles/subd/CMakeLists.txt M intern/cycles/util/util_vector.h =================================================================== diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index 08d26e5..f14c954 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -487,6 +487,7 @@ function(SETUP_BLENDER_SORTED_LIBS) if(WITH_CYCLES) list(APPEND BLENDER_LINK_LIBS cycles_render + cycles_graph cycles_bvh cycles_device cycles_kernel @@ -600,6 +601,7 @@ function(SETUP_BLENDER_SORTED_LIBS) bf_intern_dualcon bf_intern_cycles cycles_render + cycles_graph cycles_bvh cycles_device cycles_kernel diff --git a/intern/cycles/CMakeLists.txt b/intern/cycles/CMakeLists.txt index efc36f0..3b410b2 100644 --- a/intern/cycles/CMakeLists.txt +++ b/intern/cycles/CMakeLists.txt @@ -237,6 +237,7 @@ endif() add_subdirectory(bvh) add_subdirectory(device) add_subdirectory(doc) +add_subdirectory(graph) add_subdirectory(kernel) add_subdirectory(render) add_subdirectory(subd) diff --git a/intern/cycles/app/CMakeLists.txt b/intern/cycles/app/CMakeLists.txt index d40a1a1..73dbf16 100644 --- a/intern/cycles/app/CMakeLists.txt +++ b/intern/cycles/app/CMakeLists.txt @@ -1,13 +1,14 @@ set(INC . + ../bvh ../device + ../graph ../kernel ../kernel/svm - ../bvh - ../util ../render ../subd + ../util ) set(INC_SYS ) @@ -20,6 +21,7 @@ set(LIBRARIES cycles_render cycles_bvh cycles_subd + cycles_graph cycles_util ${BLENDER_GL_LIBRARIES} ${CYCLES_APP_GLEW_LIBRARY} diff --git a/intern/cycles/blender/CMakeLists.txt b/intern/cycles/blender/CMakeLists.txt index a8cc490..a79deca 100644 --- a/intern/cycles/blender/CMakeLists.txt +++ b/intern/cycles/blender/CMakeLists.txt @@ -1,5 +1,6 @@ set(INC + ../graph ../render ../device ../kernel diff --git a/intern/cycles/bvh/CMakeLists.txt b/intern/cycles/bvh/CMakeLists.txt index cbbd23f..5729fa6 100644 --- a/intern/cycles/bvh/CMakeLists.txt +++ b/intern/cycles/bvh/CMakeLists.txt @@ -1,6 +1,7 @@ set(INC . + ../graph ../kernel ../kernel/svm ../render diff --git a/intern/cycles/device/CMakeLists.txt b/intern/cycles/device/CMakeLists.txt index 2a9ec0c..c34677e 100644 --- a/intern/cycles/device/CMakeLists.txt +++ b/intern/cycles/device/CMakeLists.txt @@ -1,6 +1,7 @@ set(INC . + ../graph ../kernel ../kernel/svm ../kernel/osl diff --git a/intern/cycles/graph/CMakeLists.txt b/intern/cycles/graph/CMakeLists.txt new file mode 100644 index 0000000..401bdb4 --- /dev/null +++ b/intern/cycles/graph/CMakeLists.txt @@ -0,0 +1,22 @@ + +set(INC + . + ../util +) + +set(SRC + node.cpp + node_type.cpp +) + +set(SRC_HEADERS + node.h + node_enum.h + node_type.h +) + +include_directories(${INC}) +include_directories(SYSTEM ${INC_SYS}) + +add_library(cycles_graph ${SRC} ${SRC_HEADERS}) + diff --git a/intern/cycles/graph/node.cpp b/intern/cycles/graph/node.cpp new file mode 100644 index 0000000..d9a6bde --- /dev/null +++ b/intern/cycles/graph/node.cpp @@ -0,0 +1,354 @@ +/* + * Copyright 2011-2016 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "node.h" +#include "node_type.h" + +#include "util_foreach.h" +#include "util_param.h" +#include "util_transform.h" + +CCL_NAMESPACE_BEGIN + +/* Node Type */ + +Node::Node(const NodeType *type_, ustring name_) +: name(name_), type(type_) +{ + assert(type); + + /* assign non-empty name, convenient for debugging */ + if(name.empty()) { + name = type->name; + } + + /* initialize default values */ + typedef unordered_map<ustring, SocketType, ustringHash> map_type; + foreach(const map_type::value_type& it, type->inputs) { + const SocketType& socket = it.second; + const void *src = socket.default_value; + void *dst = ((char*)this) + socket.struct_offset; + memcpy(dst, src, socket.size()); + } +} + +Node::~Node() +{ +} + +template<typename T> +static T& get_socket_value(const Node *node, const SocketType& socket) +{ + return (T&)*(((char*)node) + socket.struct_offset); +} + +static bool is_socket_float3(const SocketType& socket) +{ + return socket.type == SocketType::COLOR || + socket.type == SocketType::POINT || + socket.type == SocketType::VECTOR || + socket.type == SocketType::NORMAL; +} + +static bool is_socket_array_float3(const SocketType& socket) +{ + return socket.type == SocketType::COLOR_ARRAY || + socket.type == SocketType::POINT_ARRAY || + socket.type == SocketType::VECTOR_ARRAY || + socket.type == SocketType::NORMAL_ARRAY; +} + +/* set values */ +void Node::set(const SocketType& input, bool value) +{ + assert(input.type == SocketType::BOOLEAN); + get_socket_value<bool>(this, input) = value; +} + +void Node::set(const SocketType& input, int value) +{ + assert((input.type == SocketType::INT || input.type == SocketType::ENUM)); + get_socket_value<int>(this, input) = value; +} + +void Node::set(const SocketType& input, float value) +{ + assert(input.type == SocketType::FLOAT); + get_socket_value<float>(this, input) = value; +} + +void Node::set(const SocketType& input, float2 value) +{ + assert(input.type == SocketType::FLOAT); + get_socket_value<float2>(this, input) = value; +} + +void Node::set(const SocketType& input, float3 value) +{ + assert(is_socket_float3(input)); + get_socket_value<float3>(this, input) = value; +} + +void Node::set(const SocketType& input, ustring value) +{ + if(input.type == SocketType::STRING) { + get_socket_value<ustring>(this, input) = value; + } + else if(input.type == SocketType::ENUM) { + const NodeEnum& enm = *input.enum_values; + if(enm.exists(value)) { + get_socket_value<int>(this, input) = enm[value]; + } + else { + assert(0); + } + } + else { + assert(0); + } +} + +void Node::set(const SocketType& input, const Transform& value) +{ + assert(input.type == SocketType::TRANSFORM); + get_socket_value<Transform>(this, input) = value; +} + +void Node::set(const SocketType& input, Node *value) +{ + assert(input.type == SocketType::TRANSFORM); + get_socket_value<Node*>(this, input) = value; +} + +/* set array values */ +void Node::set(const SocketType& input, array<bool>& value) +{ + assert(input.type == SocketType::BOOLEAN_ARRAY); + get_socket_value<array<bool> >(this, input).steal_data(value); +} + +void Node::set(const SocketType& input, array<int>& value) +{ + assert(input.type == SocketType::INT_ARRAY); + get_socket_value<array<int> >(this, input).steal_data(value); +} + +void Node::set(const SocketType& input, array<float>& value) +{ + assert(input.type == SocketType::FLOAT_ARRAY); + get_socket_value<array<float> >(this, input).steal_data(value); +} + +void Node::set(const SocketType& input, array<float2>& value) +{ + assert(input.type == SocketType::FLOAT_ARRAY); + get_socket_value<array<float2> >(this, input).steal_data(value); +} + +void Node::set(const SocketType& input, array<float3>& value) +{ + assert(is_socket_array_float3(input)); + get_socket_value<array<float3> >(this, input).steal_data(value); +} + +void Node::set(const SocketType& input, array<ustring>& value) +{ + assert(input.type == SocketType::STRING_ARRAY); + get_socket_value<array<ustring> >(this, input).steal_data(value); +} + +void Node::set(const SocketType& input, array<Transform>& value) +{ + assert(input.type == SocketType::TRANSFORM_ARRAY); + get_socket_value<array<Transform> >(this, input).steal_data(value); +} + +void Node::set(const SocketType& input, array<Node*>& value) +{ + assert(input.type == SocketType::TRANSFORM_ARRAY); + get_socket_value<array<Node*> >(this, input).steal_data(value); +} + +/* get values */ +bool Node::get_bool(const SocketType& input) const +{ + assert(input.type == SocketType::BOOLEAN); + return get_socket_value<bool>(this, input); +} + +int Node::get_int(const SocketType& input) const +{ + assert(input.type == SocketType::INT || input.type == SocketType::ENUM); + return get_socket_value<int>(this, input); +} + +float Node::get_float(const SocketType& input) const +{ + assert(input.type == SocketType::FLOAT); + return get_socket_value<float>(this, input); +} + +float2 Node::get_float2(const SocketType& input) const +{ + assert(input.type == SocketType::FLOAT); + return get_socket_value<float2>(this, input); +} + +float3 Node::get_float3(const SocketType& input) const +{ + assert(is_socket_float3(input)); + return get_socket_value<float3>(this, input); +} + +ustring Node::get_string(const SocketType& input) const +{ + if(input.type == SocketType::STRING) { + return get_socket_value<ustring>(this, input); + } + else if(input.type == SocketType::ENUM) { + const NodeEnum& enm = *input.enum_values; + int intvalue = get_socket_value<int>(this, input); + return (enm.exists(intvalue)) ? enm[intvalue] : ustring(); + } + else { + assert(0); + return ustring(); + } +} + +Transform Node::get_transform(const SocketType& input) const +{ + assert(input.type == SocketType::TRANSFORM); + return get_socket_value<Transform>(this, input); +} + +Node *Node::get_node(const SocketType& input) const +{ + assert(input.type == SocketType::NODE); + return get_socket_value<Node*>(this, input); +} + +/* get array values */ +const array<bool>& Node::get_bool_array(const SocketType& input) const +{ + assert(input.type == SocketType::BOOLEAN_ARRAY); + return get_socket_value<array<bool> >(this, input); +} + +const array<int>& Node::get_int_array(const SocketType& input) const +{ + assert(input.type == SocketType::INT_ARRAY); + return get_socket_value<array<int> >(this, input); +} + +const array<float>& Node::get_float_array(const SocketType& input) const +{ + assert(input.type == SocketType::FLOAT_ARRAY); + return get_socket_value<array<float> >(this, input); +} + +const array<float2>& Node::get_float2_array(const SocketType& input) const +{ + assert(input.type == SocketType::FLOAT_ARRAY); + return get_socket_val @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list [email protected] https://lists.blender.org/mailman/listinfo/bf-blender-cvs
