Query Buffer

Started by sumwise, September 09, 2020, 19:07:37

Previous topic - Next topic



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


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.


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.


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....


Thanks Sumwise, the buffer object offset overloads will be available in the next 3.2.4 snapshot (will be available soon).


Thanks both for your answers!
Now that is some awesome news (not so much for lwjgl2 but that's fine) so thanks again