简体   繁体   English

OpenGL着色器错误1282

[英]OpenGL Shader error 1282

I am trying to add lighting to my current scene of a simple cube. 我正在尝试将光照添加到我当前的简单立方体场景中。 After setting up my uniforms I get a 1282 error from glGetError() for this piece of code 在设置我的制服之后,我从glGetError()获得了这段代码的1282错误

GLuint ambientHandle = glGetUniformLocation(program->getHandle(), "ambientProduct");
glUniform4fv( ambientHandle, 1, ambientProduct );
GLuint diffuseHandle = glGetUniformLocation(program->getHandle(), "diffuseProduct");
glUniform4fv( diffuseHandle, 1, diffuseProduct );
GLuint specularHandle = glGetUniformLocation(program->getHandle(), "specularProduct");
glUniform4fv( specularHandle, 1, specularProduct );
GLuint lightPosHandle = glGetUniformLocation(program->getHandle(), "lightPosition");
glUniform4fv( lightPosHandle, 1, light.position );
GLuint shinyHandle = glGetUniformLocation(program->getHandle(), "shininess");
glUniform1f( shinyHandle, materialShininess );

Here are my shaders: vertex.glsl 这是我的着色器:vertex.glsl

#version 120

attribute vec4 coord3d;
attribute vec3 normal3d;

// output values that will be interpretated per-fragment
varying  vec3 fN;
varying  vec3 fE;
varying  vec3 fL;

uniform vec4 lightPosition;
uniform mat4 mTransform;

void main()
{
    fN = normal3d;
    fE = coord3d.xyz;
    fL = lightPosition.xyz;

    if( lightPosition.w != 0.0 ) {
    fL = lightPosition.xyz - coord3d.xyz;
    }

    gl_Position = mTransform*coord3d;
}

fragment.glsl fragment.glsl

// per-fragment interpolated values from the vertex shader
varying  vec3 fN;
varying  vec3 fL;
varying  vec3 fE;

uniform vec4 ambientProduct, diffuseProduct, specularProduct;
uniform mat4 mTransform;
uniform vec4 lightPosition;
uniform float shininess;

void main() 
{ 
    // Normalize the input lighting vectors
    vec3 N = normalize(fN);
    vec3 E = normalize(fE);
    vec3 L = normalize(fL);

    vec3 H = normalize( L + E );

    vec4 ambient = ambientProduct;

    float Kd = max(dot(L, N), 0.0);
    vec4 diffuse = Kd*diffuseProduct;

    float Ks = pow(max(dot(N, H), 0.0), shininess);
    vec4 specular = Ks*specularProduct;

    // discard the specular highlight if the light's behind the vertex
    if( dot(L, N) < 0.0 ) {
    specular = vec4(0.0, 0.0, 0.0, 1.0);
    }

    gl_FragColor = ambient + diffuse + specular;
    gl_FragColor.a = 1.0;
} 

The products and position are each a struct of three GLfloats and shininess is a float. 产品和位置都是三个GLfloats的结构,光泽是浮动。 I have checked all of the values of the handles and the values I am passing and they all seem valid. 我检查了句柄的所有值和我传递的值,它们似乎都有效。 Ideas? 想法?

--EDIT: I have narrowed it to the glUniform4fv calls. --EDIT:我把它缩小到glUniform4fv调用。 It happens after each one. 它发生在每一个之后。 Also I have double checked that the program->getHandle() is pointing to something that looks valid. 我还仔细检查过program-> getHandle()指向看起来有效的东西。

I have checked program->getHandle is a valid program Here are the values of all handles: Program handle 3 ambientHandle 0 diffuseHandle 1 specularHandle 5 lightPosHandle 2 shinyHandle 4 我检查了program-> getHandle是一个有效的程序以下是所有句柄的值:程序句柄3 ambientHandle 0 diffuseHandle 1 specularHandle 5 lightPosHandle 2 shinyHandle 4

So they all look good. 所以他们看起来都很好。 For testing I am commenting out the lines below the ones for ambientProduct. 为了测试我正在评论ambientProduct的下面的行。 For clarity I am explicitly using this line instead 为清楚起见,我明确地使用这一行代替

glUniform4f( ambientHandle, ambientProd.x, ambientProd.y, ambientProd.z, ambientProd.w );

These are the values for ambientProd at the time that line is executed. 这些是执行该行时ambientProd的值。 x = 0.200000003, y = 0.0, z = 0.200000003, w = 1.0 x = 0.200000003,y = 0.0,z = 0.200000003,w = 1.0

A collaborator on this project moved the call for glUseProgram. 该项目的合作者移动了glUseProgram的调用。 Thanks for the help folks. 谢谢你们的帮助。

Error number ´1282` is not very descriptive. 错误号'1282`不是很具描述性。

Possible error codes for glGetUniformLocation are: glGetUniformLocation可能错误代码是:

GL_INVALID_VALUE
GL_INVALID_OPERATION

Which don't have a fixed value. 哪个没有固定值。 Try to get the error string with gluErrorString() or take a look in the header to which of those 1282 maps. 尝试使用gluErrorString()获取错误字符串,或者在标题中查看这些1282映射中的哪一个。

Just a shot in the dark: but did you ... 只是在黑暗中拍摄:但是你......

  • check your shader got compiled without error? 检查你的着色器编译没有错误?

  • check your shader got linked without error? 检查您的着色器是否链接没有错误?

BTW: return type is GLint not GLuint BTW:返回类型是GLint而不是GLuint

"Shaders compiled and linked without error" Hmm, this looks odd. “着色器编译和链接没有错误”嗯,这看起来很奇怪。

According to spec (see: http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml ) GL_INVALID_OPERATION should only be generated if: 根据规范(参见: http//www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml ),只有在以下情况下才能生成GL_INVALID_OPERATION

  • program is not a program objec 程序不是程序目标

  • program has not been successfully linked 程序尚未成功链接

Other question: 其他问题:

  • are you sure the getHandle() method of the class your program Object belongs to returns the right id. 你确定你的program对象所属的类的getHandle()方法返回正确的id。 I mean the one that was used in the sucessfully linking. 我指的是成功连接中使用的那个。

    you should be able to verify with checking if glIsProgram(program-getHandle()) returns GL_TRUE 您应该能够验证glIsProgram(program-getHandle())返回GL_TRUE

EDIT: Ah - I missed those calls to glUniform4fv in your example. 编辑:啊 - 我在你的例子中错过了对glUniform4fv调用。

Correct return type for glGetUniformLocation is still GLint , but I don't think thats the problem. glGetUniformLocation正确返回类型仍然是GLint ,但我不认为这是问题所在。

According to spec (see: http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml ) GLUniformXX generates GL_INVALID_OPERATION for a whole bunch of reasons. 根据规范(参见: http//www.opengl.org/sdk/docs/man/xhtml/glUniform.xml ), GLUniformXX生成GL_INVALID_OPERATION有很多原因。 To me the only one that possibly seems to apply is: 对我来说,唯一可能适用的是:

  • there is no current program object 没有当前的程序对象

    Did you call glUseProgram (program->getHandle()) prior to trying to calling glUniform() ? 你在尝试调用glUniform()之前调用了glUseProgram (program->getHandle()) glUniform()吗?

Generally this error number occurs when you are using a different programID from the programID generated by openGL at the time of creating the shader. 通常,当您在创建着色器时使用openGL生成的programID中的不同programID时,会出现此错误编号。 It means that you are using a different programID at the time of binding vertexShader or fragmentShader or whatever other shader you are using. 这意味着您在绑定vertexShaderfragmentShader或您正在使用的任何其他着色器时使用不同的programID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM