diff options
Diffstat (limited to 'servers/visual/shader_language.h')
-rw-r--r-- | servers/visual/shader_language.h | 148 |
1 files changed, 74 insertions, 74 deletions
diff --git a/servers/visual/shader_language.h b/servers/visual/shader_language.h index 2d1851928e..67c273d267 100644 --- a/servers/visual/shader_language.h +++ b/servers/visual/shader_language.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -33,7 +33,7 @@ #include "core/list.h" #include "core/map.h" -#include "core/string_db.h" +#include "core/string_name.h" #include "core/typedefs.h" #include "core/ustring.h" #include "core/variant.h" @@ -42,7 +42,6 @@ class ShaderLanguage { public: enum TokenType { - TK_EMPTY, TK_IDENTIFIER, TK_TRUE, @@ -267,18 +266,15 @@ public: FLOW_OP_SWITCH, FLOW_OP_CONTINUE, FLOW_OP_DISCARD - }; enum ArgumentQualifier { ARGUMENT_QUALIFIER_IN, ARGUMENT_QUALIFIER_OUT, ARGUMENT_QUALIFIER_INOUT, - }; struct Node { - Node *next; enum Type { @@ -296,7 +292,9 @@ public: Type type; virtual DataType get_datatype() const { return TYPE_VOID; } - + Node(Type t) : + next(NULL), + type(t) {} virtual ~Node() {} }; @@ -311,18 +309,17 @@ public: Node *nodes; struct OperatorNode : public Node { - DataType return_cache; DataPrecision return_precision_cache; Operator op; Vector<Node *> arguments; virtual DataType get_datatype() const { return return_cache; } - OperatorNode() { - type = TYPE_OPERATOR; - return_cache = TYPE_VOID; - return_precision_cache = PRECISION_DEFAULT; - } + OperatorNode() : + Node(TYPE_OPERATOR), + return_cache(TYPE_VOID), + return_precision_cache(PRECISION_DEFAULT), + op(OP_EQUAL) {} }; struct VariableNode : public Node { @@ -330,20 +327,16 @@ public: StringName name; virtual DataType get_datatype() const { return datatype_cache; } - VariableNode() { - - type = TYPE_VARIABLE; - datatype_cache = TYPE_VOID; - } + VariableNode() : + Node(TYPE_VARIABLE), + datatype_cache(TYPE_VOID) {} }; struct VariableDeclarationNode : public Node { - DataPrecision precision; DataType datatype; struct Declaration { - StringName name; Node *initializer; }; @@ -351,13 +344,13 @@ public: Vector<Declaration> declarations; virtual DataType get_datatype() const { return datatype; } - VariableDeclarationNode() { - type = TYPE_VARIABLE_DECLARATION; - } + VariableDeclarationNode() : + Node(TYPE_VARIABLE_DECLARATION), + precision(PRECISION_DEFAULT), + datatype(TYPE_VOID) {} }; struct ConstantNode : public Node { - DataType datatype; union Value { @@ -370,7 +363,9 @@ public: Vector<Value> values; virtual DataType get_datatype() const { return datatype; } - ConstantNode() { type = TYPE_CONSTANT; } + ConstantNode() : + Node(TYPE_CONSTANT), + datatype(TYPE_VOID) {} }; struct FunctionNode; @@ -388,39 +383,41 @@ public: Map<StringName, Variable> variables; List<Node *> statements; bool single_statement; - BlockNode() { - type = TYPE_BLOCK; - parent_block = NULL; - parent_function = NULL; - single_statement = false; - } + + BlockNode() : + Node(TYPE_BLOCK), + parent_function(NULL), + parent_block(NULL), + single_statement(false) {} }; struct ControlFlowNode : public Node { - FlowOperation flow_op; Vector<Node *> expressions; Vector<BlockNode *> blocks; - ControlFlowNode() { - type = TYPE_CONTROL_FLOW; - flow_op = FLOW_OP_IF; - } + + ControlFlowNode() : + Node(TYPE_CONTROL_FLOW), + flow_op(FLOW_OP_IF) {} }; struct MemberNode : public Node { - DataType basetype; DataType datatype; StringName name; Node *owner; + virtual DataType get_datatype() const { return datatype; } - MemberNode() { type = TYPE_MEMBER; } + + MemberNode() : + Node(TYPE_MEMBER), + basetype(TYPE_VOID), + datatype(TYPE_VOID), + owner(NULL) {} }; struct FunctionNode : public Node { - struct Argument { - ArgumentQualifier qualifier; StringName name; DataType type; @@ -434,16 +431,15 @@ public: BlockNode *body; bool can_discard; - FunctionNode() { - type = TYPE_FUNCTION; - return_type = TYPE_VOID; - return_precision = PRECISION_DEFAULT; - can_discard = false; - } + FunctionNode() : + Node(TYPE_FUNCTION), + return_type(TYPE_VOID), + return_precision(PRECISION_DEFAULT), + body(NULL), + can_discard(false) {} }; struct ShaderNode : public Node { - struct Function { StringName name; FunctionNode *function; @@ -454,7 +450,12 @@ public: struct Varying { DataType type; DataInterpolation interpolation; - DataPrecision precission; + DataPrecision precision; + + Varying() : + type(TYPE_VOID), + interpolation(INTERPOLATION_FLAT), + precision(PRECISION_DEFAULT) {} }; struct Uniform { @@ -474,16 +475,20 @@ public: int order; int texture_order; DataType type; - DataPrecision precission; + DataPrecision precision; Vector<ConstantNode::Value> default_value; Hint hint; float hint_range[3]; - Uniform() { - hint = HINT_NONE; - hint_range[0] = 0; - hint_range[1] = 1; - hint_range[2] = 0.001; + Uniform() : + order(0), + texture_order(0), + type(TYPE_VOID), + precision(PRECISION_DEFAULT), + hint(HINT_NONE) { + hint_range[0] = 0.0f; + hint_range[1] = 1.0f; + hint_range[2] = 0.001f; } }; @@ -493,11 +498,11 @@ public: Vector<Function> functions; - ShaderNode() { type = TYPE_SHADER; } + ShaderNode() : + Node(TYPE_SHADER) {} }; struct Expression { - bool is_op; union { Operator op; @@ -506,7 +511,6 @@ public: }; struct VarInfo { - StringName name; DataType type; }; @@ -522,7 +526,6 @@ public: }; struct Token { - TokenType type; StringName text; double constant; @@ -556,11 +559,14 @@ public: struct BuiltInInfo { DataType type; bool constant; - BuiltInInfo() {} - BuiltInInfo(DataType p_type, bool p_constant = false) { - type = p_type; - constant = p_constant; - } + + BuiltInInfo() : + type(TYPE_VOID), + constant(false) {} + + BuiltInInfo(DataType p_type, bool p_constant = false) : + type(p_type), + constant(p_constant) {} }; struct FunctionInfo { @@ -573,6 +579,7 @@ private: TokenType token; const char *text; }; + static const KeyWord keyword_list[]; bool error_set; @@ -628,22 +635,18 @@ private: }; 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 _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); struct BuiltinFuncDef { - enum { MAX_ARGS = 5 }; const char *name; DataType rettype; const DataType args[MAX_ARGS]; }; - struct BuiltinFuncOutArgs { //arguments used as out in built in funcions - + struct BuiltinFuncOutArgs { //arguments used as out in built in functions const char *name; int argument; }; @@ -656,20 +659,17 @@ private: int completion_argument; bool _get_completable_identifier(BlockNode *p_block, CompletionType p_type, StringName &identifier); - static const BuiltinFuncDef builtin_func_defs[]; static const BuiltinFuncOutArgs builtin_func_out_args[]; - 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); bool _parse_function_arguments(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, OperatorNode *p_func, int *r_complete_arg = NULL); Node *_parse_expression(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types); - ShaderLanguage::Node *_reduce_expression(BlockNode *p_block, ShaderLanguage::Node *p_node); - Node *_parse_and_reduce_expression(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types); + Node *_parse_and_reduce_expression(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types); Error _parse_block(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, bool p_just_one = false, bool p_can_break = false, bool p_can_continue = false); - Error _parse_shader(const Map<StringName, FunctionInfo> &p_functions, const Vector<StringName> &p_render_modes, const Set<String> &p_shader_types); public: |