diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2016-05-08 02:32:09 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2016-05-28 16:49:15 +0300 |
commit | b94bfe4cd8362abc4e8d256a081dc364c28a3117 (patch) | |
tree | ab45f201ece543ef69bd30eea897dee7df234ab4 /intern/cycles/render/graph.h | |
parent | a9f7bbc9f8f745d65ebf612a6b880782320831f7 (diff) |
Code refactor: make ShaderNode match Node a bit more, reusing types and enums.
Differential Revision: https://developer.blender.org/D2016
Diffstat (limited to 'intern/cycles/render/graph.h')
-rw-r--r-- | intern/cycles/render/graph.h | 105 |
1 files changed, 29 insertions, 76 deletions
diff --git a/intern/cycles/render/graph.h b/intern/cycles/render/graph.h index bd3f5ca689a..760b19f447a 100644 --- a/intern/cycles/render/graph.h +++ b/intern/cycles/render/graph.h @@ -17,6 +17,8 @@ #ifndef __GRAPH_H__ #define __GRAPH_H__ +#include "node.h" + #include "kernel_types.h" #include "util_list.h" @@ -39,23 +41,6 @@ class SVMCompiler; class OSLCompiler; class OutputNode; -/* Socket Type - * - * Data type for inputs and outputs */ - -enum ShaderSocketType { - SHADER_SOCKET_UNDEFINED, - - SHADER_SOCKET_FLOAT, - SHADER_SOCKET_INT, - SHADER_SOCKET_COLOR, - SHADER_SOCKET_VECTOR, - SHADER_SOCKET_POINT, - SHADER_SOCKET_NORMAL, - SHADER_SOCKET_CLOSURE, - SHADER_SOCKET_STRING -}; - /* Bump * * For bump mapping, a node may be evaluated multiple times, using different @@ -86,30 +71,6 @@ enum ShaderNodeSpecialType { SHADER_SPECIAL_TYPE_BUMP, }; -/* Enum - * - * Utility class for enum values. */ - -class ShaderEnum { -public: - bool empty() const { return left.empty(); } - void insert(const char *x, int y) { - left[ustring(x)] = y; - right[y] = ustring(x); - } - - bool exists(ustring x) { return left.find(x) != left.end(); } - bool exists(int y) { return right.find(y) != right.end(); } - - int operator[](const char *x) { return left[ustring(x)]; } - int operator[](ustring x) { return left[x]; } - ustring operator[](int y) { return right[y]; } - -protected: - map<ustring, int> left; - map<int, ustring> right; -}; - /* Input * * Input socket for a shader node. May be linked to an output or not. If not @@ -118,39 +79,27 @@ protected: class ShaderInput { public: - enum DefaultValue { - TEXTURE_GENERATED, - TEXTURE_UV, - INCOMING, - NORMAL, - POSITION, - TANGENT, - NONE - }; - - enum Usage { - USE_SVM = 1, - USE_OSL = 2, - USE_ALL = USE_SVM|USE_OSL - }; - - ShaderInput(ShaderNode *parent, const char *name, ShaderSocketType type); - void set(const float3& v) { value = v; } - void set(float f) { value = make_float3(f, 0, 0); } - void set(const ustring v) { value_string = v; } - - const char *name; - ShaderSocketType type; + ShaderInput(ShaderNode *parent, const char *name, SocketType::Type type); + + ustring name() { return name_; } + int flags() { return flags_; } + SocketType::Type type() { return type_; } + + float3& value() { return value_; } + float& value_float() { return value_.x; } + ustring& value_string() { return value_string_; } + + ustring name_; + SocketType::Type type_; ShaderNode *parent; ShaderOutput *link; - DefaultValue default_value; - float3 value; - ustring value_string; + float3 value_; + ustring value_string_; int stack_offset; /* for SVM compiler */ - int usage; + int flags_; }; /* Output @@ -159,12 +108,15 @@ public: class ShaderOutput { public: - ShaderOutput(ShaderNode *parent, const char *name, ShaderSocketType type); + ShaderOutput(ShaderNode *parent, const char *name, SocketType::Type type); - const char *name; - ShaderNode *parent; - ShaderSocketType type; + ustring name() { return name_; } + SocketType::Type type() { return type_; } + ustring name_; + SocketType::Type type_; + + ShaderNode *parent; vector<ShaderInput*> links; int stack_offset; /* for SVM compiler */ @@ -182,11 +134,12 @@ public: ShaderInput *input(const char *name); ShaderOutput *output(const char *name); + ShaderInput *input(ustring name); + ShaderOutput *output(ustring name); - ShaderInput *add_input(const char *name, ShaderSocketType type, float value=0.0f, int usage=ShaderInput::USE_ALL); - ShaderInput *add_input(const char *name, ShaderSocketType type, float3 value, int usage=ShaderInput::USE_ALL); - ShaderInput *add_input(const char *name, ShaderSocketType type, ShaderInput::DefaultValue value, int usage=ShaderInput::USE_ALL); - ShaderOutput *add_output(const char *name, ShaderSocketType type); + ShaderInput *add_input(const char *name, SocketType::Type type, float value=0.0f, int flags=0); + ShaderInput *add_input(const char *name, SocketType::Type type, float3 value, int flags=0); + ShaderOutput *add_output(const char *name, SocketType::Type type); virtual ShaderNode *clone() const = 0; virtual void attributes(Shader *shader, AttributeRequestSet *attributes); |