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

Allow multiple declarations in for loop in a shader #57579

Merged
merged 1 commit into from
Feb 3, 2022

Conversation

Chaosus
Copy link
Member

@Chaosus Chaosus commented Feb 3, 2022

This will allow the creation of more complex loop declarations like:

for(int i = 0, j = 0, k[] = {0, 1}; i < 10, j > -10; i++, j--) {
}

translated to

for (int m_i=0,m_j=0,m_k[2]=int[2](0,1);(m_i<10),(m_j>-10);m_i++,m_j--) {
}

by the shader compiler.

GLSL also allows empty statements in the for loop, so the following statement will be valid after merging this PR:

for(;;;) {
}

The only restriction I've added is for the initialization block to accept only a variable declaration, eg not allowing to write:

int i = 0;
for(i /= 10;;){
}

@Chaosus Chaosus requested a review from a team as a code owner February 3, 2022 08:26
@Chaosus Chaosus added this to the 4.0 milestone Feb 3, 2022
@akien-mga akien-mga merged commit 17d33c0 into godotengine:master Feb 3, 2022
@akien-mga
Copy link
Member

Thanks!

@Chaosus Chaosus deleted the shader_better_for_loop branch February 3, 2022 14:07
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.

2 participants