2 * Copyright © 2017 VMware, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 * WGL utility functions, based on GLX utility functions by Eric Anholt.
31 #include "piglit-util-gl.h"
32 #include "piglit-wgl-util.h"
35 int piglit_width
= 100;
36 int piglit_height
= 100;
39 static LRESULT CALLBACK
40 WndProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
47 //reshape(LOWORD(lParam), HIWORD(lParam));
50 if (wParam
== VK_ESCAPE
)
55 return DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
60 piglit_get_wgl_window(void)
64 DWORD dwExStyle
, dwStyle
;
71 static const PIXELFORMATDESCRIPTOR pfd
= {
72 sizeof(PIXELFORMATDESCRIPTOR
),
74 PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
,
91 winrect
.right
= piglit_width
;
93 winrect
.bottom
= piglit_height
;
95 hInst
= GetModuleHandle(NULL
);
96 wc
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_OWNDC
;
97 wc
.lpfnWndProc
= (WNDPROC
)WndProc
;
100 wc
.hInstance
= hInst
;
101 wc
.hIcon
= LoadIcon(NULL
, IDI_WINLOGO
);
102 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
103 wc
.hbrBackground
= NULL
;
104 wc
.lpszMenuName
= NULL
;
105 wc
.lpszClassName
= name
;
106 if (!RegisterClass(&wc
)) {
107 /* This fails for second and subsequent calls */
109 fprintf(stderr, "failed to register class\n");
115 dwExStyle
= WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
;
116 dwStyle
= WS_OVERLAPPEDWINDOW
;
117 AdjustWindowRectEx(&winrect
, dwStyle
, FALSE
, dwExStyle
);
119 if (!(hWnd
= CreateWindowEx(dwExStyle
, name
, name
,
120 WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
| dwStyle
,
122 winrect
.right
- winrect
.left
,
123 winrect
.bottom
- winrect
.top
,
124 NULL
, NULL
, hInst
, NULL
))) {
125 fprintf(stderr
, "failed to create window\n");
130 if (!(hDC
= GetDC(hWnd
))) {
131 fprintf(stderr
, "GetDC failed\n");
136 if (!(pixelFormat
= ChoosePixelFormat(hDC
, &pfd
))) {
137 fprintf(stderr
, "ChoosePixelFormat failed\n");
142 if (!(SetPixelFormat(hDC
, pixelFormat
, &pfd
))) {
143 fprintf(stderr
, "SetPixelFormat failed\n");
148 ShowWindow(hWnd
, SW_SHOW
);
149 SetForegroundWindow(hWnd
);
157 piglit_get_wgl_context(HWND hWnd
)
162 if (!(hDC
= GetDC(hWnd
))) {
163 fprintf(stderr
, "GetDC failed\n");
168 if (!(hRC
= wglCreateContext(hDC
))) {
169 fprintf(stderr
, "wglCreateContext failed\n");
179 piglit_wgl_event_loop(enum piglit_result (*draw
)(void))
182 enum piglit_result result
= PIGLIT_SKIP
;
185 if (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
)) {
186 if (msg
.message
== WM_QUIT
)
188 TranslateMessage(&msg
);
189 DispatchMessage(&msg
);
194 if (piglit_automatic
) {
199 piglit_report_result(result
);