2016-08-17 157 views
0

我在寫一個計算着色器,它應該在PC和Android上運行。它在PC上運行良好,但不能在Android上編譯。OpenGL着色器無法在設備上編譯

這是着色器:

#version 310 es 

uniform vec2 lightPos; // passed from the app 

layout (local_size_x = 512, local_size_y = 1) in; 
layout (rgba8, binding = 0) uniform image2D img_output; 
layout (rgba8, binding = 1) uniform readonly image2D colorTex; 
layout (rgba8, binding = 2) uniform readonly image2D transpTex; 

void main() { 
    imageStore(img_output, ivec2(3, 6), vec4(0.3 ,0.2 ,0.5 ,0.9)); 
} 

和錯誤是:
Shader compile error: ERROR: '' : unsupported format on read/write image

如果我改變的最後一個參數ivec4uvec4我得到:
ERROR: 'imageStore' : no matching overloaded function found

GL.GetString(StringName.Version);回報 GL version:OpenGL ES 3.1 [email protected] ([email protected])

這是在索尼Xperia Z5上(Android仿真器似乎不支持OpenGL ES 3.1)。

+0

https://www.opengl.org/sdk/docs/man/html/imageStore.xhtml查看opengl版本是否支持'imageStore'功能。 – ASK

+0

@ASK支持ES 3.1:https://www.khronos.org/opengles/sdk/docs/man31/html/imageStore.xhtml(我的着色器是ES 3.1) – sydd

回答

1

這在GLSL ES 3.10 spec被指定時,72頁中的章節「4.9內存訪問限定符」:

除了與格式限定符R32F,r32i和r32ui合格圖像變量,圖象變量必須指定內存限定符只讀或內存限定符writeonly。

此限制在GLSL ES 3.20中仍然適用。

0

着色器編譯僅在輸出圖像聲明寫:

layout (rgba8, binding = 0) uniform writeonly image2D img_output;

不知道爲什麼這是必要的,沒有任何人有一個鏈接,其中討論這個規範?