2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* shader_language.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2020-01-01 10:16:22 +00:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifndef SHADER_LANGUAGE_H
|
|
|
|
#define SHADER_LANGUAGE_H
|
|
|
|
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/list.h"
|
|
|
|
#include "core/map.h"
|
2019-07-06 04:03:17 +00:00
|
|
|
#include "core/script_language.h"
|
2019-02-12 12:30:56 +00:00
|
|
|
#include "core/string_name.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/typedefs.h"
|
|
|
|
#include "core/ustring.h"
|
|
|
|
#include "core/variant.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
class ShaderLanguage {
|
2014-02-10 01:10:30 +00:00
|
|
|
public:
|
2014-09-18 02:23:42 +00:00
|
|
|
enum TokenType {
|
|
|
|
TK_EMPTY,
|
2016-10-03 19:33:42 +00:00
|
|
|
TK_IDENTIFIER,
|
2014-09-18 02:23:42 +00:00
|
|
|
TK_TRUE,
|
|
|
|
TK_FALSE,
|
|
|
|
TK_REAL_CONSTANT,
|
2016-10-03 19:33:42 +00:00
|
|
|
TK_INT_CONSTANT,
|
2014-09-18 02:23:42 +00:00
|
|
|
TK_TYPE_VOID,
|
|
|
|
TK_TYPE_BOOL,
|
2016-10-03 19:33:42 +00:00
|
|
|
TK_TYPE_BVEC2,
|
|
|
|
TK_TYPE_BVEC3,
|
|
|
|
TK_TYPE_BVEC4,
|
|
|
|
TK_TYPE_INT,
|
|
|
|
TK_TYPE_IVEC2,
|
|
|
|
TK_TYPE_IVEC3,
|
|
|
|
TK_TYPE_IVEC4,
|
|
|
|
TK_TYPE_UINT,
|
|
|
|
TK_TYPE_UVEC2,
|
|
|
|
TK_TYPE_UVEC3,
|
|
|
|
TK_TYPE_UVEC4,
|
2014-09-18 02:23:42 +00:00
|
|
|
TK_TYPE_FLOAT,
|
|
|
|
TK_TYPE_VEC2,
|
|
|
|
TK_TYPE_VEC3,
|
|
|
|
TK_TYPE_VEC4,
|
2015-03-10 03:53:09 +00:00
|
|
|
TK_TYPE_MAT2,
|
2014-09-18 02:23:42 +00:00
|
|
|
TK_TYPE_MAT3,
|
|
|
|
TK_TYPE_MAT4,
|
2016-10-03 19:33:42 +00:00
|
|
|
TK_TYPE_SAMPLER2D,
|
|
|
|
TK_TYPE_ISAMPLER2D,
|
|
|
|
TK_TYPE_USAMPLER2D,
|
2018-06-26 11:59:26 +00:00
|
|
|
TK_TYPE_SAMPLER2DARRAY,
|
|
|
|
TK_TYPE_ISAMPLER2DARRAY,
|
|
|
|
TK_TYPE_USAMPLER2DARRAY,
|
|
|
|
TK_TYPE_SAMPLER3D,
|
|
|
|
TK_TYPE_ISAMPLER3D,
|
|
|
|
TK_TYPE_USAMPLER3D,
|
2016-10-03 19:33:42 +00:00
|
|
|
TK_TYPE_SAMPLERCUBE,
|
2020-05-01 12:34:23 +00:00
|
|
|
TK_TYPE_SAMPLERCUBEARRAY,
|
2017-11-27 15:47:46 +00:00
|
|
|
TK_INTERPOLATION_FLAT,
|
|
|
|
TK_INTERPOLATION_SMOOTH,
|
2019-05-30 14:19:24 +00:00
|
|
|
TK_CONST,
|
2020-01-17 19:35:22 +00:00
|
|
|
TK_STRUCT,
|
2016-10-03 19:33:42 +00:00
|
|
|
TK_PRECISION_LOW,
|
|
|
|
TK_PRECISION_MID,
|
|
|
|
TK_PRECISION_HIGH,
|
2014-09-18 02:23:42 +00:00
|
|
|
TK_OP_EQUAL,
|
|
|
|
TK_OP_NOT_EQUAL,
|
|
|
|
TK_OP_LESS,
|
|
|
|
TK_OP_LESS_EQUAL,
|
|
|
|
TK_OP_GREATER,
|
|
|
|
TK_OP_GREATER_EQUAL,
|
|
|
|
TK_OP_AND,
|
|
|
|
TK_OP_OR,
|
|
|
|
TK_OP_NOT,
|
|
|
|
TK_OP_ADD,
|
|
|
|
TK_OP_SUB,
|
|
|
|
TK_OP_MUL,
|
|
|
|
TK_OP_DIV,
|
2016-10-03 19:33:42 +00:00
|
|
|
TK_OP_MOD,
|
|
|
|
TK_OP_SHIFT_LEFT,
|
|
|
|
TK_OP_SHIFT_RIGHT,
|
2014-09-18 02:23:42 +00:00
|
|
|
TK_OP_ASSIGN,
|
|
|
|
TK_OP_ASSIGN_ADD,
|
|
|
|
TK_OP_ASSIGN_SUB,
|
|
|
|
TK_OP_ASSIGN_MUL,
|
|
|
|
TK_OP_ASSIGN_DIV,
|
2016-10-03 19:33:42 +00:00
|
|
|
TK_OP_ASSIGN_MOD,
|
|
|
|
TK_OP_ASSIGN_SHIFT_LEFT,
|
|
|
|
TK_OP_ASSIGN_SHIFT_RIGHT,
|
|
|
|
TK_OP_ASSIGN_BIT_AND,
|
|
|
|
TK_OP_ASSIGN_BIT_OR,
|
|
|
|
TK_OP_ASSIGN_BIT_XOR,
|
|
|
|
TK_OP_BIT_AND,
|
|
|
|
TK_OP_BIT_OR,
|
|
|
|
TK_OP_BIT_XOR,
|
|
|
|
TK_OP_BIT_INVERT,
|
|
|
|
TK_OP_INCREMENT,
|
|
|
|
TK_OP_DECREMENT,
|
2014-09-18 02:23:42 +00:00
|
|
|
TK_CF_IF,
|
|
|
|
TK_CF_ELSE,
|
2016-10-03 19:33:42 +00:00
|
|
|
TK_CF_FOR,
|
|
|
|
TK_CF_WHILE,
|
|
|
|
TK_CF_DO,
|
|
|
|
TK_CF_SWITCH,
|
|
|
|
TK_CF_CASE,
|
2019-08-14 11:22:25 +00:00
|
|
|
TK_CF_DEFAULT,
|
2016-10-03 19:33:42 +00:00
|
|
|
TK_CF_BREAK,
|
|
|
|
TK_CF_CONTINUE,
|
2014-09-18 02:23:42 +00:00
|
|
|
TK_CF_RETURN,
|
2017-08-29 13:14:07 +00:00
|
|
|
TK_CF_DISCARD,
|
2014-09-18 02:23:42 +00:00
|
|
|
TK_BRACKET_OPEN,
|
|
|
|
TK_BRACKET_CLOSE,
|
|
|
|
TK_CURLY_BRACKET_OPEN,
|
|
|
|
TK_CURLY_BRACKET_CLOSE,
|
|
|
|
TK_PARENTHESIS_OPEN,
|
|
|
|
TK_PARENTHESIS_CLOSE,
|
2016-10-03 19:33:42 +00:00
|
|
|
TK_QUESTION,
|
2014-09-18 02:23:42 +00:00
|
|
|
TK_COMMA,
|
2016-10-03 19:33:42 +00:00
|
|
|
TK_COLON,
|
2014-09-18 02:23:42 +00:00
|
|
|
TK_SEMICOLON,
|
|
|
|
TK_PERIOD,
|
|
|
|
TK_UNIFORM,
|
2020-04-17 02:52:00 +00:00
|
|
|
TK_INSTANCE,
|
|
|
|
TK_GLOBAL,
|
2016-10-03 19:33:42 +00:00
|
|
|
TK_VARYING,
|
2017-04-07 02:36:37 +00:00
|
|
|
TK_ARG_IN,
|
|
|
|
TK_ARG_OUT,
|
|
|
|
TK_ARG_INOUT,
|
2016-10-03 19:33:42 +00:00
|
|
|
TK_RENDER_MODE,
|
|
|
|
TK_HINT_WHITE_TEXTURE,
|
|
|
|
TK_HINT_BLACK_TEXTURE,
|
|
|
|
TK_HINT_NORMAL_TEXTURE,
|
2019-09-14 03:37:42 +00:00
|
|
|
TK_HINT_ROUGHNESS_NORMAL_TEXTURE,
|
|
|
|
TK_HINT_ROUGHNESS_R,
|
|
|
|
TK_HINT_ROUGHNESS_G,
|
|
|
|
TK_HINT_ROUGHNESS_B,
|
|
|
|
TK_HINT_ROUGHNESS_A,
|
|
|
|
TK_HINT_ROUGHNESS_GRAY,
|
2016-11-21 01:49:53 +00:00
|
|
|
TK_HINT_ANISO_TEXTURE,
|
2016-10-07 14:31:18 +00:00
|
|
|
TK_HINT_ALBEDO_TEXTURE,
|
2016-11-21 01:49:53 +00:00
|
|
|
TK_HINT_BLACK_ALBEDO_TEXTURE,
|
2016-10-07 14:31:18 +00:00
|
|
|
TK_HINT_COLOR,
|
2016-10-03 19:33:42 +00:00
|
|
|
TK_HINT_RANGE,
|
2020-04-17 02:52:00 +00:00
|
|
|
TK_HINT_INSTANCE_INDEX,
|
2019-07-21 14:31:30 +00:00
|
|
|
TK_FILTER_NEAREST,
|
|
|
|
TK_FILTER_LINEAR,
|
|
|
|
TK_FILTER_NEAREST_MIPMAP,
|
|
|
|
TK_FILTER_LINEAR_MIPMAP,
|
|
|
|
TK_FILTER_NEAREST_MIPMAP_ANISO,
|
|
|
|
TK_FILTER_LINEAR_MIPMAP_ANISO,
|
|
|
|
TK_REPEAT_ENABLE,
|
|
|
|
TK_REPEAT_DISABLE,
|
2017-04-07 02:36:37 +00:00
|
|
|
TK_SHADER_TYPE,
|
2016-10-07 14:31:18 +00:00
|
|
|
TK_CURSOR,
|
2014-09-18 02:23:42 +00:00
|
|
|
TK_ERROR,
|
2016-10-03 19:33:42 +00:00
|
|
|
TK_EOF,
|
2014-09-18 02:23:42 +00:00
|
|
|
TK_MAX
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
/* COMPILER */
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
// lame work around to Apple defining this as a macro in 10.12 SDK
|
|
|
|
#ifdef TYPE_BOOL
|
|
|
|
#undef TYPE_BOOL
|
|
|
|
#endif
|
2017-01-04 10:56:56 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
enum DataType {
|
|
|
|
TYPE_VOID,
|
|
|
|
TYPE_BOOL,
|
2016-10-03 19:33:42 +00:00
|
|
|
TYPE_BVEC2,
|
|
|
|
TYPE_BVEC3,
|
|
|
|
TYPE_BVEC4,
|
|
|
|
TYPE_INT,
|
|
|
|
TYPE_IVEC2,
|
|
|
|
TYPE_IVEC3,
|
|
|
|
TYPE_IVEC4,
|
|
|
|
TYPE_UINT,
|
|
|
|
TYPE_UVEC2,
|
|
|
|
TYPE_UVEC3,
|
|
|
|
TYPE_UVEC4,
|
2014-02-10 01:10:30 +00:00
|
|
|
TYPE_FLOAT,
|
|
|
|
TYPE_VEC2,
|
|
|
|
TYPE_VEC3,
|
|
|
|
TYPE_VEC4,
|
2015-03-10 03:53:09 +00:00
|
|
|
TYPE_MAT2,
|
2014-02-10 01:10:30 +00:00
|
|
|
TYPE_MAT3,
|
|
|
|
TYPE_MAT4,
|
2016-10-03 19:33:42 +00:00
|
|
|
TYPE_SAMPLER2D,
|
|
|
|
TYPE_ISAMPLER2D,
|
|
|
|
TYPE_USAMPLER2D,
|
2018-06-26 11:59:26 +00:00
|
|
|
TYPE_SAMPLER2DARRAY,
|
|
|
|
TYPE_ISAMPLER2DARRAY,
|
|
|
|
TYPE_USAMPLER2DARRAY,
|
|
|
|
TYPE_SAMPLER3D,
|
|
|
|
TYPE_ISAMPLER3D,
|
|
|
|
TYPE_USAMPLER3D,
|
2016-10-03 19:33:42 +00:00
|
|
|
TYPE_SAMPLERCUBE,
|
2020-05-01 12:34:23 +00:00
|
|
|
TYPE_SAMPLERCUBEARRAY,
|
2020-01-17 19:35:22 +00:00
|
|
|
TYPE_STRUCT,
|
2020-04-17 02:52:00 +00:00
|
|
|
TYPE_MAX
|
2016-10-03 19:33:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum DataPrecision {
|
|
|
|
PRECISION_LOWP,
|
|
|
|
PRECISION_MEDIUMP,
|
|
|
|
PRECISION_HIGHP,
|
|
|
|
PRECISION_DEFAULT,
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2017-11-27 15:47:46 +00:00
|
|
|
enum DataInterpolation {
|
|
|
|
INTERPOLATION_FLAT,
|
|
|
|
INTERPOLATION_SMOOTH,
|
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
enum Operator {
|
2016-10-03 19:33:42 +00:00
|
|
|
OP_EQUAL,
|
|
|
|
OP_NOT_EQUAL,
|
|
|
|
OP_LESS,
|
|
|
|
OP_LESS_EQUAL,
|
|
|
|
OP_GREATER,
|
|
|
|
OP_GREATER_EQUAL,
|
|
|
|
OP_AND,
|
|
|
|
OP_OR,
|
|
|
|
OP_NOT,
|
|
|
|
OP_NEGATE,
|
2014-02-10 01:10:30 +00:00
|
|
|
OP_ADD,
|
|
|
|
OP_SUB,
|
|
|
|
OP_MUL,
|
|
|
|
OP_DIV,
|
2016-10-03 19:33:42 +00:00
|
|
|
OP_MOD,
|
|
|
|
OP_SHIFT_LEFT,
|
|
|
|
OP_SHIFT_RIGHT,
|
|
|
|
OP_ASSIGN,
|
2014-02-10 01:10:30 +00:00
|
|
|
OP_ASSIGN_ADD,
|
|
|
|
OP_ASSIGN_SUB,
|
|
|
|
OP_ASSIGN_MUL,
|
|
|
|
OP_ASSIGN_DIV,
|
2016-10-03 19:33:42 +00:00
|
|
|
OP_ASSIGN_MOD,
|
|
|
|
OP_ASSIGN_SHIFT_LEFT,
|
|
|
|
OP_ASSIGN_SHIFT_RIGHT,
|
|
|
|
OP_ASSIGN_BIT_AND,
|
|
|
|
OP_ASSIGN_BIT_OR,
|
|
|
|
OP_ASSIGN_BIT_XOR,
|
|
|
|
OP_BIT_AND,
|
|
|
|
OP_BIT_OR,
|
|
|
|
OP_BIT_XOR,
|
|
|
|
OP_BIT_INVERT,
|
|
|
|
OP_INCREMENT,
|
|
|
|
OP_DECREMENT,
|
|
|
|
OP_SELECT_IF,
|
|
|
|
OP_SELECT_ELSE, //used only internally, then only IF appears with 3 arguments
|
|
|
|
OP_POST_INCREMENT,
|
|
|
|
OP_POST_DECREMENT,
|
2014-02-10 01:10:30 +00:00
|
|
|
OP_CALL,
|
|
|
|
OP_CONSTRUCT,
|
2020-01-17 19:35:22 +00:00
|
|
|
OP_STRUCT,
|
2017-04-07 02:36:37 +00:00
|
|
|
OP_INDEX,
|
2014-02-10 01:10:30 +00:00
|
|
|
OP_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
enum FlowOperation {
|
|
|
|
FLOW_OP_IF,
|
|
|
|
FLOW_OP_RETURN,
|
2016-10-03 19:33:42 +00:00
|
|
|
FLOW_OP_FOR,
|
|
|
|
FLOW_OP_WHILE,
|
|
|
|
FLOW_OP_DO,
|
|
|
|
FLOW_OP_BREAK,
|
|
|
|
FLOW_OP_SWITCH,
|
2019-08-14 11:22:25 +00:00
|
|
|
FLOW_OP_CASE,
|
|
|
|
FLOW_OP_DEFAULT,
|
2017-08-29 13:14:07 +00:00
|
|
|
FLOW_OP_CONTINUE,
|
|
|
|
FLOW_OP_DISCARD
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
enum ArgumentQualifier {
|
|
|
|
ARGUMENT_QUALIFIER_IN,
|
|
|
|
ARGUMENT_QUALIFIER_OUT,
|
|
|
|
ARGUMENT_QUALIFIER_INOUT,
|
|
|
|
};
|
|
|
|
|
2020-02-07 11:50:11 +00:00
|
|
|
enum SubClassTag {
|
|
|
|
TAG_GLOBAL,
|
|
|
|
TAG_ARRAY,
|
|
|
|
};
|
|
|
|
|
2019-07-21 14:31:30 +00:00
|
|
|
enum TextureFilter {
|
|
|
|
FILTER_NEAREST,
|
|
|
|
FILTER_LINEAR,
|
|
|
|
FILTER_NEAREST_MIPMAP,
|
|
|
|
FILTER_LINEAR_MIPMAP,
|
|
|
|
FILTER_NEAREST_MIPMAP_ANISO,
|
|
|
|
FILTER_LINEAR_MIPMAP_ANISO,
|
|
|
|
FILTER_DEFAULT,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum TextureRepeat {
|
|
|
|
REPEAT_DISABLE,
|
|
|
|
REPEAT_ENABLE,
|
|
|
|
REPEAT_DEFAULT,
|
|
|
|
};
|
|
|
|
|
2020-04-17 02:52:00 +00:00
|
|
|
enum {
|
|
|
|
MAX_INSTANCE_UNIFORM_INDICES = 16
|
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
struct Node {
|
2020-05-12 15:01:17 +00:00
|
|
|
Node *next = nullptr;
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
enum Type {
|
2016-10-03 19:33:42 +00:00
|
|
|
TYPE_SHADER,
|
2014-02-10 01:10:30 +00:00
|
|
|
TYPE_FUNCTION,
|
|
|
|
TYPE_BLOCK,
|
|
|
|
TYPE_VARIABLE,
|
2017-09-05 18:22:33 +00:00
|
|
|
TYPE_VARIABLE_DECLARATION,
|
2014-02-10 01:10:30 +00:00
|
|
|
TYPE_CONSTANT,
|
|
|
|
TYPE_OPERATOR,
|
|
|
|
TYPE_CONTROL_FLOW,
|
2019-07-10 16:52:50 +00:00
|
|
|
TYPE_MEMBER,
|
|
|
|
TYPE_ARRAY,
|
|
|
|
TYPE_ARRAY_DECLARATION,
|
2020-02-11 19:03:04 +00:00
|
|
|
TYPE_ARRAY_CONSTRUCT,
|
2020-01-17 19:35:22 +00:00
|
|
|
TYPE_STRUCT,
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Type type;
|
|
|
|
|
|
|
|
virtual DataType get_datatype() const { return TYPE_VOID; }
|
2020-01-17 19:35:22 +00:00
|
|
|
virtual String get_datatype_name() const { return ""; }
|
|
|
|
|
2019-01-30 01:12:41 +00:00
|
|
|
Node(Type t) :
|
|
|
|
type(t) {}
|
2014-02-10 01:10:30 +00:00
|
|
|
virtual ~Node() {}
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
template <class T>
|
|
|
|
T *alloc_node() {
|
|
|
|
T *node = memnew(T);
|
|
|
|
node->next = nodes;
|
|
|
|
nodes = node;
|
2016-10-03 19:33:42 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node *nodes;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
struct OperatorNode : public Node {
|
2020-05-12 15:01:17 +00:00
|
|
|
DataType return_cache = TYPE_VOID;
|
|
|
|
DataPrecision return_precision_cache = PRECISION_DEFAULT;
|
|
|
|
Operator op = OP_EQUAL;
|
2020-01-17 19:35:22 +00:00
|
|
|
StringName struct_name;
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector<Node *> arguments;
|
2014-02-10 01:10:30 +00:00
|
|
|
virtual DataType get_datatype() const { return return_cache; }
|
2020-01-17 19:35:22 +00:00
|
|
|
virtual String get_datatype_name() const { return String(struct_name); }
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-01-30 01:12:41 +00:00
|
|
|
OperatorNode() :
|
2020-05-12 15:01:17 +00:00
|
|
|
Node(TYPE_OPERATOR) {}
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct VariableNode : public Node {
|
2020-05-12 15:01:17 +00:00
|
|
|
DataType datatype_cache = TYPE_VOID;
|
2014-02-10 01:10:30 +00:00
|
|
|
StringName name;
|
2020-01-17 19:35:22 +00:00
|
|
|
StringName struct_name;
|
2014-02-10 01:10:30 +00:00
|
|
|
virtual DataType get_datatype() const { return datatype_cache; }
|
2020-01-17 19:35:22 +00:00
|
|
|
virtual String get_datatype_name() const { return String(struct_name); }
|
2020-05-12 15:01:17 +00:00
|
|
|
bool is_const = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-01-30 01:12:41 +00:00
|
|
|
VariableNode() :
|
2020-05-12 15:01:17 +00:00
|
|
|
Node(TYPE_VARIABLE) {}
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2017-09-05 18:22:33 +00:00
|
|
|
struct VariableDeclarationNode : public Node {
|
2020-05-12 15:01:17 +00:00
|
|
|
DataPrecision precision = PRECISION_DEFAULT;
|
|
|
|
DataType datatype = TYPE_VOID;
|
2020-01-17 19:35:22 +00:00
|
|
|
String struct_name;
|
2020-05-12 15:01:17 +00:00
|
|
|
bool is_const = false;
|
2017-09-05 18:22:33 +00:00
|
|
|
|
|
|
|
struct Declaration {
|
|
|
|
StringName name;
|
|
|
|
Node *initializer;
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Declaration> declarations;
|
|
|
|
virtual DataType get_datatype() const { return datatype; }
|
|
|
|
|
2019-01-30 01:12:41 +00:00
|
|
|
VariableDeclarationNode() :
|
2020-05-12 15:01:17 +00:00
|
|
|
Node(TYPE_VARIABLE_DECLARATION) {}
|
2017-09-05 18:22:33 +00:00
|
|
|
};
|
|
|
|
|
2019-07-10 16:52:50 +00:00
|
|
|
struct ArrayNode : public Node {
|
2020-05-12 15:01:17 +00:00
|
|
|
DataType datatype_cache = TYPE_VOID;
|
2020-01-17 19:35:22 +00:00
|
|
|
StringName struct_name;
|
2019-07-10 16:52:50 +00:00
|
|
|
StringName name;
|
2020-05-12 15:01:17 +00:00
|
|
|
Node *index_expression = nullptr;
|
|
|
|
Node *call_expression = nullptr;
|
|
|
|
bool is_const = false;
|
2019-07-10 16:52:50 +00:00
|
|
|
|
|
|
|
virtual DataType get_datatype() const { return datatype_cache; }
|
2020-01-17 19:35:22 +00:00
|
|
|
virtual String get_datatype_name() const { return String(struct_name); }
|
2019-07-10 16:52:50 +00:00
|
|
|
|
|
|
|
ArrayNode() :
|
2020-05-12 15:01:17 +00:00
|
|
|
Node(TYPE_ARRAY) {}
|
2019-07-10 16:52:50 +00:00
|
|
|
};
|
|
|
|
|
2020-02-11 19:03:04 +00:00
|
|
|
struct ArrayConstructNode : public Node {
|
2020-05-12 15:01:17 +00:00
|
|
|
DataType datatype = TYPE_VOID;
|
2020-02-11 19:03:04 +00:00
|
|
|
String struct_name;
|
|
|
|
Vector<Node *> initializer;
|
|
|
|
|
|
|
|
ArrayConstructNode() :
|
2020-05-12 15:01:17 +00:00
|
|
|
Node(TYPE_ARRAY_CONSTRUCT) {}
|
2020-02-11 19:03:04 +00:00
|
|
|
};
|
|
|
|
|
2019-07-10 16:52:50 +00:00
|
|
|
struct ArrayDeclarationNode : public Node {
|
2020-05-12 15:01:17 +00:00
|
|
|
DataPrecision precision = PRECISION_DEFAULT;
|
|
|
|
DataType datatype = TYPE_VOID;
|
2020-01-17 19:35:22 +00:00
|
|
|
String struct_name;
|
2020-05-12 15:01:17 +00:00
|
|
|
bool is_const = false;
|
2019-07-10 16:52:50 +00:00
|
|
|
|
|
|
|
struct Declaration {
|
|
|
|
StringName name;
|
|
|
|
uint32_t size;
|
2019-07-15 15:47:22 +00:00
|
|
|
Vector<Node *> initializer;
|
2019-07-10 16:52:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Declaration> declarations;
|
|
|
|
virtual DataType get_datatype() const { return datatype; }
|
|
|
|
|
|
|
|
ArrayDeclarationNode() :
|
2020-05-12 15:01:17 +00:00
|
|
|
Node(TYPE_ARRAY_DECLARATION) {}
|
2019-07-10 16:52:50 +00:00
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
struct ConstantNode : public Node {
|
2020-05-12 15:01:17 +00:00
|
|
|
DataType datatype = TYPE_VOID;
|
2019-10-11 17:43:42 +00:00
|
|
|
String struct_name = "";
|
|
|
|
int array_size = 0;
|
2016-10-07 14:31:18 +00:00
|
|
|
|
|
|
|
union Value {
|
|
|
|
bool boolean;
|
|
|
|
float real;
|
|
|
|
int32_t sint;
|
|
|
|
uint32_t uint;
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Value> values;
|
2019-10-11 17:43:42 +00:00
|
|
|
Vector<ArrayDeclarationNode::Declaration> array_declarations;
|
2014-02-10 01:10:30 +00:00
|
|
|
virtual DataType get_datatype() const { return datatype; }
|
2019-10-11 17:43:42 +00:00
|
|
|
virtual String get_datatype_name() const { return struct_name; }
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-01-30 01:12:41 +00:00
|
|
|
ConstantNode() :
|
2020-05-12 15:01:17 +00:00
|
|
|
Node(TYPE_CONSTANT) {}
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
struct FunctionNode;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
struct BlockNode : public Node {
|
2020-05-12 15:01:17 +00:00
|
|
|
FunctionNode *parent_function = nullptr;
|
|
|
|
BlockNode *parent_block = nullptr;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-08-14 11:22:25 +00:00
|
|
|
enum BlockType {
|
|
|
|
BLOCK_TYPE_STANDART,
|
2020-03-26 10:32:39 +00:00
|
|
|
BLOCK_TYPE_FOR,
|
2019-08-14 11:22:25 +00:00
|
|
|
BLOCK_TYPE_SWITCH,
|
|
|
|
BLOCK_TYPE_CASE,
|
|
|
|
BLOCK_TYPE_DEFAULT,
|
|
|
|
};
|
|
|
|
|
2020-05-12 15:01:17 +00:00
|
|
|
int block_type = BLOCK_TYPE_STANDART;
|
|
|
|
SubClassTag block_tag = SubClassTag::TAG_GLOBAL;
|
2019-08-14 11:22:25 +00:00
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
struct Variable {
|
|
|
|
DataType type;
|
2020-01-17 19:35:22 +00:00
|
|
|
StringName struct_name;
|
2016-10-03 19:33:42 +00:00
|
|
|
DataPrecision precision;
|
2016-10-07 14:31:18 +00:00
|
|
|
int line; //for completion
|
2019-07-10 16:52:50 +00:00
|
|
|
int array_size;
|
2019-08-05 07:35:53 +00:00
|
|
|
bool is_const;
|
2016-10-03 19:33:42 +00:00
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Map<StringName, Variable> variables;
|
|
|
|
List<Node *> statements;
|
2020-05-12 15:01:17 +00:00
|
|
|
bool single_statement = false;
|
2019-01-30 01:12:41 +00:00
|
|
|
|
|
|
|
BlockNode() :
|
2020-05-12 15:01:17 +00:00
|
|
|
Node(TYPE_BLOCK) {}
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ControlFlowNode : public Node {
|
2020-05-12 15:01:17 +00:00
|
|
|
FlowOperation flow_op = FLOW_OP_IF;
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector<Node *> expressions;
|
|
|
|
Vector<BlockNode *> blocks;
|
2019-01-30 01:12:41 +00:00
|
|
|
|
|
|
|
ControlFlowNode() :
|
2020-05-12 15:01:17 +00:00
|
|
|
Node(TYPE_CONTROL_FLOW) {}
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MemberNode : public Node {
|
2020-05-12 15:01:17 +00:00
|
|
|
DataType basetype = TYPE_VOID;
|
|
|
|
bool basetype_const = false;
|
2020-01-17 19:35:22 +00:00
|
|
|
StringName base_struct_name;
|
|
|
|
DataPrecision precision;
|
2020-05-12 15:01:17 +00:00
|
|
|
DataType datatype = TYPE_VOID;
|
|
|
|
int array_size = 0;
|
2020-01-17 19:35:22 +00:00
|
|
|
StringName struct_name;
|
2014-02-10 01:10:30 +00:00
|
|
|
StringName name;
|
2020-05-12 15:01:17 +00:00
|
|
|
Node *owner = nullptr;
|
|
|
|
Node *index_expression = nullptr;
|
|
|
|
bool has_swizzling_duplicates = false;
|
2019-01-30 01:12:41 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
virtual DataType get_datatype() const { return datatype; }
|
2020-01-17 19:35:22 +00:00
|
|
|
virtual String get_datatype_name() const { return String(struct_name); }
|
2019-01-30 01:12:41 +00:00
|
|
|
|
|
|
|
MemberNode() :
|
2020-05-12 15:01:17 +00:00
|
|
|
Node(TYPE_MEMBER) {}
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2020-01-17 19:35:22 +00:00
|
|
|
struct StructNode : public Node {
|
|
|
|
List<MemberNode *> members;
|
|
|
|
StructNode() :
|
|
|
|
Node(TYPE_STRUCT) {}
|
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
struct FunctionNode : public Node {
|
|
|
|
struct Argument {
|
2017-04-07 02:36:37 +00:00
|
|
|
ArgumentQualifier qualifier;
|
2014-02-10 01:10:30 +00:00
|
|
|
StringName name;
|
|
|
|
DataType type;
|
2020-01-17 19:35:22 +00:00
|
|
|
StringName type_str;
|
2016-10-03 19:33:42 +00:00
|
|
|
DataPrecision precision;
|
2019-07-21 14:31:30 +00:00
|
|
|
//for passing textures as arguments
|
|
|
|
bool tex_argument_check;
|
|
|
|
TextureFilter tex_argument_filter;
|
|
|
|
TextureRepeat tex_argument_repeat;
|
|
|
|
bool tex_builtin_check;
|
|
|
|
StringName tex_builtin;
|
2020-07-01 08:55:49 +00:00
|
|
|
bool is_const;
|
2019-07-21 14:31:30 +00:00
|
|
|
|
2020-03-17 06:33:00 +00:00
|
|
|
Map<StringName, Set<int>> tex_argument_connect;
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
StringName name;
|
2020-05-12 15:01:17 +00:00
|
|
|
DataType return_type = TYPE_VOID;
|
2020-01-17 19:35:22 +00:00
|
|
|
StringName return_struct_name;
|
2020-05-12 15:01:17 +00:00
|
|
|
DataPrecision return_precision = PRECISION_DEFAULT;
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector<Argument> arguments;
|
2020-05-12 15:01:17 +00:00
|
|
|
BlockNode *body = nullptr;
|
|
|
|
bool can_discard = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-01-30 01:12:41 +00:00
|
|
|
FunctionNode() :
|
2020-05-12 15:01:17 +00:00
|
|
|
Node(TYPE_FUNCTION) {}
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
struct ShaderNode : public Node {
|
2019-05-30 14:19:24 +00:00
|
|
|
struct Constant {
|
2020-04-11 09:40:17 +00:00
|
|
|
StringName name;
|
2019-05-30 14:19:24 +00:00
|
|
|
DataType type;
|
2020-01-17 19:35:22 +00:00
|
|
|
StringName type_str;
|
2019-05-30 14:19:24 +00:00
|
|
|
DataPrecision precision;
|
|
|
|
ConstantNode *initializer;
|
2019-10-11 17:43:42 +00:00
|
|
|
int array_size;
|
2019-05-30 14:19:24 +00:00
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
struct Function {
|
|
|
|
StringName name;
|
2017-03-05 15:44:50 +00:00
|
|
|
FunctionNode *function;
|
2016-10-10 21:31:01 +00:00
|
|
|
Set<StringName> uses_function;
|
2016-10-03 19:33:42 +00:00
|
|
|
bool callable;
|
|
|
|
};
|
|
|
|
|
2020-01-17 19:35:22 +00:00
|
|
|
struct Struct {
|
|
|
|
StringName name;
|
|
|
|
StructNode *shader_struct;
|
|
|
|
};
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
struct Varying {
|
2020-05-12 15:01:17 +00:00
|
|
|
DataType type = TYPE_VOID;
|
|
|
|
DataInterpolation interpolation = INTERPOLATION_FLAT;
|
|
|
|
DataPrecision precision = PRECISION_DEFAULT;
|
|
|
|
int array_size = 0;
|
2019-01-30 01:12:41 +00:00
|
|
|
|
2020-05-12 15:01:17 +00:00
|
|
|
Varying() {}
|
2016-10-03 19:33:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Uniform {
|
|
|
|
enum Hint {
|
|
|
|
HINT_NONE,
|
2016-10-07 14:31:18 +00:00
|
|
|
HINT_COLOR,
|
2016-10-03 19:33:42 +00:00
|
|
|
HINT_RANGE,
|
2016-10-07 14:31:18 +00:00
|
|
|
HINT_ALBEDO,
|
2016-11-21 01:49:53 +00:00
|
|
|
HINT_BLACK_ALBEDO,
|
2016-10-07 14:31:18 +00:00
|
|
|
HINT_NORMAL,
|
2019-09-14 03:37:42 +00:00
|
|
|
HINT_ROUGHNESS_NORMAL,
|
|
|
|
HINT_ROUGHNESS_R,
|
|
|
|
HINT_ROUGHNESS_G,
|
|
|
|
HINT_ROUGHNESS_B,
|
|
|
|
HINT_ROUGHNESS_A,
|
|
|
|
HINT_ROUGHNESS_GRAY,
|
2016-10-07 14:31:18 +00:00
|
|
|
HINT_BLACK,
|
|
|
|
HINT_WHITE,
|
2016-11-21 01:49:53 +00:00
|
|
|
HINT_ANISO,
|
2016-10-07 14:31:18 +00:00
|
|
|
HINT_MAX
|
2016-10-03 19:33:42 +00:00
|
|
|
};
|
|
|
|
|
2020-04-17 02:52:00 +00:00
|
|
|
enum Scope {
|
|
|
|
SCOPE_LOCAL,
|
|
|
|
SCOPE_INSTANCE,
|
|
|
|
SCOPE_GLOBAL,
|
|
|
|
};
|
|
|
|
|
2020-05-12 15:01:17 +00:00
|
|
|
int order = 0;
|
|
|
|
int texture_order = 0;
|
|
|
|
DataType type = TYPE_VOID;
|
|
|
|
DataPrecision precision = PRECISION_DEFAULT;
|
2016-10-07 14:31:18 +00:00
|
|
|
Vector<ConstantNode::Value> default_value;
|
2020-05-12 15:01:17 +00:00
|
|
|
Scope scope = SCOPE_LOCAL;
|
|
|
|
Hint hint = HINT_NONE;
|
|
|
|
TextureFilter filter = FILTER_DEFAULT;
|
|
|
|
TextureRepeat repeat = REPEAT_DEFAULT;
|
2016-10-03 19:33:42 +00:00
|
|
|
float hint_range[3];
|
2020-05-12 15:01:17 +00:00
|
|
|
int instance_index = 0;
|
|
|
|
|
|
|
|
Uniform() {
|
2019-01-30 01:12:41 +00:00
|
|
|
hint_range[0] = 0.0f;
|
|
|
|
hint_range[1] = 1.0f;
|
|
|
|
hint_range[2] = 0.001f;
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2019-05-30 14:19:24 +00:00
|
|
|
Map<StringName, Constant> constants;
|
2017-03-05 15:44:50 +00:00
|
|
|
Map<StringName, Varying> varyings;
|
|
|
|
Map<StringName, Uniform> uniforms;
|
2020-01-17 19:35:22 +00:00
|
|
|
Map<StringName, Struct> structs;
|
2016-10-10 21:31:01 +00:00
|
|
|
Vector<StringName> render_modes;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Vector<Function> functions;
|
2020-04-11 09:40:17 +00:00
|
|
|
Vector<Constant> vconstants;
|
2020-01-17 19:35:22 +00:00
|
|
|
Vector<Struct> vstructs;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-01-30 01:12:41 +00:00
|
|
|
ShaderNode() :
|
|
|
|
Node(TYPE_SHADER) {}
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2014-09-18 02:23:42 +00:00
|
|
|
struct Expression {
|
|
|
|
bool is_op;
|
|
|
|
union {
|
2016-10-03 19:33:42 +00:00
|
|
|
Operator op;
|
2014-09-18 02:23:42 +00:00
|
|
|
Node *node;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
struct VarInfo {
|
|
|
|
StringName name;
|
|
|
|
DataType type;
|
|
|
|
};
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
enum CompletionType {
|
|
|
|
COMPLETION_NONE,
|
2016-10-07 14:31:18 +00:00
|
|
|
COMPLETION_RENDER_MODE,
|
|
|
|
COMPLETION_MAIN_FUNCTION,
|
2016-10-03 19:33:42 +00:00
|
|
|
COMPLETION_IDENTIFIER,
|
2016-10-07 14:31:18 +00:00
|
|
|
COMPLETION_FUNCTION_CALL,
|
2016-10-03 19:33:42 +00:00
|
|
|
COMPLETION_CALL_ARGUMENTS,
|
|
|
|
COMPLETION_INDEX,
|
2020-01-17 19:35:22 +00:00
|
|
|
COMPLETION_STRUCT,
|
2016-10-03 19:33:42 +00:00
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
struct Token {
|
|
|
|
TokenType type;
|
|
|
|
StringName text;
|
2016-10-03 19:33:42 +00:00
|
|
|
double constant;
|
|
|
|
uint16_t line;
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2016-10-07 14:31:18 +00:00
|
|
|
static String get_operator_text(Operator p_op);
|
2016-10-03 19:33:42 +00:00
|
|
|
static String get_token_text(Token p_token);
|
2016-10-07 14:31:18 +00:00
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
static bool is_token_datatype(TokenType p_type);
|
2018-11-12 11:36:26 +00:00
|
|
|
static bool is_token_variable_datatype(TokenType p_type);
|
2016-10-03 19:33:42 +00:00
|
|
|
static DataType get_token_datatype(TokenType p_type);
|
2017-11-27 15:47:46 +00:00
|
|
|
static bool is_token_interpolation(TokenType p_type);
|
|
|
|
static DataInterpolation get_token_interpolation(TokenType p_type);
|
2016-10-03 19:33:42 +00:00
|
|
|
static bool is_token_precision(TokenType p_type);
|
|
|
|
static DataPrecision get_token_precision(TokenType p_type);
|
2019-07-15 15:47:22 +00:00
|
|
|
static String get_precision_name(DataPrecision p_type);
|
2016-10-03 19:33:42 +00:00
|
|
|
static String get_datatype_name(DataType p_type);
|
|
|
|
static bool is_token_nonvoid_datatype(TokenType p_type);
|
|
|
|
static bool is_token_operator(TokenType p_type);
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
static bool convert_constant(ConstantNode *p_constant, DataType p_to_type, ConstantNode::Value *p_value = nullptr);
|
2016-10-07 14:31:18 +00:00
|
|
|
static DataType get_scalar_type(DataType p_type);
|
2018-04-29 18:58:42 +00:00
|
|
|
static int get_cardinality(DataType p_type);
|
2016-10-07 14:31:18 +00:00
|
|
|
static bool is_scalar_type(DataType p_type);
|
2016-10-10 21:31:01 +00:00
|
|
|
static bool is_sampler_type(DataType p_type);
|
2018-11-16 11:20:23 +00:00
|
|
|
static Variant constant_value_to_variant(const Vector<ShaderLanguage::ConstantNode::Value> &p_value, DataType p_type, ShaderLanguage::ShaderNode::Uniform::Hint p_hint = ShaderLanguage::ShaderNode::Uniform::HINT_NONE);
|
2019-07-21 14:31:30 +00:00
|
|
|
static PropertyInfo uniform_to_property_info(const ShaderNode::Uniform &p_uniform);
|
|
|
|
static uint32_t get_type_size(DataType p_type);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-07 14:31:18 +00:00
|
|
|
static void get_keyword_list(List<String> *r_keywords);
|
2016-10-10 21:31:01 +00:00
|
|
|
static void get_builtin_funcs(List<String> *r_keywords);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-12-15 21:23:16 +00:00
|
|
|
struct BuiltInInfo {
|
2020-05-12 15:01:17 +00:00
|
|
|
DataType type = TYPE_VOID;
|
|
|
|
bool constant = false;
|
2019-01-30 01:12:41 +00:00
|
|
|
|
2020-05-12 15:01:17 +00:00
|
|
|
BuiltInInfo() {}
|
2019-01-30 01:12:41 +00:00
|
|
|
|
|
|
|
BuiltInInfo(DataType p_type, bool p_constant = false) :
|
|
|
|
type(p_type),
|
|
|
|
constant(p_constant) {}
|
2017-12-15 21:23:16 +00:00
|
|
|
};
|
|
|
|
|
2020-09-06 12:18:10 +00:00
|
|
|
struct StageFunctionInfo {
|
|
|
|
struct Argument {
|
|
|
|
StringName name;
|
|
|
|
DataType type;
|
|
|
|
|
|
|
|
Argument(const StringName &p_name = StringName(), DataType p_type = TYPE_VOID) {
|
|
|
|
name = p_name;
|
|
|
|
type = p_type;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Argument> arguments;
|
|
|
|
DataType return_type = TYPE_VOID;
|
|
|
|
};
|
|
|
|
|
2017-08-29 13:14:07 +00:00
|
|
|
struct FunctionInfo {
|
2017-12-15 21:23:16 +00:00
|
|
|
Map<StringName, BuiltInInfo> built_ins;
|
2020-09-06 12:18:10 +00:00
|
|
|
Map<StringName, StageFunctionInfo> stage_functions;
|
|
|
|
|
2017-08-29 13:14:07 +00:00
|
|
|
bool can_discard;
|
|
|
|
};
|
2019-10-29 11:36:11 +00:00
|
|
|
static bool has_builtin(const Map<StringName, ShaderLanguage::FunctionInfo> &p_functions, const StringName &p_name);
|
2017-08-29 13:14:07 +00:00
|
|
|
|
2020-04-17 02:52:00 +00:00
|
|
|
typedef DataType (*GlobalVariableGetTypeFunc)(const StringName &p_name);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
private:
|
|
|
|
struct KeyWord {
|
|
|
|
TokenType token;
|
|
|
|
const char *text;
|
|
|
|
};
|
2019-01-30 01:12:41 +00:00
|
|
|
|
2016-10-07 14:31:18 +00:00
|
|
|
static const KeyWord keyword_list[];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-04-17 02:52:00 +00:00
|
|
|
GlobalVariableGetTypeFunc global_var_get_type_func;
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
bool error_set;
|
|
|
|
String error_str;
|
|
|
|
int error_line;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
String code;
|
|
|
|
int char_idx;
|
|
|
|
int tk_line;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-10 21:31:01 +00:00
|
|
|
StringName current_function;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-07 14:31:18 +00:00
|
|
|
struct TkPos {
|
|
|
|
int char_idx;
|
|
|
|
int tk_line;
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-07 14:31:18 +00:00
|
|
|
TkPos _get_tkpos() {
|
|
|
|
TkPos tkp;
|
2017-03-05 15:44:50 +00:00
|
|
|
tkp.char_idx = char_idx;
|
|
|
|
tkp.tk_line = tk_line;
|
2016-10-07 14:31:18 +00:00
|
|
|
return tkp;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-07 14:31:18 +00:00
|
|
|
void _set_tkpos(TkPos p_pos) {
|
2017-03-05 15:44:50 +00:00
|
|
|
char_idx = p_pos.char_idx;
|
|
|
|
tk_line = p_pos.tk_line;
|
2016-10-07 14:31:18 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void _set_error(const String &p_str) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (error_set) {
|
2016-10-03 19:33:42 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
error_line = tk_line;
|
|
|
|
error_set = true;
|
|
|
|
error_str = p_str;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static const char *token_names[TK_MAX];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Token _make_token(TokenType p_type, const StringName &p_text = StringName());
|
2016-10-03 19:33:42 +00:00
|
|
|
Token _get_token();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
ShaderNode *shader;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
enum IdentifierType {
|
|
|
|
IDENTIFIER_FUNCTION,
|
|
|
|
IDENTIFIER_UNIFORM,
|
|
|
|
IDENTIFIER_VARYING,
|
|
|
|
IDENTIFIER_FUNCTION_ARGUMENT,
|
|
|
|
IDENTIFIER_LOCAL_VAR,
|
|
|
|
IDENTIFIER_BUILTIN_VAR,
|
2019-05-30 14:19:24 +00:00
|
|
|
IDENTIFIER_CONSTANT,
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2020-09-06 12:18:10 +00:00
|
|
|
bool _find_identifier(const BlockNode *p_block, bool p_allow_reassign, const FunctionInfo &p_function_info, const StringName &p_identifier, DataType *r_data_type = nullptr, IdentifierType *r_type = nullptr, bool *r_is_const = nullptr, int *r_array_size = nullptr, StringName *r_struct_name = nullptr);
|
2017-12-15 21:23:16 +00:00
|
|
|
bool _is_operator_assign(Operator p_op) const;
|
2020-09-06 12:18:10 +00:00
|
|
|
bool _validate_assign(Node *p_node, const FunctionInfo &p_function_info, String *r_message = nullptr);
|
2020-04-01 23:20:12 +00:00
|
|
|
bool _validate_operator(OperatorNode *p_op, DataType *r_ret_type = nullptr);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-07 14:31:18 +00:00
|
|
|
struct BuiltinFuncDef {
|
2017-03-05 15:44:50 +00:00
|
|
|
enum { MAX_ARGS = 5 };
|
|
|
|
const char *name;
|
2014-02-10 01:10:30 +00:00
|
|
|
DataType rettype;
|
|
|
|
const DataType args[MAX_ARGS];
|
2019-07-10 16:52:50 +00:00
|
|
|
SubClassTag tag;
|
2019-10-30 09:38:35 +00:00
|
|
|
bool high_end;
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2019-02-13 08:23:29 +00:00
|
|
|
struct BuiltinFuncOutArgs { //arguments used as out in built in functions
|
2018-11-14 21:55:38 +00:00
|
|
|
const char *name;
|
|
|
|
int argument;
|
|
|
|
};
|
|
|
|
|
2016-10-07 14:31:18 +00:00
|
|
|
CompletionType completion_type;
|
|
|
|
int completion_line;
|
|
|
|
BlockNode *completion_block;
|
|
|
|
DataType completion_base;
|
2019-07-10 16:52:50 +00:00
|
|
|
SubClassTag completion_class;
|
2016-10-07 14:31:18 +00:00
|
|
|
StringName completion_function;
|
2020-01-17 19:35:22 +00:00
|
|
|
StringName completion_struct;
|
2016-10-07 14:31:18 +00:00
|
|
|
int completion_argument;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool _get_completable_identifier(BlockNode *p_block, CompletionType p_type, StringName &identifier);
|
2016-10-07 14:31:18 +00:00
|
|
|
static const BuiltinFuncDef builtin_func_defs[];
|
2018-11-14 21:55:38 +00:00
|
|
|
static const BuiltinFuncOutArgs builtin_func_out_args[];
|
2015-01-11 14:43:31 +00:00
|
|
|
|
2019-11-03 10:28:29 +00:00
|
|
|
Error _validate_datatype(DataType p_type);
|
2020-01-17 19:35:22 +00:00
|
|
|
bool _compare_datatypes_in_nodes(Node *a, Node *b) const;
|
2019-11-03 10:28:29 +00:00
|
|
|
|
2020-09-06 12:18:10 +00:00
|
|
|
bool _validate_function_call(BlockNode *p_block, const FunctionInfo &p_function_info, OperatorNode *p_func, DataType *r_ret_type, StringName *r_ret_type_str);
|
|
|
|
bool _parse_function_arguments(BlockNode *p_block, const FunctionInfo &p_function_info, OperatorNode *p_func, int *r_complete_arg = nullptr);
|
2019-07-21 14:31:30 +00:00
|
|
|
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);
|
2015-01-11 14:43:31 +00:00
|
|
|
|
2020-09-06 12:18:10 +00:00
|
|
|
Node *_parse_expression(BlockNode *p_block, const FunctionInfo &p_function_info);
|
2017-03-05 15:44:50 +00:00
|
|
|
ShaderLanguage::Node *_reduce_expression(BlockNode *p_block, ShaderLanguage::Node *p_node);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-09-06 12:18:10 +00:00
|
|
|
Node *_parse_and_reduce_expression(BlockNode *p_block, const FunctionInfo &p_function_info);
|
|
|
|
Error _parse_block(BlockNode *p_block, const FunctionInfo &p_function_info, bool p_just_one = false, bool p_can_break = false, bool p_can_continue = false);
|
2019-10-26 15:41:47 +00:00
|
|
|
String _get_shader_type_list(const Set<String> &p_shader_types) const;
|
2020-02-12 20:16:47 +00:00
|
|
|
String _get_qualifier_str(ArgumentQualifier p_qualifier) const;
|
2019-10-26 15:41:47 +00:00
|
|
|
|
2018-07-14 21:15:42 +00:00
|
|
|
Error _parse_shader(const Map<StringName, FunctionInfo> &p_functions, const Vector<StringName> &p_render_modes, const Set<String> &p_shader_types);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-08-23 12:40:42 +00:00
|
|
|
Error _find_last_flow_op_in_block(BlockNode *p_block, FlowOperation p_op);
|
|
|
|
Error _find_last_flow_op_in_op(ControlFlowNode *p_flow, FlowOperation p_op);
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
public:
|
2017-01-14 11:26:56 +00:00
|
|
|
//static void get_keyword_list(ShaderType p_type,List<String> *p_keywords);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
void clear();
|
2017-04-07 02:36:37 +00:00
|
|
|
|
|
|
|
static String get_shader_type(const String &p_code);
|
2020-04-17 02:52:00 +00:00
|
|
|
Error compile(const String &p_code, const Map<StringName, FunctionInfo> &p_functions, const Vector<StringName> &p_render_modes, const Set<String> &p_shader_types, GlobalVariableGetTypeFunc p_global_variable_type_func);
|
|
|
|
Error complete(const String &p_code, const Map<StringName, FunctionInfo> &p_functions, const Vector<StringName> &p_render_modes, const Set<String> &p_shader_types, GlobalVariableGetTypeFunc p_global_variable_type_func, List<ScriptCodeCompletionOption> *r_options, String &r_call_hint);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
String get_error_text();
|
|
|
|
int get_error_line();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-07 14:31:18 +00:00
|
|
|
ShaderNode *get_shader();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String token_debug(const String &p_code);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
ShaderLanguage();
|
|
|
|
~ShaderLanguage();
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SHADER_LANGUAGE_H
|