2 * Some tests for OpenGL functions
4 * Copyright (C) 2007-2008 Roderick Colenbrander
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/test.h"
25 void WINAPI glClearColor(float red, float green, float blue, float alpha);
26 void WINAPI glClear(unsigned int mask);
27 #define GL_COLOR 0x1800
28 typedef unsigned int GLenum;
30 void WINAPI glCopyPixels(int x, int y, int width, int height, GLenum type);
31 void WINAPI glFinish(void);
32 #define GL_NO_ERROR 0x0
33 #define GL_INVALID_OPERATION 0x502
34 GLenum WINAPI glGetError(void);
35 #define GL_COLOR_BUFFER_BIT 0x00004000
36 const unsigned char * WINAPI glGetString(unsigned int);
37 #define GL_VENDOR 0x1F00
38 #define GL_RENDERER 0x1F01
39 #define GL_VERSION 0x1F02
41 #define GL_VIEWPORT 0x0ba2
42 void WINAPI glGetIntegerv(GLenum pname, GLint *params);
44 #define MAX_FORMATS 256
45 typedef void* HPBUFFERARB;
47 /* WGL_ARB_create_context */
48 static HGLRC (WINAPI *pwglCreateContextAttribsARB)(HDC hDC, HGLRC hShareContext, const int *attribList);
50 #define ERROR_INVALID_VERSION_ARB 0x2095
51 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
52 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
53 #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
54 #define WGL_CONTEXT_FLAGS_ARB 0x2094
55 /* Flags for WGL_CONTEXT_FLAGS_ARB */
56 #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
57 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
59 /* WGL_ARB_extensions_string */
60 static const char* (WINAPI *pwglGetExtensionsStringARB)(HDC);
61 static int (WINAPI *pwglReleasePbufferDCARB)(HPBUFFERARB, HDC);
63 /* WGL_ARB_make_current_read */
64 static BOOL (WINAPI *pwglMakeContextCurrentARB)(HDC hdraw, HDC hread, HGLRC hglrc);
65 static HDC (WINAPI *pwglGetCurrentReadDCARB)(void);
67 /* WGL_ARB_pixel_format */
68 #define WGL_ACCELERATION_ARB 0x2003
69 #define WGL_COLOR_BITS_ARB 0x2014
70 #define WGL_RED_BITS_ARB 0x2015
71 #define WGL_GREEN_BITS_ARB 0x2017
72 #define WGL_BLUE_BITS_ARB 0x2019
73 #define WGL_ALPHA_BITS_ARB 0x201B
74 #define WGL_SUPPORT_GDI_ARB 0x200F
75 #define WGL_DOUBLE_BUFFER_ARB 0x2011
76 #define WGL_NO_ACCELERATION_ARB 0x2025
77 #define WGL_GENERIC_ACCELERATION_ARB 0x2026
78 #define WGL_FULL_ACCELERATION_ARB 0x2027
80 static BOOL (WINAPI *pwglChoosePixelFormatARB)(HDC, const int *, const FLOAT *, UINT, int *, UINT *);
81 static BOOL (WINAPI *pwglGetPixelFormatAttribivARB)(HDC, int, int, UINT, const int *, int *);
84 #define WGL_DRAW_TO_PBUFFER_ARB 0x202D
85 static HPBUFFERARB* (WINAPI *pwglCreatePbufferARB)(HDC, int, int, int, const int *);
86 static HDC (WINAPI *pwglGetPbufferDCARB)(HPBUFFERARB);
88 static const char* wgl_extensions = NULL;
90 static void init_functions(void)
92 #define GET_PROC(func) \
93 p ## func = (void*)wglGetProcAddress(#func); \
95 trace("wglGetProcAddress(%s) failed\n", #func);
97 /* WGL_ARB_create_context */
98 GET_PROC(wglCreateContextAttribsARB);
100 /* WGL_ARB_extensions_string */
101 GET_PROC(wglGetExtensionsStringARB)
103 /* WGL_ARB_make_current_read */
104 GET_PROC(wglMakeContextCurrentARB);
105 GET_PROC(wglGetCurrentReadDCARB);
107 /* WGL_ARB_pixel_format */
108 GET_PROC(wglChoosePixelFormatARB)
109 GET_PROC(wglGetPixelFormatAttribivARB)
111 /* WGL_ARB_pbuffer */
112 GET_PROC(wglCreatePbufferARB)
113 GET_PROC(wglGetPbufferDCARB)
114 GET_PROC(wglReleasePbufferDCARB)
119 static void test_pbuffers(HDC hdc)
121 const int iAttribList[] = { WGL_DRAW_TO_PBUFFER_ARB, 1, /* Request pbuffer support */
123 int iFormats[MAX_FORMATS];
124 unsigned int nOnscreenFormats;
125 unsigned int nFormats;
127 int iPixelFormat = 0;
129 nOnscreenFormats = DescribePixelFormat(hdc, 0, 0, NULL);
131 /* When you want to render to a pbuffer you need to call wglGetPbufferDCARB which
132 * returns a 'magic' HDC which you can then pass to wglMakeCurrent to switch rendering
133 * to the pbuffer. Below some tests are performed on what happens if you use standard WGL calls
134 * on this 'magic' HDC for both a pixelformat that support onscreen and offscreen rendering
135 * and a pixelformat that's only available for offscreen rendering (this means that only
136 * wglChoosePixelFormatARB and friends know about the format.
138 * The first thing we need are pixelformats with pbuffer capabilities.
140 res = pwglChoosePixelFormatARB(hdc, iAttribList, NULL, MAX_FORMATS, iFormats, &nFormats);
143 skip("No pbuffer compatible formats found while WGL_ARB_pbuffer is supported\n");
146 trace("nOnscreenFormats: %d\n", nOnscreenFormats);
147 trace("Total number of pbuffer capable pixelformats: %d\n", nFormats);
149 /* Try to select an onscreen pixelformat out of the list */
150 for(i=0; i < nFormats; i++)
152 /* Check if the format is onscreen, if it is choose it */
153 if(iFormats[i] <= nOnscreenFormats)
155 iPixelFormat = iFormats[i];
156 trace("Selected iPixelFormat=%d\n", iPixelFormat);
161 /* A video driver supports a large number of onscreen and offscreen pixelformats.
162 * The traditional WGL calls only see a subset of the whole pixelformat list. First
163 * of all they only see the onscreen formats (the offscreen formats are at the end of the
164 * pixelformat list) and second extended pixelformat capabilities are hidden from the
165 * standard WGL calls. Only functions that depend on WGL_ARB_pixel_format can see them.
167 * Below we check if the pixelformat is also supported onscreen.
169 if(iPixelFormat != 0)
172 HPBUFFERARB pbuffer = pwglCreatePbufferARB(hdc, iPixelFormat, 640 /* width */, 480 /* height */, NULL);
174 skip("Pbuffer creation failed!\n");
176 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
177 pbuffer_hdc = pwglGetPbufferDCARB(pbuffer);
178 res = GetPixelFormat(pbuffer_hdc);
179 ok(res == iPixelFormat, "Unexpected iPixelFormat=%d returned by GetPixelFormat for format %d\n", res, iPixelFormat);
180 trace("iPixelFormat returned by GetPixelFormat: %d\n", res);
181 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat);
183 pwglReleasePbufferDCARB(pbuffer, hdc);
185 else skip("Pbuffer test for onscreen pixelformat skipped as no onscreen format with pbuffer capabilities have been found\n");
187 /* Search for a real offscreen format */
188 for(i=0, iPixelFormat=0; i<nFormats; i++)
190 if(iFormats[i] > nOnscreenFormats)
192 iPixelFormat = iFormats[i];
193 trace("Selected iPixelFormat: %d\n", iPixelFormat);
198 if(iPixelFormat != 0)
201 HPBUFFERARB pbuffer = pwglCreatePbufferARB(hdc, iPixelFormat, 640 /* width */, 480 /* height */, NULL);
203 skip("Pbuffer creation failed!\n");
205 /* Test the pixelformat returned by GetPixelFormat on a pbuffer as the behavior is not clear */
206 pbuffer_hdc = pwglGetPbufferDCARB(pbuffer);
207 res = GetPixelFormat(pbuffer_hdc);
209 ok(res == 1, "Unexpected iPixelFormat=%d (1 expected) returned by GetPixelFormat for offscreen format %d\n", res, iPixelFormat);
210 trace("iPixelFormat returned by GetPixelFormat: %d\n", res);
211 trace("PixelFormat from wglChoosePixelFormatARB: %d\n", iPixelFormat);
212 pwglReleasePbufferDCARB(pbuffer, hdc);
214 else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
217 static void test_setpixelformat(HDC winhdc)
224 PIXELFORMATDESCRIPTOR pfd = {
225 sizeof(PIXELFORMATDESCRIPTOR),
231 24, /* 24-bit color depth */
232 0, 0, 0, 0, 0, 0, /* color bits */
233 0, /* alpha buffer */
235 0, /* accumulation buffer */
236 0, 0, 0, 0, /* accum bits */
238 0, /* stencil buffer */
239 0, /* auxiliary buffer */
240 PFD_MAIN_PLANE, /* main layer */
242 0, 0, 0 /* layer masks */
246 ok(hdc != 0, "GetDC(0) failed!\n");
248 /* This should pass even on the main device context */
249 pf = ChoosePixelFormat(hdc, &pfd);
250 ok(pf != 0, "ChoosePixelFormat failed on main device context\n");
252 /* SetPixelFormat on the main device context 'X root window' should fail,
253 * but some broken drivers allow it
255 res = SetPixelFormat(hdc, pf, &pfd);
256 trace("SetPixelFormat on main device context %s\n", res ? "succeeded" : "failed");
258 /* Setting the same format that was set on the HDC is allowed; other
260 nCfgs = DescribePixelFormat(winhdc, 0, 0, NULL);
261 pf = GetPixelFormat(winhdc);
262 for(i = 1;i <= nCfgs;i++)
264 int res = SetPixelFormat(winhdc, i, NULL);
265 if(i == pf) ok(res, "Failed to set the same pixel format\n");
266 else ok(!res, "Unexpectedly set an alternate pixel format\n");
269 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
270 10, 10, 200, 200, NULL, NULL, NULL, NULL);
271 ok(hwnd != NULL, "err: %d\n", GetLastError());
274 HDC hdc = GetDC( hwnd );
275 pf = ChoosePixelFormat( hdc, &pfd );
276 ok( pf != 0, "ChoosePixelFormat failed\n" );
277 res = SetPixelFormat( hdc, pf, &pfd );
278 ok( res != 0, "SetPixelFormat failed\n" );
279 i = GetPixelFormat( hdc );
280 ok( i == pf, "GetPixelFormat returned wrong format %d/%d\n", i, pf );
281 ReleaseDC( hwnd, hdc );
282 hdc = GetWindowDC( hwnd );
283 i = GetPixelFormat( hdc );
284 ok( i == pf, "GetPixelFormat returned wrong format %d/%d\n", i, pf );
285 ReleaseDC( hwnd, hdc );
286 DestroyWindow( hwnd );
289 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
290 10, 10, 200, 200, NULL, NULL, NULL, NULL);
291 ok(hwnd != NULL, "err: %d\n", GetLastError());
294 HDC hdc = GetWindowDC( hwnd );
295 pf = ChoosePixelFormat( hdc, &pfd );
296 ok( pf != 0, "ChoosePixelFormat failed\n" );
297 res = SetPixelFormat( hdc, pf, &pfd );
298 ok( res != 0, "SetPixelFormat failed\n" );
299 i = GetPixelFormat( hdc );
300 ok( i == pf, "GetPixelFormat returned wrong format %d/%d\n", i, pf );
301 ReleaseDC( hwnd, hdc );
302 DestroyWindow( hwnd );
306 static void test_sharelists(HDC winhdc)
308 HGLRC hglrc1, hglrc2, hglrc3;
311 hglrc1 = wglCreateContext(winhdc);
312 res = wglShareLists(0, 0);
313 ok(res == FALSE, "Sharing display lists for no contexts passed!\n");
315 /* Test 1: Create a context and just share lists without doing anything special */
316 hglrc2 = wglCreateContext(winhdc);
319 res = wglShareLists(hglrc1, hglrc2);
320 ok(res, "Sharing of display lists failed\n");
321 wglDeleteContext(hglrc2);
324 /* Test 2: Share display lists with a 'destination' context which has been made current */
325 hglrc2 = wglCreateContext(winhdc);
328 res = wglMakeCurrent(winhdc, hglrc2);
329 ok(res, "Make current failed\n");
330 res = wglShareLists(hglrc1, hglrc2);
331 todo_wine ok(res, "Sharing display lists with a destination context which has been made current failed\n");
332 wglMakeCurrent(0, 0);
333 wglDeleteContext(hglrc2);
336 /* Test 3: Share display lists with a context which already shares display lists with another context.
337 * According to MSDN the second parameter cannot share any display lists but some buggy drivers might allow it */
338 hglrc3 = wglCreateContext(winhdc);
341 res = wglShareLists(hglrc3, hglrc1);
342 ok(res == FALSE, "Sharing of display lists passed for a context which already shared lists before\n");
343 wglDeleteContext(hglrc3);
346 /* Test 4: Share display lists with a 'source' context which has been made current */
347 hglrc2 = wglCreateContext(winhdc);
350 res = wglMakeCurrent(winhdc, hglrc1);
351 ok(res, "Make current failed\n");
352 res = wglShareLists(hglrc1, hglrc2);
353 ok(res, "Sharing display lists with a source context which has been made current failed\n");
354 wglMakeCurrent(0, 0);
355 wglDeleteContext(hglrc2);
359 static void test_makecurrent(HDC winhdc)
365 hglrc = wglCreateContext(winhdc);
366 ok( hglrc != 0, "wglCreateContext failed\n" );
368 ret = wglMakeCurrent( winhdc, hglrc );
369 ok( ret, "wglMakeCurrent failed\n" );
371 ok( wglGetCurrentContext() == hglrc, "wrong context\n" );
373 /* set the same context again */
374 ret = wglMakeCurrent( winhdc, hglrc );
375 ok( ret, "wglMakeCurrent failed\n" );
377 /* check wglMakeCurrent(x, y) after another call to wglMakeCurrent(x, y) */
378 ret = wglMakeCurrent( winhdc, NULL );
379 ok( ret, "wglMakeCurrent failed\n" );
381 ret = wglMakeCurrent( winhdc, NULL );
382 ok( ret, "wglMakeCurrent failed\n" );
384 SetLastError( 0xdeadbeef );
385 ret = wglMakeCurrent( NULL, NULL );
386 ok( !ret, "wglMakeCurrent succeeded\n" );
387 error = GetLastError();
388 ok( error == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got error=%x\n", error);
390 ret = wglMakeCurrent( winhdc, NULL );
391 ok( ret, "wglMakeCurrent failed\n" );
393 ret = wglMakeCurrent( winhdc, hglrc );
394 ok( ret, "wglMakeCurrent failed\n" );
396 ret = wglMakeCurrent( NULL, NULL );
397 ok( ret, "wglMakeCurrent failed\n" );
399 ok( wglGetCurrentContext() == NULL, "wrong context\n" );
401 SetLastError( 0xdeadbeef );
402 ret = wglMakeCurrent( NULL, NULL );
403 ok( !ret, "wglMakeCurrent succeeded\n" );
404 error = GetLastError();
405 ok( error == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got error=%x\n", error);
407 ret = wglMakeCurrent( winhdc, hglrc );
408 ok( ret, "wglMakeCurrent failed\n" );
411 static void test_colorbits(HDC hdc)
413 const int iAttribList[] = { WGL_COLOR_BITS_ARB, WGL_RED_BITS_ARB, WGL_GREEN_BITS_ARB,
414 WGL_BLUE_BITS_ARB, WGL_ALPHA_BITS_ARB };
415 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
416 const int iAttribs[] = { WGL_ALPHA_BITS_ARB, 1, 0 };
417 unsigned int nFormats;
419 int iPixelFormat = 0;
421 if (!pwglChoosePixelFormatARB)
423 win_skip("wglChoosePixelFormatARB is not available\n");
427 /* We need a pixel format with at least one bit of alpha */
428 res = pwglChoosePixelFormatARB(hdc, iAttribs, NULL, 1, &iPixelFormat, &nFormats);
429 if(res == FALSE || nFormats == 0)
431 skip("No suitable pixel formats found\n");
435 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
436 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList, iAttribRet);
439 skip("wglGetPixelFormatAttribivARB failed\n");
442 iAttribRet[1] += iAttribRet[2]+iAttribRet[3]+iAttribRet[4];
443 ok(iAttribRet[0] == iAttribRet[1], "WGL_COLOR_BITS_ARB (%d) does not equal R+G+B+A (%d)!\n",
444 iAttribRet[0], iAttribRet[1]);
447 static void test_gdi_dbuf(HDC hdc)
449 const int iAttribList[] = { WGL_SUPPORT_GDI_ARB, WGL_DOUBLE_BUFFER_ARB };
450 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
451 unsigned int nFormats;
455 if (!pwglGetPixelFormatAttribivARB)
457 win_skip("wglGetPixelFormatAttribivARB is not available\n");
461 nFormats = DescribePixelFormat(hdc, 0, 0, NULL);
462 for(iPixelFormat = 1;iPixelFormat <= nFormats;iPixelFormat++)
464 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
465 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList,
467 ok(res!=FALSE, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat);
471 ok(!(iAttribRet[0] && iAttribRet[1]), "GDI support and double buffering on pixel format %d\n", iPixelFormat);
475 static void test_acceleration(HDC hdc)
477 const int iAttribList[] = { WGL_ACCELERATION_ARB };
478 int iAttribRet[sizeof(iAttribList)/sizeof(iAttribList[0])];
479 unsigned int nFormats;
482 PIXELFORMATDESCRIPTOR pfd;
484 if (!pwglGetPixelFormatAttribivARB)
486 win_skip("wglGetPixelFormatAttribivARB is not available\n");
490 nFormats = DescribePixelFormat(hdc, 0, 0, NULL);
491 for(iPixelFormat = 1; iPixelFormat <= nFormats; iPixelFormat++)
493 res = pwglGetPixelFormatAttribivARB(hdc, iPixelFormat, 0,
494 sizeof(iAttribList)/sizeof(iAttribList[0]), iAttribList,
496 ok(res!=FALSE, "wglGetPixelFormatAttribivARB failed for pixel format %d\n", iPixelFormat);
500 memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
501 DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
503 switch(iAttribRet[0])
505 case WGL_NO_ACCELERATION_ARB:
506 ok( (pfd.dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED)) == PFD_GENERIC_FORMAT , "Expected only PFD_GENERIC_FORMAT to be set for WGL_NO_ACCELERATION_ARB!: iPixelFormat=%d, dwFlags=%x!\n", iPixelFormat, pfd.dwFlags);
508 case WGL_GENERIC_ACCELERATION_ARB:
509 ok( (pfd.dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED)) == (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED), "Expected both PFD_GENERIC_FORMAT and PFD_GENERIC_ACCELERATION to be set for WGL_GENERIC_ACCELERATION_ARB: iPixelFormat=%d, dwFlags=%x!\n", iPixelFormat, pfd.dwFlags);
511 case WGL_FULL_ACCELERATION_ARB:
512 ok( (pfd.dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED)) == 0, "Expected no PFD_GENERIC_FORMAT/_ACCELERATION to be set for WGL_FULL_ACCELERATION_ARB: iPixelFormat=%d, dwFlags=%x!\n", iPixelFormat, pfd.dwFlags);
518 static void test_bitmap_rendering( BOOL use_dib )
520 PIXELFORMATDESCRIPTOR pfd;
521 int i, ret, bpp, iPixelFormat=0;
522 unsigned int nFormats;
525 HBITMAP bmpDst, oldDst, bmp2;
526 HDC hdcDst, hdcScreen;
527 UINT *dstBuffer = NULL;
529 hdcScreen = CreateCompatibleDC(0);
530 hdcDst = CreateCompatibleDC(0);
535 memset(&biDst, 0, sizeof(BITMAPINFO));
536 biDst.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
537 biDst.bmiHeader.biWidth = 4;
538 biDst.bmiHeader.biHeight = -4;
539 biDst.bmiHeader.biPlanes = 1;
540 biDst.bmiHeader.biBitCount = 32;
541 biDst.bmiHeader.biCompression = BI_RGB;
543 bmpDst = CreateDIBSection(0, &biDst, DIB_RGB_COLORS, (void**)&dstBuffer, NULL, 0);
545 biDst.bmiHeader.biWidth = 12;
546 biDst.bmiHeader.biHeight = -12;
547 biDst.bmiHeader.biBitCount = 16;
548 bmp2 = CreateDIBSection(0, &biDst, DIB_RGB_COLORS, NULL, NULL, 0);
552 bpp = GetDeviceCaps( hdcScreen, BITSPIXEL );
553 bmpDst = CreateBitmap( 4, 4, 1, bpp, NULL );
554 bmp2 = CreateBitmap( 12, 12, 1, bpp, NULL );
557 oldDst = SelectObject(hdcDst, bmpDst);
559 trace( "testing on %s\n", use_dib ? "DIB" : "DDB" );
561 /* Pick a pixel format by hand because ChoosePixelFormat is unreliable */
562 nFormats = DescribePixelFormat(hdcDst, 0, 0, NULL);
563 for(i=1; i<=nFormats; i++)
565 memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
566 DescribePixelFormat(hdcDst, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
568 if((pfd.dwFlags & PFD_DRAW_TO_BITMAP) &&
569 (pfd.dwFlags & PFD_SUPPORT_OPENGL) &&
570 (pfd.cColorBits == bpp) &&
571 (pfd.cAlphaBits == 8) )
580 skip("Unable to find a suitable pixel format\n");
584 ret = SetPixelFormat(hdcDst, iPixelFormat, &pfd);
585 ok( ret, "SetPixelFormat failed\n" );
586 ret = GetPixelFormat( hdcDst );
587 ok( ret == iPixelFormat, "GetPixelFormat returned %d/%d\n", ret, iPixelFormat );
588 ret = SetPixelFormat(hdcDst, iPixelFormat + 1, &pfd);
589 ok( !ret, "SetPixelFormat succeeded\n" );
590 hglrc = wglCreateContext(hdcDst);
591 ok(hglrc != NULL, "Unable to create a context\n");
596 wglMakeCurrent(hdcDst, hglrc);
597 hglrc2 = wglCreateContext(hdcDst);
598 ok(hglrc2 != NULL, "Unable to create a context\n");
600 /* Note this is RGBA but we read ARGB back */
601 glClearColor((float)0x22/0xff, (float)0x33/0xff, (float)0x44/0xff, (float)0x11/0xff);
602 glClear(GL_COLOR_BUFFER_BIT);
603 glGetIntegerv( GL_VIEWPORT, viewport );
606 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 4 && viewport[3] == 4,
607 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
608 /* Note apparently the alpha channel is not supported by the software renderer (bitmap only works using software) */
610 for (i = 0; i < 16; i++)
611 ok(dstBuffer[i] == 0x223344 || dstBuffer[i] == 0x11223344, "Received color=%x at %u\n",
614 SelectObject(hdcDst, bmp2);
615 ret = GetPixelFormat( hdcDst );
616 ok( ret == iPixelFormat, "GetPixelFormat returned %d/%d\n", ret, iPixelFormat );
617 ret = SetPixelFormat(hdcDst, iPixelFormat + 1, &pfd);
618 ok( !ret, "SetPixelFormat succeeded\n" );
620 /* context still uses the old pixel format and viewport */
621 glClearColor((float)0x44/0xff, (float)0x33/0xff, (float)0x22/0xff, (float)0x11/0xff);
622 glClear(GL_COLOR_BUFFER_BIT);
624 glGetIntegerv( GL_VIEWPORT, viewport );
625 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 4 && viewport[3] == 4,
626 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
628 wglMakeCurrent(NULL, NULL);
629 wglMakeCurrent(hdcDst, hglrc);
630 glClearColor((float)0x44/0xff, (float)0x55/0xff, (float)0x66/0xff, (float)0x11/0xff);
631 glClear(GL_COLOR_BUFFER_BIT);
633 glGetIntegerv( GL_VIEWPORT, viewport );
634 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 4 && viewport[3] == 4,
635 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
637 wglMakeCurrent(hdcDst, hglrc2);
638 glGetIntegerv( GL_VIEWPORT, viewport );
639 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 12 && viewport[3] == 12,
640 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
642 wglMakeCurrent(hdcDst, hglrc);
643 glGetIntegerv( GL_VIEWPORT, viewport );
644 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 4 && viewport[3] == 4,
645 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
647 SelectObject(hdcDst, bmpDst);
648 ret = GetPixelFormat( hdcDst );
649 ok( ret == iPixelFormat, "GetPixelFormat returned %d/%d\n", ret, iPixelFormat );
650 ret = SetPixelFormat(hdcDst, iPixelFormat + 1, &pfd);
651 ok( !ret, "SetPixelFormat succeeded\n" );
652 wglMakeCurrent(hdcDst, hglrc2);
653 glGetIntegerv( GL_VIEWPORT, viewport );
654 ok( viewport[0] == 0 && viewport[1] == 0 && viewport[2] == 12 && viewport[3] == 12,
655 "wrong viewport %d,%d,%d,%d\n", viewport[0], viewport[1], viewport[2], viewport[3] );
659 SelectObject(hdcDst, oldDst);
661 DeleteObject(bmpDst);
666 struct wgl_thread_param
668 HANDLE test_finished;
674 static DWORD WINAPI wgl_thread(void *param)
676 struct wgl_thread_param *p = param;
678 SetLastError(0xdeadbeef);
679 p->hglrc_deleted = wglDeleteContext(p->hglrc);
680 p->last_error = GetLastError();
681 SetEvent(p->test_finished);
686 static void test_deletecontext(HDC hdc)
688 struct wgl_thread_param thread_params;
689 HGLRC hglrc = wglCreateContext(hdc);
690 HANDLE thread_handle;
693 SetLastError(0xdeadbeef);
694 res = wglDeleteContext(NULL);
695 ok(res == FALSE, "wglDeleteContext succeeded\n");
696 ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
700 skip("wglCreateContext failed!\n");
704 res = wglMakeCurrent(hdc, hglrc);
707 skip("wglMakeCurrent failed!\n");
711 /* WGL doesn't allow you to delete a context from a different thread than the one in which it is current.
712 * This differs from GLX which does allow it but it delays actual deletion until the context becomes not current.
714 thread_params.hglrc = hglrc;
715 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
716 thread_handle = CreateThread(NULL, 0, wgl_thread, &thread_params, 0, &tid);
717 ok(!!thread_handle, "Failed to create thread, last error %#x.\n", GetLastError());
720 WaitForSingleObject(thread_handle, INFINITE);
721 ok(thread_params.hglrc_deleted == FALSE, "Attempt to delete WGL context from another thread passed but should fail!\n");
722 ok(thread_params.last_error == ERROR_BUSY, "Expected last error to be ERROR_BUSY, got %u\n", thread_params.last_error);
724 CloseHandle(thread_params.test_finished);
726 res = wglDeleteContext(hglrc);
727 ok(res == TRUE, "wglDeleteContext failed\n");
729 /* Attempting to delete the same context twice should fail. */
730 SetLastError(0xdeadbeef);
731 res = wglDeleteContext(hglrc);
732 ok(res == FALSE, "wglDeleteContext succeeded\n");
733 ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected last error to be ERROR_INVALID_HANDLE, got %u\n", GetLastError());
735 /* WGL makes a context not current when deleting it. This differs from GLX behavior where
736 * deletion takes place when the thread becomes not current. */
737 hglrc = wglGetCurrentContext();
738 ok(hglrc == NULL, "A WGL context is active while none was expected\n");
741 static void test_make_current_read(HDC hdc)
745 HGLRC hglrc = wglCreateContext(hdc);
749 skip("wglCreateContext failed!\n");
753 res = wglMakeCurrent(hdc, hglrc);
756 skip("wglMakeCurrent failed!\n");
760 /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */
761 hread = pwglGetCurrentReadDCARB();
762 trace("hread %p, hdc %p\n", hread, hdc);
763 ok(hread == hdc, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n");
765 pwglMakeContextCurrentARB(hdc, hdc, hglrc);
766 hread = pwglGetCurrentReadDCARB();
767 ok(hread == hdc, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n");
770 static void test_dc(HWND hwnd, HDC hdc)
775 /* Get another DC and make sure it has the same pixel format */
779 pf1 = GetPixelFormat(hdc);
780 pf2 = GetPixelFormat(hdc2);
781 ok(pf1 == pf2, "Second DC does not have the same format (%d != %d)\n", pf1, pf2);
784 skip("Could not get a different DC for the window\n");
788 ReleaseDC(hwnd, hdc2);
793 /* Nvidia converts win32 error codes to (0xc007 << 16) | win32_error_code */
794 #define NVIDIA_HRESULT_FROM_WIN32(x) (HRESULT_FROM_WIN32(x) | 0x40000000)
795 static void test_opengl3(HDC hdc)
797 /* Try to create a context compatible with OpenGL 1.x; 1.0-2.1 is allowed */
800 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 1, 0};
802 gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
803 ok(gl3Ctx != 0, "pwglCreateContextAttribsARB for a 1.x context failed!\n");
804 wglDeleteContext(gl3Ctx);
807 /* Try to pass an invalid HDC */
811 gl3Ctx = pwglCreateContextAttribsARB((HDC)0xdeadbeef, 0, 0);
812 ok(gl3Ctx == 0, "pwglCreateContextAttribsARB using an invalid HDC passed\n");
813 error = GetLastError();
814 todo_wine ok(error == ERROR_DC_NOT_FOUND ||
815 broken(error == NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_DATA)), /* Nvidia Vista + Win7 */
816 "Expected ERROR_DC_NOT_FOUND, got error=%x\n", error);
817 wglDeleteContext(gl3Ctx);
820 /* Try to pass an invalid shareList */
824 gl3Ctx = pwglCreateContextAttribsARB(hdc, (HGLRC)0xdeadbeef, 0);
825 todo_wine ok(gl3Ctx == 0, "pwglCreateContextAttribsARB using an invalid shareList passed\n");
826 error = GetLastError();
827 /* The Nvidia implementation seems to return hresults instead of win32 error codes */
828 todo_wine ok(error == ERROR_INVALID_OPERATION ||
829 error == NVIDIA_HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION), "Expected ERROR_INVALID_OPERATION, got error=%x\n", error);
830 wglDeleteContext(gl3Ctx);
833 /* Try to create an OpenGL 3.0 context */
835 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
836 HGLRC gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
840 skip("Skipping the rest of the WGL_ARB_create_context test due to lack of OpenGL 3.0\n");
844 wglDeleteContext(gl3Ctx);
847 /* Test matching an OpenGL 3.0 context with an older one, OpenGL 3.0 should allow it until the new object model is introduced in a future revision */
849 HGLRC glCtx = wglCreateContext(hdc);
851 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
852 int attribs_future[] = {WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
854 HGLRC gl3Ctx = pwglCreateContextAttribsARB(hdc, glCtx, attribs);
855 ok(gl3Ctx != NULL, "Sharing of a display list between OpenGL 3.0 and OpenGL 1.x/2.x failed!\n");
857 wglDeleteContext(gl3Ctx);
859 gl3Ctx = pwglCreateContextAttribsARB(hdc, glCtx, attribs_future);
860 ok(gl3Ctx != NULL, "Sharing of a display list between a forward compatible OpenGL 3.0 context and OpenGL 1.x/2.x failed!\n");
862 wglDeleteContext(gl3Ctx);
865 wglDeleteContext(glCtx);
868 /* Try to create an OpenGL 3.0 context and test windowless rendering */
871 int attribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 0, 0};
874 gl3Ctx = pwglCreateContextAttribsARB(hdc, 0, attribs);
875 ok(gl3Ctx != 0, "pwglCreateContextAttribsARB for a 3.0 context failed!\n");
877 /* OpenGL 3.0 allows offscreen rendering WITHOUT a drawable
878 * Neither AMD or Nvidia support it at this point. The WGL_ARB_create_context specs also say that
879 * it is hard because drivers use the HDC to enter the display driver and it sounds like they don't
880 * expect drivers to ever offer it.
882 res = wglMakeCurrent(0, gl3Ctx);
883 ok(res == FALSE, "Wow, OpenGL 3.0 windowless rendering passed while it was expected not to!\n");
885 wglMakeCurrent(0, 0);
888 wglDeleteContext(gl3Ctx);
892 static void test_minimized(void)
894 PIXELFORMATDESCRIPTOR pf_desc =
896 sizeof(PIXELFORMATDESCRIPTOR),
898 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
900 24, /* 24-bit color depth */
901 0, 0, 0, 0, 0, 0, /* color bits */
902 0, /* alpha buffer */
904 0, /* accumulation buffer */
905 0, 0, 0, 0, /* accum bits */
907 0, /* stencil buffer */
908 0, /* auxiliary buffer */
909 PFD_MAIN_PLANE, /* main layer */
911 0, 0, 0 /* layer masks */
920 window = CreateWindowA("static", "opengl32_test",
921 WS_POPUP | WS_MINIMIZE, 0, 0, 640, 480, 0, 0, 0, 0);
922 ok(!!window, "Failed to create window, last error %#x.\n", GetLastError());
925 ok(!!dc, "Failed to get DC.\n");
927 pixel_format = ChoosePixelFormat(dc, &pf_desc);
930 win_skip("Failed to find pixel format.\n");
931 ReleaseDC(window, dc);
932 DestroyWindow(window);
936 ret = SetPixelFormat(dc, pixel_format, &pf_desc);
937 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
939 style = GetWindowLongA(window, GWL_STYLE);
940 ok(style & WS_MINIMIZE, "Window should be minimized, got style %#x.\n", style);
942 ctx = wglCreateContext(dc);
943 ok(!!ctx, "Failed to create GL context, last error %#x.\n", GetLastError());
945 ret = wglMakeCurrent(dc, ctx);
946 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
948 style = GetWindowLongA(window, GWL_STYLE);
949 ok(style & WS_MINIMIZE, "window should be minimized, got style %#x.\n", style);
951 ret = wglMakeCurrent(NULL, NULL);
952 ok(ret, "Failed to clear current context, last error %#x.\n", GetLastError());
954 ret = wglDeleteContext(ctx);
955 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
957 ReleaseDC(window, dc);
958 DestroyWindow(window);
961 static void test_window_dc(void)
963 PIXELFORMATDESCRIPTOR pf_desc =
965 sizeof(PIXELFORMATDESCRIPTOR),
967 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
969 24, /* 24-bit color depth */
970 0, 0, 0, 0, 0, 0, /* color bits */
971 0, /* alpha buffer */
973 0, /* accumulation buffer */
974 0, 0, 0, 0, /* accum bits */
976 0, /* stencil buffer */
977 0, /* auxiliary buffer */
978 PFD_MAIN_PLANE, /* main layer */
980 0, 0, 0 /* layer masks */
989 window = CreateWindowA("static", "opengl32_test",
990 WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, 0, 0);
991 ok(!!window, "Failed to create window, last error %#x.\n", GetLastError());
993 ShowWindow(window, SW_SHOW);
995 dc = GetWindowDC(window);
996 ok(!!dc, "Failed to get DC.\n");
998 pixel_format = ChoosePixelFormat(dc, &pf_desc);
1001 win_skip("Failed to find pixel format.\n");
1002 ReleaseDC(window, dc);
1003 DestroyWindow(window);
1007 ret = SetPixelFormat(dc, pixel_format, &pf_desc);
1008 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1010 ctx = wglCreateContext(dc);
1011 ok(!!ctx, "Failed to create GL context, last error %#x.\n", GetLastError());
1013 ret = wglMakeCurrent(dc, ctx);
1014 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1016 GetClientRect(window, &r);
1017 glGetIntegerv(GL_VIEWPORT, (GLint *)&vp);
1018 ok(EqualRect(&r, &vp), "Viewport not equal to client rect.\n");
1020 ret = wglMakeCurrent(NULL, NULL);
1021 ok(ret, "Failed to clear current context, last error %#x.\n", GetLastError());
1023 ret = wglDeleteContext(ctx);
1024 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1026 ReleaseDC(window, dc);
1027 DestroyWindow(window);
1030 static void test_destroy(HDC oldhdc)
1032 PIXELFORMATDESCRIPTOR pf_desc =
1034 sizeof(PIXELFORMATDESCRIPTOR),
1036 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
1038 24, /* 24-bit color depth */
1039 0, 0, 0, 0, 0, 0, /* color bits */
1040 0, /* alpha buffer */
1042 0, /* accumulation buffer */
1043 0, 0, 0, 0, /* accum bits */
1045 0, /* stencil buffer */
1046 0, /* auxiliary buffer */
1047 PFD_MAIN_PLANE, /* main layer */
1049 0, 0, 0 /* layer masks */
1058 HGLRC oldctx = wglGetCurrentContext();
1060 ok(!!oldctx, "Expected to find a valid current context.\n");
1062 window = CreateWindowA("static", "opengl32_test",
1063 WS_POPUP, 0, 0, 640, 480, 0, 0, 0, 0);
1064 ok(!!window, "Failed to create window, last error %#x.\n", GetLastError());
1067 ok(!!dc, "Failed to get DC.\n");
1069 pixel_format = ChoosePixelFormat(dc, &pf_desc);
1072 win_skip("Failed to find pixel format.\n");
1073 ReleaseDC(window, dc);
1074 DestroyWindow(window);
1078 ret = SetPixelFormat(dc, pixel_format, &pf_desc);
1079 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1081 ctx = wglCreateContext(dc);
1082 ok(!!ctx, "Failed to create GL context, last error %#x.\n", GetLastError());
1084 ret = wglMakeCurrent(dc, ctx);
1085 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1087 glClear(GL_COLOR_BUFFER_BIT);
1089 glerr = glGetError();
1090 ok(glerr == GL_NO_ERROR, "Failed glClear, error %#x.\n", glerr);
1091 ret = SwapBuffers(dc);
1092 ok(ret, "Failed SwapBuffers, error %#x.\n", GetLastError());
1094 ret = DestroyWindow(window);
1095 ok(ret, "Failed to destroy window, last error %#x.\n", GetLastError());
1097 ok(wglGetCurrentContext() == ctx, "Wrong current context.\n");
1099 SetLastError(0xdeadbeef);
1100 ret = wglMakeCurrent(dc, ctx);
1101 err = GetLastError();
1102 ok(!ret && err == ERROR_INVALID_HANDLE,
1103 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1104 SetLastError(0xdeadbeef);
1105 ret = SwapBuffers(dc);
1106 err = GetLastError();
1107 ok(!ret && err == ERROR_INVALID_HANDLE, "Unexpected behavior with SwapBuffer, last error %#x.\n", err);
1109 ok(wglGetCurrentContext() == ctx, "Wrong current context.\n");
1111 glClear(GL_COLOR_BUFFER_BIT);
1113 glerr = glGetError();
1114 ok(glerr == GL_NO_ERROR, "Failed glClear, error %#x.\n", glerr);
1115 SetLastError(0xdeadbeef);
1116 ret = SwapBuffers(dc);
1117 err = GetLastError();
1118 ok(!ret && err == ERROR_INVALID_HANDLE, "Unexpected behavior with SwapBuffer, last error %#x.\n", err);
1120 ret = wglMakeCurrent(NULL, NULL);
1121 ok(ret, "Failed to clear current context, last error %#x.\n", GetLastError());
1123 glClear(GL_COLOR_BUFFER_BIT);
1125 glerr = glGetError();
1126 todo_wine ok(glerr == GL_INVALID_OPERATION, "Failed glClear, error %#x.\n", glerr);
1127 SetLastError(0xdeadbeef);
1128 ret = SwapBuffers(dc);
1129 err = GetLastError();
1130 ok(!ret && err == ERROR_INVALID_HANDLE, "Unexpected behavior with SwapBuffer, last error %#x.\n", err);
1132 SetLastError(0xdeadbeef);
1133 ret = wglMakeCurrent(dc, ctx);
1134 err = GetLastError();
1135 ok(!ret && err == ERROR_INVALID_HANDLE,
1136 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1138 ok(wglGetCurrentContext() == NULL, "Wrong current context.\n");
1140 ret = wglMakeCurrent(oldhdc, oldctx);
1141 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1142 ok(wglGetCurrentContext() == oldctx, "Wrong current context.\n");
1144 SetLastError(0xdeadbeef);
1145 ret = wglMakeCurrent(dc, ctx);
1146 err = GetLastError();
1147 ok(!ret && err == ERROR_INVALID_HANDLE,
1148 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1150 ok(wglGetCurrentContext() == oldctx, "Wrong current context.\n");
1152 ret = wglDeleteContext(ctx);
1153 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1155 ReleaseDC(window, dc);
1157 ret = wglMakeCurrent(oldhdc, oldctx);
1158 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1161 static void test_destroy_read(HDC oldhdc)
1163 PIXELFORMATDESCRIPTOR pf_desc =
1165 sizeof(PIXELFORMATDESCRIPTOR),
1167 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
1169 24, /* 24-bit color depth */
1170 0, 0, 0, 0, 0, 0, /* color bits */
1171 0, /* alpha buffer */
1173 0, /* accumulation buffer */
1174 0, 0, 0, 0, /* accum bits */
1176 0, /* stencil buffer */
1177 0, /* auxiliary buffer */
1178 PFD_MAIN_PLANE, /* main layer */
1180 0, 0, 0 /* layer masks */
1183 HWND draw_window, read_window;
1186 HDC read_dc, draw_dc;
1189 HGLRC oldctx = wglGetCurrentContext();
1191 ok(!!oldctx, "Expected to find a valid current context\n");
1193 draw_window = CreateWindowA("static", "opengl32_test",
1194 WS_POPUP, 0, 0, 640, 480, 0, 0, 0, 0);
1195 ok(!!draw_window, "Failed to create window, last error %#x.\n", GetLastError());
1197 draw_dc = GetDC(draw_window);
1198 ok(!!draw_dc, "Failed to get DC.\n");
1200 pixel_format = ChoosePixelFormat(draw_dc, &pf_desc);
1203 win_skip("Failed to find pixel format.\n");
1204 ReleaseDC(draw_window, draw_dc);
1205 DestroyWindow(draw_window);
1209 ret = SetPixelFormat(draw_dc, pixel_format, &pf_desc);
1210 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1212 read_window = CreateWindowA("static", "opengl32_test",
1213 WS_POPUP, 0, 0, 640, 480, 0, 0, 0, 0);
1214 ok(!!read_window, "Failed to create window, last error %#x.\n", GetLastError());
1216 read_dc = GetDC(read_window);
1217 ok(!!draw_dc, "Failed to get DC.\n");
1219 pixel_format = ChoosePixelFormat(read_dc, &pf_desc);
1222 win_skip("Failed to find pixel format.\n");
1223 ReleaseDC(read_window, read_dc);
1224 DestroyWindow(read_window);
1225 ReleaseDC(draw_window, draw_dc);
1226 DestroyWindow(draw_window);
1230 ret = SetPixelFormat(read_dc, pixel_format, &pf_desc);
1231 ok(ret, "Failed to set pixel format, last error %#x.\n", GetLastError());
1233 ctx = wglCreateContext(draw_dc);
1234 ok(!!ctx, "Failed to create GL context, last error %#x.\n", GetLastError());
1236 ret = pwglMakeContextCurrentARB(draw_dc, read_dc, ctx);
1237 ok(ret, "Failed to make context current, last error %#x.\n", GetLastError());
1239 glCopyPixels(0, 0, 640, 480, GL_COLOR);
1241 glerr = glGetError();
1242 ok(glerr == GL_NO_ERROR, "Failed glCopyPixel, error %#x.\n", glerr);
1243 ret = SwapBuffers(draw_dc);
1244 ok(ret, "Failed SwapBuffers, error %#x.\n", GetLastError());
1246 ret = DestroyWindow(read_window);
1247 ok(ret, "Failed to destroy window, last error %#x.\n", GetLastError());
1249 ok(wglGetCurrentContext() == ctx, "Wrong current context.\n");
1251 if (0) /* Crashes on AMD on Windows */
1253 glCopyPixels(0, 0, 640, 480, GL_COLOR);
1255 glerr = glGetError();
1256 ok(glerr == GL_NO_ERROR, "Failed glCopyPixel, error %#x.\n", glerr);
1259 glClear(GL_COLOR_BUFFER_BIT);
1261 glerr = glGetError();
1262 ok(glerr == GL_NO_ERROR, "Failed glClear, error %#x.\n", glerr);
1263 ret = SwapBuffers(draw_dc);
1264 ok(ret, "Failed SwapBuffers, error %#x.\n", GetLastError());
1266 ret = wglMakeCurrent(NULL, NULL);
1267 ok(ret, "Failed to clear current context, last error %#x.\n", GetLastError());
1269 if (0) /* This crashes with Nvidia drivers on Windows. */
1271 SetLastError(0xdeadbeef);
1272 ret = pwglMakeContextCurrentARB(draw_dc, read_dc, ctx);
1273 err = GetLastError();
1274 ok(!ret && err == ERROR_INVALID_HANDLE,
1275 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1278 ret = DestroyWindow(draw_window);
1279 ok(ret, "Failed to destroy window, last error %#x.\n", GetLastError());
1281 glClear(GL_COLOR_BUFFER_BIT);
1283 glerr = glGetError();
1284 todo_wine ok(glerr == GL_INVALID_OPERATION, "Failed glClear, error %#x.\n", glerr);
1285 SetLastError(0xdeadbeef);
1286 ret = SwapBuffers(draw_dc);
1287 err = GetLastError();
1288 ok(!ret && err == ERROR_INVALID_HANDLE, "Unexpected behavior with SwapBuffer, last error %#x.\n", err);
1290 SetLastError(0xdeadbeef);
1291 ret = pwglMakeContextCurrentARB(draw_dc, read_dc, ctx);
1292 err = GetLastError();
1293 ok(!ret && (err == ERROR_INVALID_HANDLE || err == 0xc0070006),
1294 "Unexpected behavior when making context current, ret %d, last error %#x.\n", ret, err);
1296 ok(wglGetCurrentContext() == NULL, "Wrong current context.\n");
1298 wglMakeCurrent(NULL, NULL);
1300 wglMakeCurrent(oldhdc, oldctx);
1301 ok(wglGetCurrentContext() == oldctx, "Wrong current context.\n");
1303 SetLastError(0xdeadbeef);
1304 ret = pwglMakeContextCurrentARB(draw_dc, read_dc, ctx);
1305 err = GetLastError();
1306 ok(!ret && (err == ERROR_INVALID_HANDLE || err == 0xc0070006),
1307 "Unexpected behavior when making context current, last error %#x.\n", err);
1309 ok(wglGetCurrentContext() == oldctx, "Wrong current context.\n");
1311 ret = wglDeleteContext(ctx);
1312 ok(ret, "Failed to delete GL context, last error %#x.\n", GetLastError());
1314 ReleaseDC(read_window, read_dc);
1315 ReleaseDC(draw_window, draw_dc);
1317 wglMakeCurrent(oldhdc, oldctx);
1323 PIXELFORMATDESCRIPTOR pfd = {
1324 sizeof(PIXELFORMATDESCRIPTOR),
1326 PFD_DRAW_TO_WINDOW |
1327 PFD_SUPPORT_OPENGL |
1330 24, /* 24-bit color depth */
1331 0, 0, 0, 0, 0, 0, /* color bits */
1332 0, /* alpha buffer */
1334 0, /* accumulation buffer */
1335 0, 0, 0, 0, /* accum bits */
1337 0, /* stencil buffer */
1338 0, /* auxiliary buffer */
1339 PFD_MAIN_PLANE, /* main layer */
1341 0, 0, 0 /* layer masks */
1344 hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
1345 10, 10, 200, 200, NULL, NULL, NULL, NULL);
1346 ok(hwnd != NULL, "err: %d\n", GetLastError());
1350 int iPixelFormat, res;
1353 ShowWindow(hwnd, SW_SHOW);
1357 iPixelFormat = ChoosePixelFormat(hdc, &pfd);
1358 if(iPixelFormat == 0)
1360 /* This should never happen as ChoosePixelFormat always returns a closest match, but currently this fails in Wine if we don't have glX */
1361 win_skip("Unable to find pixel format.\n");
1365 /* We shouldn't be able to create a context from a hdc which doesn't have a pixel format set */
1366 hglrc = wglCreateContext(hdc);
1367 ok(hglrc == NULL, "wglCreateContext should fail when no pixel format has been set, but it passed\n");
1368 error = GetLastError();
1369 ok(error == ERROR_INVALID_PIXEL_FORMAT, "expected ERROR_INVALID_PIXEL_FORMAT for wglCreateContext without a pixelformat set, but received %#x\n", error);
1371 res = SetPixelFormat(hdc, iPixelFormat, &pfd);
1372 ok(res, "SetPixelformat failed: %x\n", GetLastError());
1374 test_bitmap_rendering( TRUE );
1375 test_bitmap_rendering( FALSE );
1380 hglrc = wglCreateContext(hdc);
1381 res = wglMakeCurrent(hdc, hglrc);
1382 ok(res, "wglMakeCurrent failed!\n");
1385 trace("OpenGL renderer: %s\n", glGetString(GL_RENDERER));
1386 trace("OpenGL driver version: %s\n", glGetString(GL_VERSION));
1387 trace("OpenGL vendor: %s\n", glGetString(GL_VENDOR));
1391 skip("Skipping OpenGL tests without a current context\n");
1395 /* Initialisation of WGL functions depends on an implicit WGL context. For this reason we can't load them before making
1396 * any WGL call :( On Wine this would work but not on real Windows because there can be different implementations (software, ICD, MCD).
1399 /* The lack of wglGetExtensionsStringARB in general means broken software rendering or the lack of decent OpenGL support, skip tests in such cases */
1400 if (!pwglGetExtensionsStringARB)
1402 win_skip("wglGetExtensionsStringARB is not available\n");
1406 test_deletecontext(hdc);
1407 test_makecurrent(hdc);
1408 test_setpixelformat(hdc);
1410 test_sharelists(hdc);
1411 test_colorbits(hdc);
1413 test_acceleration(hdc);
1415 wgl_extensions = pwglGetExtensionsStringARB(hdc);
1416 if(wgl_extensions == NULL) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n");
1418 if(strstr(wgl_extensions, "WGL_ARB_create_context"))
1421 if(strstr(wgl_extensions, "WGL_ARB_make_current_read"))
1423 test_make_current_read(hdc);
1424 test_destroy_read(hdc);
1427 skip("WGL_ARB_make_current_read not supported, skipping test\n");
1429 if(strstr(wgl_extensions, "WGL_ARB_pbuffer"))
1432 skip("WGL_ARB_pbuffer not supported, skipping pbuffer test\n");
1435 ReleaseDC(hwnd, hdc);
1436 DestroyWindow(hwnd);