2015-10-18 105 views
4

我能够在桌面上使用GLSL 330核心实例渲染,但我无法在Android上运行相同的C++代码(使用SDL2和NDK构建系统和Android Studio)。OpenGL ES 3实例渲染失败,但在桌面上工作

的logcat的误差如下所示:

-18 15:49:57.264 20996-21026/package I/SDL/APP: shaders/mobile/sceneShader.frag.glsl compiled successfully 
10-18 15:49:57.274 20996-21026/package I/SDL/APP: Program link failed: --From Vertex Shader: 
10-18 15:49:57.274 20996-21026/packageI/SDL/APP: linker error: multiple attribute attempt to bind at same location 
10-18 15:49:57.274 20996-21026/packageI/SDL/APP: --From Fragment Shader: 
10-18 15:49:57.274 20996-21026/package I/SDL/APP: linker error: multiple attribute attempt to bind at same location 

我的桌面和移动着色器代码是除了在文件的顶部,其中的#Version线(分别指定ES或桌面版本)相同。

我的移动着色器代码如下所示:

#version 300 es 

precision mediump float; 

// attribute data 
layout (location = 0) in vec3 VertexPosition; 
layout (location = 1) in vec2 VertexTexCoord; 
layout (location = 2) in vec3 VertexNormal; 
layout (location = 3) in mat4 InstanceTransform; // used for translating the positions of instance renders 

// varying data 
layout (location = 0) out vec3 vPosition; 
layout (location = 1) out vec2 vTexCoord0; 
layout (location = 2) out vec2 vTexCoord1; 
layout (location = 3) out vec3 vTexSkyboxCoord; 
layout (location = 4) out vec3 vNormal; 
layout (location = 5) out vec3 vClampColor; 

// uniform data 
layout (location = 0) uniform bool uInstanceRendering; 

layout (location = 1) uniform mat4 uModelViewMatrix; 
layout (location = 2) uniform mat4 uProjectionMatrix; 
layout (location = 3) uniform mat3 uNormalMatrix; 

layout (location = 4) uniform vec2 uTexOffset0; 
layout (location = 5) uniform vec2 uTexOffset1; 

void main(void) 
{ 
    vec4 mvPosition; 

    if (uInstanceRendering) 
    { 
     mvPosition = uModelViewMatrix * InstanceTransform * vec4(VertexPosition, 1.0); 
    } 
    else 
    { 
     mvPosition = uModelViewMatrix * vec4(VertexPosition, 1.0); 
    } 

    vTexSkyboxCoord = VertexPosition; // for skybox rendering 

    const float atlasRows = 6.0f; 
    vTexCoord0 = (VertexTexCoord/atlasRows) + uTexOffset0; 
    vTexCoord1 = (VertexTexCoord/atlasRows) + uTexOffset1; 

    vPosition = mvPosition.xyz; 

    vNormal = normalize(uNormalMatrix * VertexNormal); 

    vClampColor = clamp(VertexPosition, 0.0, 1.0); 

    gl_Position = uProjectionMatrix * mvPosition; 

#ifdef GL_ES 
    gl_PointSize = 10.0f; 
#endif 
} 

繁琐使用在C++侧和GLSL侧二者的评论我已销指向的错误这行代码后:

mvPosition = uModelViewMatrix * InstanceTransform * vec4(VertexPosition, 1.0); 

如果我将它注释掉,程序将会编译,但不会执行glDraw * Instaced调用,而没有大量与gpu相关的错误(如logcat所示)。

10-18 15:58:42.504 29196-29238/package W/Adreno-GSL: <gsl_ldd_control:408>: ioctl fd 49 code 0xc02c093d (IOCTL_KGSL_SUBMIT_COMMANDS) failed: errno 35 Resource deadlock would occur 
10-18 15:58:42.504 29196-29238/package W/Adreno-GSL: <log_gpu_snapshot:323>: panel.gpuSnapshotPath is not set.not generating user snapshot 
10-18 15:58:42.504 29196-29238/packageW/Adreno-GSL: <gsl_ldd_control:408>: ioctl fd 49 code 0xc02c093d (IOCTL_KGSL_SUBMIT_COMMANDS) failed: errno 35 Resource deadlock would occur 
10-18 15:58:42.504 29196-29238/packageW/Adreno-GSL: <log_gpu_snapshot:323>: panel.gpuSnapshotPath is not set.not generating user snapshot 
10-18 15:58:42.504 29196-29238/packageW/Adreno-GSL: <gsl_ldd_control:408>: ioctl fd 49 code 0xc02c093d (IOCTL_KGSL_SUBMIT_COMMANDS) failed: errno 35 Resource deadlock would occur 
10-18 15:58:42.504 29196-29238/packageW/Adreno-GSL: <log_gpu_snapshot:323>: panel.gpuSnapshotPath is not set.not generating user snapshot 
10-18 15:58:42.504 29196-29238/packageW/Adreno-GSL: <gsl_ldd_control:408>: ioctl fd 49 code 0xc02c093d (IOCTL_KGSL_SUBMIT_COMMANDS) failed: errno 35 Resource deadlock would occur 
10-18 15:58:42.504 29196-29238/packageW/Adreno-GSL: <log_gpu_snapshot:323>: panel.gpuSnapshotPath is not set.not generating user snapshot 
10-18 15:58:42.504 29196-29238/packageW/Adreno-GSL: <gsl_ldd_control:408>: ioctl fd 49 code 0xc02c093d (IOCTL_KGSL_SUBMIT_COMMANDS) failed: errno 35 Resource deadlock would occur 
10-18 15:58:42.504 29196-29238/packageW/Adreno-GSL: <log_gpu_snapshot:323>: panel.gpuSnapshotPath is not set.not generating user snapshot 
10-18 15:58:42.504 29196-29238/packageW/Adreno-ES20: <finish_current_fbo_rendering:315>: GL_OUT_OF_MEMORY 

