Skip to content

do not use terniary operator with structs#530

Open
tmptknn wants to merge 2 commits into
laurentlb:masterfrom
tmptknn:structsfailed
Open

do not use terniary operator with structs#530
tmptknn wants to merge 2 commits into
laurentlb:masterfrom
tmptknn:structsfailed

Conversation

@tmptknn

@tmptknn tmptknn commented Jan 9, 2026

Copy link
Copy Markdown

GLSL does not allow structs as return type form terniary operator.

@laurentlb

laurentlb commented Jan 13, 2026

Copy link
Copy Markdown
Owner

From https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.60.pdf:

The ternary selection operator (?:). It operates on three expressions (exp1 ? exp2 : exp3). This operator evaluates the first expression, which must result in a scalar Boolean. If the result is true, it selects to evaluate the second expression, otherwise it selects to evaluate the third expression. Only one of the second and third expressions is evaluated. The second and third expressions cannot be opaque types, or there will be a compile-time error. Otherwise, the second and third expressions can be any type, including void, as long their types match, or there is a conversion in section “Implicit Conversions” that can be applied to one of the expressions to make their types match. This resulting matching type is the type of the entire expression.

It looks like a struct should be allowed here, but shadertoy rejects it. I think it's reasonable to avoid it. Ideally, we should also reject opaque types like sampler2d, but it can be done in a future PR.

Could you please add a test about it?
Based on the CI, ed-209.frag.expected needs to be updated.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants