* Initialize and validate the EGL config attributes.
*/
static EGLBoolean
-init_config_attributes(_EGLConfig *conf, EGLint api_mask,
- const struct native_config *nconf)
+init_config_attributes(_EGLConfig *conf, const struct native_config *nconf,
+ EGLint api_mask, enum pipe_format depth_stencil_format)
{
uint rgba[4], depth_stencil[2], buffer_size;
EGLint surface_type;
buffer_size += rgba[i];
}
for (i = 0; i < 2; i++) {
- if (nconf->depth_format != PIPE_FORMAT_NONE) {
- depth_stencil[i] = util_format_get_component_bits(nconf->depth_format,
+ if (depth_stencil_format != PIPE_FORMAT_NONE) {
+ depth_stencil[i] =
+ util_format_get_component_bits(depth_stencil_format,
UTIL_FORMAT_COLORSPACE_ZS, i);
}
else {
*/
static EGLBoolean
egl_g3d_init_config(_EGLDriver *drv, _EGLDisplay *dpy,
- _EGLConfig *conf, const struct native_config *nconf)
+ _EGLConfig *conf, const struct native_config *nconf,
+ enum pipe_format depth_stencil_format)
{
struct egl_g3d_driver *gdrv = egl_g3d_driver(drv);
struct egl_g3d_config *gconf = egl_g3d_config(conf);
gconf->stvis.buffer_mask = buffer_mask;
gconf->stvis.color_format = nconf->color_format;
- gconf->stvis.depth_stencil_format = nconf->depth_format;
+ gconf->stvis.depth_stencil_format = depth_stencil_format;
gconf->stvis.accum_format = PIPE_FORMAT_NONE;
gconf->stvis.samples = nconf->samples;
nconf->native_visual_id);
}
- valid = init_config_attributes(&gconf->base, api_mask, nconf);
+ valid = init_config_attributes(&gconf->base,
+ nconf, api_mask, depth_stencil_format);
if (!valid) {
_eglLog(_EGL_DEBUG, "skip invalid config 0x%x", nconf->native_visual_id);
return EGL_FALSE;
return EGL_TRUE;
}
+/**
+ * Get all interested depth/stencil formats of a display.
+ */
+static EGLint
+egl_g3d_fill_depth_stencil_formats(_EGLDisplay *dpy,
+ enum pipe_format formats[8])
+{
+ struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+ struct pipe_screen *screen = gdpy->native->screen;
+ const EGLint candidates[] = {
+ 1, PIPE_FORMAT_Z16_UNORM,
+ 1, PIPE_FORMAT_Z32_UNORM,
+ 2, PIPE_FORMAT_Z24_UNORM_S8_USCALED, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
+ 2, PIPE_FORMAT_Z24X8_UNORM, PIPE_FORMAT_X8Z24_UNORM,
+ 0
+ };
+ const EGLint *fmt = candidates;
+ EGLint count;
+
+ count = 0;
+ formats[count++] = PIPE_FORMAT_NONE;
+
+ while (*fmt) {
+ EGLint i, n = *fmt++;
+
+ /* pick the first supported format */
+ for (i = 0; i < n; i++) {
+ if (screen->is_format_supported(screen, fmt[i],
+ PIPE_TEXTURE_2D, PIPE_BIND_DEPTH_STENCIL, 0)) {
+ formats[count++] = fmt[i];
+ break;
+ }
+ }
+
+ fmt += n;
+ }
+
+ return count;
+}
+
/**
* Add configs to display and return the next config ID.
*/
{
struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
const struct native_config **native_configs;
- int num_configs, i;
+ enum pipe_format depth_stencil_formats[8];
+ int num_formats, num_configs, i, j;
native_configs = gdpy->native->get_configs(gdpy->native, &num_configs);
if (!num_configs) {
return id;
}
+ num_formats = egl_g3d_fill_depth_stencil_formats(dpy,
+ depth_stencil_formats);
+
for (i = 0; i < num_configs; i++) {
- struct egl_g3d_config *gconf;
-
- gconf = CALLOC_STRUCT(egl_g3d_config);
- if (gconf) {
- _eglInitConfig(&gconf->base, dpy, id);
- if (!egl_g3d_init_config(drv, dpy, &gconf->base, native_configs[i])) {
- free(gconf);
- continue;
+ for (j = 0; j < num_formats; j++) {
+ struct egl_g3d_config *gconf;
+
+ gconf = CALLOC_STRUCT(egl_g3d_config);
+ if (gconf) {
+ _eglInitConfig(&gconf->base, dpy, id);
+ if (!egl_g3d_init_config(drv, dpy, &gconf->base,
+ native_configs[i], depth_stencil_formats[j])) {
+ free(gconf);
+ break;
+ }
+
+ _eglAddConfig(dpy, &gconf->base);
+ id++;
}
-
- _eglAddConfig(dpy, &gconf->base);
- id++;
}
}
return count;
}
-static int
-choose_depth_stencil_format(const __GLcontextModes *mode,
- enum pipe_format formats[32])
-{
- int count = 0;
-
- switch (mode->depthBits) {
- case 32:
- formats[count++] = PIPE_FORMAT_Z32_UNORM;
- break;
- case 24:
- if (mode->stencilBits) {
- formats[count++] = PIPE_FORMAT_Z24_UNORM_S8_USCALED;
- formats[count++] = PIPE_FORMAT_S8_USCALED_Z24_UNORM;
- }
- else {
- formats[count++] = PIPE_FORMAT_Z24X8_UNORM;
- formats[count++] = PIPE_FORMAT_X8Z24_UNORM;
- }
- break;
- case 16:
- formats[count++] = PIPE_FORMAT_Z16_UNORM;
- break;
- default:
- break;
- }
-
- return count;
-}
-
static boolean
is_format_supported(struct pipe_screen *screen,
enum pipe_format fmt, boolean is_color)
if (!mode->xRenderable || !mode->drawableType)
return FALSE;
- nconf->color_format = PIPE_FORMAT_NONE;
- nconf->depth_format = PIPE_FORMAT_NONE;
- nconf->stencil_format = PIPE_FORMAT_NONE;
-
nconf->buffer_mask = 1 << NATIVE_ATTACHMENT_FRONT_LEFT;
if (mode->doubleBufferMode)
nconf->buffer_mask |= 1 << NATIVE_ATTACHMENT_BACK_LEFT;
if (nconf->color_format == PIPE_FORMAT_NONE)
return FALSE;
- /* choose depth/stencil format */
- num_formats = choose_depth_stencil_format(mode, formats);
- for (i = 0; i < num_formats; i++) {
- if (is_format_supported(ndpy->screen, formats[i], FALSE)) {
- nconf->depth_format = formats[i];
- nconf->stencil_format = formats[i];
- break;
- }
- }
- if ((mode->depthBits && nconf->depth_format == PIPE_FORMAT_NONE) ||
- (mode->stencilBits && nconf->stencil_format == PIPE_FORMAT_NONE))
- return FALSE;
-
if (mode->drawableType & GLX_WINDOW_BIT)
nconf->window_bit = TRUE;
if (mode->drawableType & GLX_PIXMAP_BIT)
/* first time */
if (!xdpy->configs) {
const XVisualInfo *visuals;
- int num_visuals, count, j;
+ int num_visuals, count;
visuals = x11_screen_get_visuals(xdpy->xscr, &num_visuals);
if (!visuals)
count = 0;
for (i = 0; i < num_visuals; i++) {
- for (j = 0; j < 2; j++) {
- struct ximage_config *xconf = &xdpy->configs[count];
-
- xconf->visual = &visuals[i];
- xconf->base.color_format = choose_format(xconf->visual);
- if (xconf->base.color_format == PIPE_FORMAT_NONE)
- continue;
-
- xconf->base.buffer_mask =
- (1 << NATIVE_ATTACHMENT_FRONT_LEFT) |
- (1 << NATIVE_ATTACHMENT_BACK_LEFT);
-
- xconf->base.depth_format = PIPE_FORMAT_NONE;
- xconf->base.stencil_format = PIPE_FORMAT_NONE;
- /* create the second config with depth/stencil buffer */
- if (j == 1) {
- xconf->base.depth_format = PIPE_FORMAT_Z24_UNORM_S8_USCALED;
- xconf->base.stencil_format = PIPE_FORMAT_Z24_UNORM_S8_USCALED;
- }
-
- xconf->base.window_bit = TRUE;
- xconf->base.pixmap_bit = TRUE;
-
- xconf->base.native_visual_id = xconf->visual->visualid;
+ struct ximage_config *xconf = &xdpy->configs[count];
+
+ xconf->visual = &visuals[i];
+ xconf->base.color_format = choose_format(xconf->visual);
+ if (xconf->base.color_format == PIPE_FORMAT_NONE)
+ continue;
+
+ xconf->base.buffer_mask =
+ (1 << NATIVE_ATTACHMENT_FRONT_LEFT) |
+ (1 << NATIVE_ATTACHMENT_BACK_LEFT);
+
+ xconf->base.window_bit = TRUE;
+ xconf->base.pixmap_bit = TRUE;
+
+ xconf->base.native_visual_id = xconf->visual->visualid;
#if defined(__cplusplus) || defined(c_plusplus)
- xconf->base.native_visual_type = xconf->visual->c_class;
+ xconf->base.native_visual_type = xconf->visual->c_class;
#else
- xconf->base.native_visual_type = xconf->visual->class;
+ xconf->base.native_visual_type = xconf->visual->class;
#endif
- xconf->base.slow_config = TRUE;
+ xconf->base.slow_config = TRUE;
- count++;
- }
+ count++;
}
xdpy->num_configs = count;