Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add const qualifier support for function arguments in shaders (3.x) #55103

Merged
merged 1 commit into from
Nov 19, 2021

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Nov 18, 2021

3.x version of #40010. I found out about this while skimming over commits for writing the 4.0 alpha changelog 🙂

Example:

void test(const int t) {}
shader_type spatial;

vec3 test_function_mutable(float red) {
	red = 0.0;
	return vec3(red, 0.3, 0.3);
}

vec3 test_function_const(const float red) {
	//red = 0.0; // This causes an error if uncommented.
	return vec3(red, 0.3, 0.3);
}

void fragment() {
	ALBEDO = test_function_const(0.9);
}

@Calinou Calinou requested a review from a team as a code owner November 18, 2021 21:21
@Calinou Calinou added this to the 3.5 milestone Nov 18, 2021
@Chaosus
Copy link
Member

Chaosus commented Nov 19, 2021

@Chaosus The following code gives me an error on both master and 3.x, is this expected?

Seems like it's bugged and it's allowed in GLSL.

@Calinou You can add the changes from #55113 (shader_language.cpp) to fix that.

@Calinou Calinou changed the title Add const qualifier support for function arguments in shaders Add const qualifier support for function arguments in shaders (3.x) Nov 19, 2021
This prevents the function argument from being reassigned within
the function.

Example:

    void test(const int t) {}
@Calinou
Copy link
Member Author

Calinou commented Nov 19, 2021

@Calinou You can add the changes from #55113 (shader_language.cpp) to fix that.

Done 🙂 I tested the PR again on both GLES3 and GLES2.

@Calinou Calinou force-pushed the shader-func-arg-const-qual-3.x branch from 8c64ff4 to d7d35e4 Compare November 19, 2021 20:20
@Chaosus Chaosus self-requested a review November 19, 2021 20:33
@akien-mga akien-mga merged commit e0cdb8f into godotengine:3.x Nov 19, 2021
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants