Skip to content

Add GL_ES precision qualifiers to Glsl150ShaderGenerator for GLES3 compatibility#2634

Merged
riccardobl merged 2 commits intomasterfrom
copilot/add-glslcompat-to-shadergenerator
Mar 3, 2026
Merged

Add GL_ES precision qualifiers to Glsl150ShaderGenerator for GLES3 compatibility#2634
riccardobl merged 2 commits intomasterfrom
copilot/add-glslcompat-to-shadergenerator

Conversation

Copy link
Contributor

Copilot AI commented Mar 3, 2026

Shader node shaders generated for GLES3 (via Glsl300ShaderGenerator) fail compilation with No precision specified for (float) because GLSL ES 3.0 requires explicit precision qualifiers in fragment shaders, and the generator wasn't emitting them.

Changes

  • Glsl150ShaderGenerator.generateCompatibilityDefines: Added the same GL_ES precision block already present in GLSLCompat.glsllib (lines 1–16) directly into the generated fragment shader output:
#ifdef GL_ES
precision highp float;
precision highp int;
#if __VERSION__ >= 130
precision highp sampler2DArray;
#endif
precision highp sampler2DShadow;
precision highp samplerCube;
precision highp sampler3D;
precision highp sampler2D;
#if __VERSION__ >= 310
precision highp sampler2DMS;
#endif
#endif

The block is guarded by #ifdef GL_ES, so desktop GLSL rendering is unaffected. Since Glsl300ShaderGenerator extends Glsl150ShaderGenerator and only overrides getLanguageAndVersion(), this fix covers GLES3 without requiring changes to the subclass.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED -XX:MaxMetaspaceSize=384m -XX:+HeapDumpOnOutOfMemoryError -Xms256m -Xmx512m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.8-bin/dl7vupf4psengwqhwktix4v1/gradle-8.8/lib/gradle-launcher-8.8.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.8-bin/dl7vupf4psengwqhwktix4v1/gradle-8.8/lib/agents/gradle-instrumentation-agent-8.8.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Glsl150ShaderGenerator should include GLSLCompat for GLES3</issue_title>
<issue_description>Glsl150ShaderGenerator should include GLSLCompat in the shaders, or otherwise manually set the default precisions otherwise shadernodes for GLES3 will fail compilation with

com.jme3.renderer.RendererException: compile error in: ShaderSource[name=Default.frag, defines, type=Fragment, language=GLSL300]
ERROR: 0:11: '' : No precision specified for (float)
ERROR: 0:13: '' : No precision specified for (float)
ERROR: 0:14: '' : No precision specified for (float)
ERROR: 0:15: '' : No precision specified for (float)
 ...
```</issue_description>

<agent_instructions>implement this fix properly, do not use the workaround</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@riccardobl</author><body>
## Workaround

1. add this patched generator to the app
```java
package com.animotiv.designertest.system;

import com.jme3.asset.AssetManager;
import com.jme3.material.ShaderGenerationInfo;
import com.jme3.shader.Glsl300ShaderGenerator;
import com.jme3.shader.Shader;


public class GLES300ShaderGenerator extends Glsl300ShaderGenerator {

    public GLES300ShaderGenerator(AssetManager assetManager) {
        super(assetManager);
    }

    protected void generateUniforms(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) {
        source.append( "#ifdef GL_ES\n" +
                "  #ifdef FRAGMENT_SHADER\n" +
                "    precision highp float;\n" +
                "    precision highp int;\n" +
                "    #if __VERSION__ >= 130\n" +
                "      precision highp sampler2DArray;        \n" +
                "    #endif\n" +
                "    precision highp sampler2DArray;\n" +
                "    precision highp sampler2DShadow;\n" +
                "    precision highp samplerCube;\n" +
                "    precision highp sampler3D;\n" +
                "    precision highp sampler2D;\n" +
                "    #if __VERSION__ >= 310\n" +
                "      precision highp sampler2DMS;\n" +
                "    #endif\n" +
                "  #endif\n" +
                "#endif\n");
        super.generateUniforms(source, info, type);
    }
}

  1. pass it in the assetManager at the beginning of simpleInitApp
        assetManager.setShaderGenerator(new GLES300ShaderGenerator(assetManager));

note: this is not a very pretty solution, if possible it should be fixed properly in the engine</comment_new>
<comment_new>@stephengold
@riccardobl Thank you for documenting the issue and the workaround.</comment_new>


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…S3 support

Co-authored-by: riccardobl <4943530+riccardobl@users.noreply.github.com>
@riccardobl riccardobl marked this pull request as ready for review March 3, 2026 02:06
Copilot AI changed the title [WIP] Add GLSLCompat to Glsl150ShaderGenerator for GLES3 Add GL_ES precision qualifiers to Glsl150ShaderGenerator for GLES3 compatibility Mar 3, 2026
@riccardobl riccardobl merged commit e2ffd8b into master Mar 3, 2026
17 checks passed
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.

Glsl150ShaderGenerator should include GLSLCompat for GLES3

2 participants