1 /***********************************************************************/
2 /* Open Visualization Data Explorer                                    */
3 /* (C) Copyright IBM Corp. 1989,1999                                   */
4 /* ALL RIGHTS RESERVED                                                 */
5 /* This code licensed under the                                        */
6 /*    "IBM PUBLIC LICENSE - Open Visualization Data Explorer"          */
7 /***********************************************************************/
8 /*
9  * (C) COPYRIGHT International Business Machines Corp. 1997
10  * All Rights Reserved
11  * Licensed Materials - Property of IBM
12  *
13  * US Government Users Restricted Rights - Use, duplication or
14  * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
15  */
16 
17 #include <dxconfig.h>
18 
19 
20 
21 #define String dxString
22 #define Object dxObject
23 #define Angle dxAngle
24 #define Matrix dxMatrix
25 #define Screen dxScreen
26 #define Boolean dxBoolean
27 
28 #include <dx/dx.h>
29 
30 #undef String
31 #undef Object
32 #undef Angle
33 #undef Matrix
34 #undef Screen
35 #undef Boolean
36 
37 #if !defined(DX_NATIVE_WINDOWS)
38 #include <X11/Xlib.h>
39 #endif
40 
41 #include <math.h>
42 #include <stdlib.h>     /* for getenv prototype */
43 
44 #include "hwDeclarations.h"
45 #include "hwWindow.h"
46 #include "hwStereo.h"
47 
48 /************** Default Stereo System Modes ********************
49  * Default intialization is no system initialization. Default exit
50  * is to delete the left and right windows if they differ from the
51  * frame.  Two default window modes, both viewports inside the frame.
52  * The first is side-by-size, dividing the frame in half.  The second
53  * is top/bottom, with the top in the topmost 492 scanlines of the
54  * window and the bottom in the lowest 492 scan lines.
55  ****************************************************************/
56 
57 #if defined(DX_NATIVE_WINDOWS)
58 static int  defInitializeStereoSystemMode0(HDC, HWND);
59 static int  defExitStereoSystem0(HDC, HWND, HRGN *, HRGN *);
60 static int  defCreateStereoWindows0(HDC, HWND, HRGN *, WindowInfo *, HRGN *, WindowInfo *);
61 
62 static int  defInitializeStereoSystemMode1(HDC, HWND);
63 static int  defExitStereoSystem1(HDC, HWND, HRGN *, HRGN *);
64 static int  defCreateStereoWindows1(HDC, HWND, HRGN *, WindowInfo *, HRGN *, WindowInfo *);
65 
66 static int  defInitializeStereoSystemMode2(HDC, HWND);
67 static int  defExitStereoSystem2(HDC, HWND, HRGN *, HRGN *);
68 static int  defCreateStereoWindows2(HDC, HWND, HRGN *, WindowInfo *, HRGN *, WindowInfo *);
69 
70 static int  defInitializeStereoSystemMode3(HDC, HWND);
71 static int  defExitStereoSystem3(HDC, HWND, HRGN *, HRGN *);
72 static int  defCreateStereoWindows3(HDC, HWND, HRGN *, WindowInfo *, HRGN *, WindowInfo *);
73 
74 #else
75 static int  defInitializeStereoSystemMode0(Display *, Window);
76 static int  defExitStereoSystem0(Display *, Window, Window, Window);
77 static int  defCreateStereoWindows0(Display *, Window,
78 					Window *, WindowInfo *,
79 					Window *, WindowInfo *);
80 
81 static int  defInitializeStereoSystemMode1(Display *, Window);
82 static int  defExitStereoSystem1(Display *, Window, Window, Window);
83 static int  defCreateStereoWindows1(Display *, Window,
84 					Window *, WindowInfo *,
85 					Window *, WindowInfo *);
86 
87 static int  defInitializeStereoSystemMode2(Display *, Window);
88 static int  defExitStereoSystem2(Display *, Window, Window, Window);
89 static int  defCreateStereoWindows2(Display *, Window,
90 					Window *, WindowInfo *,
91 					Window *, WindowInfo *);
92 
93 static int  defInitializeStereoSystemMode3(Display *, Window);
94 static int  defExitStereoSystem3(Display *, Window, Window, Window);
95 static int  defCreateStereoWindows3(Display *, Window,
96 					Window *, WindowInfo *,
97 					Window *, WindowInfo *);
98 #endif
99 
100 static StereoSystemMode _defaultStereoSystemModes[4];
101 
102 int
DXDefaultStereoSystemModes(int * n,StereoSystemMode ** ssms)103 DXDefaultStereoSystemModes(int *n, StereoSystemMode **ssms)
104 {
105     *ssms = _defaultStereoSystemModes;
106 
107     (*ssms)[0].initializeStereoSystemMode = defInitializeStereoSystemMode0;
108     (*ssms)[0].exitStereo 		  = defExitStereoSystem0;
109     (*ssms)[0].createStereoWindows 	  = defCreateStereoWindows0;
110 
111     (*ssms)[1].initializeStereoSystemMode = defInitializeStereoSystemMode1;
112     (*ssms)[1].exitStereo 		  = defExitStereoSystem1;
113     (*ssms)[1].createStereoWindows 	  = defCreateStereoWindows1;
114 
115     (*ssms)[2].initializeStereoSystemMode = defInitializeStereoSystemMode2;
116     (*ssms)[2].exitStereo 		  = defExitStereoSystem2;
117     (*ssms)[2].createStereoWindows 	  = defCreateStereoWindows2;
118 
119 	(*ssms)[3].exitStereo                 = defExitStereoSystem3;
120 	(*ssms)[3].createStereoWindows        = defCreateStereoWindows3;
121 	(*ssms)[3].initializeStereoSystemMode = defInitializeStereoSystemMode3;
122 
123     *n = 4;
124     return OK;
125 }
126 
127 #if defined(DX_NATIVE_WINDOWS)
128 static int
defInitializeStereoSystemMode0(HDC hdc,HWND w)129 defInitializeStereoSystemMode0(HDC hdc, HWND w)
130 #else
131 static int
132 defInitializeStereoSystemMode0(Display *dpy, Window w)
133 #endif
134 {
135     return OK;
136 }
137 
138 #if defined(DX_NATIVE_WINDOWS)
139 static int
defExitStereoSystem0(HDC hdc,HWND w,HRGN * left,HRGN * right)140 defExitStereoSystem0(HDC hdc, HWND w, HRGN *left, HRGN *right)
141 #else
142 static int
143 defExitStereoSystem0(Display *dpy, Window frame, Window left, Window right)
144 #endif
145 {
146 #if defined(DX_NATIVE_WINDOWS)
147 	return ERROR;
148 #else
149     if (left != frame)
150 	XDestroyWindow(dpy, left);
151     if (right != frame)
152 	XDestroyWindow(dpy, right);
153     return OK;
154 #endif
155 }
156 
157 #if defined(DX_NATIVE_WINDOWS)
158 Error
defCreateStereoWindows0(HDC hdc,HWND w,HRGN * left,WindowInfo * leftWI,HRGN * right,WindowInfo * rightWI)159 defCreateStereoWindows0(HDC hdc, HWND w,
160 						 HRGN *left, WindowInfo *leftWI,
161 						 HRGN *right, WindowInfo *rightWI)
162 #else
163 Error
164 defCreateStereoWindows0(Display *dpy, Window frame,
165 		Window *left, WindowInfo *leftWI,
166 		Window *right, WindowInfo *rightWI)
167 #endif
168 {
169 #if defined(DX_NATIVE_WINDOWS)
170 	return ERROR;
171 #else
172     XWindowAttributes xwattr;
173     XGetWindowAttributes(dpy, frame, &xwattr);
174 
175     *left = frame;
176     leftWI->xOffset = 0;
177     leftWI->yOffset = 0;
178     leftWI->xSize = xwattr.width/2;
179     leftWI->ySize = xwattr.height;
180 
181     leftWI->aspect = xwattr.height / xwattr.width;
182 
183     *right = frame;
184     rightWI->xOffset = xwattr.width/2;
185     rightWI->yOffset = 0;
186     rightWI->xSize = xwattr.width/2;
187     rightWI->ySize = xwattr.height;
188 
189     rightWI->aspect = xwattr.height / xwattr.width;
190 
191     return OK;
192 #endif
193 }
194 
195 #if defined(DX_NATIVE_WINDOWS)
196 static int
defInitializeStereoSystemMode1(HDC hdc,HWND w)197 defInitializeStereoSystemMode1(HDC hdc, HWND w)
198 #else
199 static int
200 defInitializeStereoSystemMode1(Display *dpy, Window w)
201 #endif
202 {
203 #ifdef sgi
204     system("/usr/gfx/setmon -n STR_RECT");
205 #endif
206     return OK;
207 }
208 
209 #if defined(DX_NATIVE_WINDOWS)
210 static int
defExitStereoSystem1(HDC hdc,HWND w,HRGN * left,HRGN * right)211 defExitStereoSystem1(HDC hdc, HWND w, HRGN *left, HRGN *right)
212 #else
213 static int
214 defExitStereoSystem1(Display *dpy, Window frame, Window left, Window right)
215 #endif
216 {
217 #if defined(DX_NATIVE_WINDOWS)
218 	return ERROR;
219 #else
220 #ifdef sgi
221     system("/usr/gfx/setmon -n 60HZ");
222 #endif
223     if (left != frame)
224 	XDestroyWindow(dpy, left);
225     if (right != frame)
226 	XDestroyWindow(dpy, right);
227     return OK;
228 #endif
229 }
230 
231 #if defined(DX_NATIVE_WINDOWS)
232 Error
defCreateStereoWindows1(HDC hdc,HWND w,HRGN * left,WindowInfo * leftWI,HRGN * right,WindowInfo * rightWI)233 defCreateStereoWindows1(HDC hdc, HWND w,
234 						 HRGN *left, WindowInfo *leftWI,
235 						 HRGN *right, WindowInfo *rightWI)
236 #else
237 Error
238 defCreateStereoWindows1(Display *dpy, Window frame,
239 		Window *left, WindowInfo *leftWI,
240 		Window *right, WindowInfo *rightWI)
241 #endif
242 {
243 #if defined(DX_NATIVE_WINDOWS)
244 	return ERROR;
245 #else
246     XWindowAttributes xwattr;
247     XGetWindowAttributes(dpy, frame, &xwattr);
248 
249     *left = frame;
250     leftWI->xOffset = 0;
251     leftWI->yOffset = 0;
252     leftWI->xSize = xwattr.width;
253     leftWI->ySize = 492;
254 
255     leftWI->aspect = 492.0 / xwattr.width;
256 
257     *right = frame;
258     rightWI->xOffset = 0;
259     rightWI->yOffset = xwattr.height-492;
260     rightWI->xSize = xwattr.width;
261     rightWI->ySize = 492;
262 
263     rightWI->aspect = 492.0 / xwattr.width;
264 
265     return OK;
266 #endif
267 }
268 
269 #if defined(DX_NATIVE_WINDOWS)
270 static int
defInitializeStereoSystemMode2(HDC hdc,HWND w)271 defInitializeStereoSystemMode2(HDC hdc, HWND w)
272 #else
273 static int
274 defInitializeStereoSystemMode2(Display *dpy, Window w)
275 #endif
276 {
277     char *cmd = getenv("DX_INIT_STEREO_COMMAND");
278     if (cmd)
279 	system(cmd);
280 
281     return OK;
282 }
283 
284 #if defined(DX_NATIVE_WINDOWS)
285 static int
defExitStereoSystem2(HDC hdc,HWND w,HRGN * left,HRGN * right)286 defExitStereoSystem2(HDC hdc, HWND w, HRGN *left, HRGN *right)
287 #else
288 static int
289 defExitStereoSystem2(Display *dpy, Window frame, Window left, Window right)
290 #endif
291 {
292     char *cmd = getenv("DX_EXIT_STEREO_COMMAND");
293     if (cmd)
294 	system(cmd);
295 
296 #if defined(DX_NATIVE_WINDOWS)
297 	return OK;
298 #else
299     if (left != frame)
300 	XDestroyWindow(dpy, left);
301     if (right != frame)
302 	XDestroyWindow(dpy, right);
303     return OK;
304 #endif
305 }
306 
307 #if defined(DX_NATIVE_WINDOWS)
308 Error
defCreateStereoWindows2(HDC hdc,HWND w,HRGN * left,WindowInfo * leftWI,HRGN * right,WindowInfo * rightWI)309 defCreateStereoWindows2(HDC hdc, HWND w,
310 						 HRGN *left, WindowInfo *leftWI,
311 						 HRGN *right, WindowInfo *rightWI)
312 #else
313 Error
314 defCreateStereoWindows2(Display *dpy, Window frame,
315 		Window *left, WindowInfo *leftWI,
316 		Window *right, WindowInfo *rightWI)
317 #endif
318 {
319 #if defined(DX_NATIVE_WINDOWS)
320 	return ERROR;
321 #else
322 
323     XWindowAttributes xwattr;
324     XGetWindowAttributes(dpy, frame, &xwattr);
325 
326     *left = frame;
327     leftWI->xOffset = 0;
328     leftWI->yOffset = 0;
329     leftWI->xSize = xwattr.width;
330     leftWI->ySize = xwattr.height/2;
331 
332     rightWI->aspect = ((float)rightWI->ySize) / rightWI->xSize;
333 
334     *right = frame;
335     rightWI->xOffset = 0;
336     rightWI->yOffset = xwattr.height/2;
337     rightWI->xSize = xwattr.width;
338     rightWI->ySize = xwattr.height/2;
339 
340     rightWI->aspect = ((float)rightWI->ySize) / rightWI->xSize;
341 
342     return OK;
343 #endif
344 }
345 
346 /********************************************************************/
347 /* GL stereo mode */
348 
349 #if !defined(DX_NATIVE_WINDOWS)
350 Error
defCreateStereoWindows3(Display * dpy,Window frame,Window * left,WindowInfo * leftWI,Window * right,WindowInfo * rightWI)351 defCreateStereoWindows3(Display *dpy, Window frame,
352 		Window *left, WindowInfo *leftWI,
353 		Window *right, WindowInfo *rightWI) {
354 	return ERROR;
355 
356 #else
357 
358 int defCreateStereoWindows3(HDC hdc, HWND w,
359 						 HRGN *left, WindowInfo *leftWI,
360 						 HRGN *right, WindowInfo *rightWI) {
361 	RECT rect;
362 
363 	if (GetWindowRect(w, &rect)) {
364 		leftWI->xOffset = rightWI->xOffset = 0;
365 		leftWI->yOffset = rightWI->yOffset = 0;
366 		leftWI->xSize   = rightWI->xSize   = rect.right - rect.left;
367 		leftWI->ySize   = rightWI->ySize   = rect.bottom - rect.top;
368 		leftWI->aspect  = rightWI->aspect  =
369 			((float) leftWI->ySize) / leftWI->xSize;
370 		return OK;
371 	}
372 	return ERROR;
373 #endif
374 }
375 
376 #if !defined(DX_NATIVE_WINDOWS)
377 static int defInitializeStereoSystemMode3(Display *dpy, Window w) {
378 	return ERROR;
379 
380 #else
381 
382 static int defInitializeStereoSystemMode3(HDC hdc, HWND w) {
383 	char *cmd;
384 	int checkID;
385 	PIXELFORMATDESCRIPTOR checkPfd;
386 
387 	/* reuse 'cmd' here */
388 	cmd = getenv("DX_USE_GL_STEREO");
389 	if (!atoi(cmd)) {
390 		DXMessage("InitStereoSysMode: GL stereo not requested, aborting.");
391 		return ERROR;
392 	}
393 	checkID  = GetPixelFormat(hdc);
394 	if (!DescribePixelFormat(hdc, checkID,
395 		sizeof(PIXELFORMATDESCRIPTOR), &checkPfd)) {
396 		return ERROR;
397 	}
398 	if ((checkPfd.dwFlags & PFD_STEREO) == 0) {
399 		DXMessage("InitStereoSysMode: init failed: PFD_STEREO not set");
400 		return ERROR;
401 	}
402 
403 	return OK;
404 #endif
405 }
406 
407 #if !defined(DX_NATIVE_WINDOWS)
408 static int defExitStereoSystem3(Display *dpy, Window frame, Window left, Window right) {
409 	return ERROR;
410 
411 #else
412 
413 static int defExitStereoSystem3(HDC hdc, HWND w, HRGN *left, HRGN *right) {
414 //	char *cmd;
415 
416 /* needed?
417 	cmd = getenv("DX_EXIT_STEREO_COMMAND");
418 	if (cmd)			system(cmd);
419 */
420 	return OK;
421 #endif
422 }
423