Hello Guest

Query Buffer

  • 5 Replies
  • 121 Views
Query Buffer
« on: September 09, 2020, 19:07:37 »
Hello,

I'm having a hard time trying to wrap my head around how to make use of OpenGL GL_QUERY_BUFFER
From what i understand, as soon as a buffer is bound to that target, glGetQueryObject changes its behaviour,
however looking at https://github.com/LWJGL/lwjgl3/blob/master/modules/lwjgl/opengl/src/generated/java/org/lwjgl/opengl/GL15C.java line 940
it seems to always use the memAddress of the provided IntBuffer, is there an extra method added for that purpose that i cannot find?

EDIT: I'm sorry i should mention that i search for a solution that supports both, lwjgl2 and lwjgl3 as for lwjgl3 i could just call the nglGetQueryObject (notice the n) method myself

Thanks a lot in advance and have a nice day
Sumwise

« Last Edit: September 09, 2020, 19:22:43 by sumwise »

*

Offline KaiHH

  • ****
  • 277
Re: Query Buffer
« Reply #1 on: September 10, 2020, 10:08:31 »
The method overload of glGetQueryObjectiv taking an IntBuffer calls https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGetQueryObject.xhtml and stores the result of that call (i.e. either GL_QUERY_RESULT or GL_QUERY_RESULT_AVAILABLE) into the supplied IntBuffer. It has nothing to do with query buffer objects.
Also note that you cannot use both LWJGL 2 and LWJGL 3 at runtime as both define the same classes with different/incompatible signatures and natives. You can _only_ have either LWJGL 2 or LWJGL 3 in the runtime classpath/modulepath.

Re: Query Buffer
« Reply #2 on: September 10, 2020, 20:19:17 »
Thanks for your reply
However the same link you provided mentions the exact same behaviour that I tried to explain.
Additionally calling nglGetQueryObject(id, GL_QUERY_RESULT, 0) when a buffer is bound to the aforementioned target, it actually works and the expected values are written into the beginning of the buffer.

However I assume (on the way atm and cannot test it) it will crash the app when no buffer is bound to that target as GL will interpret it as a memory address (hence the memAddress(intbuffer) part that is used to "calculate" the last parameter for the ngl call and there is no way to get the same behaviour with lwjgl2 at least to my knowledge

Why I mention lwjgl2 and lwjgl3 is because I use jMonkeyengine and providing an implementation for those that use lwjgl2 still would have been handy.

*

Offline KaiHH

  • ****
  • 277
Re: Query Buffer
« Reply #3 on: September 10, 2020, 21:21:48 »
I am very sorry, I did actually misunderstand your initial question. That really was an error on my part.
Yes, it seems that this particular method is missing an important overload taking a simple long like glVertexAttribPointer() or glDrawElements() when the last argument should be interpreted as a buffer offset when a buffer object is bound to a particular buffer binding point.
To use this method with a bound buffer you would have to use the 'n' overload in LWJGL 3, indeed. And I don't see a solution for LWJGL 2 to achieve the same. You would essentially need to construct a NIO buffer with an explicit buffer address (which would then be the offset), which is only doable in LWJGL 3's MemoryUtil.memByteBuffer(long, int) , but not so much in LWJGL 2... hmm....
« Last Edit: September 11, 2020, 10:52:18 by KaiHH »

*

Offline spasi

  • *****
  • 2198
    • WebHotelier
Re: Query Buffer
« Reply #4 on: September 11, 2020, 12:12:31 »
Thanks Sumwise, the buffer object offset overloads will be available in the next 3.2.4 snapshot (will be available soon).

Re: Query Buffer
« Reply #5 on: September 11, 2020, 14:53:28 »
Thanks both for your answers!
Now that is some awesome news (not so much for lwjgl2 but that's fine) so thanks again