LWJGL
May 22, 2013, 22:29:30 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.9.0 released!
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: [CLOSED] GL11.glGetInteger(GL11.GL_VIEWPORT, ..)  (Read 2934 times)
michael.nischt
Newbie
*
Posts: 9


« on: April 19, 2011, 14:20:24 »

The following

Code:
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:
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)
Logged
jediTofu
Prolific Timewaster
****
Posts: 280



« Reply #1 on: April 19, 2011, 17:41:58 »

Try doing "viewport.rewind()" right before glGetInteger.
Logged

cool story, bro
Matthias
Talks Too Much
***
Posts: 180


WWW
« Reply #2 on: April 19, 2011, 22: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.
Logged

michael.nischt
Newbie
*
Posts: 9


« Reply #3 on: April 20, 2011, 03: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.
Logged
Fool Running
Nerdus Imperius
*****
Posts: 742


« Reply #4 on: April 20, 2011, 05: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. Grin
Logged

Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option Grin
michael.nischt
Newbie
*
Posts: 9


« Reply #5 on: April 20, 2011, 05: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!
Logged
spasi
Nerdus Imperius
*****
Posts: 752



WWW
« Reply #6 on: April 21, 2011, 07: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.
Logged
michael.nischt
Newbie
*
Posts: 9


« Reply #7 on: April 22, 2011, 02: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 :-)
Logged
Matthias
Talks Too Much
***
Posts: 180


WWW
« Reply #8 on: April 22, 2011, 03:41:06 »

But don't post bug reports about VM crashes when you use this parameter.
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!