1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 |
|
---|
8 | #define WIN32_LEAN_AND_MEAN
|
---|
9 | #include <windows.h>
|
---|
10 |
|
---|
11 | #include <stdlib.h>
|
---|
12 | #include <stdio.h>
|
---|
13 | #include <memory.h>
|
---|
14 |
|
---|
15 | #include "cr_environment.h"
|
---|
16 | #include "cr_error.h"
|
---|
17 | #include "cr_string.h"
|
---|
18 | #include "renderspu.h"
|
---|
19 | #include "cr_mem.h"
|
---|
20 |
|
---|
21 | #define WINDOW_NAME window->title
|
---|
22 |
|
---|
23 | static BOOL
|
---|
24 | bSetupPixelFormat( HDC hdc, GLbitfield visAttribs );
|
---|
25 |
|
---|
26 | GLboolean renderspu_SystemInitVisual( VisualInfo *visual )
|
---|
27 | {
|
---|
28 | if (visual->visAttribs & CR_PBUFFER_BIT) {
|
---|
29 | crWarning("Render SPU: PBuffers not support on Windows yet.");
|
---|
30 | }
|
---|
31 |
|
---|
32 | /* In the windows world, we need a window before a context.
|
---|
33 | * Use the device_context as a marker to do just that */
|
---|
34 | visual->device_context = 0;
|
---|
35 |
|
---|
36 | return TRUE;
|
---|
37 | }
|
---|
38 |
|
---|
39 | void renderspu_SystemDestroyWindow( WindowInfo *window )
|
---|
40 | {
|
---|
41 | VBOX_RENDERSPU_DESTROY_WINDOW vrdw;
|
---|
42 |
|
---|
43 | CRASSERT(window);
|
---|
44 |
|
---|
45 | /*DestroyWindow( window->hWnd );*/
|
---|
46 |
|
---|
47 | vrdw.hWnd = window->hWnd;
|
---|
48 |
|
---|
49 | if (render_spu.dwWinThreadId)
|
---|
50 | {
|
---|
51 | PostThreadMessage(render_spu.dwWinThreadId, WM_VBOX_RENDERSPU_DESTROY_WINDOW, 0, (LPARAM) &vrdw);
|
---|
52 | WaitForSingleObject(render_spu.hWinThreadReadyEvent, INFINITE);
|
---|
53 | }
|
---|
54 | else
|
---|
55 | {
|
---|
56 | crError("Render SPU: window thread is not running");
|
---|
57 | }
|
---|
58 |
|
---|
59 | window->hWnd = NULL;
|
---|
60 | window->visual = NULL;
|
---|
61 | }
|
---|
62 |
|
---|
63 | static LONG WINAPI
|
---|
64 | MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
|
---|
65 | {
|
---|
66 | /* int w,h; */
|
---|
67 |
|
---|
68 | switch ( uMsg ) {
|
---|
69 |
|
---|
70 | case WM_SIZE:
|
---|
71 | /* w = LOWORD( lParam );
|
---|
72 | * h = HIWORD( lParam ); */
|
---|
73 |
|
---|
74 | /* glViewport( 0, 0, w, h ); */
|
---|
75 | #if 0
|
---|
76 | glViewport( -render_spu.mural_x, -render_spu.mural_y,
|
---|
77 | render_spu.mural_width, render_spu.mural_height );
|
---|
78 | glScissor( -render_spu.mural_x, -render_spu.mural_y,
|
---|
79 | render_spu.mural_width, render_spu.mural_height );
|
---|
80 | #endif
|
---|
81 | break;
|
---|
82 |
|
---|
83 | case WM_CLOSE:
|
---|
84 | crWarning( "Render SPU: caught WM_CLOSE -- quitting." );
|
---|
85 | exit( 0 );
|
---|
86 | break;
|
---|
87 |
|
---|
88 | case WM_NCHITTEST:
|
---|
89 | crDebug("WM_NCHITTEST");
|
---|
90 | return HTNOWHERE;
|
---|
91 | }
|
---|
92 |
|
---|
93 | return DefWindowProc( hWnd, uMsg, wParam, lParam );
|
---|
94 | }
|
---|
95 |
|
---|
96 | static BOOL
|
---|
97 | bSetupPixelFormatEXT( HDC hdc, GLbitfield visAttribs)
|
---|
98 | {
|
---|
99 | PIXELFORMATDESCRIPTOR ppfd;
|
---|
100 | int pixelFormat;
|
---|
101 | int attribList[100];
|
---|
102 | float fattribList[] = { 0.0, 0.0 };
|
---|
103 | int numFormats;
|
---|
104 | int i = 0;
|
---|
105 | BOOL vis;
|
---|
106 |
|
---|
107 | CRASSERT(visAttribs & CR_RGB_BIT); /* anybody need color index */
|
---|
108 |
|
---|
109 | crWarning("Render SPU: Using WGL_EXT_pixel_format to select visual ID.");
|
---|
110 |
|
---|
111 | attribList[i++] = WGL_DRAW_TO_WINDOW_EXT;
|
---|
112 | attribList[i++] = GL_TRUE;
|
---|
113 | attribList[i++] = WGL_ACCELERATION_EXT;
|
---|
114 | attribList[i++] = WGL_FULL_ACCELERATION_EXT;
|
---|
115 | attribList[i++] = WGL_COLOR_BITS_EXT;
|
---|
116 | attribList[i++] = 24;
|
---|
117 | attribList[i++] = WGL_RED_BITS_EXT;
|
---|
118 | attribList[i++] = 1;
|
---|
119 | attribList[i++] = WGL_GREEN_BITS_EXT;
|
---|
120 | attribList[i++] = 1;
|
---|
121 | attribList[i++] = WGL_BLUE_BITS_EXT;
|
---|
122 | attribList[i++] = 1;
|
---|
123 |
|
---|
124 | crWarning("Render SPU: Visual chosen is... RGB");
|
---|
125 |
|
---|
126 | if (visAttribs & CR_ALPHA_BIT)
|
---|
127 | {
|
---|
128 | attribList[i++] = WGL_ALPHA_BITS_EXT;
|
---|
129 | attribList[i++] = 1;
|
---|
130 | crWarning("A");
|
---|
131 | }
|
---|
132 |
|
---|
133 | crWarning(", ");
|
---|
134 |
|
---|
135 | if (visAttribs & CR_DOUBLE_BIT) {
|
---|
136 | attribList[i++] = WGL_DOUBLE_BUFFER_EXT;
|
---|
137 | attribList[i++] = GL_TRUE;
|
---|
138 | crWarning("DB, ");
|
---|
139 | }
|
---|
140 |
|
---|
141 | if (visAttribs & CR_STEREO_BIT) {
|
---|
142 | attribList[i++] = WGL_STEREO_EXT;
|
---|
143 | attribList[i++] = GL_TRUE;
|
---|
144 | crWarning("Stereo, ");
|
---|
145 | }
|
---|
146 |
|
---|
147 | if (visAttribs & CR_DEPTH_BIT)
|
---|
148 | {
|
---|
149 | attribList[i++] = WGL_DEPTH_BITS_EXT;
|
---|
150 | attribList[i++] = 1;
|
---|
151 | crWarning("Z, ");
|
---|
152 | }
|
---|
153 |
|
---|
154 | if (visAttribs & CR_STENCIL_BIT)
|
---|
155 | {
|
---|
156 | attribList[i++] = WGL_STENCIL_BITS_EXT;
|
---|
157 | attribList[i++] = 1;
|
---|
158 | crWarning("Stencil, ");
|
---|
159 | }
|
---|
160 |
|
---|
161 | if (visAttribs & CR_ACCUM_BIT)
|
---|
162 | {
|
---|
163 | attribList[i++] = WGL_ACCUM_RED_BITS_EXT;
|
---|
164 | attribList[i++] = 1;
|
---|
165 | attribList[i++] = WGL_ACCUM_GREEN_BITS_EXT;
|
---|
166 | attribList[i++] = 1;
|
---|
167 | attribList[i++] = WGL_ACCUM_BLUE_BITS_EXT;
|
---|
168 | attribList[i++] = 1;
|
---|
169 | crWarning("Accum, ");
|
---|
170 | if (visAttribs & CR_ALPHA_BIT)
|
---|
171 | {
|
---|
172 | attribList[i++] = WGL_ACCUM_ALPHA_BITS_EXT;
|
---|
173 | attribList[i++] = 1;
|
---|
174 | crWarning("Accum Alpha, ");
|
---|
175 | }
|
---|
176 | }
|
---|
177 |
|
---|
178 | if (visAttribs & CR_MULTISAMPLE_BIT)
|
---|
179 | {
|
---|
180 | attribList[i++] = WGL_SAMPLE_BUFFERS_EXT;
|
---|
181 | attribList[i++] = 1;
|
---|
182 | attribList[i++] = WGL_SAMPLES_EXT;
|
---|
183 | attribList[i++] = 4;
|
---|
184 | crWarning("Multisample, ");
|
---|
185 | }
|
---|
186 |
|
---|
187 | crWarning("\n");
|
---|
188 |
|
---|
189 | /* End the list */
|
---|
190 | attribList[i++] = 0;
|
---|
191 | attribList[i++] = 0;
|
---|
192 |
|
---|
193 | vis = render_spu.ws.wglChoosePixelFormatEXT( hdc, attribList, fattribList, 1, &pixelFormat, &numFormats);
|
---|
194 |
|
---|
195 | crDebug("Render SPU: wglChoosePixelFormatEXT (vis 0x%x, LastError 0x%x, pixelFormat 0x%x", vis, GetLastError(), pixelFormat);
|
---|
196 |
|
---|
197 | render_spu.ws.wglSetPixelFormat( hdc, pixelFormat, &ppfd );
|
---|
198 |
|
---|
199 | crDebug("Render SPU: wglSetPixelFormat (Last error 0x%x)", GetLastError());
|
---|
200 |
|
---|
201 | return vis;
|
---|
202 | }
|
---|
203 |
|
---|
204 | static BOOL
|
---|
205 | bSetupPixelFormatNormal( HDC hdc, GLbitfield visAttribs )
|
---|
206 | {
|
---|
207 | PIXELFORMATDESCRIPTOR pfd = {
|
---|
208 | sizeof(PIXELFORMATDESCRIPTOR), /* size of this pfd */
|
---|
209 | 1, /* version number */
|
---|
210 | PFD_DRAW_TO_WINDOW | /* support window */
|
---|
211 | PFD_SUPPORT_OPENGL, /* support OpenGL */
|
---|
212 | PFD_TYPE_RGBA, /* RGBA type */
|
---|
213 | 24, /* 24-bit color depth */
|
---|
214 | 0, 0, 0, 0, 0, 0, /* color bits ignored */
|
---|
215 | 0, /* no alpha buffer */
|
---|
216 | 0, /* shift bit ignored */
|
---|
217 | 0, /* no accumulation buffer */
|
---|
218 | 0, 0, 0, 0, /* accum bits ignored */
|
---|
219 | 0, /* set depth buffer */
|
---|
220 | 0, /* set stencil buffer */
|
---|
221 | 0, /* no auxiliary buffer */
|
---|
222 | PFD_MAIN_PLANE, /* main layer */
|
---|
223 | 0, /* reserved */
|
---|
224 | 0, 0, 0 /* layer masks ignored */
|
---|
225 | };
|
---|
226 | PIXELFORMATDESCRIPTOR *ppfd = &pfd;
|
---|
227 | char s[1000];
|
---|
228 | GLbitfield b = 0;
|
---|
229 | int pixelformat;
|
---|
230 |
|
---|
231 | renderspuMakeVisString( visAttribs, s );
|
---|
232 |
|
---|
233 | crWarning( "Render SPU: WGL wants these visual capabilities: %s", s);
|
---|
234 |
|
---|
235 | /* These really come into play with sort-last configs */
|
---|
236 | if (visAttribs & CR_DEPTH_BIT)
|
---|
237 | ppfd->cDepthBits = 24;
|
---|
238 | if (visAttribs & CR_ACCUM_BIT)
|
---|
239 | ppfd->cAccumBits = 16;
|
---|
240 | if (visAttribs & CR_RGB_BIT)
|
---|
241 | ppfd->cColorBits = 24;
|
---|
242 | if (visAttribs & CR_STENCIL_BIT)
|
---|
243 | ppfd->cStencilBits = 8;
|
---|
244 | if (visAttribs & CR_ALPHA_BIT)
|
---|
245 | ppfd->cAlphaBits = 8;
|
---|
246 | if (visAttribs & CR_DOUBLE_BIT)
|
---|
247 | ppfd->dwFlags |= PFD_DOUBLEBUFFER;
|
---|
248 | if (visAttribs & CR_STEREO_BIT)
|
---|
249 | ppfd->dwFlags |= PFD_STEREO;
|
---|
250 |
|
---|
251 | /*
|
---|
252 | * We call the wgl functions directly if the SPU was loaded
|
---|
253 | * by our faker library, otherwise we have to call the GDI
|
---|
254 | * versions.
|
---|
255 | */
|
---|
256 | if (crGetenv( "CR_WGL_DO_NOT_USE_GDI" ) != NULL)
|
---|
257 | {
|
---|
258 | pixelformat = render_spu.ws.wglChoosePixelFormat( hdc, ppfd );
|
---|
259 | /* doing this twice is normal Win32 magic */
|
---|
260 | pixelformat = render_spu.ws.wglChoosePixelFormat( hdc, ppfd );
|
---|
261 | if ( pixelformat == 0 )
|
---|
262 | {
|
---|
263 | crError( "render_spu.ws.wglChoosePixelFormat failed" );
|
---|
264 | }
|
---|
265 | if ( !render_spu.ws.wglSetPixelFormat( hdc, pixelformat, ppfd ) )
|
---|
266 | {
|
---|
267 | crError( "render_spu.ws.wglSetPixelFormat failed" );
|
---|
268 | }
|
---|
269 |
|
---|
270 | render_spu.ws.wglDescribePixelFormat( hdc, pixelformat, sizeof(*ppfd), ppfd );
|
---|
271 | }
|
---|
272 | else
|
---|
273 | {
|
---|
274 | /* Okay, we were loaded manually. Call the GDI functions. */
|
---|
275 | pixelformat = ChoosePixelFormat( hdc, ppfd );
|
---|
276 | /* doing this twice is normal Win32 magic */
|
---|
277 | pixelformat = ChoosePixelFormat( hdc, ppfd );
|
---|
278 | if ( pixelformat == 0 )
|
---|
279 | {
|
---|
280 | crError( "ChoosePixelFormat failed" );
|
---|
281 | }
|
---|
282 | if ( !SetPixelFormat( hdc, pixelformat, ppfd ) )
|
---|
283 | {
|
---|
284 | crError( "SetPixelFormat failed (Error 0x%x)", GetLastError() );
|
---|
285 | }
|
---|
286 |
|
---|
287 | DescribePixelFormat( hdc, pixelformat, sizeof(*ppfd), ppfd );
|
---|
288 | }
|
---|
289 |
|
---|
290 |
|
---|
291 | if (ppfd->cDepthBits > 0)
|
---|
292 | b |= CR_DEPTH_BIT;
|
---|
293 | if (ppfd->cAccumBits > 0)
|
---|
294 | b |= CR_ACCUM_BIT;
|
---|
295 | if (ppfd->cColorBits > 8)
|
---|
296 | b |= CR_RGB_BIT;
|
---|
297 | if (ppfd->cStencilBits > 0)
|
---|
298 | b |= CR_STENCIL_BIT;
|
---|
299 | if (ppfd->cAlphaBits > 0)
|
---|
300 | b |= CR_ALPHA_BIT;
|
---|
301 | if (ppfd->dwFlags & PFD_DOUBLEBUFFER)
|
---|
302 | b |= CR_DOUBLE_BIT;
|
---|
303 | if (ppfd->dwFlags & PFD_STEREO)
|
---|
304 | b |= CR_STEREO_BIT;
|
---|
305 |
|
---|
306 | renderspuMakeVisString( b, s );
|
---|
307 |
|
---|
308 | crWarning( "Render SPU: WGL chose these visual capabilities: %s", s);
|
---|
309 | return TRUE;
|
---|
310 | }
|
---|
311 |
|
---|
312 | static BOOL
|
---|
313 | bSetupPixelFormat( HDC hdc, GLbitfield visAttribs )
|
---|
314 | {
|
---|
315 | /* According to http://www.opengl.org/resources/faq/technical/mswindows.htm
|
---|
316 | we shouldn't be using wgl functions to setup pixel formats unless we're loading ICD driver.
|
---|
317 | In particular, bSetupPixelFormatEXT bugs with Intel drivers.
|
---|
318 | */
|
---|
319 | return bSetupPixelFormatNormal(hdc, visAttribs);
|
---|
320 | }
|
---|
321 |
|
---|
322 | GLboolean renderspu_SystemCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window )
|
---|
323 | {
|
---|
324 | HDESK desktop;
|
---|
325 | HINSTANCE hinstance;
|
---|
326 | WNDCLASS wc;
|
---|
327 | DWORD window_style;
|
---|
328 | int window_plus_caption_width;
|
---|
329 | int window_plus_caption_height;
|
---|
330 |
|
---|
331 | window->visual = visual;
|
---|
332 | window->nativeWindow = 0;
|
---|
333 |
|
---|
334 | if ( render_spu.use_L2 )
|
---|
335 | {
|
---|
336 | crWarning( "Going fullscreen because we think we're using Lightning-2." );
|
---|
337 | render_spu.fullscreen = 1;
|
---|
338 | }
|
---|
339 |
|
---|
340 | /*
|
---|
341 | * Begin Windows / WGL code
|
---|
342 | */
|
---|
343 |
|
---|
344 | hinstance = GetModuleHandle( NULL );
|
---|
345 | if (!hinstance)
|
---|
346 | {
|
---|
347 | crError( "Render SPU: Couldn't get a handle to my module." );
|
---|
348 | return GL_FALSE;
|
---|
349 | }
|
---|
350 | crDebug( "Render SPU: Got the module handle: 0x%x", hinstance );
|
---|
351 |
|
---|
352 | /* If we were launched from a service, telnet, or rsh, we need to
|
---|
353 | * get the input desktop. */
|
---|
354 |
|
---|
355 | desktop = OpenInputDesktop( 0, FALSE,
|
---|
356 | DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
|
---|
357 | DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
|
---|
358 | DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
|
---|
359 | DESKTOP_SWITCHDESKTOP | GENERIC_WRITE );
|
---|
360 |
|
---|
361 | if ( !desktop )
|
---|
362 | {
|
---|
363 | crError( "Render SPU: Couldn't aquire input desktop" );
|
---|
364 | return GL_FALSE;
|
---|
365 | }
|
---|
366 | crDebug( "Render SPU: Got the desktop: 0x%x", desktop );
|
---|
367 |
|
---|
368 | if ( !SetThreadDesktop( desktop ) )
|
---|
369 | {
|
---|
370 | /* If this function fails, it's probably because
|
---|
371 | * it's already been called (i.e., the render SPU
|
---|
372 | * is bolted to an application?) */
|
---|
373 |
|
---|
374 | /*crError( "Couldn't set thread to input desktop" ); */
|
---|
375 | }
|
---|
376 | crDebug( "Render SPU: Set the thread desktop -- this might have failed." );
|
---|
377 |
|
---|
378 | if ( !GetClassInfo(hinstance, WINDOW_NAME, &wc) )
|
---|
379 | {
|
---|
380 | wc.style = CS_OWNDC;
|
---|
381 | wc.lpfnWndProc = (WNDPROC) MainWndProc;
|
---|
382 | wc.cbClsExtra = 0;
|
---|
383 | wc.cbWndExtra = 0;
|
---|
384 | wc.hInstance = hinstance;
|
---|
385 | wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
|
---|
386 | wc.hCursor = LoadCursor( NULL, IDC_ARROW );
|
---|
387 | wc.hbrBackground = NULL;
|
---|
388 | wc.lpszMenuName = NULL;
|
---|
389 | wc.lpszClassName = WINDOW_NAME;
|
---|
390 |
|
---|
391 | if ( !RegisterClass( &wc ) )
|
---|
392 | {
|
---|
393 | crError( "Render SPU: Couldn't register window class -- you're not trying "
|
---|
394 | "to do multi-pipe stuff on windows, are you?\n\nNote --"
|
---|
395 | "This error message is from 1997 and probably doesn't make"
|
---|
396 | "any sense any more, but it's nostalgic for Humper." );
|
---|
397 | return GL_FALSE;
|
---|
398 | }
|
---|
399 | crDebug( "Render SPU: Registered the class" );
|
---|
400 | }
|
---|
401 | crDebug( "Render SPU: Got the class information" );
|
---|
402 |
|
---|
403 | /* Full screen window should be a popup (undecorated) window */
|
---|
404 | #if 1
|
---|
405 | window_style = ( render_spu.fullscreen ? WS_POPUP : WS_CAPTION );
|
---|
406 | #else
|
---|
407 | window_style = ( WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN );
|
---|
408 | window_style |= WS_SYSMENU;
|
---|
409 | #endif
|
---|
410 |
|
---|
411 | crDebug( "Render SPU: Fullscreen: %s", render_spu.fullscreen ? "yes" : "no");
|
---|
412 |
|
---|
413 | if ( render_spu.fullscreen )
|
---|
414 | {
|
---|
415 | #if 0
|
---|
416 |
|
---|
417 | int smCxFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME );
|
---|
418 | int smCyFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME ) + 1;
|
---|
419 | int smCyCaption = GetSystemMetrics( SM_CYCAPTION );
|
---|
420 |
|
---|
421 | window->width = GetSystemMetrics( SM_CXSCREEN ) ;
|
---|
422 | window->height = GetSystemMetrics( SM_CYSCREEN ) ;
|
---|
423 |
|
---|
424 | crDebug( "Render SPU: Window Dims: %d, %d", window->width, window->height );
|
---|
425 |
|
---|
426 | window->x = render_spu->defaultX - smCxFixedFrame - 1;
|
---|
427 | window->y = render_spu->defaultY - smCyFixedFrame - smCyCaption;
|
---|
428 |
|
---|
429 | window_plus_caption_width = window->width + 2 * smCxFixedFrame;
|
---|
430 | window_plus_caption_height = window->height + 2 * smCyFixedFrame + smCyCaption;
|
---|
431 |
|
---|
432 | #else
|
---|
433 | /* Since it's undecorated, we don't have to do anything fancy
|
---|
434 | * with these parameters. */
|
---|
435 |
|
---|
436 | window->width = GetSystemMetrics( SM_CXSCREEN ) ;
|
---|
437 | window->height = GetSystemMetrics( SM_CYSCREEN ) ;
|
---|
438 | window->x = 0;
|
---|
439 | window->y = 0;
|
---|
440 | window_plus_caption_width = window->width;
|
---|
441 | window_plus_caption_height = window->height;
|
---|
442 |
|
---|
443 | #endif
|
---|
444 | }
|
---|
445 | else
|
---|
446 | {
|
---|
447 | /* CreateWindow takes the size of the entire window, so we add
|
---|
448 | * in the size necessary for the frame and the caption. */
|
---|
449 |
|
---|
450 | int smCxFixedFrame, smCyFixedFrame, smCyCaption;
|
---|
451 | smCxFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME );
|
---|
452 | crDebug( "Render SPU: Got the X fixed frame" );
|
---|
453 | smCyFixedFrame = GetSystemMetrics( SM_CYFIXEDFRAME );
|
---|
454 | crDebug( "Render SPU: Got the Y fixed frame" );
|
---|
455 | smCyCaption = GetSystemMetrics( SM_CYCAPTION );
|
---|
456 | crDebug( "Render SPU: Got the Caption " );
|
---|
457 |
|
---|
458 | window_plus_caption_width = window->width + 2 * smCxFixedFrame;
|
---|
459 | window_plus_caption_height = window->height + 2 * smCyFixedFrame + smCyCaption;
|
---|
460 |
|
---|
461 | window->x = render_spu.defaultX - smCxFixedFrame;
|
---|
462 | window->y = render_spu.defaultY - smCyFixedFrame - smCyCaption;
|
---|
463 | }
|
---|
464 |
|
---|
465 | crDebug( "Render SPU: Creating the window: (%d,%d), (%d,%d)", render_spu.defaultX, render_spu.defaultY, window_plus_caption_width, window_plus_caption_height );
|
---|
466 | window->hWnd = CreateWindow( WINDOW_NAME, WINDOW_NAME,
|
---|
467 | window_style,
|
---|
468 | window->x, window->y,
|
---|
469 | window_plus_caption_width,
|
---|
470 | window_plus_caption_height,
|
---|
471 | NULL, NULL, hinstance, &render_spu );
|
---|
472 |
|
---|
473 | if ( !window->hWnd )
|
---|
474 | {
|
---|
475 | crError( "Render SPU: Create Window failed! That's almost certainly terrible." );
|
---|
476 | return GL_FALSE;
|
---|
477 | }
|
---|
478 |
|
---|
479 | if (showIt) {
|
---|
480 | /* NO ERROR CODE FOR SHOWWINDOW */
|
---|
481 | crDebug( "Render SPU: Showing the window" );
|
---|
482 | ShowWindow( window->hWnd, SW_SHOWNORMAL );
|
---|
483 | }
|
---|
484 |
|
---|
485 | SetForegroundWindow( window->hWnd );
|
---|
486 |
|
---|
487 | SetWindowPos( window->hWnd, HWND_TOP, window->x, window->y,
|
---|
488 | window_plus_caption_width, window_plus_caption_height,
|
---|
489 | ( render_spu.fullscreen ? (SWP_SHOWWINDOW |
|
---|
490 | SWP_NOSENDCHANGING |
|
---|
491 | SWP_NOREDRAW |
|
---|
492 | SWP_NOACTIVATE ) :
|
---|
493 | 0 ) );
|
---|
494 |
|
---|
495 | if ( render_spu.fullscreen )
|
---|
496 | ShowCursor( FALSE );
|
---|
497 |
|
---|
498 | window->device_context = GetDC( window->hWnd );
|
---|
499 |
|
---|
500 | crDebug( "Render SPU: Got the DC: 0x%x", window->device_context );
|
---|
501 |
|
---|
502 | if ( !bSetupPixelFormat( window->device_context, visual->visAttribs ) )
|
---|
503 | {
|
---|
504 | crError( "Render SPU: Couldn't set up the device context! Yikes!" );
|
---|
505 | return GL_FALSE;
|
---|
506 | }
|
---|
507 |
|
---|
508 | return GL_TRUE;
|
---|
509 | }
|
---|
510 |
|
---|
511 | GLboolean renderspu_SystemVBoxCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window )
|
---|
512 | {
|
---|
513 | HDESK desktop;
|
---|
514 | HINSTANCE hinstance;
|
---|
515 | WNDCLASS wc;
|
---|
516 | DWORD window_style;
|
---|
517 | int window_plus_caption_width;
|
---|
518 | int window_plus_caption_height;
|
---|
519 |
|
---|
520 | window->visual = visual;
|
---|
521 | window->nativeWindow = 0;
|
---|
522 |
|
---|
523 | if ( render_spu.use_L2 )
|
---|
524 | {
|
---|
525 | crWarning( "Going fullscreen because we think we're using Lightning-2." );
|
---|
526 | render_spu.fullscreen = 1;
|
---|
527 | }
|
---|
528 |
|
---|
529 | /*
|
---|
530 | * Begin Windows / WGL code
|
---|
531 | */
|
---|
532 |
|
---|
533 | hinstance = GetModuleHandle( NULL );
|
---|
534 | if (!hinstance)
|
---|
535 | {
|
---|
536 | crError( "Render SPU: Couldn't get a handle to my module." );
|
---|
537 | return GL_FALSE;
|
---|
538 | }
|
---|
539 | crDebug( "Render SPU: Got the module handle: 0x%x", hinstance );
|
---|
540 |
|
---|
541 | #if 0
|
---|
542 | /* If we were launched from a service, telnet, or rsh, we need to
|
---|
543 | * get the input desktop. */
|
---|
544 |
|
---|
545 | desktop = OpenInputDesktop( 0, FALSE,
|
---|
546 | DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
|
---|
547 | DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
|
---|
548 | DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
|
---|
549 | DESKTOP_SWITCHDESKTOP | GENERIC_WRITE );
|
---|
550 |
|
---|
551 | if ( !desktop )
|
---|
552 | {
|
---|
553 | crError( "Render SPU: Couldn't aquire input desktop" );
|
---|
554 | return GL_FALSE;
|
---|
555 | }
|
---|
556 | crDebug( "Render SPU: Got the desktop: 0x%x", desktop );
|
---|
557 |
|
---|
558 | if ( !SetThreadDesktop( desktop ) )
|
---|
559 | {
|
---|
560 | /* If this function fails, it's probably because
|
---|
561 | * it's already been called (i.e., the render SPU
|
---|
562 | * is bolted to an application?) */
|
---|
563 |
|
---|
564 | /*crError( "Couldn't set thread to input desktop" ); */
|
---|
565 | }
|
---|
566 | crDebug( "Render SPU: Set the thread desktop -- this might have failed." );
|
---|
567 | #endif
|
---|
568 |
|
---|
569 | if ( !GetClassInfo(hinstance, WINDOW_NAME, &wc) )
|
---|
570 | {
|
---|
571 | wc.style = CS_OWNDC; // | CS_PARENTDC;
|
---|
572 | wc.lpfnWndProc = (WNDPROC) MainWndProc;
|
---|
573 | wc.cbClsExtra = 0;
|
---|
574 | wc.cbWndExtra = 0;
|
---|
575 | wc.hInstance = hinstance;
|
---|
576 | wc.hIcon = NULL; //LoadIcon( NULL, IDI_APPLICATION );
|
---|
577 | wc.hCursor = NULL; //LoadCursor( NULL, IDC_ARROW );
|
---|
578 | wc.hbrBackground = NULL;
|
---|
579 | wc.lpszMenuName = NULL;
|
---|
580 | wc.lpszClassName = WINDOW_NAME;
|
---|
581 |
|
---|
582 | if ( !RegisterClass( &wc ) )
|
---|
583 | {
|
---|
584 | crError( "Render SPU: Couldn't register window class -- you're not trying "
|
---|
585 | "to do multi-pipe stuff on windows, are you?\n\nNote --"
|
---|
586 | "This error message is from 1997 and probably doesn't make"
|
---|
587 | "any sense any more, but it's nostalgic for Humper." );
|
---|
588 | return GL_FALSE;
|
---|
589 | }
|
---|
590 | crDebug( "Render SPU: Registered the class" );
|
---|
591 | }
|
---|
592 | crDebug( "Render SPU: Got the class information" );
|
---|
593 |
|
---|
594 | /* Full screen window should be a popup (undecorated) window */
|
---|
595 | #if 1
|
---|
596 | window_style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_DISABLED;
|
---|
597 | if (render_spu_parent_window_id)
|
---|
598 | {
|
---|
599 | window_style |= WS_CHILD;
|
---|
600 | }
|
---|
601 | #else
|
---|
602 | window_style = ( WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN );
|
---|
603 | window_style |= WS_SYSMENU;
|
---|
604 | #endif
|
---|
605 |
|
---|
606 | crDebug( "Render SPU: Fullscreen: %s", render_spu.fullscreen ? "yes" : "no");
|
---|
607 |
|
---|
608 | if ( render_spu.fullscreen )
|
---|
609 | {
|
---|
610 | #if 0
|
---|
611 |
|
---|
612 | int smCxFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME );
|
---|
613 | int smCyFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME ) + 1;
|
---|
614 | int smCyCaption = GetSystemMetrics( SM_CYCAPTION );
|
---|
615 |
|
---|
616 | window->width = GetSystemMetrics( SM_CXSCREEN ) ;
|
---|
617 | window->height = GetSystemMetrics( SM_CYSCREEN ) ;
|
---|
618 |
|
---|
619 | crDebug( "Render SPU: Window Dims: %d, %d", window->width, window->height );
|
---|
620 |
|
---|
621 | window->x = render_spu->defaultX - smCxFixedFrame - 1;
|
---|
622 | window->y = render_spu->defaultY - smCyFixedFrame - smCyCaption;
|
---|
623 |
|
---|
624 | window_plus_caption_width = window->width + 2 * smCxFixedFrame;
|
---|
625 | window_plus_caption_height = window->height + 2 * smCyFixedFrame + smCyCaption;
|
---|
626 |
|
---|
627 | #else
|
---|
628 | /* Since it's undecorated, we don't have to do anything fancy
|
---|
629 | * with these parameters. */
|
---|
630 |
|
---|
631 | window->width = GetSystemMetrics( SM_CXSCREEN ) ;
|
---|
632 | window->height = GetSystemMetrics( SM_CYSCREEN ) ;
|
---|
633 | window->x = 0;
|
---|
634 | window->y = 0;
|
---|
635 | window_plus_caption_width = window->width;
|
---|
636 | window_plus_caption_height = window->height;
|
---|
637 |
|
---|
638 | #endif
|
---|
639 | }
|
---|
640 | else
|
---|
641 | {
|
---|
642 | /* CreateWindow takes the size of the entire window, so we add
|
---|
643 | * in the size necessary for the frame and the caption. */
|
---|
644 | int smCxFixedFrame, smCyFixedFrame, smCyCaption;
|
---|
645 | smCxFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME );
|
---|
646 | crDebug( "Render SPU: Got the X fixed frame" );
|
---|
647 | smCyFixedFrame = GetSystemMetrics( SM_CYFIXEDFRAME );
|
---|
648 | crDebug( "Render SPU: Got the Y fixed frame" );
|
---|
649 | smCyCaption = GetSystemMetrics( SM_CYCAPTION );
|
---|
650 | crDebug( "Render SPU: Got the Caption " );
|
---|
651 |
|
---|
652 | window_plus_caption_width = window->width + 2 * smCxFixedFrame;
|
---|
653 | window_plus_caption_height = window->height + 2 * smCyFixedFrame + smCyCaption;
|
---|
654 |
|
---|
655 | window->x = render_spu.defaultX;
|
---|
656 | window->y = render_spu.defaultY;
|
---|
657 | }
|
---|
658 |
|
---|
659 | crDebug( "Render SPU: Creating the window: (%d,%d), (%d,%d)", render_spu.defaultX, render_spu.defaultY, window_plus_caption_width, window_plus_caption_height );
|
---|
660 | /*window->hWnd = CreateWindowEx( WS_EX_NOACTIVATE | WS_EX_NOPARENTNOTIFY,
|
---|
661 | WINDOW_NAME, WINDOW_NAME,
|
---|
662 | window_style,
|
---|
663 | window->x, window->y,
|
---|
664 | window->width,
|
---|
665 | window->height,
|
---|
666 | (void*) render_spu_parent_window_id, NULL, hinstance, &render_spu );*/
|
---|
667 | {
|
---|
668 | CREATESTRUCT cs;
|
---|
669 |
|
---|
670 | cs.lpCreateParams = &window->hWnd;
|
---|
671 |
|
---|
672 | cs.dwExStyle = WS_EX_NOACTIVATE | WS_EX_NOPARENTNOTIFY;
|
---|
673 | cs.lpszName = WINDOW_NAME;
|
---|
674 | cs.lpszClass = WINDOW_NAME;
|
---|
675 | cs.style = window_style;
|
---|
676 | cs.x = window->x;
|
---|
677 | cs.y = window->y;
|
---|
678 | cs.cx = window->width;
|
---|
679 | cs.cy = window->height;
|
---|
680 | cs.hwndParent = (void*) render_spu_parent_window_id;
|
---|
681 | cs.hMenu = NULL;
|
---|
682 | cs.hInstance = hinstance;
|
---|
683 |
|
---|
684 | if (render_spu.dwWinThreadId)
|
---|
685 | {
|
---|
686 | DWORD res;
|
---|
687 | int cnt=0;
|
---|
688 |
|
---|
689 | if (!PostThreadMessage(render_spu.dwWinThreadId, WM_VBOX_RENDERSPU_CREATE_WINDOW, 0, (LPARAM) &cs))
|
---|
690 | {
|
---|
691 | crError("Render SPU: PostThreadMessage failed with %i", GetLastError());
|
---|
692 | return GL_FALSE;
|
---|
693 | }
|
---|
694 |
|
---|
695 | do
|
---|
696 | {
|
---|
697 | res = WaitForSingleObject(render_spu.hWinThreadReadyEvent, 1000);
|
---|
698 | cnt++;
|
---|
699 | }
|
---|
700 | while ((res!=WAIT_OBJECT_0) && (cnt<10));
|
---|
701 |
|
---|
702 | crDebug("Render SPU: window thread waited %i secs", cnt);
|
---|
703 |
|
---|
704 | if (res!=WAIT_OBJECT_0)
|
---|
705 | {
|
---|
706 | crError("Render SPU: window thread not responded after %i tries", cnt);
|
---|
707 | return GL_FALSE;
|
---|
708 | }
|
---|
709 | }
|
---|
710 | else
|
---|
711 | {
|
---|
712 | crError("Render SPU: window thread is not running");
|
---|
713 | return GL_FALSE;
|
---|
714 | }
|
---|
715 | }
|
---|
716 |
|
---|
717 | if ( !window->hWnd )
|
---|
718 | {
|
---|
719 | crError( "Render SPU: Create Window failed! That's almost certainly terrible." );
|
---|
720 | return GL_FALSE;
|
---|
721 | }
|
---|
722 |
|
---|
723 | if (showIt) {
|
---|
724 | /* NO ERROR CODE FOR SHOWWINDOW */
|
---|
725 | crDebug( "Render SPU: Showing the window" );
|
---|
726 | ShowWindow( window->hWnd, SW_SHOWNORMAL );
|
---|
727 | }
|
---|
728 |
|
---|
729 | //SetForegroundWindow( visual->hWnd );
|
---|
730 |
|
---|
731 | SetWindowPos( window->hWnd, HWND_TOP, window->x, window->y,
|
---|
732 | window->width, window->height,
|
---|
733 | ( render_spu.fullscreen ?
|
---|
734 | (SWP_SHOWWINDOW | SWP_NOSENDCHANGING | SWP_NOREDRAW | SWP_NOACTIVATE ) : SWP_NOACTIVATE
|
---|
735 | ) );
|
---|
736 | crDebug("Render SPU: SetWindowPos (%x, %d, %d, %d, %d)", window->hWnd,
|
---|
737 | window->x, window->y, window->width, window->height);
|
---|
738 |
|
---|
739 | if ( render_spu.fullscreen )
|
---|
740 | ShowCursor( FALSE );
|
---|
741 |
|
---|
742 | window->device_context = GetDC( window->hWnd );
|
---|
743 |
|
---|
744 | crDebug( "Render SPU: Got the DC: 0x%x", window->device_context );
|
---|
745 |
|
---|
746 | if ( !bSetupPixelFormat( window->device_context, visual->visAttribs ) )
|
---|
747 | {
|
---|
748 | crError( "Render SPU: Couldn't set up the device context! Yikes!" );
|
---|
749 | return GL_FALSE;
|
---|
750 | }
|
---|
751 |
|
---|
752 | return GL_TRUE;
|
---|
753 | }
|
---|
754 |
|
---|
755 |
|
---|
756 | /* Either show or hide the render SPU's window. */
|
---|
757 | void renderspu_SystemShowWindow( WindowInfo *window, GLboolean showIt )
|
---|
758 | {
|
---|
759 | if (showIt)
|
---|
760 | ShowWindow( window->hWnd, SW_SHOWNORMAL );
|
---|
761 | else
|
---|
762 | ShowWindow( window->hWnd, SW_HIDE );
|
---|
763 | }
|
---|
764 |
|
---|
765 | GLboolean renderspu_SystemCreateContext( VisualInfo *visual, ContextInfo *context, ContextInfo *sharedContext )
|
---|
766 | {
|
---|
767 | (void) sharedContext;
|
---|
768 | context->visual = visual;
|
---|
769 |
|
---|
770 | /* Found a visual, so we're o.k. to create the context now */
|
---|
771 | if (0/*visual->device_context*/) {
|
---|
772 |
|
---|
773 | //crDebug( "Render SPU: Using the DC: 0x%x", visual->device_context );
|
---|
774 |
|
---|
775 | //context->hRC = render_spu.ws.wglCreateContext( visual->device_context );
|
---|
776 | if (!context->hRC)
|
---|
777 | {
|
---|
778 | crError( "Render SPU: wglCreateContext failed (error 0x%x)", GetLastError() );
|
---|
779 | return GL_FALSE;
|
---|
780 | }
|
---|
781 | } else {
|
---|
782 | crDebug( "Render SPU: Delaying DC creation " );
|
---|
783 | context->hRC = NULL; /* create it later in makecurrent */
|
---|
784 | }
|
---|
785 |
|
---|
786 |
|
---|
787 | return GL_TRUE;
|
---|
788 | }
|
---|
789 |
|
---|
790 | void renderspu_SystemDestroyContext( ContextInfo *context )
|
---|
791 | {
|
---|
792 | render_spu.ws.wglDeleteContext( context->hRC );
|
---|
793 | context->hRC = NULL;
|
---|
794 | }
|
---|
795 |
|
---|
796 | void renderspu_SystemMakeCurrent( WindowInfo *window, GLint nativeWindow, ContextInfo *context )
|
---|
797 | {
|
---|
798 | CRASSERT(render_spu.ws.wglMakeCurrent);
|
---|
799 |
|
---|
800 | if (context && window) {
|
---|
801 | if (window->visual != context->visual) {
|
---|
802 | /*
|
---|
803 | * XXX have to revisit this issue!!!
|
---|
804 | *
|
---|
805 | * But for now we destroy the current window
|
---|
806 | * and re-create it with the context's visual abilities
|
---|
807 | */
|
---|
808 |
|
---|
809 | /*@todo Chromium has no correct code to remove window ids and associated info from
|
---|
810 | * various tables. This is hack which just hides the root case.
|
---|
811 | */
|
---|
812 | crDebug("Recreating window in renderspu_SystemMakeCurrent\n");
|
---|
813 | renderspu_SystemDestroyWindow( window );
|
---|
814 | renderspu_SystemVBoxCreateWindow( context->visual, window->visible, window );
|
---|
815 | }
|
---|
816 |
|
---|
817 | if (render_spu.render_to_app_window && nativeWindow)
|
---|
818 | {
|
---|
819 | /* The render_to_app_window option
|
---|
820 | * is set and we've got a nativeWindow
|
---|
821 | * handle, save the handle for
|
---|
822 | * later calls to swapbuffers().
|
---|
823 | *
|
---|
824 | * NOTE: This doesn't work, except
|
---|
825 | * for software driven Mesa.
|
---|
826 | * We'd need to object link the
|
---|
827 | * crappfaker and crserver to be able to share
|
---|
828 | * the HDC values between processes.. FIXME!
|
---|
829 | */
|
---|
830 | window->nativeWindow = (HDC) nativeWindow;
|
---|
831 | if (context->hRC == 0) {
|
---|
832 | context->hRC = render_spu.ws.wglCreateContext( window->nativeWindow );
|
---|
833 | if (!context->hRC)
|
---|
834 | {
|
---|
835 | crError( "(MakeCurrent) Couldn't create the context for the window (error 0x%x)", GetLastError() );
|
---|
836 | }
|
---|
837 | }
|
---|
838 | render_spu.ws.wglMakeCurrent( window->nativeWindow, context->hRC );
|
---|
839 | }
|
---|
840 | else
|
---|
841 | {
|
---|
842 | if (!context->visual->device_context) {
|
---|
843 | context->visual->device_context = GetDC( window->hWnd );
|
---|
844 |
|
---|
845 | crDebug( "Render SPU: MakeCurrent made the DC: 0x%x", context->visual->device_context );
|
---|
846 |
|
---|
847 | if ( !bSetupPixelFormat( context->visual->device_context, context->visual->visAttribs ) )
|
---|
848 | {
|
---|
849 | crError( "Render SPU: (MakeCurrent) Couldn't set up the device context! Yikes!" );
|
---|
850 | }
|
---|
851 | }
|
---|
852 |
|
---|
853 | if (!context->hRC) {
|
---|
854 | context->hRC = render_spu.ws.wglCreateContext(context->visual->device_context);
|
---|
855 | if (!context->hRC)
|
---|
856 | {
|
---|
857 | crError( "Render SPU: (MakeCurrent) Couldn't create the context for the window (error 0x%x)", GetLastError() );
|
---|
858 | }
|
---|
859 | }
|
---|
860 |
|
---|
861 | if (!render_spu.ws.wglMakeCurrent(window->device_context, context->hRC))
|
---|
862 | {
|
---|
863 | DWORD err = GetLastError();
|
---|
864 | crError("Render SPU: (MakeCurrent) failed to make 0x%x, 0x%x current with 0x%x error.", window->device_context, context->hRC, err);
|
---|
865 | }
|
---|
866 | }
|
---|
867 |
|
---|
868 | }
|
---|
869 | else {
|
---|
870 | render_spu.ws.wglMakeCurrent( 0, 0 );
|
---|
871 | }
|
---|
872 | }
|
---|
873 |
|
---|
874 | void renderspu_SystemWindowSize( WindowInfo *window, GLint w, GLint h )
|
---|
875 | {
|
---|
876 | int winprop;
|
---|
877 | CRASSERT(window);
|
---|
878 | CRASSERT(window->visual);
|
---|
879 | if ( render_spu.fullscreen )
|
---|
880 | winprop = SWP_SHOWWINDOW | SWP_NOSENDCHANGING |
|
---|
881 | SWP_NOREDRAW | SWP_NOACTIVATE;
|
---|
882 | else
|
---|
883 | winprop = SWP_NOACTIVATE | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_NOZORDER; //SWP_SHOWWINDOW;
|
---|
884 |
|
---|
885 | /*SetWindowRgn(window->hWnd, NULL, false);*/
|
---|
886 |
|
---|
887 | if (!SetWindowPos( window->hWnd, HWND_TOP,
|
---|
888 | window->x, window->y, w, h, winprop )) {
|
---|
889 | crWarning("!!!FAILED!!! Render SPU: SetWindowPos (%x, %d, %d, %d, %d)", window->hWnd, window->x, window->y, w, h);
|
---|
890 | } else {
|
---|
891 | crDebug("Render SPU: SetWindowSize (%x, %d, %d, %d, %d)", window->hWnd, window->x, window->y, w, h);
|
---|
892 | }
|
---|
893 | /* save the new size */
|
---|
894 | window->width = w;
|
---|
895 | window->height = h;
|
---|
896 | }
|
---|
897 |
|
---|
898 |
|
---|
899 | void renderspu_SystemGetWindowGeometry( WindowInfo *window, GLint *x, GLint *y, GLint *w, GLint *h )
|
---|
900 | {
|
---|
901 | RECT rect;
|
---|
902 |
|
---|
903 | CRASSERT(window);
|
---|
904 | CRASSERT(window->visual);
|
---|
905 |
|
---|
906 | GetClientRect( window->hWnd, &rect );
|
---|
907 | *x = rect.left;
|
---|
908 | *y = rect.top;
|
---|
909 | *w = rect.right - rect.left;
|
---|
910 | *h = rect.bottom - rect.top;
|
---|
911 | }
|
---|
912 |
|
---|
913 |
|
---|
914 | void renderspu_SystemGetMaxWindowSize( WindowInfo *window, GLint *w, GLint *h )
|
---|
915 | {
|
---|
916 | /* XXX fix this */
|
---|
917 | (void) window;
|
---|
918 | *w = 1600;
|
---|
919 | *h = 1200;
|
---|
920 | }
|
---|
921 |
|
---|
922 |
|
---|
923 | void renderspu_SystemWindowPosition( WindowInfo *window, GLint x, GLint y )
|
---|
924 | {
|
---|
925 | int winprop;
|
---|
926 | CRASSERT(window);
|
---|
927 | CRASSERT(window->visual);
|
---|
928 | if ( render_spu.fullscreen )
|
---|
929 | winprop = SWP_SHOWWINDOW | SWP_NOSENDCHANGING |
|
---|
930 | SWP_NOREDRAW | SWP_NOACTIVATE;
|
---|
931 | else
|
---|
932 | winprop = SWP_NOACTIVATE | SWP_DEFERERASE | SWP_NOSENDCHANGING | SWP_NOZORDER; //SWP_SHOWWINDOW;
|
---|
933 |
|
---|
934 | /*SetWindowRgn(window->visual->hWnd, NULL, false);*/
|
---|
935 |
|
---|
936 | if (!SetWindowPos( window->hWnd, HWND_TOP,
|
---|
937 | x, y, window->width, window->height, winprop )) {
|
---|
938 | crWarning("!!!FAILED!!! Render SPU: SetWindowPos (%x, %d, %d, %d, %d)", window->hWnd, x, y, window->width, window->height);
|
---|
939 | } else {
|
---|
940 | crDebug("Render SPU: SetWindowPos (%x, %d, %d, %d, %d)", window->hWnd,
|
---|
941 | x, y, window->width, window->height);
|
---|
942 | }
|
---|
943 | }
|
---|
944 |
|
---|
945 | void renderspu_SystemWindowVisibleRegion(WindowInfo *window, GLint cRects, GLint* pRects)
|
---|
946 | {
|
---|
947 | GLint i;
|
---|
948 | HRGN hRgn, hTmpRgn;
|
---|
949 |
|
---|
950 | CRASSERT(window);
|
---|
951 | CRASSERT(window->visual);
|
---|
952 |
|
---|
953 | hRgn = CreateRectRgn(0, 0, 0, 0);
|
---|
954 |
|
---|
955 | for (i=0; i<cRects; i++)
|
---|
956 | {
|
---|
957 | hTmpRgn = CreateRectRgn(pRects[4*i], pRects[4*i+1], pRects[4*i+2], pRects[4*i+3]);
|
---|
958 | CombineRgn(hRgn, hRgn, hTmpRgn, RGN_OR);
|
---|
959 | DeleteObject(hTmpRgn);
|
---|
960 | }
|
---|
961 |
|
---|
962 | SetWindowRgn(window->hWnd, hRgn, true);
|
---|
963 | crDebug("Render SPU: SetWindowRgn (%x, cRects=%i)", window->hWnd, cRects);
|
---|
964 | }
|
---|
965 |
|
---|
966 | static void renderspuHandleWindowMessages( HWND hWnd )
|
---|
967 | {
|
---|
968 | MSG msg;
|
---|
969 | while ( PeekMessage( &msg, hWnd, 0, 0xffffffff, PM_REMOVE ) )
|
---|
970 | {
|
---|
971 | TranslateMessage( &msg );
|
---|
972 | DispatchMessage( &msg );
|
---|
973 | }
|
---|
974 |
|
---|
975 | //BringWindowToTop( hWnd );
|
---|
976 | }
|
---|
977 |
|
---|
978 | void renderspu_SystemSwapBuffers( WindowInfo *w, GLint flags )
|
---|
979 | {
|
---|
980 | int return_value;
|
---|
981 |
|
---|
982 | /* peek at the windows message queue */
|
---|
983 | renderspuHandleWindowMessages( w->hWnd );
|
---|
984 |
|
---|
985 | /* render_to_app_window:
|
---|
986 | * w->nativeWindow will only be non-zero if the
|
---|
987 | * render_spu.render_to_app_window option is true and
|
---|
988 | * MakeCurrent() recorded the nativeWindow handle in the WindowInfo
|
---|
989 | * structure.
|
---|
990 | */
|
---|
991 | if (render_spu.render_to_app_window && w->nativeWindow) {
|
---|
992 | return_value = render_spu.ws.wglSwapBuffers( w->nativeWindow );
|
---|
993 | } else {
|
---|
994 | /*
|
---|
995 | HRGN hRgn1, hRgn2, hRgn3;
|
---|
996 | HWND hWndParent;
|
---|
997 | LONG ws;
|
---|
998 |
|
---|
999 | hRgn1 = CreateRectRgn(0, 0, w->width, w->height);
|
---|
1000 | hRgn2 = CreateRectRgn(50, 50, 100, 100);
|
---|
1001 | hRgn3 = CreateRectRgn(0, 0, 0, 0);
|
---|
1002 | CombineRgn(hRgn3, hRgn1, hRgn2, RGN_DIFF);
|
---|
1003 | SetWindowRgn(w->visual->hWnd, hRgn3, true);
|
---|
1004 | DeleteObject(hRgn1);
|
---|
1005 | DeleteObject(hRgn2);
|
---|
1006 |
|
---|
1007 | hWndParent = GetParent(w->visual->hWnd);
|
---|
1008 | ws = GetWindowLong(hWndParent, GWL_STYLE);
|
---|
1009 | ws &= ~WS_CLIPCHILDREN;
|
---|
1010 | SetWindowLong(hWndParent, GWL_STYLE, ws);
|
---|
1011 |
|
---|
1012 | RECT rcClip;
|
---|
1013 |
|
---|
1014 | rcClip.left = 50;
|
---|
1015 | rcClip.top = 50;
|
---|
1016 | rcClip.right = 100;
|
---|
1017 | rcClip.bottom = 100;
|
---|
1018 | ValidateRect(w->visual->hWnd, &rcClip);
|
---|
1019 |
|
---|
1020 | return_value = GetClipBox(w->visual->device_context, &rcClip);
|
---|
1021 | crDebug("GetClipBox returned %d (NR=%d,SR=%d,CR=%d,ERR=%d)",
|
---|
1022 | return_value, NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR);
|
---|
1023 |
|
---|
1024 | crDebug("rcClip(%d, %d, %d, %d)", rcClip.left, rcClip.top, rcClip.right, rcClip.bottom);
|
---|
1025 |
|
---|
1026 | return_value = ExcludeClipRect(w->visual->device_context, 50, 50, 100, 100);
|
---|
1027 | crDebug("ExcludeClipRect returned %d (NR=%d,SR=%d,CR=%d,ERR=%d)",
|
---|
1028 | return_value, NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR);
|
---|
1029 |
|
---|
1030 | return_value = GetClipBox(w->visual->device_context, &rcClip);
|
---|
1031 | crDebug("GetClipBox returned %d (NR=%d,SR=%d,CR=%d,ERR=%d)",
|
---|
1032 | return_value, NULLREGION, SIMPLEREGION, COMPLEXREGION, ERROR);
|
---|
1033 | crDebug("rcClip(%d, %d, %d, %d)", rcClip.left, rcClip.top, rcClip.right, rcClip.bottom);
|
---|
1034 | */
|
---|
1035 | return_value = render_spu.ws.wglSwapBuffers( w->device_context );
|
---|
1036 | }
|
---|
1037 | if (!return_value)
|
---|
1038 | {
|
---|
1039 | /* GOD DAMN IT. The latest versions of the NVIDIA drivers
|
---|
1040 | * return failure from wglSwapBuffers, but it works just fine.
|
---|
1041 | * WHAT THE HELL?! */
|
---|
1042 |
|
---|
1043 | crWarning( "wglSwapBuffers failed: return value of %d!", return_value);
|
---|
1044 | }
|
---|
1045 | }
|
---|