summaryrefslogtreecommitdiff
path: root/servers/visual/shader_language.h
diff options
context:
space:
mode:
Diffstat (limited to 'servers/visual/shader_language.h')
-rw-r--r--servers/visual/shader_language.h46
1 files changed, 43 insertions, 3 deletions
diff --git a/servers/visual/shader_language.h b/servers/visual/shader_language.h
index da5b0600ff..4d474086a6 100644
--- a/servers/visual/shader_language.h
+++ b/servers/visual/shader_language.h
@@ -82,6 +82,7 @@ public:
TK_INTERPOLATION_FLAT,
TK_INTERPOLATION_SMOOTH,
TK_CONST,
+ TK_STRUCT,
TK_PRECISION_LOW,
TK_PRECISION_MID,
TK_PRECISION_HIGH,
@@ -214,6 +215,7 @@ public:
TYPE_ISAMPLER3D,
TYPE_USAMPLER3D,
TYPE_SAMPLERCUBE,
+ TYPE_STRUCT,
};
enum DataPrecision {
@@ -269,6 +271,7 @@ public:
OP_POST_DECREMENT,
OP_CALL,
OP_CONSTRUCT,
+ OP_STRUCT,
OP_INDEX,
OP_MAX
};
@@ -329,11 +332,14 @@ public:
TYPE_MEMBER,
TYPE_ARRAY,
TYPE_ARRAY_DECLARATION,
+ TYPE_STRUCT,
};
Type type;
virtual DataType get_datatype() const { return TYPE_VOID; }
+ virtual String get_datatype_name() const { return ""; }
+
Node(Type t) :
next(NULL),
type(t) {}
@@ -354,20 +360,25 @@ public:
DataType return_cache;
DataPrecision return_precision_cache;
Operator op;
+ StringName struct_name;
Vector<Node *> arguments;
virtual DataType get_datatype() const { return return_cache; }
+ virtual String get_datatype_name() const { return String(struct_name); }
OperatorNode() :
Node(TYPE_OPERATOR),
return_cache(TYPE_VOID),
return_precision_cache(PRECISION_DEFAULT),
- op(OP_EQUAL) {}
+ op(OP_EQUAL),
+ struct_name("") {}
};
struct VariableNode : public Node {
DataType datatype_cache;
StringName name;
+ StringName struct_name;
virtual DataType get_datatype() const { return datatype_cache; }
+ virtual String get_datatype_name() const { return String(struct_name); }
bool is_const;
VariableNode() :
@@ -379,6 +390,7 @@ public:
struct VariableDeclarationNode : public Node {
DataPrecision precision;
DataType datatype;
+ String struct_name;
bool is_const;
struct Declaration {
@@ -398,12 +410,14 @@ public:
struct ArrayNode : public Node {
DataType datatype_cache;
+ StringName struct_name;
StringName name;
Node *index_expression;
Node *call_expression;
bool is_const;
virtual DataType get_datatype() const { return datatype_cache; }
+ virtual String get_datatype_name() const { return String(struct_name); }
ArrayNode() :
Node(TYPE_ARRAY),
@@ -416,6 +430,7 @@ public:
struct ArrayDeclarationNode : public Node {
DataPrecision precision;
DataType datatype;
+ String struct_name;
bool is_const;
struct Declaration {
@@ -470,6 +485,7 @@ public:
struct Variable {
DataType type;
+ StringName struct_name;
DataPrecision precision;
int line; //for completion
int array_size;
@@ -501,11 +517,15 @@ public:
struct MemberNode : public Node {
DataType basetype;
+ StringName base_struct_name;
+ DataPrecision precision;
DataType datatype;
+ StringName struct_name;
StringName name;
Node *owner;
virtual DataType get_datatype() const { return datatype; }
+ virtual String get_datatype_name() const { return String(struct_name); }
MemberNode() :
Node(TYPE_MEMBER),
@@ -514,12 +534,20 @@ public:
owner(NULL) {}
};
+ struct StructNode : public Node {
+
+ List<MemberNode *> members;
+ StructNode() :
+ Node(TYPE_STRUCT) {}
+ };
+
struct FunctionNode : public Node {
struct Argument {
ArgumentQualifier qualifier;
StringName name;
DataType type;
+ StringName type_str;
DataPrecision precision;
//for passing textures as arguments
bool tex_argument_check;
@@ -533,6 +561,7 @@ public:
StringName name;
DataType return_type;
+ StringName return_struct_name;
DataPrecision return_precision;
Vector<Argument> arguments;
BlockNode *body;
@@ -550,6 +579,7 @@ public:
struct Constant {
DataType type;
+ StringName type_str;
DataPrecision precision;
ConstantNode *initializer;
};
@@ -561,6 +591,11 @@ public:
bool callable;
};
+ struct Struct {
+ StringName name;
+ StructNode *shader_struct;
+ };
+
struct Varying {
DataType type;
DataInterpolation interpolation;
@@ -621,9 +656,11 @@ public:
Map<StringName, Constant> constants;
Map<StringName, Varying> varyings;
Map<StringName, Uniform> uniforms;
+ Map<StringName, Struct> structs;
Vector<StringName> render_modes;
Vector<Function> functions;
+ Vector<Struct> vstructs;
ShaderNode() :
Node(TYPE_SHADER) {}
@@ -650,6 +687,7 @@ public:
COMPLETION_FUNCTION_CALL,
COMPLETION_CALL_ARGUMENTS,
COMPLETION_INDEX,
+ COMPLETION_STRUCT,
};
struct Token {
@@ -766,7 +804,7 @@ private:
IDENTIFIER_CONSTANT,
};
- bool _find_identifier(const BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, const StringName &p_identifier, DataType *r_data_type = NULL, IdentifierType *r_type = NULL, bool *r_is_const = NULL, int *r_array_size = NULL);
+ bool _find_identifier(const BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, const StringName &p_identifier, DataType *r_data_type = NULL, IdentifierType *r_type = NULL, bool *r_is_const = NULL, int *r_array_size = NULL, StringName *r_struct_name = NULL);
bool _is_operator_assign(Operator p_op) const;
bool _validate_assign(Node *p_node, const Map<StringName, BuiltInInfo> &p_builtin_types, String *r_message = NULL);
bool _validate_operator(OperatorNode *p_op, DataType *r_ret_type = NULL);
@@ -791,6 +829,7 @@ private:
DataType completion_base;
SubClassTag completion_class;
StringName completion_function;
+ StringName completion_struct;
int completion_argument;
bool _get_completable_identifier(BlockNode *p_block, CompletionType p_type, StringName &identifier);
@@ -798,8 +837,9 @@ private:
static const BuiltinFuncOutArgs builtin_func_out_args[];
Error _validate_datatype(DataType p_type);
+ bool _compare_datatypes_in_nodes(Node *a, Node *b) const;
- bool _validate_function_call(BlockNode *p_block, OperatorNode *p_func, DataType *r_ret_type);
+ bool _validate_function_call(BlockNode *p_block, OperatorNode *p_func, DataType *r_ret_type, StringName *r_ret_type_str);
bool _parse_function_arguments(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, OperatorNode *p_func, int *r_complete_arg = NULL);
bool _propagate_function_call_sampler_uniform_settings(StringName p_name, int p_argument, TextureFilter p_filter, TextureRepeat p_repeat);
bool _propagate_function_call_sampler_builtin_reference(StringName p_name, int p_argument, const StringName &p_builtin);