1 // BEGIN_COPYRIGHT -*- glean -*-
3 // Copyright (C) 1999 Allen Akin All Rights Reserved.
5 // Permission is hereby granted, free of charge, to any person
6 // obtaining a copy of this software and associated documentation
7 // files (the "Software"), to deal in the Software without
8 // restriction, including without limitation the rights to use,
9 // copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 // KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
32 // winsys.cpp: implementation of window-system services class
47 ///////////////////////////////////////////////////////////////////////////////
49 ///////////////////////////////////////////////////////////////////////////////
51 WindowSystem::WindowSystem(Options
& o
) {
52 // If running in "compare" mode we never actually use the window
53 // system, so we don't initialize it here. This allows us to run
54 // on systems without graphics hardware/software.
55 if (o
.mode
== Options::compare
) {
57 GLXVersMajor
= GLXVersMinor
= 0;
62 // Open the X11 display:
63 dpy
= XOpenDisplay(o
.dpyName
.c_str());
65 throw CantOpenDisplay();
67 // Verify that GLX is supported:
68 int error_base
, event_base
;
69 if (glXQueryExtension(dpy
, &error_base
, &event_base
) == False
)
72 // Record version numbers for later use:
73 if (glXQueryVersion(dpy
, &GLXVersMajor
, &GLXVersMinor
) == False
)
74 throw Error(); // this should never happen :-)
76 // Get the list of raw XVisualInfo structures:
78 vit
.screen
= DefaultScreen(dpy
);
80 vip
= XGetVisualInfo(dpy
, VisualScreenMask
, &vit
, &n
);
82 // Construct a vector of DrawingSurfaceConfigs corresponding to the
83 // XVisualInfo structures that indicate they support OpenGL:
84 vector
<DrawingSurfaceConfig
*> glxv
;
85 for (int i
= 0; i
< n
; ++i
) {
87 glXGetConfig(dpy
, &vip
[i
], GLX_USE_GL
, &supportsOpenGL
);
89 glxv
.push_back(new DrawingSurfaceConfig (dpy
, &vip
[i
]));
92 // Filter the basic list of DrawingSurfaceConfigs according to
93 // constraints provided by the user. (This makes it convenient
94 // to run tests on just a subset of all available configs.)
95 DrawingSurfaceFilter
f(o
.visFilter
); // may throw an exception!
96 surfConfigs
= f
.filter(glxv
, o
.maxVisuals
);
97 } // WindowSystem::WindowSystem
99 #elif defined(__WIN__)
100 WindowSystem::WindowSystem(Options
& o
) {
101 // register an window class
105 wc
.lpfnWndProc
= Window::WindowProc
;
108 wc
.hInstance
= GetModuleHandle(NULL
);
109 wc
.hIcon
= LoadIcon(wc
.hInstance
, "glean");
110 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
111 wc
.hbrBackground
= (HBRUSH
) (COLOR_WINDOW
+ 1);
112 wc
.lpszMenuName
= NULL
;
113 wc
.lpszClassName
= "glean";
115 if (!RegisterClass(&wc
))
119 HDC hDC
= GetDC(GetDesktopWindow());
121 PIXELFORMATDESCRIPTOR pfd
;
122 int n
= DescribePixelFormat(hDC
,0,sizeof(pfd
),0);
124 vector
<DrawingSurfaceConfig
*> glpf
;
126 for (int i
= 1;i
<= n
;++i
) {
127 DescribePixelFormat(hDC
,i
,sizeof(pfd
),&pfd
);
129 glpf
.push_back(new DrawingSurfaceConfig(i
,&pfd
));
132 ReleaseDC(GetDesktopWindow(),hDC
);
134 // Filter the basic list of DrawingSurfaceConfigs according to
135 // constraints provided by the user. (This makes it convenient
136 // to run tests on just a subset of all available configs.)
137 DrawingSurfaceFilter
f(o
.visFilter
); // may throw an exception!
138 surfConfigs
= f
.filter(glpf
, o
.maxVisuals
);
141 #elif defined(__BEWIN__)
142 WindowSystem::WindowSystem(Options
& o
) {
143 //cout << "Implement Me! WindowSystem::WindowSystem(Options& o)\n";
145 theApp
= new BApplication("application/x-AJH-glean");
147 /* for BeOS, we just stack the current config onto the vector so */
148 /* there is at least one thing to iterate over */
149 vector
<DrawingSurfaceConfig
*> glconfigs
;
150 glconfigs
.push_back(new DrawingSurfaceConfig());
152 DrawingSurfaceFilter
f(o
.visFilter
); // may throw an exception!
153 surfConfigs
= f
.filter(glconfigs
, o
.maxVisuals
);
157 #elif defined(__AGL__)
158 WindowSystem::WindowSystem(Options
& o
) {
160 //HW/SW Depth Reserved
161 GLint testTypes
[][3] = {
162 {AGL_ACCELERATED
, 16, 0 },
163 {AGL_ACCELERATED
, 16, 0 },
164 {AGL_ACCELERATED
, 16, 0 },
169 GLint testAttrib
[][10]= {
170 { AGL_RGBA
, AGL_DOUBLEBUFFER
, AGL_ACCELERATED
, 16, AGL_NONE
, AGL_NONE
, AGL_NONE
, AGL_NONE
, AGL_NONE
, AGL_NONE
},
171 { AGL_RGBA
, AGL_ACCELERATED
, AGL_DOUBLEBUFFER
, AGL_DEPTH_SIZE
, 16, AGL_NONE
, AGL_NONE
, AGL_NONE
, AGL_NONE
, AGL_NONE
},
172 { AGL_RGBA
, AGL_DOUBLEBUFFER
, AGL_NONE
, AGL_NONE
, AGL_NONE
, AGL_NONE
, AGL_NONE
, AGL_NONE
, AGL_NONE
, AGL_NONE
},
173 { AGL_RENDERER_ID
, AGL_RENDERER_GENERIC_ID
, AGL_RGBA
, AGL_DOUBLEBUFFER
, AGL_NONE
, AGL_NONE
, AGL_NONE
, AGL_NONE
, AGL_NONE
, AGL_NONE
},
174 { AGL_RENDERER_ID
, AGL_RENDERER_GENERIC_ID
, AGL_RGBA
, AGL_DOUBLEBUFFER
, AGL_DEPTH_SIZE
, 16 , AGL_NONE
, AGL_NONE
, AGL_NONE
, AGL_NONE
}
179 mainGD
= GetMainDevice();
181 throw CantOpenDisplay();
183 // Construct a vector of DrawingSurfaceConfigs corresponding to the
184 // returned pixel formats
185 vector
<DrawingSurfaceConfig
*> glpf
;
187 while (testTypes
[index
][1] != 0)
189 pf
= aglChoosePixelFormat(&mainGD
, 1, testAttrib
[index
]);
190 if ( (pf
== NULL
) && ( testTypes
[index
][0] == 0) )
192 testAttrib
[index
][1] = 0x30300;
193 pf
= aglChoosePixelFormat(&mainGD
, 1, testAttrib
[index
]);
195 if (pf
!= NULL
) glpf
.push_back(new DrawingSurfaceConfig (index
+1, pf
));
200 // Filter the basic list of DrawingSurfaceConfigs according to
201 // constraints provided by the user. (This makes it convenient
202 // to run tests on just a subset of all available configs.)
203 DrawingSurfaceFilter
f(o
.visFilter
); // may throw an exception!
204 surfConfigs
= f
.filter(glpf
, o
.maxVisuals
);
209 ///////////////////////////////////////////////////////////////////////////////
211 ///////////////////////////////////////////////////////////////////////////////
213 WindowSystem::~WindowSystem() {
215 } // WindowSystem:: ~WindowSystem
217 #elif defined(__WIN__)
218 WindowSystem::~WindowSystem() {
220 #elif defined(__BEWIN__)
221 WindowSystem::~WindowSystem() {
223 } // WindowSystem:: ~WindowSystem
224 #elif defined(__AGL__)
225 WindowSystem::~WindowSystem() {
229 ///////////////////////////////////////////////////////////////////////////////
230 // makeCurrent and friends - binding contexts and drawing surfaces
231 ///////////////////////////////////////////////////////////////////////////////
234 WindowSystem::makeCurrent() {
235 # if defined(__X11__)
236 # if defined(GLX_VERSION_1_3)
237 // XXX Need to write GLX 1.3 MakeCurrent code
239 return glXMakeCurrent(dpy
, None
, 0);
240 # elif defined(__WIN__)
241 return wglMakeCurrent(0,0);
242 # elif defined(__AGL__)
243 return aglSetCurrentContext(NULL
);
245 } // WindowSystem::makeCurrent
248 WindowSystem::makeCurrent(RenderingContext
& r
, Window
& w
) {
249 # if defined(__X11__)
250 # if defined(GLX_VERSION_1_3)
251 // XXX Need to write GLX 1.3 MakeCurrent code
253 return glXMakeCurrent(dpy
, w
.xWindow
, r
.rc
);
254 # elif defined(__WIN__)
255 return wglMakeCurrent(w
.get_dc(),r
.rc
);
256 # elif defined(__AGL__)
257 if (GL_FALSE
== aglSetDrawable(r
.rc
, (AGLDrawable
) GetWindowPort (w
.macWindow
)))
259 if (GL_FALSE
== aglSetCurrentContext(r
.rc
))
263 } // WindowSystem::makeCurrent
266 WindowSystem::quiesce() {
267 # if defined(__X11__)
269 # elif defined(__WIN__)
271 } // WindowSystem::quiesce