我做了一个小例子来简单测试实例渲染和同样的问题与OpenGL ES的3(也使用SDL仍然)弹出。

#version 300 es 
precision mediump float; 

// attribute data 
layout (location = 0) in vec3 aVertexPosition; 
layout (location = 1) in vec2 aVertexTexCoord; 
layout (location = 2) in vec3 aVertexNormal; 
layout (location = 3) in mat4 aInstanceTransform; 

// varying data 
out vec3 vPosition; 
out vec2 vTexCoord; 
out vec3 vNormal; 

// uniform data 
uniform mat4 uModelViewMatrix; 
uniform mat4 uProjectionMatrix; 
uniform mat3 uNormalMatrix; 

void main(void) 
{ 
    vec4 mvTransform = uModelViewMatrix * aInstanceTransform * vec4(aVertexPosition, 1.0); 

    vTexCoord = aVertexTexCoord; 

    vPosition = mvTransform.xyz; 

    vNormal = normalize(uNormalMatrix * aVertexNormal); 

    gl_Position = uProjectionMatrix * mvTransform; 
} 

这里是我设置的顶点数据:

glBindBuffer(GL_ARRAY_BUFFER, mVBO_InstanceData); 
glBufferData(GL_ARRAY_BUFFER, instanceData.size() * sizeof(glm::mat4), instanceData.data(), GL_STATIC_DRAW); 

glEnableVertexAttribArray(3); 
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), reinterpret_cast<GLvoid*>(0)); 
glVertexAttribDivisor(3, 1); // increment instance data by 1 each iteration 

glEnableVertexAttribArray(4); 
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), reinterpret_cast<GLvoid*>(sizeof(glm::vec4))); 
glVertexAttribDivisor(4, 1); 

glEnableVertexAttribArray(5); 
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), reinterpret_cast<GLvoid*>(2 * sizeof(glm::vec4))); 
glVertexAttribDivisor(5, 1); 

glEnableVertexAttribArray(6); 
glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), reinterpret_cast<GLvoid*>(3 * sizeof(glm::vec4))); 
glVertexAttribDivisor(6, 1); 

回答

0

我发现在顶点着色器中只使用'glBindAttribLocation'而不是布局限定符修复了问题。我甚至使用了与布局限定符相同的编号方案。我想知道我是否可以用4个vec4设置实例数据?我想mat4会在我的移动设备上抛出编号方案?

4

你的一些location预选赛是不符合300 es着色器版本。你的顶点着色器包含以下定义:

layout (location = 0) out vec3 vPosition; 
... 

的GLSL ES 3.00规范说:

顶点着色不能有输出布局预选赛。

顶点和片段着色器允许在输出变量声明位置布局限定符:

此限制仅在3.10版本,其中相应的措词已经改变到解除。

几乎同样的道理也适用于制服,在您使用:

layout (location = 0) uniform bool uInstanceRendering; 
... 

而且这里,着色器版本3.00不允许在制服layout预选赛:

布局预选赛可用于统一块,但不用于非块统一声明。

此外,该选项在版本3.10中添加。

+0

啊,感谢您查看我的代码并通知我这件事。在我移植到移动设备之前,我在桌面上进行了大部分测试,因此我必须对其进行调整。但是,这并没有解决我的GPU实例问题。我认为这可能是我的硬件(我的电话),但我还不确定。 – BlazePascal

+0

如果您删除布局指令,您仍然收到链接错误吗?对于制服,你当然必须使用'glGetUniformLocation()'来代替。 –

+0

是的,在将布局限定符添加到输出和统一变量之前,出现了错误。我只是添加了它们,因为我认为它可以解决移动端的绑定问题。 – BlazePascal