The following
IntBuffer viewport = BufferUtils.createIntBuffer(4);
GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);
System.out.println("viewport: " + viewport.get() + " " + viewport.get() + " " + viewport.get() + " " + viewport.get());
yields to
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Number of remaining buffer elements is 4, must be at least 16
at org.lwjgl.BufferChecks.throwBufferSizeException(BufferChecks.java:162)
at org.lwjgl.BufferChecks.checkBufferSize(BufferChecks.java:189)
at org.lwjgl.BufferChecks.checkBuffer(BufferChecks.java:244)
at org.lwjgl.opengl.GL11.glGetInteger(GL11.java:1355)
Try doing "viewport.rewind()" right before glGetInteger.
As the error message indicates - glGetInteger requires a buffer with 16 remaining slots. This is the maximum number of values which OpenGL's glGetInteger can return.
Quote from: Matthias on April 20, 2011, 05:20:01
As the error message indicates - glGetInteger requires a buffer with 16 remaining slots. This is the maximum number of values which OpenGL's glGetInteger can return.
Although 16 values probably is the maximum number glGetInteger can return, with pname 'GL_VIEWPORT' it is 4.
http://www.opengl.org/sdk/docs/man/xhtml/glGet.xml (http://www.opengl.org/sdk/docs/man/xhtml/glGet.xml):
Quote
GL_VIEWPORT params returns four values:
the x and y window coordinates of the viewport, followed by its width and height. Initially the x and y window coordinates are both set to 0, and the width and height are set to the width and height of the window into which the GL will do its rendering. See glViewport.
This has been discussed before for another similar function (glGetFloat): http://lwjgl.org/forum/index.php/topic,1354.0.html
Although you only use 4 in this case, there is no fast and simple way to determine how much space you should have based on your parameters, so LWJGL just requires you to have 16 (the maximum that could be returned).
You may not like it, but that is just the way it is. ;D
Sad, but I guess I'll have to live with that..
at least note in the Javadoc would be appreciated though if the function are not standard conform!
At the C level there's no check; if you ask for GL_VIEWPORT and pass a pointer with 0-3 values left, you get buffer overflow nastiness. At the Java levels we have 3 options:
a) Do no check at all, let the programmer figure out what happened when the VM crashes.
b) Add a big switch statement with all possible parameters (that's a LOT of params, many new ones are added with each GL version/extension), find the necessary space required, then check the buffer's remaining().
c) Do what we do now, require a 16-value buffer which covers all possible parameters.
I think c) offers the best balance between performance, safety and maintainability. You can also make LWJGL work like a), by passing the org.lwjgl.util.NoChecks=true VM parameter. Finally, we provide scalar versions of glGet functions which cover the majority of usages (e.g. int glGetInteger(int pname) in GL11).
Good point about the Javadoc though, I'll see if I can add comments to the appropriate methods.
Quote from: spasi on April 21, 2011, 14:19:58
You can also make LWJGL work like a), by passing the org.lwjgl.util.NoChecks=true VM parameter.
Cool, that's actually not a bad option - thx for the info :-)
But don't post bug reports about VM crashes when you use this parameter.