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
);
104 for (piAttrib
= piAttribList
; *piAttrib
; piAttrib
++) {
106 case WGL_PBUFFER_LARGEST_ARB
:
108 useLargest
= *piAttrib
;
110 case WGL_TEXTURE_FORMAT_ARB
:
111 /* WGL_ARB_render_texture */
113 textureFormat
= *piAttrib
;
114 if (textureFormat
!= WGL_TEXTURE_RGB_ARB
&&
115 textureFormat
!= WGL_TEXTURE_RGBA_ARB
&&
116 textureFormat
!= WGL_NO_TEXTURE_ARB
) {
117 SetLastError(ERROR_INVALID_DATA
);
121 case WGL_TEXTURE_TARGET_ARB
:
122 /* WGL_ARB_render_texture */
124 textureTarget
= *piAttrib
;
125 if (textureTarget
!= WGL_TEXTURE_CUBE_MAP_ARB
&&
126 textureTarget
!= WGL_TEXTURE_1D_ARB
&&
127 textureTarget
!= WGL_TEXTURE_2D_ARB
&&
128 textureTarget
!= WGL_NO_TEXTURE_ARB
) {
129 SetLastError(ERROR_INVALID_DATA
);
133 case WGL_MIPMAP_TEXTURE_ARB
:
134 /* WGL_ARB_render_texture */
136 textureMipmap
= !!*piAttrib
;
139 SetLastError(ERROR_INVALID_DATA
);
140 debug_printf("wgl: Unsupported attribute 0x%x in %s\n",
141 *piAttrib
, __func__
);
146 if (iWidth
> stw_dev
->max_2d_length
) {
148 iWidth
= stw_dev
->max_2d_length
;
150 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
155 if (iHeight
> stw_dev
->max_2d_length
) {
157 iHeight
= stw_dev
->max_2d_length
;
159 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
165 * Implement pbuffers through invisible windows
170 memset(&wc
, 0, sizeof wc
);
171 wc
.hbrBackground
= (HBRUSH
) (COLOR_BTNFACE
+ 1);
172 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
173 wc
.hIcon
= LoadIcon(NULL
, IDI_APPLICATION
);
174 wc
.lpfnWndProc
= WndProc
;
175 wc
.lpszClassName
= "wglpbuffer";
176 wc
.style
= CS_OWNDC
| CS_HREDRAW
| CS_VREDRAW
;
182 dwStyle
= WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
186 * Don't hide the window -- useful for debugging what the application is
190 dwStyle
|= WS_VISIBLE
| WS_OVERLAPPEDWINDOW
;
192 dwStyle
|= WS_POPUPWINDOW
;
197 rect
.right
= rect
.left
+ iWidth
;
198 rect
.bottom
= rect
.top
+ iHeight
;
201 * The CreateWindowEx parameters are the total (outside) dimensions of the
202 * window, which can vary with Windows version and user settings. Use
203 * AdjustWindowRect to get the required total area for the given client area.
205 * AdjustWindowRectEx does not accept WS_OVERLAPPED style (which is defined
206 * as 0), which means we need to use some other style instead, e.g.,
207 * WS_OVERLAPPEDWINDOW or WS_POPUPWINDOW as above.
210 AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
212 hWnd
= CreateWindowEx(dwExStyle
,
213 "wglpbuffer", /* wc.lpszClassName */
216 CW_USEDEFAULT
, /* x */
217 CW_USEDEFAULT
, /* y */
218 rect
.right
- rect
.left
, /* width */
219 rect
.bottom
- rect
.top
, /* height */
230 * Verify the client area size matches the specified size.
233 GetClientRect(hWnd
, &rect
);
234 assert(rect
.left
== 0);
235 assert(rect
.top
== 0);
236 assert(rect
.right
- rect
.left
== iWidth
);
237 assert(rect
.bottom
- rect
.top
== iHeight
);
246 * We can't pass non-displayable pixel formats to GDI, which is why we
247 * create the framebuffer object before calling SetPixelFormat().
249 fb
= stw_framebuffer_create(hDC
, iPixelFormat
);
251 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
257 /* WGL_ARB_render_texture fields */
258 fb
->textureTarget
= textureTarget
;
259 fb
->textureFormat
= textureFormat
;
260 fb
->textureMipmap
= textureMipmap
;
262 iDisplayablePixelFormat
= fb
->iDisplayablePixelFormat
;
264 stw_framebuffer_unlock(fb
);
267 * We need to set a displayable pixel format on the hidden window DC
268 * so that wglCreateContext and wglMakeCurrent are not overruled by GDI.
270 bRet
= SetPixelFormat(hDC
, iDisplayablePixelFormat
, &pfd
);
273 return (HPBUFFERARB
)fb
;
278 wglGetPbufferDCARB(HPBUFFERARB hPbuffer
)
280 struct stw_framebuffer
*fb
;
284 SetLastError(ERROR_INVALID_HANDLE
);
288 fb
= stw_framebuffer_from_HPBUFFERARB(hPbuffer
);
290 hDC
= GetDC(fb
->hWnd
);
297 wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
,
300 struct stw_framebuffer
*fb
;
303 SetLastError(ERROR_INVALID_HANDLE
);
307 fb
= stw_framebuffer_from_HPBUFFERARB(hPbuffer
);
309 return ReleaseDC(fb
->hWnd
, hDC
);
314 wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
316 struct stw_framebuffer
*fb
;
319 SetLastError(ERROR_INVALID_HANDLE
);
323 fb
= stw_framebuffer_from_HPBUFFERARB(hPbuffer
);
325 /* This will destroy all our data */
326 return DestroyWindow(fb
->hWnd
);
331 wglQueryPbufferARB(HPBUFFERARB hPbuffer
,
335 struct stw_framebuffer
*fb
;
338 SetLastError(ERROR_INVALID_HANDLE
);
342 fb
= stw_framebuffer_from_HPBUFFERARB(hPbuffer
);
344 switch (iAttribute
) {
345 case WGL_PBUFFER_WIDTH_ARB
:
346 *piValue
= fb
->width
;
348 case WGL_PBUFFER_HEIGHT_ARB
:
349 *piValue
= fb
->height
;
351 case WGL_PBUFFER_LOST_ARB
:
352 /* We assume that no content is ever lost due to display mode change */
355 /* WGL_ARB_render_texture */
356 case WGL_TEXTURE_TARGET_ARB
:
357 *piValue
= fb
->textureTarget
;
359 case WGL_TEXTURE_FORMAT_ARB
:
360 *piValue
= fb
->textureFormat
;
362 case WGL_MIPMAP_TEXTURE_ARB
:
363 *piValue
= fb
->textureMipmap
;
365 case WGL_MIPMAP_LEVEL_ARB
:
366 *piValue
= fb
->textureLevel
;
368 case WGL_CUBE_MAP_FACE_ARB
:
369 *piValue
= fb
->textureFace
+ WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
;
372 SetLastError(ERROR_INVALID_DATA
);