From: Paul Gofman pgofman@codeweavers.com
Signed-off-by: Paul Gofman pgofman@codeweavers.com --- dlls/opengl32/tests/opengl.c | 21 +++++++++++++++++++++ dlls/opengl32/wgl.c | 16 +++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/dlls/opengl32/tests/opengl.c b/dlls/opengl32/tests/opengl.c index 8b0e70ccf9c..0a37223ab80 100644 --- a/dlls/opengl32/tests/opengl.c +++ b/dlls/opengl32/tests/opengl.c @@ -342,6 +342,27 @@ static void test_choosepixelformat(void) pfd.cDepthBits = 0; pfd.cStencilBits = 0; pfd.dwFlags &= ~PFD_DEPTH_DONTCARE; + + pfd.cDepthBits = 16; + ok( test_pfd(&pfd, &ret_fmt), "depth 16 failed.\n" ); + ok( ret_fmt.cDepthBits >= 16, "Got unexpected cDepthBits %u.\n", ret_fmt.cDepthBits ); + pfd.cDepthBits = 0; + + pfd.cDepthBits = 16; + pfd.cStencilBits = 8; + ok( test_pfd(&pfd, &ret_fmt), "depth 16, stencil 8 failed.\n" ); + ok( ret_fmt.cDepthBits >= 16, "Got unexpected cDepthBits %u.\n", ret_fmt.cDepthBits ); + ok( ret_fmt.cStencilBits == 8, "Got unexpected cStencilBits %u.\n", ret_fmt.cStencilBits ); + pfd.cDepthBits = 0; + pfd.cStencilBits = 0; + + pfd.cDepthBits = 8; + pfd.cStencilBits = 8; + ok( test_pfd(&pfd, &ret_fmt), "depth 8, stencil 8 failed.\n" ); + ok( ret_fmt.cDepthBits >= 16, "Got unexpected cDepthBits %u.\n", ret_fmt.cDepthBits ); + ok( ret_fmt.cStencilBits == 8, "Got unexpected cStencilBits %u.\n", ret_fmt.cStencilBits ); + pfd.cDepthBits = 0; + pfd.cStencilBits = 0; }
static void WINAPI gl_debug_message_callback(GLenum source, GLenum type, GLuint id, GLenum severity, diff --git a/dlls/opengl32/wgl.c b/dlls/opengl32/wgl.c index bd7f7d22e98..a2845a08ca8 100644 --- a/dlls/opengl32/wgl.c +++ b/dlls/opengl32/wgl.c @@ -454,6 +454,7 @@ INT WINAPI wglChoosePixelFormat(HDC hdc, const PIXELFORMATDESCRIPTOR* ppfd) PIXELFORMATDESCRIPTOR format, best; int i, count, best_format; int bestDBuffer = -1, bestStereo = -1; + BYTE cDepthBits;
TRACE_(wgl)( "%p %p: size %u version %u flags %u type %u color %u %u,%u,%u,%u " "accum %u depth %u stencil %u aux %u\n", @@ -464,6 +465,15 @@ INT WINAPI wglChoosePixelFormat(HDC hdc, const PIXELFORMATDESCRIPTOR* ppfd) count = wglDescribePixelFormat( hdc, 0, 0, NULL ); if (!count) return 0;
+ cDepthBits = ppfd->cDepthBits; + if (ppfd->dwFlags & PFD_DEPTH_DONTCARE) cDepthBits = 0; + else if (ppfd->cStencilBits && cDepthBits <= 16) + { + /* Even if, e. g., depth 16, stencil 8 is available Window / AMD may return 24x8 (and not 16x0). + * Adjust to 24 as 24x8 is universally available and we won't end up without stencil. */ + cDepthBits = 24; + } + best_format = 0; best.dwFlags = 0; best.cAlphaBits = -1; @@ -564,10 +574,10 @@ INT WINAPI wglChoosePixelFormat(HDC hdc, const PIXELFORMATDESCRIPTOR* ppfd) continue; } } - if (ppfd->cDepthBits && !(ppfd->dwFlags & PFD_DEPTH_DONTCARE)) + if (cDepthBits) { - if (((ppfd->cDepthBits > best.cDepthBits) && (format.cDepthBits > best.cDepthBits)) || - ((format.cDepthBits >= ppfd->cDepthBits) && (format.cDepthBits < best.cDepthBits))) + if (((cDepthBits > best.cDepthBits) && (format.cDepthBits > best.cDepthBits)) || + ((format.cDepthBits >= cDepthBits) && (format.cDepthBits < best.cDepthBits))) goto found;
if (best.cDepthBits != format.cDepthBits)