diff --git a/modules/rostests/apitests/CMakeLists.txt b/modules/rostests/apitests/CMakeLists.txt index 5312b2838f..cea2bd6ed0 100644 --- a/modules/rostests/apitests/CMakeLists.txt +++ b/modules/rostests/apitests/CMakeLists.txt @@ -25,6 +25,7 @@ add_subdirectory(netapi32) add_subdirectory(netshell) add_subdirectory(ntdll) add_subdirectory(ole32) +add_subdirectory(opengl32) add_subdirectory(pefile) add_subdirectory(powrprof) add_subdirectory(sdk) diff --git a/modules/rostests/apitests/opengl32/CMakeLists.txt b/modules/rostests/apitests/opengl32/CMakeLists.txt new file mode 100644 index 0000000000..6fddd120e1 --- /dev/null +++ b/modules/rostests/apitests/opengl32/CMakeLists.txt @@ -0,0 +1,6 @@ + +add_executable(opengl32_apitest sw_extensions.c sw_pixelformat.c testlist.c) +target_link_libraries(opengl32_apitest wine) +set_module_type(opengl32_apitest win32cui) +add_importlibs(opengl32_apitest opengl32 gdi32 user32 msvcrt kernel32) +add_rostests_file(TARGET opengl32_apitest) diff --git a/modules/rostests/apitests/opengl32/sw_extensions.c b/modules/rostests/apitests/opengl32/sw_extensions.c new file mode 100644 index 0000000000..3329645ae4 --- /dev/null +++ b/modules/rostests/apitests/opengl32/sw_extensions.c @@ -0,0 +1,78 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: BSD - See COPYING.ARM in the top level directory + * PURPOSE: Tests extensions exposed by the software implementation + * PROGRAMMERS: Jérôme Gardou + */ + +#include +#include +#include + +#include "wine/test.h" + +START_TEST(sw_extensions) +{ + BITMAPINFO biDst; + HDC hdcDst = CreateCompatibleDC(0); + HBITMAP bmpDst, bmpOld; + INT nFormats, iPixelFormat, res, i; + PIXELFORMATDESCRIPTOR pfd; + const char* output; + HGLRC Context; + UINT *dstBuffer = NULL; + + memset(&biDst, 0, sizeof(BITMAPINFO)); + biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + biDst.bmiHeader.biWidth = 4; + biDst.bmiHeader.biHeight = -4; + biDst.bmiHeader.biPlanes = 1; + biDst.bmiHeader.biBitCount = 32; + biDst.bmiHeader.biCompression = BI_RGB; + + bmpDst = CreateDIBSection(0, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer, NULL, 0); + + bmpOld = SelectObject(hdcDst, bmpDst); + + /* Choose a pixel format */ + nFormats = DescribePixelFormat(hdcDst, 0, 0, NULL); + for(i=1; i<=nFormats; i++) + { + memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); + DescribePixelFormat(hdcDst, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd); + + if((pfd.dwFlags & PFD_DRAW_TO_BITMAP) && + (pfd.dwFlags & PFD_SUPPORT_OPENGL) && + (pfd.cColorBits == 32) && + (pfd.cAlphaBits == 8) ) + { + iPixelFormat = i; + break; + } + } + + ok(pfd.dwFlags & PFD_GENERIC_FORMAT, "We found a pixel format for drawing to bitmap which is not generic !\n"); + ok (iPixelFormat >= 1 && iPixelFormat <= nFormats, "Could not find a suitable pixel format.\n"); + res = SetPixelFormat(hdcDst, iPixelFormat, &pfd); + ok (res != 0, "SetPixelFormat failed.\n"); + Context = wglCreateContext(hdcDst); + ok(Context != NULL, "We failed to create a GL context.\n"); + wglMakeCurrent(hdcDst, Context); + + /* Get the version */ + output = (const char*)glGetString(GL_VERSION); + ok(strcmp(output, "1.1.0") == 0, "Expected version 1.1.0, got \"%s\".\n", output); + + /* Get the extensions list */ + output = (const char*)glGetString(GL_EXTENSIONS); + trace("GL extensions are %s.\n", output); + ok (strlen(output) == strlen("GL_WIN_swap_hint GL_EXT_bgra GL_EXT_paletted_texture"), "Wrong extension list : \"%s\".\n", output); + ok(strstr(output, "GL_WIN_swap_hint") != NULL, "GL_WIN_swap_hint extension is not present.\n"); + ok(strstr(output, "GL_EXT_bgra") != NULL, "GL_EXT_bgra extension is not present.\n"); + ok(strstr(output, "GL_EXT_paletted_texture") != NULL, "GL_EXT_paletted_texture extension is not present.\n"); + + /* cleanup */ + wglDeleteContext(Context); + SelectObject(hdcDst, bmpOld); + DeleteDC(hdcDst); +} diff --git a/modules/rostests/apitests/opengl32/sw_pixelformat.c b/modules/rostests/apitests/opengl32/sw_pixelformat.c new file mode 100644 index 0000000000..ce2877d018 --- /dev/null +++ b/modules/rostests/apitests/opengl32/sw_pixelformat.c @@ -0,0 +1,206 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: BSD - See COPYING.ARM in the top level directory + * PURPOSE: Tests extensions exposed by the software implementation + * PROGRAMMERS: Jérôme Gardou + */ + +#include +#include +#include +#include + +#include "wine/test.h" + +static char* str_dbg_pfd_flags(DWORD flags) +{ + static char buffer[1000]; + BOOL first = TRUE; + + buffer[0] = 0; + +#define FLAGS_TO_STR(__x__) \ + do { \ + if (flags & __x__) \ + { \ + if (!first) strcat(buffer, " | "); \ + strcat(buffer, #__x__); \ + first = FALSE; \ + flags &= ~__x__; \ + } \ + } while(0) + + FLAGS_TO_STR(PFD_DOUBLEBUFFER); + FLAGS_TO_STR(PFD_STEREO); + FLAGS_TO_STR(PFD_DRAW_TO_WINDOW); + FLAGS_TO_STR(PFD_DRAW_TO_BITMAP); + FLAGS_TO_STR(PFD_SUPPORT_GDI); + FLAGS_TO_STR(PFD_SUPPORT_OPENGL); + FLAGS_TO_STR(PFD_GENERIC_FORMAT); + FLAGS_TO_STR(PFD_NEED_PALETTE); + FLAGS_TO_STR(PFD_NEED_SYSTEM_PALETTE); + FLAGS_TO_STR(PFD_SWAP_EXCHANGE); + FLAGS_TO_STR(PFD_SWAP_COPY); + FLAGS_TO_STR(PFD_SWAP_LAYER_BUFFERS); + FLAGS_TO_STR(PFD_GENERIC_ACCELERATED); + FLAGS_TO_STR(PFD_SUPPORT_COMPOSITION); + + if (flags) + { + char tmp[16]; + sprintf(tmp, " | 0x%08x", (UINT)flags); + strcat(buffer, tmp); + } + + return buffer; +} + +static const struct +{ + BYTE iPixelType; + BYTE cColorBits; + BYTE cRedBits; BYTE cRedShift; + BYTE cGreenBits; BYTE cGreenShift; + BYTE cBlueBits; BYTE cBlueShift; + BYTE cAlphaBits; BYTE cAlphaShift; + BYTE cAccumBits; + BYTE cAccumRedBits; BYTE cAccumGreenBits; BYTE cAccumBlueBits; BYTE cAccumAlphaBits; +} test_colors[] = +{ + {PFD_TYPE_RGBA, 32, 8, 16, 8, 8, 8, 0, 0, 0, 64, 16, 16, 16, 0}, + {PFD_TYPE_RGBA, 32, 8, 16, 8, 8, 8, 0, 8, 0, 64, 16, 16, 16, 16}, + {PFD_TYPE_COLORINDEX, 32, 8, 16, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0}, + {PFD_TYPE_RGBA, 24, 8, 16, 8, 8, 8, 0, 0, 0, 64, 16, 16, 16, 0}, + {PFD_TYPE_RGBA, 24, 8, 16, 8, 8, 8, 0, 8, 0, 64, 16, 16, 16, 16}, + {PFD_TYPE_COLORINDEX, 24, 8, 16, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0}, + {PFD_TYPE_RGBA, 16, 5, 10, 5, 5, 5, 0, 0, 0, 32, 11, 11, 10, 0}, + {PFD_TYPE_RGBA, 16, 5, 10, 5, 5, 5, 0, 8, 0, 32, 8, 8, 8, 8}, + {PFD_TYPE_COLORINDEX, 16, 5, 10, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0}, + {PFD_TYPE_RGBA, 8, 3, 0, 3, 3, 2, 6, 0, 0, 32, 11, 11, 10, 0}, + {PFD_TYPE_RGBA, 8, 3, 0, 3, 3, 2, 6, 8, 0, 32, 8, 8, 8, 8}, + {PFD_TYPE_COLORINDEX, 8, 3, 0, 3, 3, 2, 6, 0, 0, 0, 0, 0, 0, 0}, + {PFD_TYPE_RGBA, 4, 1, 0, 1, 1, 1, 2, 0, 0, 16, 5, 6, 5, 0}, + {PFD_TYPE_RGBA, 4, 1, 0, 1, 1, 1, 2, 8, 0, 16, 4, 4, 4, 4}, + {PFD_TYPE_COLORINDEX, 4, 1, 0, 1, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0}, +}; + +static const BYTE test_depths[] = { 32, 16 }; + +static void test_format(HDC hdc, int num_pf, int pf, int i, int j, BOOL is_window, BOOL is_double_buffered) +{ + PIXELFORMATDESCRIPTOR pfd; + int ret; + + ret = DescribePixelFormat(hdc, pf, sizeof(pfd), &pfd); + ok(ret == num_pf, "Number of pixel formats changed!\n"); + + ok(pfd.nSize == sizeof(pfd), "Wrong nSize for format %i, expected %u, got %u\n", pf, (WORD)sizeof(pfd), pfd.nSize); + ok(pfd.nVersion == 1, "Wrong nVersion for format %i, expected 1, got %u\n", pf, pfd.nVersion); + if (is_window) + { + if (is_double_buffered) + { + ok((pfd.dwFlags == (PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_GENERIC_FORMAT | PFD_SWAP_COPY)) + || (pfd.dwFlags == (PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_GENERIC_FORMAT | PFD_SWAP_COPY | PFD_SUPPORT_COMPOSITION)), + "Wrong dwFlags for format %i, expected PFD_DRAW_TO_WINDOW | PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_SUPPORT_OPENGL | PFD_GENERIC_FORMAT, got %s\n", + pf, str_dbg_pfd_flags(pfd.dwFlags)); + } + else + { + ok((pfd.dwFlags == (PFD_DRAW_TO_WINDOW | PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_SUPPORT_OPENGL | PFD_GENERIC_FORMAT)) + || (pfd.dwFlags == (PFD_DRAW_TO_WINDOW | PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_SUPPORT_OPENGL | PFD_GENERIC_FORMAT | PFD_SUPPORT_COMPOSITION)), + "Wrong dwFlags for format %i, expected PFD_DRAW_TO_WINDOW | PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_SUPPORT_OPENGL | PFD_GENERIC_FORMAT, got %s\n", + pf, str_dbg_pfd_flags(pfd.dwFlags)); + } + } + else + { + ok(pfd.dwFlags == (PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_SUPPORT_OPENGL | PFD_GENERIC_FORMAT), + "Wrong dwFlags for format %i, expected PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_SUPPORT_OPENGL | PFD_GENERIC_FORMAT, got %s\n", + pf, str_dbg_pfd_flags(pfd.dwFlags)); + } + +#define TEST_FIELD(__x__) ok(pfd.__x__ == test_colors[i].__x__, "Wrong " #__x__ " for format %i, expected %u, got %u\n", pf, test_colors[i].__x__, pfd.__x__) + TEST_FIELD(iPixelType); + TEST_FIELD(cColorBits); + TEST_FIELD(cRedBits); + TEST_FIELD(cRedShift); + TEST_FIELD(cGreenBits); + TEST_FIELD(cGreenShift); + TEST_FIELD(cBlueBits); + TEST_FIELD(cBlueShift); + TEST_FIELD(cAlphaBits); + TEST_FIELD(cAlphaShift); + TEST_FIELD(cAccumBits); + TEST_FIELD(cAccumRedBits); + TEST_FIELD(cAccumGreenBits); + TEST_FIELD(cAccumBlueBits); + TEST_FIELD(cAccumAlphaBits); +#undef TEST_FIELD + ok(pfd.cDepthBits == test_depths[j], "Wrong cDepthBit for format %i, expected %u, got %u\n", pf, test_depths[j], pfd.cDepthBits); + + /* the rest is constant */ +#define TEST_FIELD(__x__, __y__) ok(pfd.__x__ == __y__, "Wrong " #__x__ " for format %i, expected " #__y__ ", got %u\n", pf, (UINT)pfd.__x__) + TEST_FIELD(cStencilBits, 8); + TEST_FIELD(cAuxBuffers, 0); + TEST_FIELD(iLayerType, 0); + TEST_FIELD(bReserved, 0); + TEST_FIELD(dwLayerMask, 0); + TEST_FIELD(dwVisibleMask, 0); + TEST_FIELD(dwDamageMask, 0); +#undef TEST_FIELD +} + +START_TEST(sw_pixelformat) +{ + int pf, num_pf, ret; + int i, j; + HDC hdc; + HWND hwnd; + PIXELFORMATDESCRIPTOR pfd; + UINT hdc_bpp; + + hwnd = CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW, 10, 10, 200, 200, NULL, NULL, + NULL, NULL); + if (!hwnd) + { + ok(hwnd != NULL, "Failed to create a window.\n"); + return; + } + + hdc = GetDC( hwnd ); + num_pf = DescribePixelFormat(hdc, 0, 0, NULL); + ok(num_pf > 0, "DescribePixelFormat failed.\n"); + + hdc_bpp = GetDeviceCaps(hdc, BITSPIXEL); + + for (pf = 1; pf <= num_pf; pf++) + { + ret = DescribePixelFormat(hdc, pf, sizeof(pfd), &pfd); + ok(ret == num_pf, "Number of pixel formats changed!\n"); + + if (pfd.dwFlags & PFD_GENERIC_FORMAT) + break; + } + + ok(pf < num_pf, "No generic pixel format!\n"); + + for (i = 0; i < ARRAY_SIZE(test_colors); i++) + { + for (j = 0; j < ARRAY_SIZE(test_depths); j++) + { + test_format(hdc, num_pf, pf++, i, j, test_colors[i].cColorBits == hdc_bpp, FALSE); + } + + if (test_colors[i].cColorBits == hdc_bpp) + { + for (j = 0; j < ARRAY_SIZE(test_depths); j++) + { + test_format(hdc, num_pf, pf++, i, j, test_colors[i].cColorBits == hdc_bpp, TRUE); + } + } + } + + ReleaseDC( hwnd, hdc ); + DestroyWindow( hwnd ); +} diff --git a/modules/rostests/apitests/opengl32/testlist.c b/modules/rostests/apitests/opengl32/testlist.c new file mode 100644 index 0000000000..21105035fe --- /dev/null +++ b/modules/rostests/apitests/opengl32/testlist.c @@ -0,0 +1,15 @@ +#define __ROS_LONG64__ + +#define STANDALONE +#include + +extern void func_sw_extensions(void); +extern void func_sw_pixelformat(void); + +const struct test winetest_testlist[] = +{ + { "sw_extensions", func_sw_extensions }, + { "sw_pixelformat", func_sw_pixelformat }, + + { 0, 0 } +}; diff --git a/sdk/include/psdk/wingdi.h b/sdk/include/psdk/wingdi.h index dd638f1cff..537837813c 100644 --- a/sdk/include/psdk/wingdi.h +++ b/sdk/include/psdk/wingdi.h @@ -310,6 +310,7 @@ extern "C" { #define PFD_SWAP_COPY 0x00000400 #define PFD_SWAP_LAYER_BUFFERS 0x00000800 #define PFD_GENERIC_ACCELERATED 0x00001000 +#define PFD_SUPPORT_COMPOSITION 0x00008000 #define PFD_DEPTH_DONTCARE 0x20000000 #define PFD_DOUBLEBUFFER_DONTCARE 0x40000000 #define PFD_STEREO_DONTCARE 0x80000000