1 /**************************************************************************
3 * Copyright 2010 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 #define WGL_WGLEXT_PROTOTYPES
33 #include <GL/wglext.h>
35 #include "pipe/p_defines.h"
36 #include "pipe/p_screen.h"
38 #include "stw_device.h"
39 #include "stw_pixelformat.h"
40 #include "stw_framebuffer.h"
43 #define LARGE_WINDOW_SIZE 60000
46 static LRESULT CALLBACK
47 WndProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
51 case WM_GETMINMAXINFO
:
52 // Allow to create a window bigger than the desktop
53 pMMI
= (MINMAXINFO
*)lParam
;
54 pMMI
->ptMaxSize
.x
= LARGE_WINDOW_SIZE
;
55 pMMI
->ptMaxSize
.y
= LARGE_WINDOW_SIZE
;
56 pMMI
->ptMaxTrackSize
.x
= LARGE_WINDOW_SIZE
;
57 pMMI
->ptMaxTrackSize
.y
= LARGE_WINDOW_SIZE
;
63 return DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
68 wglCreatePbufferARB(HDC hCurrentDC
,
72 const int *piAttribList
)
74 static boolean first
= TRUE
;
77 const struct stw_pixelformat_info
*info
;
78 struct stw_framebuffer
*fb
;
84 int iDisplayablePixelFormat
;
85 PIXELFORMATDESCRIPTOR pfd
;
88 info
= stw_pixelformat_get_info(iPixelFormat
);
90 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
94 if (iWidth
<= 0 || iHeight
<= 0) {
95 SetLastError(ERROR_INVALID_DATA
);
99 for (piAttrib
= piAttribList
; *piAttrib
; piAttrib
++) {
101 case WGL_PBUFFER_LARGEST_ARB
:
103 useLargest
= *piAttrib
;
106 SetLastError(ERROR_INVALID_DATA
);
111 if (iWidth
> stw_dev
->max_2d_length
) {
113 iWidth
= stw_dev
->max_2d_length
;
115 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
120 if (iHeight
> stw_dev
->max_2d_length
) {
122 iHeight
= stw_dev
->max_2d_length
;
124 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
130 * Implement pbuffers through invisible windows
135 memset(&wc
, 0, sizeof wc
);
136 wc
.hbrBackground
= (HBRUSH
) (COLOR_BTNFACE
+ 1);
137 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
138 wc
.hIcon
= LoadIcon(NULL
, IDI_APPLICATION
);
139 wc
.lpfnWndProc
= WndProc
;
140 wc
.lpszClassName
= "wglpbuffer";
141 wc
.style
= CS_OWNDC
| CS_HREDRAW
| CS_VREDRAW
;
147 dwStyle
= WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
151 * Don't hide the window -- useful for debugging what the application is
155 dwStyle
|= WS_VISIBLE
| WS_OVERLAPPEDWINDOW
;
157 dwStyle
|= WS_POPUPWINDOW
;
162 rect
.right
= rect
.left
+ iWidth
;
163 rect
.bottom
= rect
.top
+ iHeight
;
166 * The CreateWindowEx parameters are the total (outside) dimensions of the
167 * window, which can vary with Windows version and user settings. Use
168 * AdjustWindowRect to get the required total area for the given client area.
170 * AdjustWindowRectEx does not accept WS_OVERLAPPED style (which is defined
171 * as 0), which means we need to use some other style instead, e.g.,
172 * WS_OVERLAPPEDWINDOW or WS_POPUPWINDOW as above.
175 AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
177 hWnd
= CreateWindowEx(dwExStyle
,
178 "wglpbuffer", /* wc.lpszClassName */
181 CW_USEDEFAULT
, /* x */
182 CW_USEDEFAULT
, /* y */
183 rect
.right
- rect
.left
, /* width */
184 rect
.bottom
- rect
.top
, /* height */
195 * Verify the client area size matches the specified size.
198 GetClientRect(hWnd
, &rect
);
199 assert(rect
.left
== 0);
200 assert(rect
.top
== 0);
201 assert(rect
.right
- rect
.left
== iWidth
);
202 assert(rect
.bottom
- rect
.top
== iHeight
);
211 * We can't pass non-displayable pixel formats to GDI, which is why we
212 * create the framebuffer object before calling SetPixelFormat().
214 fb
= stw_framebuffer_create(hDC
, iPixelFormat
);
216 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
221 iDisplayablePixelFormat
= fb
->iDisplayablePixelFormat
;
223 stw_framebuffer_release(fb
);
226 * We need to set a displayable pixel format on the hidden window DC
227 * so that wglCreateContext and wglMakeCurrent are not overruled by GDI.
229 bRet
= SetPixelFormat(hDC
, iDisplayablePixelFormat
, &pfd
);
232 return (HPBUFFERARB
)fb
;
237 wglGetPbufferDCARB(HPBUFFERARB hPbuffer
)
239 struct stw_framebuffer
*fb
;
242 fb
= (struct stw_framebuffer
*)hPbuffer
;
244 hDC
= GetDC(fb
->hWnd
);
246 assert(hDC
== fb
->hDC
);
253 wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
,
256 struct stw_framebuffer
*fb
;
258 fb
= (struct stw_framebuffer
*)hPbuffer
;
260 return ReleaseDC(fb
->hWnd
, hDC
);
265 wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
267 struct stw_framebuffer
*fb
;
269 fb
= (struct stw_framebuffer
*)hPbuffer
;
271 /* This will destroy all our data */
272 return DestroyWindow(fb
->hWnd
);
277 wglQueryPbufferARB(HPBUFFERARB hPbuffer
,
281 struct stw_framebuffer
*fb
;
283 fb
= (struct stw_framebuffer
*)hPbuffer
;
285 switch (iAttribute
) {
286 case WGL_PBUFFER_WIDTH_ARB
:
287 *piValue
= fb
->width
;
289 case WGL_PBUFFER_HEIGHT_ARB
:
290 *piValue
= fb
->height
;
292 case WGL_PBUFFER_LOST_ARB
:
293 /* We assume that no content is ever lost due to display mode change */
297 SetLastError(ERROR_INVALID_DATA
);