Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (736)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (814)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  GL_INVALID_OPERATION when setting program uniform  (Read 749 times)
0 Members and 1 Guest are viewing this topic.
Offline Ragmaanir

Junior Newbie





« Posted 2014-05-06 19:34:34 »

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):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
#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:
1  
2  
3  
4  
5  
6  
(#,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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
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.
Offline theagentd
« Reply #1 - Posted 2014-05-07 00:16:33 »

You need to use the proper OpenGL function for updating a uniform mat4 variable.
native.glProgramUniform1f
is actually an OpenGL 4.1 function, so if you want to use the same function but for matrices you need to use
glProgramUniformMatrix4()
. Most likely though you actually want to use
glUniformMatrix4()
which works on the currently bound shader program and only requires OpenGL 2.0.

Myomyomyo.
Offline Ragmaanir

Junior Newbie





« Reply #2 - Posted 2014-05-07 17:23:44 »

Thank you SO much! Cool
You have no idea how much time i wasted on this problem.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 
cybrmynd (138 views)
2017-08-02 12:28:51

cybrmynd (159 views)
2017-08-02 12:19:43

cybrmynd (153 views)
2017-08-02 12:18:09

Sralse (169 views)
2017-07-25 17:13:48

Archive (648 views)
2017-04-27 17:45:51

buddyBro (767 views)
2017-04-05 03:38:00

CopyableCougar4 (1301 views)
2017-03-24 15:39:42

theagentd (1265 views)
2017-03-24 15:32:08

Rule (1237 views)
2017-03-19 12:43:22

Rule (1312 views)
2017-03-19 12:42:17
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!