【发布时间】:2016-06-09 16:05:03
【问题描述】:
我正在尝试使用:
layout (binding = 0, rgba8ui) readonly uniform uimage2D input;
在计算着色器中。为了将纹理绑定到这个我正在使用:
glBindImageTexture(0, texture_name, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA8);
而且似乎为了让这个绑定起作用,纹理必须是不可变的,所以我已经从:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
到:
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8UI, width, height);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
但这会生成“无效操作”(特别是 glTexSubImage2D() 调用会生成它)。查看文档我发现此调用可能会导致 1282,原因如下:
GL_INVALID_OPERATION is generated if the texture array has not been defined by a previous glTexImage2D or glCopyTexImage2D operation whose internalformat matches the format of glTexSubImage2D.
GL_INVALID_OPERATION is generated if type is GL_UNSIGNED_SHORT_5_6_5 and format is not GL_RGB.
GL_INVALID_OPERATION is generated if type is GL_UNSIGNED_SHORT_4_4_4_4 or GL_UNSIGNED_SHORT_5_5_5_1 and format is not GL_RGBA
但这些都不是我的情况。
其中第一个似乎是问题(考虑到我使用的是 glTexStorage2D(),而不是 glTexImage2D())但这不是问题,因为在浮动纹理的情况下,相同的机制起作用:
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, width, height);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_FLOAT, pixels);
代替:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, pixels);
这可能无关紧要,但两种方法都适用于 PC。
关于为什么会发生这种情况的任何建议?
【问题讨论】:
-
你试过我的解决方案了吗?
标签: binding opengl-es textures compute-shader