realh / gwebgl

Provides a GObject Introspectable wrapper library for OpenGL ES that uses an API compatible with WebGL
1 stars 1 forks source link

Fix error illegal use of reserved word `highp' #2

Closed JumpLink closed 2 years ago

JumpLink commented 2 years ago

I don't know about shaders, but if I just remove the keyword highp the demo runs for me.

Error message

An error occurred compiling the shaders: 0:2(10): error: illegal use of reserved word `highp'
0:2(10): error: syntax error, unexpected ERROR_TOK
realh commented 2 years ago

The trouble is, precision specifiers are necessary in OpenGL ES (but only in fragment shaders I think). I've targeted ES because it's closer to WebGL than desktop OpenGL and supported in all the mainstream Linux drivers/libraries. However, I did have an issue with GTK/GDK ignoring the ES flag. I guess Arch has a new enough release to include the fix (because I got an error when not including highp), but your distro predates it. I can't remember why I commented out (what are now) lines 87 and 88 and added 94-112 in demo.js, but it looks like it was an attempt to workaround this issue which didn't work.

A better fix for the precision specifier issue would be to add a wrapper for the shader compiler: If the context isn't ES it can remove all occurrences of precision specifiers from the source. If the context is ES and the code doesn't contain any of those keywords, it can add default specifiers to the top of the file, like three.js.

For maximum flexibility the code should be added to gwebgl's C stubs, but it would be much easier to add it to the existing wrapper for WebGLRenderingContextBase.shaderSource.

JumpLink commented 2 years ago

Thank you, then we can close this PR and create a new one for your suggestion. I will first install Arch Linux or Manjaro and if necessary install the latest Gtk version from Git with pacman.

realh commented 2 years ago

I think the standard packages in Arch are up-to-date enough. That's what I'm using; the versions are 3.24.33 and 4.6.2.