WebGL: INVALID_OPERATION: uniform1i:当前程序的位置

时间:2022-08-21 19:38:11

I'm trying to setup two textures in my fragment shader but am getting this error if I try setup the corresponding uniform variables with:

我试图在我的碎片着色器中设置两个纹理,但是如果我尝试设置相应的均匀变量,会得到这个错误:

gl.uniform1i(getUniformLocation(program, "uTextureOne"), 0); and gl.uniform1i(getUniformLocation(program, "uTextureTwo"), 1);.

gl.uniform1i(getUniformLocation(计划,“uTextureOne”),0);和gl.uniform1i(getUniformLocation(计划,“uTextureTwo”),1);。

What does it mean? (I'm using Chrome)

这是什么意思?(我使用Chrome)

My shader looks like this:

我的阴影是这样的:

        "#ifdef GL_ES                       \r\n" +
        "precision mediump float;           \r\n" + 
        "#endif                             \r\n" +
        "uniform sampler2D uTextureOne;     \r\n" +
        "uniform sampler2D uTextureTwo;     \r\n" +
        "varying vec3 vOrgNormal;           \r\n" +
        "void main(void) {                  \r\n" +

1 个解决方案

#1


13  

“Location not for current program” means that the active shader program (gl.useProgram) is not the program which you obtained the uniform locations from.

“不为当前程序的位置”是指活动的着色程序(gl.useProgram)不是您所获得的统一位置的程序。

If you are using only one shader program, then simply make sure that in your initialization you do gl.useProgram before you do any gl.uniform….

如果您使用的是只有一个着色器程序,然后简单地确保你的初始化之前gl.useProgram你做任何gl.uniform ....

If you are using multiple shader programs, make sure that the correct one is selected before you attempt to set uniform values. Note that uniforms are specific to programs and they are remembered by the programs, so you don't have to re-set them every time you switch programs!

如果您正在使用多个着色程序,请确保在尝试设置统一值之前选择了正确的着色程序。注意,制服是特定于程序的,它们会被程序记住,所以您不必每次切换程序时都重新设置它们!

#1


13  

“Location not for current program” means that the active shader program (gl.useProgram) is not the program which you obtained the uniform locations from.

“不为当前程序的位置”是指活动的着色程序(gl.useProgram)不是您所获得的统一位置的程序。

If you are using only one shader program, then simply make sure that in your initialization you do gl.useProgram before you do any gl.uniform….

如果您使用的是只有一个着色器程序,然后简单地确保你的初始化之前gl.useProgram你做任何gl.uniform ....

If you are using multiple shader programs, make sure that the correct one is selected before you attempt to set uniform values. Note that uniforms are specific to programs and they are remembered by the programs, so you don't have to re-set them every time you switch programs!

如果您正在使用多个着色程序,请确保在尝试设置统一值之前选择了正确的着色程序。注意,制服是特定于程序的,它们会被程序记住,所以您不必每次切换程序时都重新设置它们!