Mercurial > sdl-ios-xcode
comparison src/video/wincommon/SDL_wingl.c @ 1315:e94b0d7c33bc
Merged useful fixes from 1.3 branch
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 01 Feb 2006 08:17:54 +0000 |
parents | c9b51268668f |
children | 0781906086fa |
comparison
equal
deleted
inserted
replaced
1314:2b3ebc327017 | 1315:e94b0d7c33bc |
---|---|
18 | 18 |
19 Sam Lantinga | 19 Sam Lantinga |
20 slouken@libsdl.org | 20 slouken@libsdl.org |
21 */ | 21 */ |
22 | 22 |
23 #include <stdlib.h> | |
23 #include <string.h> | 24 #include <string.h> |
24 | 25 |
25 /* WGL implementation of SDL OpenGL support */ | 26 /* WGL implementation of SDL OpenGL support */ |
26 | 27 |
27 #ifdef HAVE_OPENGL | 28 #ifdef HAVE_OPENGL |
71 } | 72 } |
72 return(status); | 73 return(status); |
73 } | 74 } |
74 | 75 |
75 #ifdef HAVE_OPENGL | 76 #ifdef HAVE_OPENGL |
77 | |
78 static int ExtensionSupported(const char *extension, const char *extensions) | |
79 { | |
80 const char *start; | |
81 const char *where, *terminator; | |
82 | |
83 /* Extension names should not have spaces. */ | |
84 where = strchr(extension, ' '); | |
85 if ( where || *extension == '\0' ) | |
86 return 0; | |
87 | |
88 if ( ! extensions ) | |
89 return 0; | |
90 | |
91 /* It takes a bit of care to be fool-proof about parsing the | |
92 * OpenGL extensions string. Don't be fooled by sub-strings, | |
93 * etc. */ | |
94 | |
95 start = extensions; | |
96 | |
97 for (;;) | |
98 { | |
99 where = strstr(start, extension); | |
100 if (!where) break; | |
101 | |
102 terminator = where + strlen(extension); | |
103 if (where == start || *(where - 1) == ' ') | |
104 if (*terminator == ' ' || *terminator == '\0') return 1; | |
105 | |
106 start = terminator; | |
107 } | |
108 | |
109 return 0; | |
110 } | |
111 | |
76 static void Init_WGL_ARB_extensions(_THIS) | 112 static void Init_WGL_ARB_extensions(_THIS) |
77 { | 113 { |
78 HWND hwnd; | 114 HWND hwnd; |
79 HDC hdc; | 115 HDC hdc; |
80 HGLRC hglrc; | 116 HGLRC hglrc; |
81 int pformat; | 117 int pformat; |
82 const char * (WINAPI *wglGetExtensionsStringARB)(HDC) = 0; | 118 const char * (WINAPI *wglGetExtensionsStringARB)(HDC) = 0; |
119 const char *extensions; | |
83 | 120 |
84 hwnd = CreateWindow(SDL_Appname, SDL_Appname, WS_POPUP | WS_DISABLED, | 121 hwnd = CreateWindow(SDL_Appname, SDL_Appname, WS_POPUP | WS_DISABLED, |
85 0, 0, 10, 10, | 122 0, 0, 10, 10, |
86 NULL, NULL, SDL_Instance,NULL); | 123 NULL, NULL, SDL_Instance, NULL); |
87 hdc = GetDC(hwnd); | 124 hdc = GetDC(hwnd); |
88 | 125 |
89 pformat = ChoosePixelFormat(hdc, &GL_pfd); | 126 pformat = ChoosePixelFormat(hdc, &GL_pfd); |
90 SetPixelFormat(hdc, pformat, &GL_pfd); | 127 SetPixelFormat(hdc, pformat, &GL_pfd); |
91 | 128 |
95 } | 132 } |
96 | 133 |
97 wglGetExtensionsStringARB = (const char * (WINAPI *)(HDC)) | 134 wglGetExtensionsStringARB = (const char * (WINAPI *)(HDC)) |
98 this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB"); | 135 this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB"); |
99 | 136 |
100 if(wglGetExtensionsStringARB && strstr(wglGetExtensionsStringARB(hdc),"WGL_ARB_pixel_format")) { | 137 if( wglGetExtensionsStringARB ) { |
138 extensions = wglGetExtensionsStringARB(hdc); | |
139 } else { | |
140 extensions = NULL; | |
141 } | |
142 | |
143 this->gl_data->WGL_ARB_pixel_format = 0; | |
144 if( ExtensionSupported("WGL_ARB_pixel_format", extensions) ) { | |
101 this->gl_data->wglChoosePixelFormatARB = | 145 this->gl_data->wglChoosePixelFormatARB = |
102 (BOOL (WINAPI *)(HDC, const int *, const FLOAT *, UINT, int *, UINT *)) | 146 (BOOL (WINAPI *)(HDC, const int *, const FLOAT *, UINT, int *, UINT *)) |
103 this->gl_data->wglGetProcAddress("wglChoosePixelFormatARB"); | 147 this->gl_data->wglGetProcAddress("wglChoosePixelFormatARB"); |
104 this->gl_data->wglGetPixelFormatAttribivARB = | 148 this->gl_data->wglGetPixelFormatAttribivARB = |
105 (BOOL (WINAPI *)(HDC, int, int, UINT, const int *, int *)) | 149 (BOOL (WINAPI *)(HDC, int, int, UINT, const int *, int *)) |
106 this->gl_data->wglGetProcAddress("wglGetPixelFormatAttribivARB"); | 150 this->gl_data->wglGetProcAddress("wglGetPixelFormatAttribivARB"); |
107 | 151 |
108 if( (this->gl_data->wglChoosePixelFormatARB != NULL) && | 152 if( (this->gl_data->wglChoosePixelFormatARB != NULL) && |
109 (this->gl_data->wglGetPixelFormatAttribivARB != NULL) ) | 153 (this->gl_data->wglGetPixelFormatAttribivARB != NULL) ) { |
110 this->gl_data->wgl_arb_pixel_format = 1; | 154 this->gl_data->WGL_ARB_pixel_format = 1; |
111 else | 155 } |
112 this->gl_data->wgl_arb_pixel_format = 0; | |
113 } else { | |
114 this->gl_data->wgl_arb_pixel_format = 0; | |
115 } | 156 } |
116 | 157 |
117 if ( hglrc ) { | 158 if ( hglrc ) { |
118 this->gl_data->wglMakeCurrent(NULL, NULL); | 159 this->gl_data->wglMakeCurrent(NULL, NULL); |
119 this->gl_data->wglDeleteContext(hglrc); | 160 this->gl_data->wglDeleteContext(hglrc); |
120 } | 161 } |
121 ReleaseDC(hwnd, hdc); | 162 ReleaseDC(hwnd, hdc); |
122 DestroyWindow(hwnd); | 163 DestroyWindow(hwnd); |
123 } | 164 } |
124 #endif /* !HAVE_OPENGL */ | 165 |
166 #endif /* HAVE_OPENGL */ | |
125 | 167 |
126 int WIN_GL_SetupWindow(_THIS) | 168 int WIN_GL_SetupWindow(_THIS) |
127 { | 169 { |
128 int retval; | 170 int retval; |
129 #ifdef HAVE_OPENGL | 171 #ifdef HAVE_OPENGL |
196 if ( this->gl_config.alpha_size ) { | 238 if ( this->gl_config.alpha_size ) { |
197 *iAttr++ = WGL_ALPHA_BITS_ARB; | 239 *iAttr++ = WGL_ALPHA_BITS_ARB; |
198 *iAttr++ = this->gl_config.alpha_size; | 240 *iAttr++ = this->gl_config.alpha_size; |
199 } | 241 } |
200 | 242 |
201 if ( this->gl_config.double_buffer ) { | 243 *iAttr++ = WGL_DOUBLE_BUFFER_ARB; |
202 *iAttr ++ = WGL_DOUBLE_BUFFER_ARB; | 244 *iAttr++ = this->gl_config.double_buffer; |
203 *iAttr ++ = GL_TRUE; | |
204 } | |
205 | 245 |
206 *iAttr++ = WGL_DEPTH_BITS_ARB; | 246 *iAttr++ = WGL_DEPTH_BITS_ARB; |
207 *iAttr++ = this->gl_config.depth_size; | 247 *iAttr++ = this->gl_config.depth_size; |
208 | 248 |
209 if ( this->gl_config.stencil_size ) { | 249 if ( this->gl_config.stencil_size ) { |
231 *iAttr++ = this->gl_config.accum_alpha_size; | 271 *iAttr++ = this->gl_config.accum_alpha_size; |
232 } | 272 } |
233 | 273 |
234 if ( this->gl_config.stereo ) { | 274 if ( this->gl_config.stereo ) { |
235 *iAttr++ = WGL_STEREO_ARB; | 275 *iAttr++ = WGL_STEREO_ARB; |
236 *iAttr++ = this->gl_config.stereo; | 276 *iAttr++ = GL_TRUE; |
237 } | 277 } |
238 | 278 |
239 if ( this->gl_config.multisamplebuffers ) { | 279 if ( this->gl_config.multisamplebuffers ) { |
240 *iAttr++ = WGL_SAMPLE_BUFFERS_ARB; | 280 *iAttr++ = WGL_SAMPLE_BUFFERS_ARB; |
241 *iAttr++ = this->gl_config.multisamplebuffers; | 281 *iAttr++ = this->gl_config.multisamplebuffers; |
247 } | 287 } |
248 | 288 |
249 *iAttr = 0; | 289 *iAttr = 0; |
250 | 290 |
251 /* Choose and set the closest available pixel format */ | 291 /* Choose and set the closest available pixel format */ |
252 if ( !this->gl_data->wgl_arb_pixel_format || | 292 if ( !this->gl_data->WGL_ARB_pixel_format || |
253 !this->gl_data->wglChoosePixelFormatARB(GL_hdc, iAttribs, fAttribs, 1, &pixel_format, &matching) || | 293 !this->gl_data->wglChoosePixelFormatARB(GL_hdc, iAttribs, fAttribs, 1, &pixel_format, &matching) || |
254 !matching ) { | 294 !matching ) { |
255 pixel_format = ChoosePixelFormat(GL_hdc, &GL_pfd); | 295 pixel_format = ChoosePixelFormat(GL_hdc, &GL_pfd); |
256 this->gl_data->wgl_arb_pixel_format = 0; | 296 this->gl_data->WGL_ARB_pixel_format = 0; |
257 } | 297 } |
258 if ( !pixel_format ) { | 298 if ( !pixel_format ) { |
259 SDL_SetError("No matching GL pixel format available"); | 299 SDL_SetError("No matching GL pixel format available"); |
260 return(-1); | 300 return(-1); |
261 } | 301 } |
329 /* Get attribute data from glX. */ | 369 /* Get attribute data from glX. */ |
330 int WIN_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) | 370 int WIN_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) |
331 { | 371 { |
332 int retval; | 372 int retval; |
333 | 373 |
334 if ( this->gl_data->wgl_arb_pixel_format ) { | 374 if ( this->gl_data->WGL_ARB_pixel_format ) { |
335 int wgl_attrib; | 375 int wgl_attrib; |
336 | 376 |
337 switch(attrib) { | 377 switch(attrib) { |
338 case SDL_GL_RED_SIZE: | 378 case SDL_GL_RED_SIZE: |
339 wgl_attrib = WGL_RED_BITS_ARB; | 379 wgl_attrib = WGL_RED_BITS_ARB; |