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 "util/u_debug.h"
40 #include "stw_device.h"
41 #include "stw_pixelformat.h"
42 #include "stw_framebuffer.h"
45 #define LARGE_WINDOW_SIZE 60000
48 static LRESULT CALLBACK
49 WndProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
53 case WM_GETMINMAXINFO
:
54 // Allow to create a window bigger than the desktop
55 pMMI
= (MINMAXINFO
*)lParam
;
56 pMMI
->ptMaxSize
.x
= LARGE_WINDOW_SIZE
;
57 pMMI
->ptMaxSize
.y
= LARGE_WINDOW_SIZE
;
58 pMMI
->ptMaxTrackSize
.x
= LARGE_WINDOW_SIZE
;
59 pMMI
->ptMaxTrackSize
.y
= LARGE_WINDOW_SIZE
;
65 return DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
70 wglCreatePbufferARB(HDC hCurrentDC
,
74 const int *piAttribList
)
76 static boolean first
= TRUE
;
79 const struct stw_pixelformat_info
*info
;
80 struct stw_framebuffer
*fb
;
86 int iDisplayablePixelFormat
;
87 PIXELFORMATDESCRIPTOR pfd
;
89 int textureFormat
= WGL_NO_TEXTURE_ARB
;
90 int textureTarget
= WGL_NO_TEXTURE_ARB
;
91 BOOL textureMipmap
= FALSE
;
93 info
= stw_pixelformat_get_info(iPixelFormat
- 1);
95 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
99 if (iWidth
<= 0 || iHeight
<= 0) {
100 SetLastError(ERROR_INVALID_DATA
);
105 for (piAttrib
= piAttribList
; *piAttrib
; piAttrib
++) {
107 case WGL_PBUFFER_LARGEST_ARB
:
109 useLargest
= *piAttrib
;
111 case WGL_TEXTURE_FORMAT_ARB
:
112 /* WGL_ARB_render_texture */
114 textureFormat
= *piAttrib
;
115 if (textureFormat
!= WGL_TEXTURE_RGB_ARB
&&
116 textureFormat
!= WGL_TEXTURE_RGBA_ARB
&&
117 textureFormat
!= WGL_NO_TEXTURE_ARB
) {
118 SetLastError(ERROR_INVALID_DATA
);
122 case WGL_TEXTURE_TARGET_ARB
:
123 /* WGL_ARB_render_texture */
125 textureTarget
= *piAttrib
;
126 if (textureTarget
!= WGL_TEXTURE_CUBE_MAP_ARB
&&
127 textureTarget
!= WGL_TEXTURE_1D_ARB
&&
128 textureTarget
!= WGL_TEXTURE_2D_ARB
&&
129 textureTarget
!= WGL_NO_TEXTURE_ARB
) {
130 SetLastError(ERROR_INVALID_DATA
);
134 case WGL_MIPMAP_TEXTURE_ARB
:
135 /* WGL_ARB_render_texture */
137 textureMipmap
= !!*piAttrib
;
140 SetLastError(ERROR_INVALID_DATA
);
141 debug_printf("wgl: Unsupported attribute 0x%x in %s\n",
142 *piAttrib
, __func__
);
148 if (iWidth
> stw_dev
->max_2d_length
) {
150 iWidth
= stw_dev
->max_2d_length
;
152 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
157 if (iHeight
> stw_dev
->max_2d_length
) {
159 iHeight
= stw_dev
->max_2d_length
;
161 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
167 * Implement pbuffers through invisible windows
172 memset(&wc
, 0, sizeof wc
);
173 wc
.hbrBackground
= (HBRUSH
) (COLOR_BTNFACE
+ 1);
174 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
175 wc
.hIcon
= LoadIcon(NULL
, IDI_APPLICATION
);
176 wc
.lpfnWndProc
= WndProc
;
177 wc
.lpszClassName
= "wglpbuffer";
178 wc
.style
= CS_OWNDC
| CS_HREDRAW
| CS_VREDRAW
;
184 dwStyle
= WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
188 * Don't hide the window -- useful for debugging what the application is
192 dwStyle
|= WS_VISIBLE
| WS_OVERLAPPEDWINDOW
;
194 dwStyle
|= WS_POPUPWINDOW
;
199 rect
.right
= rect
.left
+ iWidth
;
200 rect
.bottom
= rect
.top
+ iHeight
;
203 * The CreateWindowEx parameters are the total (outside) dimensions of the
204 * window, which can vary with Windows version and user settings. Use
205 * AdjustWindowRect to get the required total area for the given client area.
207 * AdjustWindowRectEx does not accept WS_OVERLAPPED style (which is defined
208 * as 0), which means we need to use some other style instead, e.g.,
209 * WS_OVERLAPPEDWINDOW or WS_POPUPWINDOW as above.
212 AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
214 hWnd
= CreateWindowEx(dwExStyle
,
215 "wglpbuffer", /* wc.lpszClassName */
218 CW_USEDEFAULT
, /* x */
219 CW_USEDEFAULT
, /* y */
220 rect
.right
- rect
.left
, /* width */
221 rect
.bottom
- rect
.top
, /* height */
232 * Verify the client area size matches the specified size.
235 GetClientRect(hWnd
, &rect
);
236 assert(rect
.left
== 0);
237 assert(rect
.top
== 0);
238 assert(rect
.right
- rect
.left
== iWidth
);
239 assert(rect
.bottom
- rect
.top
== iHeight
);
248 * We can't pass non-displayable pixel formats to GDI, which is why we
249 * create the framebuffer object before calling SetPixelFormat().
251 fb
= stw_framebuffer_create(hDC
, iPixelFormat
);
253 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
259 /* WGL_ARB_render_texture fields */
260 fb
->textureTarget
= textureTarget
;
261 fb
->textureFormat
= textureFormat
;
262 fb
->textureMipmap
= textureMipmap
;
264 iDisplayablePixelFormat
= fb
->iDisplayablePixelFormat
;
266 stw_framebuffer_unlock(fb
);
269 * We need to set a displayable pixel format on the hidden window DC
270 * so that wglCreateContext and wglMakeCurrent are not overruled by GDI.
272 bRet
= SetPixelFormat(hDC
, iDisplayablePixelFormat
, &pfd
);
275 return (HPBUFFERARB
)fb
;
280 wglGetPbufferDCARB(HPBUFFERARB hPbuffer
)
282 struct stw_framebuffer
*fb
;
286 SetLastError(ERROR_INVALID_HANDLE
);
290 fb
= stw_framebuffer_from_HPBUFFERARB(hPbuffer
);
292 hDC
= GetDC(fb
->hWnd
);
299 wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
,
302 struct stw_framebuffer
*fb
;
305 SetLastError(ERROR_INVALID_HANDLE
);
309 fb
= stw_framebuffer_from_HPBUFFERARB(hPbuffer
);
311 return ReleaseDC(fb
->hWnd
, hDC
);
316 wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
318 struct stw_framebuffer
*fb
;
321 SetLastError(ERROR_INVALID_HANDLE
);
325 fb
= stw_framebuffer_from_HPBUFFERARB(hPbuffer
);
327 /* This will destroy all our data */
328 return DestroyWindow(fb
->hWnd
);
333 wglQueryPbufferARB(HPBUFFERARB hPbuffer
,
337 struct stw_framebuffer
*fb
;
340 SetLastError(ERROR_INVALID_HANDLE
);
344 fb
= stw_framebuffer_from_HPBUFFERARB(hPbuffer
);
346 switch (iAttribute
) {
347 case WGL_PBUFFER_WIDTH_ARB
:
348 *piValue
= fb
->width
;
350 case WGL_PBUFFER_HEIGHT_ARB
:
351 *piValue
= fb
->height
;
353 case WGL_PBUFFER_LOST_ARB
:
354 /* We assume that no content is ever lost due to display mode change */
357 /* WGL_ARB_render_texture */
358 case WGL_TEXTURE_TARGET_ARB
:
359 *piValue
= fb
->textureTarget
;
361 case WGL_TEXTURE_FORMAT_ARB
:
362 *piValue
= fb
->textureFormat
;
364 case WGL_MIPMAP_TEXTURE_ARB
:
365 *piValue
= fb
->textureMipmap
;
367 case WGL_MIPMAP_LEVEL_ARB
:
368 *piValue
= fb
->textureLevel
;
370 case WGL_CUBE_MAP_FACE_ARB
:
371 *piValue
= fb
->textureFace
+ WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
;
374 SetLastError(ERROR_INVALID_DATA
);