Skip to content

[Fix] (Shader): Implement a comprehensive compatibility patch for mod…#9

Open
DHJComical wants to merge 1 commit intoBZLZHH:mainfrom
DHJComical:main
Open

[Fix] (Shader): Implement a comprehensive compatibility patch for mod…#9
DHJComical wants to merge 1 commit intoBZLZHH:mainfrom
DHJComical:main

Conversation

@DHJComical
Copy link

…ern desktop GLSL shaders on GLES 3.x

This commit resolves a series of critical compilation and linking errors that occurred when trying to run modern desktop GLSL shaders (e.g., from Minecraft shader packs) on an OpenGL ES 3.x environment.

The previous shader converter was insufficient, leading to multiple failures. A new, robust patching mechanism has been added to gl4es_glShaderSource to perform a full "modernization" pass on shaders before compilation.

Key fixes include:

  • GLSL Version: Automatically replaces desktop GLSL versions (e.g., #version 330 core) with a compatible GLES version (e.g., #version 320 es).
  • Input/Output Keywords:
    • Replaces attribute with in in vertex shaders.
    • Replaces varying with out in vertex shaders.
    • Replaces varying with in in fragment shaders.
  • Built-in Variables:
    • Replaces legacy output variables gl_FragColor and gl_FragData[0] with a custom, correctly declared out variable (fragColor).
    • Intelligently inserts the out variable declaration only if it doesn't already exist.
  • Built-in Functions: Replaces legacy texture2D() calls with the modern texture() equivalent.
  • GLES Specifics: Automatically adds the mandatory precision highp float; qualifier to fragment shaders to prevent precision-related compile errors on mobile platforms.
  • Insertion Logic: Employs an intelligent insertion method to ensure declarations are placed after all preprocessor directives, fixing self-induced syntax errors.

These changes collectively allow complex shaders, which previously failed, to be correctly converted, compiled, linked, and rendered successfully.

…ern desktop GLSL shaders on GLES 3.x

This commit resolves a series of critical compilation and linking errors that occurred when trying to run modern desktop GLSL shaders (e.g., from Minecraft shader packs) on an OpenGL ES 3.x environment.

The previous shader converter was insufficient, leading to multiple failures. A new, robust patching mechanism has been added to `gl4es_glShaderSource` to perform a full "modernization" pass on shaders before compilation.

Key fixes include:
- **GLSL Version:** Automatically replaces desktop GLSL versions (e.g., `#version 330 core`) with a compatible GLES version (e.g., `#version 320 es`).
- **Input/Output Keywords:**
  - Replaces `attribute` with `in` in vertex shaders.
  - Replaces `varying` with `out` in vertex shaders.
  - Replaces `varying` with `in` in fragment shaders.
- **Built-in Variables:**
  - Replaces legacy output variables `gl_FragColor` and `gl_FragData[0]` with a custom, correctly declared `out` variable (`fragColor`).
  - Intelligently inserts the `out` variable declaration only if it doesn't already exist.
- **Built-in Functions:** Replaces legacy `texture2D()` calls with the modern `texture()` equivalent.
- **GLES Specifics:** Automatically adds the mandatory `precision highp float;` qualifier to fragment shaders to prevent precision-related compile errors on mobile platforms.
- **Insertion Logic:** Employs an intelligent insertion method to ensure declarations are placed after all preprocessor directives, fixing self-induced syntax errors.

These changes collectively allow complex shaders, which previously failed, to be correctly converted, compiled, linked, and rendered successfully.
@BZLZHH
Copy link
Owner

BZLZHH commented Feb 14, 2026

5d6479b 可能是一个相同的功能,请测试一下这一个commit能否解决你的问题

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.

2 participants