libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.36k stars 1.74k forks source link

Add an ability to setup a float-point depth buffer #3633

Closed SDLBugzilla closed 1 month ago

SDLBugzilla commented 3 years ago

This bug report was migrated from our old Bugzilla tracker.

Reported in version: don't know Reported for operating system, platform: All, All

Comments on the original bug report:

On 2020-04-11 06:35:45 +0000, Andrei Kortunov wrote:

As I understood, by default SDL uses a 16-bits depth buffer, with ability to setup something like GL_DEPTH24_STENCIL8 via such command:

SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

Unfortunately, 24-bits depth buffer precision is still not enough for open-world games. Is it possible to setup a float-point depth buffer via SDL, a GL_DEPTH_COMPONENT32F, or maybe even GL_DEPTH32F_STENCIL8? If it is not, it would be nice to have such ability.

On 2020-06-26 11:54:05 +0000, wrote:

I would like to second this request.

OpenMW[1] would really benefit from having more depth buffer precision. It would all but eliminate an issue we are having with z-fighting[2].

I'm sure other software that use libsdl would benefit from this.

Cheers, Bret Curtis

[1] https://openmw.org/ [2] https://en.wikipedia.org/wiki/Z-fighting

flibitijibibo commented 2 months ago

Running through SDL_Render issues tagged for 3.0 ABI, sorry if you get multiple e-mails for this...

If it helps at all, we've added this to our GPU API at #9312 - it wouldn't help with the GL subsystem but could be helpful for migrating to _gpu and maybe SDL_Render if depth buffers are supported there.

icculus commented 1 month ago

So this is actually not available in OpenGL as requested, which surprised me.

glX doesn't have it, Cocoa doesn't have it, EGL as a whole doesn't have it.

(WGL_EXT_depth_float does offer this on windows, but the GL_ARB_depth_buffer_float spec suggests it's rarely-used.)

The correct way to do this seems to be to create your GL context as usual, maybe with no depth buffer at all, then make a framebuffer object, and attach a texture/renderbuffer in GL_DEPTH_COMPONENT32F format to that FBO, assuming that's supported on your GL implementation, and render to that instead of the window framebuffer. Then before swapping buffers, blit from the FBO to the window framebuffer. As far as I can tell.

But we can't usefully offer this as something you can set when creating the GL context through SDL_GL_SetAttribute.

(If I'm wrong, we can reopen this, though!)