Shader: add glslVersion to support GLSL3 shaders #2623
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 hopeShader
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.attribute
toin
from GLSL1 to GLSL3 (see, for example, https://webgl2fundamentals.org/webgl/lessons/webgl1-to-webgl2.html), andShader
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.:
If no version is specified,
shader.glslVersion
is set tonull
, and no change to the current behavior occurs.