“整数常量溢出”使用 GLSL (OpenGL ES2)
我需要在不使用 OpenGL 纹理的情况下将纹理数据传递给着色器程序,因为我没有使用两个纹理的幂,但我收到此片段着色器的错误。
varying highp vec2 texcoord;
uniform ivec4 texdata[172800];
void main(){
int pixel = int(360.0 * texcoord.y + texcoord.x);
gl_FragColor = vec4(texdata[pixel].x,texdata[pixel].y,texdata[pixel].z,1);
}
我怎样才能传递这些数据?
I need to pass texture data to a shader program without using OpenGL textures because I'm not using a power of two texture but I get the error with this fragment shader.
varying highp vec2 texcoord;
uniform ivec4 texdata[172800];
void main(){
int pixel = int(360.0 * texcoord.y + texcoord.x);
gl_FragColor = vec4(texdata[pixel].x,texdata[pixel].y,texdata[pixel].z,1);
}
How can I pass this data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
OpenGL/ES 2规范只要求GLSL整数至少为17位(能够表示范围[-2^16,2^16)),并且整数用于数组索引,因此你无法可靠地创建一个包含超过 65535 个元素的数组。无论如何,您可能无法创建那么大的数据,因为统一数据的总量有限制,可能要低得多。如果要访问大量数据,则需要使用纹理。
此错误可能来自您的整数常量
172800
,它对于您平台的 GLSL 实现来说显然太大。The OpenGL/ES 2 spec only requires that GLSL integers are at least 17 bits (able to represent the range [-2^16,2^16)), and integers are used for array indexes, so you can't reliably create an array with more than 65535 elements. You might not be able to create one that big in any case, as there are limits on the total amount of uniform data that may be much lower. If you want access to a larger amount of data, you need to use a texture.
This error is probably coming from your integer constant
172800
which is apparently too big for your platform's GLSL implementation.实际上,支持 OpenGL ES 2.0 的较新 iOS 型号能够使用非二次方纹理,因为 OpenGL ES 2.0 规范中已对此进行了规定。这些设备还允许通过
GL_APPLE_texture_2D_limited_npot
扩展,我在答案中更详细地描述了此处。Apple 对这些非二次幂纹理的限制是它们不得进行 mipmap,并且必须使用 GL_CLAMP_TO_EDGE 进行包装:
我在 OpenGL ES 2.0 示例应用程序中使用此类纹理此处。
您不需要寻找其他方法将纹理传递到这些设备上的着色器。
Actually, the newer iOS models that support OpenGL ES 2.0 have the ability to use non-power-of-two textures because that is provided for in the OpenGL ES 2.0 specification. These devices also allow for non-power-of-two textures to be used in OpenGL ES 1.1 via the
GL_APPLE_texture_2D_limited_npot
extension, which I describe in more detail in my answer here.The restrictions Apple places on these non-power-of-two textures is that they must not be mipmapped and they must use
GL_CLAMP_TO_EDGE
for the wrapping:I use such textures in my OpenGL ES 2.0 sample application here.
You shouldn't need to find another way to pass your textures in to your shaders on these devices.
存在非 2 次方纹理目标,因此没有理由这样做。
http://www.opengl.org/registry/specs/ARB/texture_rectangle.txt
或者您只需将非 2 的幂数据填充到 2 的幂帧中。
There are non-power-of-2 texture targets, so no reason to do this.
http://www.opengl.org/registry/specs/ARB/texture_rectangle.txt
Or you just pad your non-power-of-2 data into a power-of-2 frame.