Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKévin Dietrich <kevin.dietrich@mailoo.org>2020-11-04 13:17:38 +0300
committerKévin Dietrich <kevin.dietrich@mailoo.org>2020-11-04 15:03:33 +0300
commit31a620b9420cab6292b0aa1ea21c9dd1cf70b8bc (patch)
tree76cf425e110fe1c78930e54f3b56d24e1485877a /intern/cycles/graph/node.cpp
parenta4a848d01b26ad094dabe0e935dd698847ac8f16 (diff)
Cycles API: encapsulate Node socket members
This encapsulates Node socket members behind a set of specific methods; as such it is no longer possible to directly access Node class members from exporters and parts of Cycles. The methods are defined via the NODE_SOCKET_API macros in `graph/ node.h`, and are for getting or setting a specific socket's value, as well as querying or modifying the state of its update flag. The setters will check whether the value has changed and tag the socket as modified appropriately. This will let us know how a Node has changed and what to update, which is the first concrete step toward a more granular scene update system. Since the setters will tag the Node sockets as modified when passed different data, this patch also removes the various modified methods on Nodes in favor of Node::is_modified which checks the sockets' update flags status. Reviewed By: brecht Maniphest Tasks: T79174 Differential Revision: https://developer.blender.org/D8544
Diffstat (limited to 'intern/cycles/graph/node.cpp')
-rw-r--r--intern/cycles/graph/node.cpp86
1 files changed, 81 insertions, 5 deletions
diff --git a/intern/cycles/graph/node.cpp b/intern/cycles/graph/node.cpp
index f239040ee3d..0f073ed9b63 100644
--- a/intern/cycles/graph/node.cpp
+++ b/intern/cycles/graph/node.cpp
@@ -52,11 +52,6 @@ Node::~Node()
{
}
-template<typename T> static T &get_socket_value(const Node *node, const SocketType &socket)
-{
- return (T &)*(((char *)node) + socket.struct_offset);
-}
-
#ifndef NDEBUG
static bool is_socket_float3(const SocketType &socket)
{
@@ -387,6 +382,87 @@ void Node::copy_value(const SocketType &socket, const Node &other, const SocketT
}
}
+void Node::set_value(const SocketType &socket, const Node &other, const SocketType &other_socket)
+{
+ assert(socket.type == other_socket.type);
+ (void)other_socket;
+
+ if (socket.is_array()) {
+ switch (socket.type) {
+ case SocketType::BOOLEAN_ARRAY:
+ set(socket, get_socket_value<array<bool>>(&other, socket));
+ break;
+ case SocketType::FLOAT_ARRAY:
+ set(socket, get_socket_value<array<float>>(&other, socket));
+ break;
+ case SocketType::INT_ARRAY:
+ set(socket, get_socket_value<array<int>>(&other, socket));
+ break;
+ case SocketType::COLOR_ARRAY:
+ case SocketType::VECTOR_ARRAY:
+ case SocketType::POINT_ARRAY:
+ case SocketType::NORMAL_ARRAY:
+ set(socket, get_socket_value<array<float3>>(&other, socket));
+ break;
+ case SocketType::POINT2_ARRAY:
+ set(socket, get_socket_value<array<float2>>(&other, socket));
+ break;
+ case SocketType::STRING_ARRAY:
+ set(socket, get_socket_value<array<ustring>>(&other, socket));
+ break;
+ case SocketType::TRANSFORM_ARRAY:
+ set(socket, get_socket_value<array<Transform>>(&other, socket));
+ break;
+ case SocketType::NODE_ARRAY:
+ set(socket, get_socket_value<array<Node *>>(&other, socket));
+ break;
+ default:
+ assert(0);
+ break;
+ }
+ }
+ else {
+ switch (socket.type) {
+ case SocketType::BOOLEAN:
+ set(socket, get_socket_value<bool>(&other, socket));
+ break;
+ case SocketType::FLOAT:
+ set(socket, get_socket_value<float>(&other, socket));
+ break;
+ case SocketType::INT:
+ set(socket, get_socket_value<int>(&other, socket));
+ break;
+ case SocketType::UINT:
+ set(socket, get_socket_value<uint>(&other, socket));
+ break;
+ case SocketType::COLOR:
+ case SocketType::VECTOR:
+ case SocketType::POINT:
+ case SocketType::NORMAL:
+ set(socket, get_socket_value<float3>(&other, socket));
+ break;
+ case SocketType::POINT2:
+ set(socket, get_socket_value<float2>(&other, socket));
+ break;
+ case SocketType::STRING:
+ set(socket, get_socket_value<ustring>(&other, socket));
+ break;
+ case SocketType::ENUM:
+ set(socket, get_socket_value<int>(&other, socket));
+ break;
+ case SocketType::TRANSFORM:
+ set(socket, get_socket_value<Transform>(&other, socket));
+ break;
+ case SocketType::NODE:
+ set(socket, get_socket_value<Node *>(&other, socket));
+ break;
+ default:
+ assert(0);
+ break;
+ }
+ }
+}
+
template<typename T>
static bool is_array_equal(const Node *node, const Node *other, const SocketType &socket)
{