comparison src/video/win32/SDL_win32opengl.c @ 2150:abbe2c1dcf0a

Fixed bug #77 If the ARB pixel format selection fails, use a version of ChoosePixelFormat() that doesn't return a less capable format than was requested.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 05 Jul 2007 06:14:26 +0000
parents 420716272158
children 114a541cfae2
comparison
equal deleted inserted replaced
2149:eba4fd03b4f6 2150:abbe2c1dcf0a
153 pfd->cAccumAlphaBits); 153 pfd->cAccumAlphaBits);
154 pfd->cDepthBits = _this->gl_config.depth_size; 154 pfd->cDepthBits = _this->gl_config.depth_size;
155 pfd->cStencilBits = _this->gl_config.stencil_size; 155 pfd->cStencilBits = _this->gl_config.stencil_size;
156 } 156 }
157 157
158 /* Choose the closest pixel format that meets or exceeds the target.
159 FIXME: Should we weight any particular attribute over any other?
160 */
161 static int
162 WIN_GL_ChoosePixelFormat(HDC hdc, PIXELFORMATDESCRIPTOR * target)
163 {
164 PIXELFORMATDESCRIPTOR pfd;
165 int count, index, best = 0;
166 unsigned int dist, best_dist = ~0U;
167
168 count = DescribePixelFormat(hdc, 1, sizeof(pfd), NULL);
169
170 for (index = 1; index <= count; index++) {
171
172 if (!DescribePixelFormat(hdc, index, sizeof(pfd), &pfd)) {
173 continue;
174 }
175
176 if ((pfd.dwFlags & target->dwFlags) != target->dwFlags) {
177 continue;
178 }
179
180 if (pfd.iLayerType != target->iLayerType) {
181 continue;
182 }
183 if (pfd.iPixelType != target->iPixelType) {
184 continue;
185 }
186
187 dist = 0;
188
189 if (pfd.cColorBits < target->cColorBits) {
190 continue;
191 } else {
192 dist += (pfd.cColorBits - target->cColorBits);
193 }
194 if (pfd.cRedBits < target->cRedBits) {
195 continue;
196 } else {
197 dist += (pfd.cRedBits - target->cRedBits);
198 }
199 if (pfd.cGreenBits < target->cGreenBits) {
200 continue;
201 } else {
202 dist += (pfd.cGreenBits - target->cGreenBits);
203 }
204 if (pfd.cBlueBits < target->cBlueBits) {
205 continue;
206 } else {
207 dist += (pfd.cBlueBits - target->cBlueBits);
208 }
209 if (pfd.cAlphaBits < target->cAlphaBits) {
210 continue;
211 } else {
212 dist += (pfd.cAlphaBits - target->cAlphaBits);
213 }
214 if (pfd.cAccumBits < target->cAccumBits) {
215 continue;
216 } else {
217 dist += (pfd.cAccumBits - target->cAccumBits);
218 }
219 if (pfd.cAccumRedBits < target->cAccumRedBits) {
220 continue;
221 } else {
222 dist += (pfd.cAccumRedBits - target->cAccumRedBits);
223 }
224 if (pfd.cAccumGreenBits < target->cAccumGreenBits) {
225 continue;
226 } else {
227 dist += (pfd.cAccumGreenBits - target->cAccumGreenBits);
228 }
229 if (pfd.cAccumBlueBits < target->cAccumBlueBits) {
230 continue;
231 } else {
232 dist += (pfd.cAccumBlueBits - target->cAccumBlueBits);
233 }
234 if (pfd.cAccumAlphaBits < target->cAccumAlphaBits) {
235 continue;
236 } else {
237 dist += (pfd.cAccumAlphaBits - target->cAccumAlphaBits);
238 }
239 if (pfd.cDepthBits < target->cDepthBits) {
240 continue;
241 } else {
242 dist += (pfd.cDepthBits - target->cDepthBits);
243 }
244 if (pfd.cStencilBits < target->cStencilBits) {
245 continue;
246 } else {
247 dist += (pfd.cStencilBits - target->cStencilBits);
248 }
249
250 if (dist < best_dist) {
251 best = index;
252 best_dist = dist;
253 }
254 }
255
256 return best;
257 }
258
158 static SDL_bool 259 static SDL_bool
159 HasExtension(const char *extension, const char *extensions) 260 HasExtension(const char *extension, const char *extensions)
160 { 261 {
161 const char *start; 262 const char *start;
162 const char *where, *terminator; 263 const char *where, *terminator;
396 /* Choose and set the closest available pixel format */ 497 /* Choose and set the closest available pixel format */
397 if (!_this->gl_data->WGL_ARB_pixel_format 498 if (!_this->gl_data->WGL_ARB_pixel_format
398 || !_this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs, 499 || !_this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs,
399 1, &pixel_format, 500 1, &pixel_format,
400 &matching) || !matching) { 501 &matching) || !matching) {
401 pixel_format = ChoosePixelFormat(hdc, &pfd); 502 pixel_format = WIN_GL_ChoosePixelFormat(hdc, &pfd);
402 } 503 }
403 if (!pixel_format) { 504 if (!pixel_format) {
404 SDL_SetError("No matching GL pixel format available"); 505 SDL_SetError("No matching GL pixel format available");
405 return -1; 506 return -1;
406 } 507 }