Hi, i have a Problem with my application. When i try to set a program uniform for my shader, i get an GL_INVALID_OPERATION error. That error code seems to be some kind of more general error code, so it is difficult for me to track the error down. I hope you can help me with this or have some ideas.
Here comes some code (scala + JOGL):
override def display(glautodrawable: GLAutoDrawable) {
println("FRAME: " + frameNo)
val gl = glautodrawable.getGL.getGL3
gl.glClear(GL.GL_COLOR_BUFFER_BIT)
gl.glClearColor(0, 0.5f, 1, 0)
//gl.glEnableClientState()
if (frameNo > 1) {
//_prog.use
gl.withProgram(_prog.id) {
println(gl.getInt(GL2.GL_MAX_VERTEX_ATTRIBS_ARB)) // => 29
println(gl.getInt(GL2GL3.GL_MAJOR_VERSION)) // => 3
println(gl.getProgramUniforms(_prog.id).mkString(","))
val attrIdx = 0
//_vbo.activate(0,"position")
_vbo.bind
gl.enableVertexAttribute(attrIdx)
gl.bindAttributeLocation(_prog.id, attrIdx, "position")
gl.vertexAttribPointer(attrIdx, 3, GL.GL_FLOAT)
gl.setProgramUniform(_prog.id, "projection", _camera.projectionMatrix) // <-- HERE
gl.setProgramUniform(_prog.id, "modelview", _camera.modelViewMatrix)
gl.drawPrimitives(Primitives.Triangles, 6)
gl.glDisableVertexAttribArray(attrIdx)
}
}
frameNo += 1
}
The marked line raises the error. I also tried to set a uniform float, but received the same error. If i move the line before line 21, then i still get the same error.
This is the vertex shader:
#version 140
uniform mat4 projection;
uniform mat4 modelview;
uniform mat4 scale_matrix;
uniform mat4 transform_matrix;
in vec3 position;
out vec4 color;
void main() {
gl_Position = projection * modelview * transform_matrix * scale_matrix * vec4(position, 1.0);
color = vec4(1.0,0,0,1);
}
When i run getProgramUniforms i receive:
(#,name,type,size)
--------------------
(0,projection,35676,1),
(1,modelview,35676,1),
(2,scale_matrix,35676,1),
(3,transform_matrix,35676,1)
This should be correct i think.
And this is how i set my uniform:
def setProgramUniform(program : Int, name : String, value : Float) {
val loc = getUniformLocation(program,name)
setProgramUniform(program,loc,value)
}
def setProgramUniform(program : Int, location : Int, value : Float) {
require(program>0)
require(native.glIsProgram(program))
require(isProgramLinked(program))
require(location >= 0)
native.glProgramUniform1f(program, location, value)
throwWhenError // <-- This raises
}
This is my error-checking function:
def handleError(error : Int) {
error match {
case GL.GL_NO_ERROR => {}
case GL.GL_INVALID_ENUM => throw new GLException("GL_INVALID_ENUM")
case GL.GL_INVALID_VALUE => throw new GLException("GL_INVALID_VALUE")
case GL.GL_INVALID_OPERATION => throw new GLException("GL_INVALID_OPERATION")
case GL.GL_INVALID_FRAMEBUFFER_OPERATION => throw new GLException("GL_INVALID_FRAMEBUFFER_OPERATION")
case GL.GL_OUT_OF_MEMORY => throw new GLException("GL_OUT_OF_MEMORY")
case _ => throw new RuntimeException("invalid gl-error number")
}
}
def throwWhenError = handleError(native.glGetError)
Is there a way i can debug this easier (I also tried the DebugGL instance instead of GL3, same result)?
Is there anything missing or set up incorrectly?
I am on linux mint 15 and i can play e.g. Left 4 Dead 2, Natural Selection 2, TF2, FarSky, Rust, …, so i am pretty sure that my setup is incorrect somewhere. If you need more code (e.g. shader setup) i can put that online (even though my shaders seem to compile fine).
I am thankful for any help.