mosra / magnum

Lightweight and modular C++11 graphics middleware for games and data visualization
https://magnum.graphics/
Other
4.75k stars 439 forks source link

Add support for glDepthRangedNV() / glClipControl() #543

Closed king-numsgil closed 1 year ago

king-numsgil commented 2 years ago

Hello! I'm trying to use a Reversed Floating-Point Depth Buffer (following this post) and I see that I can create a Depth32F buffer but there are no functions for depth range. According to the post, I need to be using nVidia's extension. How would I go about adding support for this in Magnum? This could be my first contribution to an open-source project but I can't even find the GL loader...

Can someone point me in the right direction? Thanks!

pezcode commented 2 years ago

That blog post is fairly old, nowadays you can do that with glClipControl and GL_NEGATIVE_ONE_TO_ONE, but that requires GL 4.5.

If you need to use that old extension (maybe on Mac), it's a bit more involved:

You can check for its presence with:

bool supported = GL::Context::current().isExtensionSupported<GL::Extensions::NV::depth_buffer_float>();

But to use the functions, you probably need to regenerate the GL loader coming with Magnum (flextGL), since that NV extension is not listed here.

king-numsgil commented 2 years ago

Thanks for pointing that out! My target version is 4.6 core so this should be better. I just found a post from nVidia talking about that. But the problem is still there : Magnum has not exposed this function. I'll look into it. Thanks!

mosra commented 2 years ago

Hi! :)

The raw entrypoint from GL 4.5 is there, so you can just call it the same way as you'd do in plain GL, and the corresponding enums should be there as well: https://github.com/mosra/magnum/blob/663c9e17b7010414d6be7d95c894dc6ddad63e1f/src/MagnumExternal/OpenGL/GL/flextGL.h#L3294

It's not exposed in any Magnum APIs (that would have to be implemented), but since this function doesn't modify any state that Magnum would track, it should be fine to just call it directly.

If you're fine with calling the GL API directly for now, I'll add this to my list of things to implement. Rather busy right now, so I can't promise when that will get done.

king-numsgil commented 2 years ago

Alright, that'll do!! Thanks a lot! And since it can be used without changing Magnum, it could be low priority.

mosra commented 1 year ago

Implemented in 56a850f9ad24f9db23f54fb080b5fbfc68a390d2 and db290242509fb11b8a35bc445129030e54ea17db. Half a century later but nevertheless :sweat_smile: