LukasBanana / LLGL

Low Level Graphics Library (LLGL) is a thin abstraction layer for the modern graphics APIs OpenGL, Direct3D, Vulkan, and Metal
BSD 3-Clause "New" or "Revised" License
2.1k stars 139 forks source link

Fixed-index primitive restart should now work in OpenGL version 3.1 and up. #59

Closed beldenfox closed 4 years ago

beldenfox commented 4 years ago

Added a sample program which exercises the fixed-index primitive restart feature. On OpenGL before 4.3 this has to be implemented by enabling GL_PRIMITIVE_RESTART and then calling glPrimitiveRestartIndex to ensure the index is set appropriately for the width of the current index buffer entries.

This pull request is primarily a design review. The question is when to update the restart index to match the width of the index buffer entries. My approach was to do this at the point where the index buffer becomes "active" i.e. bound to the currently bound VAO (in whatever order those bindings occur). I think I tracked down the point in the code where this happens but am not entirely sure.

An alternative was to track down every glDrawElements* call and update the restart index just before the call. This would ensure that the restart index was only updated when absolutely necessary but that approach involved more changes and didn't seem as maintainable.

beldenfox commented 4 years ago

I cleaned up the screenshot. I now realize that an 800x600 window will produce a 1600x1200 screenshot on a Retina display (plus more for the title bar and such) which makes sense given how Retina works.

LukasBanana commented 4 years ago

@beldenfox I submitted a few updates with 8065922 especially to address the loading of glPrimitiveRestartIndex which seems to be part of the GL_ARB_compatibility extension (which is why it's hard to find it online).

Your example also reveals that the primitive restart index for 16 bit index buffers doesn't work for D3D12 (see attached screenshot), but that's on me. Unfortunately though, I currently don't have an elegant solution for that.

21_PrimitiveRestart_ErrorOnD3D12