e5aeeb1ab9ab5da88e4e365dca484f4ad8863d7e
[mesa.git] / src / egl / main / eglconfig.c
1 /**
2 * EGL Configuration (pixel format) functions.
3 */
4
5
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <assert.h>
10 #include "eglconfig.h"
11 #include "egldisplay.h"
12 #include "egldriver.h"
13 #include "eglglobals.h"
14
15
16 #define MIN2(A, B) (((A) < (B)) ? (A) : (B))
17
18
19 static void
20 SetConfigAttrib(_EGLConfig *config, EGLint attr, EGLint val)
21 {
22 config->Attrib[attr - FIRST_ATTRIB] = val;
23
24 switch (attr) {
25 case EGL_BUFFER_SIZE:
26 config->glmode.rgbBits = val;
27 break;
28 case EGL_ALPHA_SIZE:
29 config->glmode.alphaBits = val;
30 break;
31 case EGL_BLUE_SIZE:
32 config->glmode.blueBits = val;
33 break;
34 case EGL_GREEN_SIZE:
35 config->glmode.greenBits = val;
36 break;
37 case EGL_RED_SIZE:
38 config->glmode.redBits = val;
39 break;
40 case EGL_DEPTH_SIZE:
41 config->glmode.depthBits = val;
42 break;
43 case EGL_STENCIL_SIZE:
44 config->glmode.stencilBits = val;
45 break;
46 case EGL_CONFIG_CAVEAT:
47 break;
48 case EGL_CONFIG_ID:
49 break;
50 case EGL_LEVEL:
51 break;
52 case EGL_MAX_PBUFFER_HEIGHT:
53 break;
54 case EGL_MAX_PBUFFER_PIXELS:
55 break;
56 case EGL_MAX_PBUFFER_WIDTH:
57 break;
58 case EGL_NATIVE_RENDERABLE:
59 break;
60 case EGL_NATIVE_VISUAL_ID:
61 break;
62 case EGL_NATIVE_VISUAL_TYPE:
63 break;
64 case EGL_SAMPLES:
65 break;
66 case EGL_SAMPLE_BUFFERS:
67 break;
68 case EGL_SURFACE_TYPE:
69 config->glmode.drawableType = val;
70 break;
71 case EGL_TRANSPARENT_TYPE:
72 break;
73 case EGL_TRANSPARENT_BLUE_VALUE:
74 break;
75 case EGL_TRANSPARENT_GREEN_VALUE:
76 break;
77 case EGL_TRANSPARENT_RED_VALUE:
78 break;
79 case EGL_NONE:
80 break;
81 case EGL_BIND_TO_TEXTURE_RGB:
82 break;
83 case EGL_BIND_TO_TEXTURE_RGBA:
84 break;
85 case EGL_MIN_SWAP_INTERVAL:
86 break;
87 case EGL_MAX_SWAP_INTERVAL:
88 break;
89 default:
90 break;
91 }
92 }
93
94
95 /**
96 * Init the given _EGLconfig to default values.
97 * \param id the configuration's ID.
98 */
99 void
100 _eglInitConfig(_EGLConfig *config, EGLint id)
101 {
102 memset(config, 0, sizeof(*config));
103 config->Handle = id;
104 SetConfigAttrib(config, EGL_CONFIG_ID, id);
105 SetConfigAttrib(config, EGL_BIND_TO_TEXTURE_RGB, EGL_DONT_CARE);
106 SetConfigAttrib(config, EGL_BIND_TO_TEXTURE_RGBA, EGL_DONT_CARE);
107 SetConfigAttrib(config, EGL_CONFIG_CAVEAT, EGL_DONT_CARE);
108 SetConfigAttrib(config, EGL_NATIVE_RENDERABLE, EGL_DONT_CARE);
109 SetConfigAttrib(config, EGL_NATIVE_VISUAL_TYPE, EGL_DONT_CARE);
110 SetConfigAttrib(config, EGL_MIN_SWAP_INTERVAL, EGL_DONT_CARE);
111 SetConfigAttrib(config, EGL_MAX_SWAP_INTERVAL, EGL_DONT_CARE);
112 SetConfigAttrib(config, EGL_SURFACE_TYPE,
113 EGL_SCREEN_BIT_MESA | EGL_PBUFFER_BIT |
114 EGL_PIXMAP_BIT | EGL_WINDOW_BIT);
115 SetConfigAttrib(config, EGL_TRANSPARENT_TYPE, EGL_NONE);
116 SetConfigAttrib(config, EGL_TRANSPARENT_RED_VALUE, EGL_DONT_CARE);
117 SetConfigAttrib(config, EGL_TRANSPARENT_GREEN_VALUE, EGL_DONT_CARE);
118 SetConfigAttrib(config, EGL_TRANSPARENT_BLUE_VALUE, EGL_DONT_CARE);
119 }
120
121
122 /**
123 * Given an EGLConfig handle, return the corresponding _EGLConfig object.
124 */
125 _EGLConfig *
126 _eglLookupConfig(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config)
127 {
128 EGLint i;
129 _EGLDisplay *disp = _eglLookupDisplay(dpy);
130 for (i = 0; i < disp->NumConfigs; i++) {
131 if (disp->Configs[i].Handle == config) {
132 return disp->Configs + i;
133 }
134 }
135 return NULL;
136 }
137
138
139 /**
140 * Add the given _EGLConifg to the given display.
141 */
142 _EGLConfig *
143 _eglAddConfig(_EGLDisplay *display, const _EGLConfig *config)
144 {
145 _EGLConfig *newConfigs;
146 EGLint n;
147
148 n = display->NumConfigs;
149
150 newConfigs = (_EGLConfig *) realloc(display->Configs,
151 (n + 1) * sizeof(_EGLConfig));
152 if (newConfigs) {
153 display->Configs = newConfigs;
154 display->Configs[n] = *config; /* copy struct */
155 display->NumConfigs++;
156 return display->Configs + n;
157 }
158 else {
159 return NULL;
160 }
161 }
162
163
164 /**
165 * Parse the attrib_list to fill in the fields of the given _egl_config
166 * Return EGL_FALSE if any errors, EGL_TRUE otherwise.
167 */
168 EGLBoolean
169 _eglParseConfigAttribs(_EGLConfig *config, const EGLint *attrib_list)
170 {
171 EGLint i;
172
173 /* XXX set all config attribs to EGL_DONT_CARE */
174
175 for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) {
176 EGLint k = attrib_list[i] - FIRST_ATTRIB;
177 if (k >= 0 && k < MAX_ATTRIBS) {
178 config->Attrib[k] = attrib_list[++i];
179 }
180 else {
181 _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig");
182 return EGL_FALSE;
183 }
184 }
185 return EGL_TRUE;
186 }
187
188
189 #define EXACT 1
190 #define ATLEAST 2
191 #define MASK 3
192 #define SMALLER 4
193 #define SPECIAL 5
194 #define NONE 6
195
196 struct sort_info {
197 EGLint Attribute;
198 EGLint MatchCriteria;
199 EGLint SortOrder;
200 };
201
202 /* This encodes the info from Table 3.5 of the EGL spec, ordered by
203 * Sort Priority.
204 */
205 static struct sort_info SortInfo[] = {
206 { EGL_CONFIG_CAVEAT, EXACT, SPECIAL },
207 { EGL_RED_SIZE, ATLEAST, SPECIAL },
208 { EGL_GREEN_SIZE, ATLEAST, SPECIAL },
209 { EGL_BLUE_SIZE, ATLEAST, SPECIAL },
210 { EGL_ALPHA_SIZE, ATLEAST, SPECIAL },
211 { EGL_BUFFER_SIZE, ATLEAST, SMALLER },
212 { EGL_SAMPLE_BUFFERS, ATLEAST, SMALLER },
213 { EGL_SAMPLES, ATLEAST, SMALLER },
214 { EGL_DEPTH_SIZE, ATLEAST, SMALLER },
215 { EGL_STENCIL_SIZE, ATLEAST, SMALLER },
216 { EGL_NATIVE_VISUAL_TYPE, EXACT, SPECIAL },
217 { EGL_CONFIG_ID, EXACT, SMALLER },
218 { EGL_BIND_TO_TEXTURE_RGB, EXACT, NONE },
219 { EGL_BIND_TO_TEXTURE_RGBA, EXACT, NONE },
220 { EGL_LEVEL, EXACT, NONE },
221 { EGL_NATIVE_RENDERABLE, EXACT, NONE },
222 { EGL_MAX_SWAP_INTERVAL, EXACT, NONE },
223 { EGL_MIN_SWAP_INTERVAL, EXACT, NONE },
224 { EGL_SURFACE_TYPE, MASK, NONE },
225 { EGL_TRANSPARENT_TYPE, EXACT, NONE },
226 { EGL_TRANSPARENT_RED_VALUE, EXACT, NONE },
227 { EGL_TRANSPARENT_GREEN_VALUE, EXACT, NONE },
228 { EGL_TRANSPARENT_BLUE_VALUE, EXACT, NONE },
229 { 0, 0, 0 }
230 };
231
232
233 /**
234 * Return EGL_TRUE if the attributes of c meet or exceed the minimums
235 * specified by min.
236 */
237 EGLBoolean
238 _eglConfigQualifies(const _EGLConfig *c, const _EGLConfig *min)
239 {
240 EGLint i;
241 for (i = 0; SortInfo[i].Attribute != 0; i++) {
242 const EGLint mv = GET_CONFIG_ATTRIB(min, SortInfo[i].Attribute);
243 if (mv != EGL_DONT_CARE) {
244 const EGLint cv = GET_CONFIG_ATTRIB(c, SortInfo[i].Attribute);
245 if (SortInfo[i].MatchCriteria == EXACT) {
246 if (cv != mv) {
247 return EGL_FALSE;
248 }
249 }
250 else if (SortInfo[i].MatchCriteria == ATLEAST) {
251 if (cv < mv) {
252 return EGL_FALSE;
253 }
254 }
255 else {
256 assert(SortInfo[i].MatchCriteria == MASK);
257 if ((mv & cv) != mv) {
258 return EGL_FALSE;
259 }
260 }
261 }
262 }
263 return EGL_TRUE;
264 }
265
266
267 /**
268 * Compare configs 'a' and 'b' and return -1 if a belongs before b,
269 * 1 if a belongs after b, or 0 if they're equal.
270 */
271 EGLint
272 _eglCompareConfigs(const _EGLConfig *a, const _EGLConfig *b)
273 {
274 EGLint i;
275 for (i = 0; SortInfo[i].Attribute != 0; i++) {
276 const EGLint av = GET_CONFIG_ATTRIB(a, SortInfo[i].Attribute);
277 const EGLint bv = GET_CONFIG_ATTRIB(b, SortInfo[i].Attribute);
278 if (SortInfo[i].SortOrder == SMALLER) {
279 if (av < bv)
280 return -1;
281 else if (av > bv)
282 return 1;
283 /* else, continue examining attribute values */
284 }
285 else if (SortInfo[i].SortOrder == SPECIAL) {
286 if (SortInfo[i].Attribute == EGL_CONFIG_CAVEAT) {
287 /* values are EGL_NONE, SLOW_CONFIG, or NON_CONFORMANT_CONFIG */
288 if (av < bv)
289 return -1;
290 else if (av > bv)
291 return 1;
292 }
293 else if (SortInfo[i].Attribute == EGL_RED_SIZE ||
294 SortInfo[i].Attribute == EGL_GREEN_SIZE ||
295 SortInfo[i].Attribute == EGL_BLUE_SIZE ||
296 SortInfo[i].Attribute == EGL_ALPHA_SIZE) {
297 if (av > bv)
298 return -1;
299 else if (av < bv)
300 return 1;
301 }
302 else {
303 assert(SortInfo[i].Attribute == EGL_NATIVE_VISUAL_TYPE);
304 if (av < bv)
305 return -1;
306 else if (av > bv)
307 return 1;
308 }
309 }
310 else {
311 assert(SortInfo[i].SortOrder == NONE);
312 /* continue examining attribute values */
313 }
314 }
315 return 0;
316 }
317
318
319 /**
320 * Typical fallback routine for eglChooseConfig
321 */
322 EGLBoolean
323 _eglChooseConfig(_EGLDriver *drv, EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
324 {
325 _EGLDisplay *disp = _eglLookupDisplay(dpy);
326 _EGLConfig criteria;
327 EGLint i;
328
329 /* parse the attrib_list to initialize criteria */
330 if (!_eglParseConfigAttribs(&criteria, attrib_list)) {
331 return EGL_FALSE;
332 }
333
334 *num_config = 0;
335 for (i = 0; i < disp->NumConfigs; i++) {
336 const _EGLConfig *conf = disp->Configs + i;
337 if (_eglConfigQualifies(conf, &criteria)) {
338 if (*num_config < config_size) {
339 /* save */
340 configs[*num_config] = conf->Handle;
341 (*num_config)++;
342 }
343 else {
344 break;
345 }
346 }
347 }
348
349 /* XXX sort the list here */
350
351 return EGL_TRUE;
352 }
353
354
355 /**
356 * Fallback for eglGetConfigAttrib.
357 */
358 EGLBoolean
359 _eglGetConfigAttrib(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
360 {
361 const _EGLConfig *conf = _eglLookupConfig(drv, dpy, config);
362 const EGLint k = attribute - FIRST_ATTRIB;
363 if (k >= 0 && k < MAX_ATTRIBS) {
364 *value = conf->Attrib[k];
365 return EGL_TRUE;
366 }
367 else {
368 _eglError(EGL_BAD_ATTRIBUTE, "eglGetConfigAttrib");
369 return EGL_FALSE;
370 }
371 }
372
373
374 /**
375 * Fallback for eglGetConfigs.
376 */
377 EGLBoolean
378 _eglGetConfigs(_EGLDriver *drv, EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)
379 {
380 _EGLDisplay *disp = _eglLookupDisplay(dpy);
381
382 if (!drv->Initialized) {
383 _eglError(EGL_NOT_INITIALIZED, "eglGetConfigs");
384 return EGL_FALSE;
385 }
386
387 if (configs) {
388 EGLint i;
389 *num_config = MIN2(disp->NumConfigs, config_size);
390 for (i = 0; i < *num_config; i++) {
391 configs[i] = disp->Configs[i].Handle;
392 }
393 } else
394 *num_config = disp->NumConfigs;
395
396 return EGL_TRUE;
397 }
398
399
400 /**
401 * Creates a set of \c __GLcontextModes that a driver will expose.
402 *
403 * A set of \c __GLcontextModes will be created based on the supplied
404 * parameters. The number of modes processed will be 2 *
405 * \c num_depth_stencil_bits * \c num_db_modes.
406 *
407 * For the most part, data is just copied from \c depth_bits, \c stencil_bits,
408 * \c db_modes, and \c visType into each \c __GLcontextModes element.
409 * However, the meanings of \c fb_format and \c fb_type require further
410 * explanation. The \c fb_format specifies which color components are in
411 * each pixel and what the default order is. For example, \c GL_RGB specifies
412 * that red, green, blue are available and red is in the "most significant"
413 * position and blue is in the "least significant". The \c fb_type specifies
414 * the bit sizes of each component and the actual ordering. For example, if
415 * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11]
416 * are the blue value, bits [10:5] are the green value, and bits [4:0] are
417 * the red value.
418 *
419 * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either
420 * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the
421 * \c __GLcontextModes structure is \b identical to the \c GL_RGBA or
422 * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as
423 * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8
424 * still uses 32-bits.
425 *
426 * If in doubt, look at the tables used in the function.
427 *
428 * \param ptr_to_modes Pointer to a pointer to a linked list of
429 * \c __GLcontextModes. Upon completion, a pointer to
430 * the next element to be process will be stored here.
431 * If the function fails and returns \c GL_FALSE, this
432 * value will be unmodified, but some elements in the
433 * linked list may be modified.
434 * \param fb_format Format of the framebuffer. Currently only \c GL_RGB,
435 * \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported.
436 * \param fb_type Type of the pixels in the framebuffer. Currently only
437 * \c GL_UNSIGNED_SHORT_5_6_5,
438 * \c GL_UNSIGNED_SHORT_5_6_5_REV,
439 * \c GL_UNSIGNED_INT_8_8_8_8, and
440 * \c GL_UNSIGNED_INT_8_8_8_8_REV are supported.
441 * \param depth_bits Array of depth buffer sizes to be exposed.
442 * \param stencil_bits Array of stencil buffer sizes to be exposed.
443 * \param num_depth_stencil_bits Number of entries in both \c depth_bits and
444 * \c stencil_bits.
445 * \param db_modes Array of buffer swap modes. If an element has a
446 * value of \c GLX_NONE, then it represents a
447 * single-buffered mode. Other valid values are
448 * \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and
449 * \c GLX_SWAP_UNDEFINED_OML. See the
450 * GLX_OML_swap_method extension spec for more details.
451 * \param num_db_modes Number of entries in \c db_modes.
452 * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or
453 * \c GLX_DIRECT_COLOR.
454 *
455 * \returns
456 * \c GL_TRUE on success or \c GL_FALSE on failure. Currently the only
457 * cause of failure is a bad parameter (i.e., unsupported \c fb_format or
458 * \c fb_type).
459 *
460 * \todo
461 * There is currently no way to support packed RGB modes (i.e., modes with
462 * exactly 3 bytes per pixel) or floating-point modes. This could probably
463 * be done by creating some new, private enums with clever names likes
464 * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32,
465 * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it.
466 */
467 GLboolean
468 _eglFillInConfigs(_EGLConfig * configs,
469 GLenum fb_format, GLenum fb_type,
470 const u_int8_t * depth_bits, const u_int8_t * stencil_bits,
471 unsigned num_depth_stencil_bits,
472 const GLenum * db_modes, unsigned num_db_modes,
473 int visType) {
474 static const u_int8_t bits_table[3][4] = {
475 /* R G B A */
476 { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
477 { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */
478 { 8, 8, 8, 8 } /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */
479 };
480
481 /* The following arrays are all indexed by the fb_type masked with 0x07.
482 * Given the four supported fb_type values, this results in valid array
483 * indices of 3, 4, 5, and 7.
484 */
485 static const u_int32_t masks_table_rgb[8][4] = {
486 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
487 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
488 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
489 {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5 */
490 {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5_REV */
491 {0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000}, /* 8_8_8_8 */
492 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
493 {0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000} /* 8_8_8_8_REV */
494 };
495
496 static const u_int32_t masks_table_rgba[8][4] = {
497 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
498 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
499 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
500 {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5 */
501 {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5_REV */
502 {0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF}, /* 8_8_8_8 */
503 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
504 {0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000}, /* 8_8_8_8_REV */
505 };
506
507 static const u_int32_t masks_table_bgr[8][4] = {
508 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
509 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
510 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
511 {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5 */
512 {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5_REV */
513 {0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000}, /* 8_8_8_8 */
514 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
515 {0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000}, /* 8_8_8_8_REV */
516 };
517
518 static const u_int32_t masks_table_bgra[8][4] = {
519 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
520 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
521 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
522 {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5 */
523 {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5_REV */
524 {0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF}, /* 8_8_8_8 */
525 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
526 {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000}, /* 8_8_8_8_REV */
527 };
528
529 static const u_int8_t bytes_per_pixel[8] = {
530 0, 0, 0, 2, 2, 4, 0, 4
531 };
532
533 const u_int8_t * bits;
534 const u_int32_t * masks;
535 const int index = fb_type & 0x07;
536 _EGLConfig *config;
537 unsigned i;
538 unsigned j;
539 unsigned k;
540
541 if ( bytes_per_pixel[index] == 0 ) {
542 fprintf(stderr, "[%s:%u] Framebuffer type 0x%04x has 0 bytes per pixel.\n",
543 __FUNCTION__, __LINE__, fb_type);
544 return GL_FALSE;
545 }
546
547 /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and
548 * the _REV versions.
549 *
550 * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA.
551 */
552 switch ( fb_format ) {
553 case GL_RGB:
554 bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[1];
555 masks = masks_table_rgb[index];
556 break;
557
558 case GL_RGBA:
559 bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[2];
560 masks = masks_table_rgba[index];
561 break;
562
563 case GL_BGR:
564 bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[1];
565 masks = masks_table_bgr[index];
566 break;
567
568 case GL_BGRA:
569 bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[2];
570 masks = masks_table_bgra[index];
571 break;
572
573 default:
574 fprintf(stderr, "[%s:%u] Framebuffer format 0x%04x is not GL_RGB, GL_RGBA, GL_BGR, or GL_BGRA.\n",
575 __FUNCTION__, __LINE__, fb_format);
576 return GL_FALSE;
577 }
578
579 config = configs;
580 for (k = 0; k < num_depth_stencil_bits; k++) {
581 for (i = 0; i < num_db_modes; i++) {
582 for (j = 0; j < 2; j++) {
583
584 SetConfigAttrib(config, EGL_RED_SIZE, bits[0]);
585 SetConfigAttrib(config, EGL_GREEN_SIZE, bits[1]);
586 SetConfigAttrib(config, EGL_BLUE_SIZE, bits[2]);
587 SetConfigAttrib(config, EGL_ALPHA_SIZE, bits[3]);
588 config->glmode.redMask = masks[0];
589 config->glmode.greenMask = masks[1];
590 config->glmode.blueMask = masks[2];
591 config->glmode.alphaMask = masks[3];
592 SetConfigAttrib(config, EGL_BUFFER_SIZE,
593 config->glmode.redBits + config->glmode.greenBits +
594 config->glmode.blueBits + config->glmode.alphaBits);
595
596 config->glmode.accumRedBits = 16 * j;
597 config->glmode.accumGreenBits = 16 * j;
598 config->glmode.accumBlueBits = 16 * j;
599 config->glmode.accumAlphaBits = (masks[3] != 0) ? 16 * j : 0;
600 config->glmode.visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG;
601
602 SetConfigAttrib(config, EGL_STENCIL_SIZE, stencil_bits[k]);
603 SetConfigAttrib(config, EGL_DEPTH_SIZE, depth_bits[k]);
604
605 config->glmode.visualType = visType;
606 config->glmode.renderType = GLX_RGBA_BIT;
607 SetConfigAttrib(config, EGL_SURFACE_TYPE, EGL_SCREEN_BIT_MESA |
608 EGL_PBUFFER_BIT | EGL_PIXMAP_BIT | EGL_WINDOW_BIT);
609
610 config->glmode.rgbMode = GL_TRUE;
611
612 if (db_modes[i] == GLX_NONE) {
613 config->glmode.doubleBufferMode = GL_FALSE;
614 } else {
615 config->glmode.doubleBufferMode = GL_TRUE;
616 config->glmode.swapMethod = db_modes[i];
617 }
618
619 config->glmode.haveAccumBuffer = ((config->glmode.accumRedBits +
620 config->glmode.accumGreenBits +
621 config->glmode.accumBlueBits +
622 config->glmode.accumAlphaBits) > 0);
623 config->glmode.haveDepthBuffer = (config->glmode.depthBits > 0);
624 config->glmode.haveStencilBuffer = (config->glmode.stencilBits > 0);
625 config++;
626 }
627 }
628 }
629 return GL_TRUE;
630 }