Hello Guest

[CLOSED] GL11.glGetInteger(GL11.GL_VIEWPORT, ..)

  • 8 Replies
  • 11054 Views
[CLOSED] GL11.glGetInteger(GL11.GL_VIEWPORT, ..)
« on: April 19, 2011, 21:20:24 »
The following

Code: [Select]
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

Code: [Select]
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)

Re: [BUG] GL11.glGetInteger(GL11.GL_VIEWPORT, ..)
« Reply #1 on: April 20, 2011, 00:41:58 »
Try doing "viewport.rewind()" right before glGetInteger.
cool story, bro

Re: [BUG] GL11.glGetInteger(GL11.GL_VIEWPORT, ..)
« Reply #2 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.

Re: [BUG] GL11.glGetInteger(GL11.GL_VIEWPORT, ..)
« Reply #3 on: April 20, 2011, 10:39:21 »
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:

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.

Re: [BUG] GL11.glGetInteger(GL11.GL_VIEWPORT, ..)
« Reply #4 on: April 20, 2011, 12:35:18 »
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
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Re: [BUG] GL11.glGetInteger(GL11.GL_VIEWPORT, ..)
« Reply #5 on: April 20, 2011, 12:41:39 »
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!

*

Offline spasi

  • *****
  • 2212
    • WebHotelier
Re: [BUG] GL11.glGetInteger(GL11.GL_VIEWPORT, ..)
« Reply #6 on: April 21, 2011, 14:19:58 »
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.
« Last Edit: April 21, 2011, 15:33:23 by spasi »

Re: [BUG] GL11.glGetInteger(GL11.GL_VIEWPORT, ..)
« Reply #7 on: April 22, 2011, 09:46:54 »
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 :-)

Re: [BUG] GL11.glGetInteger(GL11.GL_VIEWPORT, ..)
« Reply #8 on: April 22, 2011, 10:41:06 »
But don't post bug reports about VM crashes when you use this parameter.