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

Invalid comparisons #101

Open
davesmith00000 opened this issue Nov 28, 2023 · 1 comment
Open

Invalid comparisons #101

davesmith00000 opened this issue Nov 28, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@davesmith00000
Copy link
Member

This is perfectly ok according to the Scala compiler: if 1.0f < 0 then ... but does not compile to GLSL because they both need to be floats, i.e.: if 1.0f < 0.0 then ...

You get a compile error in the browser logs, but it would be nice to catch this at Scala compile time.

@davesmith00000 davesmith00000 changed the title Invalid comparions Invalid comparisons Jan 2, 2024
@davesmith00000
Copy link
Member Author

As usual, it's a bit complicated.

The spec calls these "vector relational functions": "<" | "<=" | ">" | ">=" | "==" | "!="

https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf

...and it's easy enough in theory, you just need to make sure the type on the left is the same as the type on the right. However in practice, as soon as you introduce a variable then at the point of comparison, you don't have the type immediately to hand.

I did try doing a "best effort" comparison, knowing the names of the types we care about we can just check, right? Well, no, because the Scala compile things comparing float and double is totally ok, and inlines known values and whole if statements before we can even check them. 😄

So plan B might be to add it to the program validation step, which is only slightly better than the current behaviour.

@davesmith00000 davesmith00000 added the enhancement New feature or request label Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant