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"
44 wglCreatePbufferARB(HDC _hDC
,
48 const int *piAttribList
)
50 static boolean first
= TRUE
;
53 const struct stw_pixelformat_info
*info
;
54 struct stw_framebuffer
*fb
;
58 info
= stw_pixelformat_get_info(iPixelFormat
);
60 SetLastError(ERROR_INVALID_PIXEL_FORMAT
);
64 if (iWidth
<= 0 || iHeight
<= 0) {
65 SetLastError(ERROR_INVALID_DATA
);
69 for (piAttrib
= piAttribList
; *piAttrib
; piAttrib
++) {
71 case WGL_PBUFFER_LARGEST_ARB
:
73 useLargest
= *piAttrib
;
76 SetLastError(ERROR_INVALID_DATA
);
81 if (iWidth
> stw_dev
->max_2d_length
) {
83 iWidth
= stw_dev
->max_2d_length
;
85 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
90 if (iHeight
> stw_dev
->max_2d_length
) {
92 iHeight
= stw_dev
->max_2d_length
;
94 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
100 * Implement pbuffers through invisible windows
105 memset(&wc
, 0, sizeof wc
);
106 wc
.hbrBackground
= (HBRUSH
) (COLOR_BTNFACE
+ 1);
107 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
108 wc
.hIcon
= LoadIcon(NULL
, IDI_APPLICATION
);
109 wc
.lpfnWndProc
= DefWindowProc
;
110 wc
.lpszClassName
= "wglpbuffer";
111 wc
.style
= CS_OWNDC
| CS_HREDRAW
| CS_VREDRAW
;
116 hWnd
= CreateWindowEx(0,
117 "wglpbuffer", /* wc.lpszClassName */
119 #if 0 /* Useful for debugging what the application is drawing */
122 WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
,
123 CW_USEDEFAULT
, CW_USEDEFAULT
, /* x, y */
138 SetPixelFormat(hDC
, iPixelFormat
, &info
->pfd
);
140 fb
= stw_framebuffer_create(hDC
, iPixelFormat
);
142 SetLastError(ERROR_NO_SYSTEM_RESOURCES
);
145 return (HPBUFFERARB
)fb
;
150 wglGetPbufferDCARB(HPBUFFERARB hPbuffer
)
152 struct stw_framebuffer
*fb
;
155 fb
= (struct stw_framebuffer
*)hPbuffer
;
157 hDC
= GetDC(fb
->hWnd
);
158 SetPixelFormat(hDC
, fb
->iPixelFormat
, &fb
->pfi
->pfd
);
165 wglReleasePbufferDCARB(HPBUFFERARB hPbuffer
,
168 struct stw_framebuffer
*fb
;
170 fb
= (struct stw_framebuffer
*)hPbuffer
;
172 return ReleaseDC(fb
->hWnd
, hDC
);
177 wglDestroyPbufferARB(HPBUFFERARB hPbuffer
)
179 struct stw_framebuffer
*fb
;
181 fb
= (struct stw_framebuffer
*)hPbuffer
;
183 /* This will destroy all our data */
184 return DestroyWindow(fb
->hWnd
);
189 wglQueryPbufferARB(HPBUFFERARB hPbuffer
,
193 struct stw_framebuffer
*fb
;
195 fb
= (struct stw_framebuffer
*)hPbuffer
;
197 switch (iAttribute
) {
198 case WGL_PBUFFER_WIDTH_ARB
:
199 *piValue
= fb
->width
;
201 case WGL_PBUFFER_HEIGHT_ARB
:
202 *piValue
= fb
->width
;
204 case WGL_PBUFFER_LOST_ARB
:
205 /* We assume that no content is ever lost due to display mode change */
209 SetLastError(ERROR_INVALID_DATA
);