From 70a5fc323af9b9721704aeffd604f0f8aaa01538 Mon Sep 17 00:00:00 2001 From: Archez Date: Sat, 24 Feb 2024 20:24:58 -0500 Subject: [PATCH] fix opengl framebuffer depth reads (#426) (#7) (cherry picked from commit 21a5df591fe00cc982e4d6c268b33822e04d96e2) --- src/graphic/Fast3D/gfx_opengl.cpp | 4 +++- src/graphic/Fast3D/gfx_sdl2.cpp | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/graphic/Fast3D/gfx_opengl.cpp b/src/graphic/Fast3D/gfx_opengl.cpp index 512da0f80..edef951aa 100644 --- a/src/graphic/Fast3D/gfx_opengl.cpp +++ b/src/graphic/Fast3D/gfx_opengl.cpp @@ -1099,7 +1099,9 @@ gfx_opengl_get_pixel_depth(int fb_id, const std::set>& c Framebuffer& fb = framebuffers[fb_id]; - if (coordinates.size() == 1) { + // When looking up one value and the framebuffer is single-sampled, we can read pixels directly + // Otherwise we need to blit first to a new buffer then read it + if (coordinates.size() == 1 && fb.msaa_level <= 1) { uint32_t depth_stencil_value; glBindFramebuffer(GL_FRAMEBUFFER, fb.fbo); int x = coordinates.begin()->first; diff --git a/src/graphic/Fast3D/gfx_sdl2.cpp b/src/graphic/Fast3D/gfx_sdl2.cpp index afab998b9..23581b632 100644 --- a/src/graphic/Fast3D/gfx_sdl2.cpp +++ b/src/graphic/Fast3D/gfx_sdl2.cpp @@ -302,6 +302,7 @@ static void gfx_sdl_init(const char* game_name, const char* gfx_api_name, bool s if (use_opengl) { SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); } else { SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal");