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

Shader: add glslVersion to support GLSL3 shaders #2623

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

poke1024
Copy link

This is a small fix to make Shader work for GLSL 3 and probably higher (see https://en.wikipedia.org/wiki/OpenGL_Shading_Language). I need this in my project, and there currently seems no supported way to do this. I hope Shader can be extended in this direction and this is a simple workaround.

Since for js/html5 default contexts seem to be WebGL2, it seems highly unexpected that Shader does not support the WebGL2 default GLSL3. For desktop, GLSL 3 and 4 now seem pretty common.

This PR fixes two issues:

  • Shader currently cannot handle custom #version commands at the top of user-provided GLSL source code. Since "#version" needs to be in the first line of that code, and OpenFL always prepends the "precision" command, adding a custom "#version" tag will currently always produce a GLSL compiler error. This also means that shaders cannot specify their version at all.
  • Even after injecting the version tag, OpenFL is unable to find relevant input variables to vertex shaders, since the storage type has changed from attribute to in from GLSL1 to GLSL3 (see, for example, https://webgl2fundamentals.org/webgl/lessons/webgl1-to-webgl2.html), and Shader currently hard codes searching for "attribute", which fails. The resulting shader is not operable, since it lacks basic vertex position data.

With the PR, you can configure GLSL3 (or other) shaders by specifying a version tag that is suitable for the GLSL `#version' command, e.g.:

final shader = new Shader();
shader.glslVersion = "300 es";

If no version is specified, shader.glslVersion is set to null, and no change to the current behavior occurs.

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.

None yet

1 participant