Mercurial > sdl-ios-xcode
annotate src/video/wincommon/SDL_wingl.c @ 373:c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 19 May 2002 22:27:42 +0000 |
parents | 13fc64213765 |
children | 8a43e0cbf02f |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
297
f6ffac90895c
Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* WGL implementation of SDL OpenGL support */ | |
29 | |
327
13fc64213765
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
30 #include "SDL_opengl.h" |
0 | 31 #include "SDL_error.h" |
32 #include "SDL_lowvideo.h" | |
33 #include "SDL_wingl_c.h" | |
34 | |
35 #ifdef HAVE_OPENGL | |
36 #define DEFAULT_GL_DRIVER_PATH "OPENGL32.DLL" | |
37 #endif | |
38 | |
373
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
39 /* If setting the HDC fails, we may need to recreate the window (MSDN) */ |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
40 static int WIN_GL_ResetWindow(_THIS) |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
41 { |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
42 int status = 0; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
43 int can_reset = 1; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
44 |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
45 /* If we were passed a window, then we can't create a new one */ |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
46 if ( SDL_windowid ) { |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
47 can_reset = 0; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
48 } |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
49 #ifndef _WIN32_WCE /* FIXME WinCE needs the UNICODE version of CreateWindow() */ |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
50 if ( can_reset ) { |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
51 /* Save the existing window attributes */ |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
52 LONG style; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
53 RECT rect = { 0, 0, 0, 0 }; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
54 style = GetWindowLong(SDL_Window, GWL_STYLE); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
55 GetWindowRect(SDL_Window, &rect); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
56 DestroyWindow(SDL_Window); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
57 SDL_Window = CreateWindow(SDL_Appname, SDL_Appname, |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
58 style, |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
59 rect.left, rect.top, |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
60 (rect.right-rect.left)+1, |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
61 (rect.top-rect.bottom)+1, |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
62 NULL, NULL, SDL_Instance, NULL); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
63 if ( SDL_Window ) { |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
64 this->SetCaption(this, this->wm_title, this->wm_icon); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
65 } else { |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
66 SDL_SetError("Couldn't create window"); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
67 status = -1; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
68 } |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
69 } else |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
70 #endif /* !_WIN32_WCE */ |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
71 { |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
72 SDL_SetError("Unable to reset window for OpenGL context"); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
73 status = -1; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
74 } |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
75 return(status); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
76 } |
0 | 77 |
78 int WIN_GL_SetupWindow(_THIS) | |
79 { | |
80 int retval; | |
81 #ifdef HAVE_OPENGL | |
373
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
82 int i; |
0 | 83 int pixel_format; |
84 | |
85 /* load the gl driver from a default path */ | |
86 if ( ! this->gl_config.driver_loaded ) { | |
87 /* no driver has been loaded, use default (ourselves) */ | |
88 if ( WIN_GL_LoadLibrary(this, NULL) < 0 ) { | |
89 return(-1); | |
90 } | |
91 } | |
92 | |
373
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
93 for ( i=0; ; ++i ) { |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
94 /* Get the window device context for our OpenGL drawing */ |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
95 GL_hdc = GetDC(SDL_Window); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
96 if ( GL_hdc == NULL ) { |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
97 SDL_SetError("Unable to get DC for SDL_Window"); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
98 return(-1); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
99 } |
0 | 100 |
373
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
101 /* Set up the pixel format descriptor with our needed format */ |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
102 memset(&GL_pfd, 0, sizeof(GL_pfd)); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
103 GL_pfd.nSize = sizeof(GL_pfd); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
104 GL_pfd.nVersion = 1; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
105 GL_pfd.dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
106 if ( this->gl_config.double_buffer ) { |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
107 GL_pfd.dwFlags |= PFD_DOUBLEBUFFER; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
108 } |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
109 GL_pfd.iPixelType = PFD_TYPE_RGBA; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
110 GL_pfd.cColorBits = this->gl_config.buffer_size; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
111 GL_pfd.cRedBits = this->gl_config.red_size; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
112 GL_pfd.cGreenBits = this->gl_config.green_size; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
113 GL_pfd.cBlueBits = this->gl_config.blue_size; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
114 GL_pfd.cAlphaBits = this->gl_config.alpha_size; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
115 GL_pfd.cAccumRedBits = this->gl_config.accum_red_size; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
116 GL_pfd.cAccumGreenBits = this->gl_config.accum_green_size; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
117 GL_pfd.cAccumBlueBits = this->gl_config.accum_blue_size; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
118 GL_pfd.cAccumAlphaBits = this->gl_config.accum_alpha_size; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
119 GL_pfd.cAccumBits = |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
120 (GL_pfd.cAccumRedBits + GL_pfd.cAccumGreenBits + |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
121 GL_pfd.cAccumBlueBits + GL_pfd.cAccumAlphaBits); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
122 GL_pfd.cDepthBits = this->gl_config.depth_size; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
123 GL_pfd.cStencilBits = this->gl_config.stencil_size; |
0 | 124 |
373
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
125 /* Choose and set the closest available pixel format */ |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
126 pixel_format = ChoosePixelFormat(GL_hdc, &GL_pfd); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
127 if ( !pixel_format ) { |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
128 SDL_SetError("No matching GL pixel format available"); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
129 return(-1); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
130 } |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
131 if( !SetPixelFormat(GL_hdc, pixel_format, &GL_pfd) ) { |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
132 if ( i == 0 ) { |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
133 /* First time through, try resetting the window */ |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
134 if ( WIN_GL_ResetWindow(this) < 0 ) { |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
135 return(-1); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
136 } |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
137 continue; |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
138 } |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
139 SDL_SetError("Unable to set HDC pixel format"); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
140 return(-1); |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
141 } |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
142 /* We either succeeded or failed by this point */ |
c638fde8a824
Fixed setting OpenGL mode multiple times on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
327
diff
changeset
|
143 break; |
0 | 144 } |
145 DescribePixelFormat(GL_hdc, pixel_format, sizeof(GL_pfd), &GL_pfd); | |
146 | |
147 GL_hrc = this->gl_data->wglCreateContext(GL_hdc); | |
148 if( GL_hrc == NULL ) { | |
149 SDL_SetError("Unable to create GL context"); | |
150 return(-1); | |
151 } | |
152 gl_active = 1; | |
153 #else | |
154 SDL_SetError("WIN driver not configured with OpenGL"); | |
155 #endif | |
156 if ( gl_active ) { | |
157 retval = 0; | |
158 } else { | |
159 retval = -1; | |
160 } | |
161 return(retval); | |
162 } | |
163 | |
164 void WIN_GL_ShutDown(_THIS) | |
165 { | |
166 #ifdef HAVE_OPENGL | |
167 /* Clean up OpenGL */ | |
168 if ( GL_hrc ) { | |
169 this->gl_data->wglMakeCurrent(NULL, NULL); | |
170 this->gl_data->wglDeleteContext(GL_hrc); | |
171 GL_hrc = NULL; | |
172 } | |
173 if ( GL_hdc ) { | |
174 ReleaseDC(SDL_Window, GL_hdc); | |
175 GL_hdc = NULL; | |
176 } | |
177 gl_active = 0; | |
178 | |
179 WIN_GL_UnloadLibrary(this); | |
180 #endif /* HAVE_OPENGL */ | |
181 } | |
182 | |
183 #ifdef HAVE_OPENGL | |
184 | |
185 /* Make the current context active */ | |
186 int WIN_GL_MakeCurrent(_THIS) | |
187 { | |
188 int retval; | |
189 | |
190 retval = 0; | |
191 if ( ! this->gl_data->wglMakeCurrent(GL_hdc, GL_hrc) ) { | |
192 SDL_SetError("Unable to make GL context current"); | |
193 retval = -1; | |
194 } | |
195 return(retval); | |
196 } | |
197 | |
198 /* Get attribute data from glX. */ | |
199 int WIN_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) | |
200 { | |
201 int retval; | |
202 | |
203 retval = 0; | |
204 switch( attrib ) { | |
205 case SDL_GL_RED_SIZE: | |
206 *value = GL_pfd.cRedBits; | |
207 break; | |
208 case SDL_GL_GREEN_SIZE: | |
209 *value = GL_pfd.cGreenBits; | |
210 break; | |
211 case SDL_GL_BLUE_SIZE: | |
212 *value = GL_pfd.cBlueBits; | |
213 break; | |
214 case SDL_GL_ALPHA_SIZE: | |
215 *value = GL_pfd.cAlphaBits; | |
216 break; | |
217 case SDL_GL_DOUBLEBUFFER: | |
218 if ( GL_pfd.dwFlags & PFD_DOUBLEBUFFER ) { | |
219 *value = 1; | |
220 } else { | |
221 *value = 0; | |
222 } | |
223 break; | |
224 case SDL_GL_BUFFER_SIZE: | |
225 *value = GL_pfd.cColorBits; | |
226 break; | |
227 case SDL_GL_DEPTH_SIZE: | |
228 *value = GL_pfd.cDepthBits; | |
229 break; | |
230 case SDL_GL_STENCIL_SIZE: | |
231 *value = GL_pfd.cStencilBits; | |
232 break; | |
233 case SDL_GL_ACCUM_RED_SIZE: | |
234 *value = GL_pfd.cAccumRedBits; | |
235 break; | |
236 case SDL_GL_ACCUM_GREEN_SIZE: | |
237 *value = GL_pfd.cAccumGreenBits; | |
238 break; | |
239 case SDL_GL_ACCUM_BLUE_SIZE: | |
240 *value = GL_pfd.cAccumBlueBits; | |
241 break; | |
242 case SDL_GL_ACCUM_ALPHA_SIZE: | |
243 *value = GL_pfd.cAccumAlphaBits; | |
244 break; | |
245 default: | |
246 retval = -1; | |
247 break; | |
248 } | |
249 return retval; | |
250 } | |
251 | |
252 void WIN_GL_SwapBuffers(_THIS) | |
253 { | |
254 SwapBuffers(GL_hdc); | |
255 } | |
256 | |
257 #endif /* HAVE_OPENGL */ | |
258 | |
259 #ifdef HAVE_OPENGL | |
260 | |
261 void WIN_GL_UnloadLibrary(_THIS) | |
262 { | |
263 if ( this->gl_config.driver_loaded ) { | |
264 FreeLibrary((HMODULE)this->gl_config.dll_handle); | |
265 | |
266 this->gl_data->wglGetProcAddress = NULL; | |
267 this->gl_data->wglCreateContext = NULL; | |
268 this->gl_data->wglDeleteContext = NULL; | |
269 this->gl_data->wglMakeCurrent = NULL; | |
270 | |
271 this->gl_config.dll_handle = NULL; | |
272 this->gl_config.driver_loaded = 0; | |
273 } | |
274 } | |
275 | |
276 /* Passing a NULL path means load pointers from the application */ | |
277 int WIN_GL_LoadLibrary(_THIS, const char* path) | |
278 { | |
279 HMODULE handle; | |
280 | |
281 if ( gl_active ) { | |
282 SDL_SetError("OpenGL context already created"); | |
283 return -1; | |
284 } | |
285 | |
286 if ( path == NULL ) { | |
287 path = DEFAULT_GL_DRIVER_PATH; | |
288 } | |
289 handle = LoadLibrary(path); | |
290 if ( handle == NULL ) { | |
291 SDL_SetError("Could not load OpenGL library"); | |
292 return -1; | |
293 } | |
294 | |
295 /* Unload the old driver and reset the pointers */ | |
296 WIN_GL_UnloadLibrary(this); | |
297 | |
298 /* Load new function pointers */ | |
299 this->gl_data->wglGetProcAddress = (void * (WINAPI *)(const char *)) | |
300 GetProcAddress(handle, "wglGetProcAddress"); | |
301 this->gl_data->wglCreateContext = (HGLRC (WINAPI *)(HDC)) | |
302 GetProcAddress(handle, "wglCreateContext"); | |
303 this->gl_data->wglDeleteContext = (BOOL (WINAPI *)(HGLRC)) | |
304 GetProcAddress(handle, "wglDeleteContext"); | |
305 this->gl_data->wglMakeCurrent = (BOOL (WINAPI *)(HDC, HGLRC)) | |
306 GetProcAddress(handle, "wglMakeCurrent"); | |
307 | |
308 if ( (this->gl_data->wglGetProcAddress == NULL) || | |
309 (this->gl_data->wglCreateContext == NULL) || | |
310 (this->gl_data->wglDeleteContext == NULL) || | |
311 (this->gl_data->wglMakeCurrent == NULL) ) { | |
312 SDL_SetError("Could not retrieve OpenGL functions"); | |
313 FreeLibrary(handle); | |
314 return -1; | |
315 } | |
316 | |
317 this->gl_config.dll_handle = handle; | |
318 strcpy(this->gl_config.driver_path, path); | |
319 this->gl_config.driver_loaded = 1; | |
320 return 0; | |
321 } | |
322 | |
323 void *WIN_GL_GetProcAddress(_THIS, const char* proc) | |
324 { | |
325 void *func; | |
326 | |
327 /* This is to pick up extensions */ | |
328 func = this->gl_data->wglGetProcAddress(proc); | |
329 if ( ! func ) { | |
330 /* This is probably a normal GL function */ | |
331 func = GetProcAddress(this->gl_config.dll_handle, proc); | |
332 } | |
333 return func; | |
334 } | |
335 | |
336 #endif /* HAVE_OPENGL */ |