[CLSD]No glMultiDrawElements overload for bound GL_ELEMENT_ARRAY_BUFFER use case

Started by blobjim, July 15, 2019, 22:29:09

Previous topic - Next topic

blobjim

In the OpenGL spec, the 'count' parameter of glMultiDrawElements is a pointer to an array of offsets if GL_ELEMENT_ARRAY_BUFFER  is bound, and a pointer to an array containing index arrays otherwise. The standard glMultiDrawElements methods in LWJGL only accept a PointerBuffer as the count parameter, and memAddress is called on that PointerBuffer, making it not useable for the offsets version of the function (unless there's some way to coerce an IntBuffer into a PointerBuffer?). for the time being nglMultiDrawElements can be used to get around this, but it would be nice to have an overload of the function with an IntBuffer count parameter who's memory address is passed to the unsafe version, it would avoid confusion.

Correct workaround:
nglMultiDrawElements(GL_TRIANGLES, MemoryUtil.memAddress(counts), GL_UNSIGNED_INT, MemoryUtil.memAddress(offsets), offsets.remaining());

spasi

The description above is confusing, the count parameter is already an IntBuffer. If you mean that you need a version where the indices parameter is an IntBuffer, that would be wrong:

- When no GL_ELEMENT_ARRAY_BUFFER is bound, indices is an array of pointers to system memory. Each pointer points to an array of indices, with element type specified by the type parameter and length specified by the corresponding index in the count parameter.
- When a GL_ELEMENT_ARRAY_BUFFER is bound, indices is an array of byte offsets (cast to a pointer type) into the bound GL_ELEMENT_ARRAY_BUFFER to start reading indices from.

In both cases, count is an IntBuffer and indices is a PointerBuffer. In the first case you fill the PointerBuffer with pointers (e.g. by calling memAddress on NIO buffers containing the indices), in the second case you fill the PointerBuffer with offsets (automatically converted to pointer values by LWJGL).

blobjim

Now I guess I know why nglMultiDrawElements was crashing occasionally (it must have been when it was not aligned properly). I spoke too soon. Thanks for the help.