2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* test_shader_lang.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* 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
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 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
|
|
|
#include "test_shader_lang.h"
|
|
|
|
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/os/file_access.h"
|
|
|
|
#include "core/os/main_loop.h"
|
|
|
|
#include "core/os/os.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/string/print_string.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/gui/control.h"
|
|
|
|
#include "scene/gui/text_edit.h"
|
2020-03-27 18:21:27 +00:00
|
|
|
#include "servers/rendering/shader_language.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
typedef ShaderLanguage SL;
|
|
|
|
|
|
|
|
namespace TestShaderLang {
|
|
|
|
|
|
|
|
static String _mktab(int p_level) {
|
|
|
|
String tb;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < p_level; i++) {
|
|
|
|
tb += "\t";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return tb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static String _typestr(SL::DataType p_type) {
|
2016-10-07 14:31:18 +00:00
|
|
|
return ShaderLanguage::get_datatype_name(p_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static String _prestr(SL::DataPrecision p_pres) {
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_pres) {
|
2020-05-10 11:00:47 +00:00
|
|
|
case SL::PRECISION_LOWP:
|
|
|
|
return "lowp ";
|
|
|
|
case SL::PRECISION_MEDIUMP:
|
|
|
|
return "mediump ";
|
|
|
|
case SL::PRECISION_HIGHP:
|
|
|
|
return "highp ";
|
|
|
|
case SL::PRECISION_DEFAULT:
|
|
|
|
return "";
|
2016-10-07 14:31:18 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
static String _opstr(SL::Operator p_op) {
|
2016-10-07 14:31:18 +00:00
|
|
|
return ShaderLanguage::get_operator_text(p_op);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNode::Value> &p_values) {
|
|
|
|
switch (p_type) {
|
2020-05-10 11:00:47 +00:00
|
|
|
case SL::TYPE_BOOL:
|
|
|
|
return p_values[0].boolean ? "true" : "false";
|
|
|
|
case SL::TYPE_BVEC2:
|
|
|
|
return String() + "bvec2(" + (p_values[0].boolean ? "true" : "false") + (p_values[1].boolean ? "true" : "false") + ")";
|
|
|
|
case SL::TYPE_BVEC3:
|
|
|
|
return String() + "bvec3(" + (p_values[0].boolean ? "true" : "false") + "," + (p_values[1].boolean ? "true" : "false") + "," + (p_values[2].boolean ? "true" : "false") + ")";
|
|
|
|
case SL::TYPE_BVEC4:
|
|
|
|
return String() + "bvec4(" + (p_values[0].boolean ? "true" : "false") + "," + (p_values[1].boolean ? "true" : "false") + "," + (p_values[2].boolean ? "true" : "false") + "," + (p_values[3].boolean ? "true" : "false") + ")";
|
|
|
|
case SL::TYPE_INT:
|
|
|
|
return rtos(p_values[0].sint);
|
|
|
|
case SL::TYPE_IVEC2:
|
|
|
|
return String() + "ivec2(" + rtos(p_values[0].sint) + "," + rtos(p_values[1].sint) + ")";
|
|
|
|
case SL::TYPE_IVEC3:
|
|
|
|
return String() + "ivec3(" + rtos(p_values[0].sint) + "," + rtos(p_values[1].sint) + "," + rtos(p_values[2].sint) + ")";
|
|
|
|
case SL::TYPE_IVEC4:
|
|
|
|
return String() + "ivec4(" + rtos(p_values[0].sint) + "," + rtos(p_values[1].sint) + "," + rtos(p_values[2].sint) + "," + rtos(p_values[3].sint) + ")";
|
|
|
|
case SL::TYPE_UINT:
|
|
|
|
return rtos(p_values[0].real);
|
|
|
|
case SL::TYPE_UVEC2:
|
|
|
|
return String() + "uvec2(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + ")";
|
|
|
|
case SL::TYPE_UVEC3:
|
|
|
|
return String() + "uvec3(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + "," + rtos(p_values[2].real) + ")";
|
|
|
|
case SL::TYPE_UVEC4:
|
|
|
|
return String() + "uvec4(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + "," + rtos(p_values[2].real) + "," + rtos(p_values[3].real) + ")";
|
|
|
|
case SL::TYPE_FLOAT:
|
|
|
|
return rtos(p_values[0].real);
|
|
|
|
case SL::TYPE_VEC2:
|
|
|
|
return String() + "vec2(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + ")";
|
|
|
|
case SL::TYPE_VEC3:
|
|
|
|
return String() + "vec3(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + "," + rtos(p_values[2].real) + ")";
|
|
|
|
case SL::TYPE_VEC4:
|
|
|
|
return String() + "vec4(" + rtos(p_values[0].real) + "," + rtos(p_values[1].real) + "," + rtos(p_values[2].real) + "," + rtos(p_values[3].real) + ")";
|
|
|
|
default:
|
|
|
|
ERR_FAIL_V(String());
|
2016-10-07 14:31:18 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static String dump_node_code(SL::Node *p_node, int p_level) {
|
2014-02-10 01:10:30 +00:00
|
|
|
String code;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_node->type) {
|
2016-10-07 14:31:18 +00:00
|
|
|
case SL::Node::TYPE_SHADER: {
|
2017-03-05 15:44:50 +00:00
|
|
|
SL::ShaderNode *pnode = (SL::ShaderNode *)p_node;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<StringName, SL::ShaderNode::Uniform>::Element *E = pnode->uniforms.front(); E; E = E->next()) {
|
|
|
|
String ucode = "uniform ";
|
2019-01-30 01:12:41 +00:00
|
|
|
ucode += _prestr(E->get().precision);
|
2017-03-05 15:44:50 +00:00
|
|
|
ucode += _typestr(E->get().type);
|
|
|
|
ucode += " " + String(E->key());
|
2016-10-07 14:31:18 +00:00
|
|
|
|
|
|
|
if (E->get().default_value.size()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ucode += " = " + get_constant_text(E->get().type, E->get().default_value);
|
2016-10-07 14:31:18 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static const char *hint_name[SL::ShaderNode::Uniform::HINT_MAX] = {
|
2016-10-07 14:31:18 +00:00
|
|
|
"",
|
|
|
|
"color",
|
|
|
|
"range",
|
|
|
|
"albedo",
|
|
|
|
"normal",
|
|
|
|
"black",
|
|
|
|
"white"
|
|
|
|
};
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (E->get().hint) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ucode += " : " + String(hint_name[E->get().hint]);
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
code += ucode + "\n";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<StringName, SL::ShaderNode::Varying>::Element *E = pnode->varyings.front(); E; E = E->next()) {
|
|
|
|
String vcode = "varying ";
|
2019-01-30 01:12:41 +00:00
|
|
|
vcode += _prestr(E->get().precision);
|
2017-03-05 15:44:50 +00:00
|
|
|
vcode += _typestr(E->get().type);
|
|
|
|
vcode += " " + String(E->key());
|
2016-10-07 14:31:18 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
code += vcode + "\n";
|
2016-10-07 14:31:18 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < pnode->functions.size(); i++) {
|
|
|
|
SL::FunctionNode *fnode = pnode->functions[i].function;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String header;
|
2017-03-05 15:44:50 +00:00
|
|
|
header = _typestr(fnode->return_type) + " " + fnode->name + "(";
|
2019-02-12 20:10:08 +00:00
|
|
|
for (int j = 0; j < fnode->arguments.size(); j++) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (j > 0) {
|
2017-03-05 15:44:50 +00:00
|
|
|
header += ", ";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2019-02-12 20:10:08 +00:00
|
|
|
header += _prestr(fnode->arguments[j].precision) + _typestr(fnode->arguments[j].type) + " " + fnode->arguments[j].name;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
header += ")\n";
|
|
|
|
code += header;
|
|
|
|
code += dump_node_code(fnode->body, p_level + 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-10-07 14:31:18 +00:00
|
|
|
//code+=dump_node_code(pnode->body,p_level);
|
2020-01-17 19:35:22 +00:00
|
|
|
} break;
|
|
|
|
case SL::Node::TYPE_STRUCT: {
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case SL::Node::TYPE_FUNCTION: {
|
|
|
|
} break;
|
|
|
|
case SL::Node::TYPE_BLOCK: {
|
2017-03-05 15:44:50 +00:00
|
|
|
SL::BlockNode *bnode = (SL::BlockNode *)p_node;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//variables
|
2017-03-05 15:44:50 +00:00
|
|
|
code += _mktab(p_level - 1) + "{\n";
|
|
|
|
for (Map<StringName, SL::BlockNode::Variable>::Element *E = bnode->variables.front(); E; E = E->next()) {
|
|
|
|
code += _mktab(p_level) + _prestr(E->get().precision) + _typestr(E->get().type) + " " + E->key() + ";\n";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < bnode->statements.size(); i++) {
|
|
|
|
String scode = dump_node_code(bnode->statements[i], p_level);
|
2016-10-07 14:31:18 +00:00
|
|
|
|
Fix many errors found by PVS-Studio
Fix errors 2, 3, 4, 6, 8, 9, 11, 12, 13, 14, and 15.
2018-11-28 02:58:00 +00:00
|
|
|
if (bnode->statements[i]->type == SL::Node::TYPE_CONTROL_FLOW) {
|
2017-03-05 15:44:50 +00:00
|
|
|
code += scode; //use directly
|
2016-10-07 14:31:18 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
code += _mktab(p_level) + scode + ";\n";
|
2016-10-07 14:31:18 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
code += _mktab(p_level - 1) + "}\n";
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case SL::Node::TYPE_VARIABLE: {
|
2017-03-05 15:44:50 +00:00
|
|
|
SL::VariableNode *vnode = (SL::VariableNode *)p_node;
|
|
|
|
code = vnode->name;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
2018-09-26 11:13:56 +00:00
|
|
|
case SL::Node::TYPE_VARIABLE_DECLARATION: {
|
|
|
|
// FIXME: Implement
|
|
|
|
} break;
|
2019-07-10 16:52:50 +00:00
|
|
|
case SL::Node::TYPE_ARRAY: {
|
|
|
|
SL::ArrayNode *vnode = (SL::ArrayNode *)p_node;
|
|
|
|
code = vnode->name;
|
|
|
|
} break;
|
|
|
|
case SL::Node::TYPE_ARRAY_DECLARATION: {
|
|
|
|
// FIXME: Implement
|
|
|
|
} break;
|
2020-02-13 14:53:32 +00:00
|
|
|
case SL::Node::TYPE_ARRAY_CONSTRUCT: {
|
|
|
|
// FIXME: Implement
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case SL::Node::TYPE_CONSTANT: {
|
2017-03-05 15:44:50 +00:00
|
|
|
SL::ConstantNode *cnode = (SL::ConstantNode *)p_node;
|
|
|
|
return get_constant_text(cnode->datatype, cnode->values);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case SL::Node::TYPE_OPERATOR: {
|
2017-03-05 15:44:50 +00:00
|
|
|
SL::OperatorNode *onode = (SL::OperatorNode *)p_node;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (onode->op) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case SL::OP_ASSIGN:
|
|
|
|
case SL::OP_ASSIGN_ADD:
|
|
|
|
case SL::OP_ASSIGN_SUB:
|
|
|
|
case SL::OP_ASSIGN_MUL:
|
|
|
|
case SL::OP_ASSIGN_DIV:
|
2016-10-07 14:31:18 +00:00
|
|
|
case SL::OP_ASSIGN_SHIFT_LEFT:
|
|
|
|
case SL::OP_ASSIGN_SHIFT_RIGHT:
|
|
|
|
case SL::OP_ASSIGN_MOD:
|
|
|
|
case SL::OP_ASSIGN_BIT_AND:
|
|
|
|
case SL::OP_ASSIGN_BIT_OR:
|
|
|
|
case SL::OP_ASSIGN_BIT_XOR:
|
2017-03-05 15:44:50 +00:00
|
|
|
code = dump_node_code(onode->arguments[0], p_level) + _opstr(onode->op) + dump_node_code(onode->arguments[1], p_level);
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
2016-10-07 14:31:18 +00:00
|
|
|
case SL::OP_BIT_INVERT:
|
|
|
|
case SL::OP_NEGATE:
|
2014-02-10 01:10:30 +00:00
|
|
|
case SL::OP_NOT:
|
2016-10-07 14:31:18 +00:00
|
|
|
case SL::OP_DECREMENT:
|
|
|
|
case SL::OP_INCREMENT:
|
2017-03-05 15:44:50 +00:00
|
|
|
code = _opstr(onode->op) + dump_node_code(onode->arguments[0], p_level);
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
2016-10-07 14:31:18 +00:00
|
|
|
case SL::OP_POST_DECREMENT:
|
|
|
|
case SL::OP_POST_INCREMENT:
|
2017-03-05 15:44:50 +00:00
|
|
|
code = dump_node_code(onode->arguments[0], p_level) + _opstr(onode->op);
|
2016-10-07 14:31:18 +00:00
|
|
|
break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case SL::OP_CALL:
|
|
|
|
case SL::OP_CONSTRUCT:
|
2017-03-05 15:44:50 +00:00
|
|
|
code = dump_node_code(onode->arguments[0], p_level) + "(";
|
|
|
|
for (int i = 1; i < onode->arguments.size(); i++) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (i > 1) {
|
2017-03-05 15:44:50 +00:00
|
|
|
code += ", ";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
code += dump_node_code(onode->arguments[i], p_level);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
code += ")";
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
2016-10-07 14:31:18 +00:00
|
|
|
default: {
|
2017-03-05 15:44:50 +00:00
|
|
|
code = "(" + dump_node_code(onode->arguments[0], p_level) + _opstr(onode->op) + dump_node_code(onode->arguments[1], p_level) + ")";
|
2016-10-07 14:31:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case SL::Node::TYPE_CONTROL_FLOW: {
|
2017-03-05 15:44:50 +00:00
|
|
|
SL::ControlFlowNode *cfnode = (SL::ControlFlowNode *)p_node;
|
|
|
|
if (cfnode->flow_op == SL::FLOW_OP_IF) {
|
|
|
|
code += _mktab(p_level) + "if (" + dump_node_code(cfnode->expressions[0], p_level) + ")\n";
|
|
|
|
code += dump_node_code(cfnode->blocks[0], p_level + 1);
|
|
|
|
if (cfnode->blocks.size() == 2) {
|
|
|
|
code += _mktab(p_level) + "else\n";
|
|
|
|
code += dump_node_code(cfnode->blocks[1], p_level + 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (cfnode->flow_op == SL::FLOW_OP_RETURN) {
|
2016-10-07 14:31:18 +00:00
|
|
|
if (cfnode->blocks.size()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
code = "return " + dump_node_code(cfnode->blocks[0], p_level);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
code = "return";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case SL::Node::TYPE_MEMBER: {
|
2017-03-05 15:44:50 +00:00
|
|
|
SL::MemberNode *mnode = (SL::MemberNode *)p_node;
|
|
|
|
code = dump_node_code(mnode->owner, p_level) + "." + mnode->name;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static Error recreate_code(void *p_str, SL::ShaderNode *p_program) {
|
|
|
|
String *str = (String *)p_str;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
*str = dump_node_code(p_program, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-06-28 02:21:45 +00:00
|
|
|
return OK;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
MainLoop *test() {
|
2014-02-10 01:10:30 +00:00
|
|
|
List<String> cmdlargs = OS::get_singleton()->get_cmdline_args();
|
|
|
|
|
2020-12-15 12:04:21 +00:00
|
|
|
if (cmdlargs.is_empty()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//try editor!
|
2016-10-07 14:31:18 +00:00
|
|
|
print_line("usage: godot -test shader_lang <shader>");
|
2020-04-01 23:20:12 +00:00
|
|
|
return nullptr;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String test = cmdlargs.back()->get();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
FileAccess *fa = FileAccess::open(test, FileAccess::READ);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
if (!fa) {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_V(nullptr);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String code;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (true) {
|
2020-07-27 10:43:20 +00:00
|
|
|
char32_t c = fa->get_8();
|
2020-05-14 14:41:43 +00:00
|
|
|
if (fa->eof_reached()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
code += c;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-10-07 14:31:18 +00:00
|
|
|
SL sl;
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("tokens:\n\n" + sl.token_debug(code));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-29 13:14:07 +00:00
|
|
|
Map<StringName, SL::FunctionInfo> dt;
|
|
|
|
dt["fragment"].built_ins["ALBEDO"] = SL::TYPE_VEC3;
|
|
|
|
dt["fragment"].can_discard = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-07-14 21:15:42 +00:00
|
|
|
Vector<StringName> rm;
|
|
|
|
rm.push_back("popo");
|
2017-04-07 02:36:37 +00:00
|
|
|
Set<String> types;
|
|
|
|
types.insert("spatial");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-05-14 08:15:48 +00:00
|
|
|
Error err = sl.compile(code, dt, rm, types, nullptr);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-10-07 14:31:18 +00:00
|
|
|
if (err) {
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("Error at line: " + rtos(sl.get_error_line()) + ": " + sl.get_error_text());
|
2020-04-01 23:20:12 +00:00
|
|
|
return nullptr;
|
2016-10-07 14:31:18 +00:00
|
|
|
} else {
|
2019-02-12 20:10:08 +00:00
|
|
|
String code2;
|
|
|
|
recreate_code(&code2, sl.get_shader());
|
|
|
|
print_line("code:\n\n" + code2);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
return nullptr;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-12-06 20:36:34 +00:00
|
|
|
} // namespace TestShaderLang
|