1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-13 13:31:48 +00:00

Add const qualifier support for function arguments in shaders

This prevents the function argument from being reassigned within
the function.

Example:

    void test(const int t) {}
This commit is contained in:
Hugo Locurcio
2021-11-18 22:20:07 +01:00
parent 4a29f657b6
commit d7d35e4f73
4 changed files with 50 additions and 10 deletions

View File

@@ -213,6 +213,13 @@ static String _prestr(SL::DataPrecision p_pres) {
return "";
}
static String _constr(bool p_is_const) {
if (p_is_const) {
return "const ";
}
return "";
}
static String _qualstr(SL::ArgumentQualifier p_qual) {
switch (p_qual) {
case SL::ARGUMENT_QUALIFIER_IN:
@@ -373,6 +380,9 @@ void ShaderCompilerGLES3::_dump_function_deps(const SL::ShaderNode *p_node, cons
if (i > 0) {
header += ", ";
}
header += _constr(fnode->arguments[i].is_const);
if (fnode->arguments[i].type == SL::TYPE_STRUCT) {
header += _qualstr(fnode->arguments[i].qualifier) + _mkid(fnode->arguments[i].type_str) + " " + _mkid(fnode->arguments[i].name);
} else {
@@ -562,7 +572,7 @@ String ShaderCompilerGLES3::_dump_node_code(const SL::Node *p_node, int p_level,
for (int i = 0; i < pnode->vconstants.size(); i++) {
const SL::ShaderNode::Constant &cnode = pnode->vconstants[i];
String gcode;
gcode += "const ";
gcode += _constr(true);
if (pnode->vconstants[i].type == SL::TYPE_STRUCT) {
gcode += _mkid(cnode.type_str);
} else {
@@ -655,9 +665,7 @@ String ShaderCompilerGLES3::_dump_node_code(const SL::Node *p_node, int p_level,
SL::VariableDeclarationNode *vdnode = (SL::VariableDeclarationNode *)p_node;
String declaration;
if (vdnode->is_const) {
declaration += "const ";
}
declaration += _constr(vdnode->is_const);
if (vdnode->datatype == SL::TYPE_STRUCT) {
declaration += _mkid(vdnode->struct_name);
} else {