【问题标题】:OpenGL/Android GLSL ES 3.00 only仅限 OpenGL/Android GLSL ES 3.00
【发布时间】:2018-02-07 15:39:04
【问题描述】:

我的目标是在我的 Android 应用程序中使用 OpenGL 3.1 来显示纹理。 目前的问题是,着色器无法编译。

private final String vertexShaderCode =
        // This matrix member variable provides a hook to manipulate
        // the coordinates of the objects that use this vertex shader
                "uniform mat4 uMVPMatrix;" +
                "in vec4 vPosition;" +
                "in vec2 vTextureCoordinate;" +
                "out vec2 exTextureCoordinate;" +
                "void main() {" +
                // the matrix must be included as a modifier of gl_Position
                // Note that the uMVPMatrix factor *must be first* in order
                // for the matrix multiplication product to be correct.
                "  gl_Position = uMVPMatrix * vPosition;" +
                "   exTextureCoordinate = vTextureCoordinate;" +
                "}";

private final String fragmentShaderCode =
                "precision mediump float;" +
                "uniform sampler2D texture;" +
                "in vec2 exTextureCoordinate;" +
                "out vec4 out_Color;" +
                "void main() {" +
                "  out_Color = texture2D(texture, exTextureCoordinate);" +
                "}";

想法:将模型视图矩阵连同在空间中的位置和纹理坐标一起传递给顶点着色器。纹理坐标通过fragmentShader进行着色,空间坐标通过Model-View Matrix进行变换。

编译着色器时出现以下错误代码:

E/ShaderCompile: Error compiling shader!
E/ShaderCompile: 
ERROR: 0:1: 'in' : storage qualifier supported in GLSL ES 3.00 only  
ERROR: 0:1: 'in' : storage qualifier supported in GLSL ES 3.00 only  
ERROR: 0:1: 'out' : storage qualifier supported in GLSL ES 3.00 only  
E/ShaderCompile: Error compiling shader!
E/ShaderCompile: 
ERROR: 0:1: 'in' : storage qualifier supported in GLSL ES 3.00 only  
ERROR: 0:1: 'out' : storage qualifier supported in GLSL ES 3.00 only  

我使用以下代码设置OpenGLES版本:

uses-feature android:glEsVersion="0x00030001" android:required="true"
setEGLContextClientVersion(3);

【问题讨论】:

    标签: android opengl-es shader glsles


    【解决方案1】:

    您没有定义要使用的 GLSL 版本,这意味着它回退到更早的版本(不是 3)。您可以将 GLSL ES 1 与 GLES 3 一起使用,因此它不会默认为当前的 GLES 版本。

    因此,在着色器文件的顶部(第一行)声明版本:

    # version 300 es
    

    片段着色器和顶点着色器都必须这样做


    请注意,这实际上要求设备支持 GLES 和 GLSL 3。如果您使用默认的 Android 模拟器(与 SDK 一起打包的模拟器),则无法测试 GLES/GLSLES 3,因为它不支持支持它。使用真实设备(当然支持 GLES3)或支持 GLES3 的模拟器

    【讨论】:

    • 哇。谢谢。这似乎可以解决问题。但现在我得到“错误:不支持的着色器版本”
    • 听起来更像是硬件问题(GPU 中的硬件不支持它)。使用glGetString (GL_SHADING_LANGUAGE_VERSION) 并检查您的设备支持的版本。如果您使用的是模拟器(SDK 附带的模拟器;第三方可以支持 GLES3),则不能使用 GLES 3(或 GLSL 3)
    【解决方案2】:

    从 Android Studio 3.6 开始,API 29,GLES 3 和 GLSL 模拟器支持 3,无论是使用 SwiftShader 还是桌面原生 OpenGL。 您需要指定 Zoe 上面写的版本:

    # version 300 es

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-19
      相关资源
      最近更新 更多