#include <string.h>
#include <X11/Xlib.h>
#include <GL/glx.h>
+#include <EGL/egl.h>
-#include "eglconfigutil.h"
#include "eglconfig.h"
#include "eglcontext.h"
#include "egldefines.h"
}
-#define MAP_ATTRIB(attr, memb) \
- { attr, offsetof(__GLcontextModes, memb) }
-
-
static const struct {
int attr;
- int offset;
+ int egl_attr;
} fbconfig_attributes[] = {
/* table 3.1 of GLX 1.4 */
- MAP_ATTRIB(GLX_FBCONFIG_ID, fbconfigID),
- MAP_ATTRIB(GLX_BUFFER_SIZE, rgbBits),
- MAP_ATTRIB(GLX_LEVEL, level),
- MAP_ATTRIB(GLX_DOUBLEBUFFER, doubleBufferMode),
- MAP_ATTRIB(GLX_STEREO, stereoMode),
- MAP_ATTRIB(GLX_AUX_BUFFERS, numAuxBuffers),
- MAP_ATTRIB(GLX_RED_SIZE, redBits),
- MAP_ATTRIB(GLX_GREEN_SIZE, greenBits),
- MAP_ATTRIB(GLX_BLUE_SIZE, blueBits),
- MAP_ATTRIB(GLX_ALPHA_SIZE, alphaBits),
- MAP_ATTRIB(GLX_DEPTH_SIZE, depthBits),
- MAP_ATTRIB(GLX_STENCIL_SIZE, stencilBits),
- MAP_ATTRIB(GLX_ACCUM_RED_SIZE, accumRedBits),
- MAP_ATTRIB(GLX_ACCUM_GREEN_SIZE, accumGreenBits),
- MAP_ATTRIB(GLX_ACCUM_BLUE_SIZE, accumBlueBits),
- MAP_ATTRIB(GLX_ACCUM_ALPHA_SIZE, accumAlphaBits),
- MAP_ATTRIB(GLX_SAMPLE_BUFFERS, sampleBuffers),
- MAP_ATTRIB(GLX_SAMPLES, samples),
- MAP_ATTRIB(GLX_RENDER_TYPE, renderType),
- MAP_ATTRIB(GLX_DRAWABLE_TYPE, drawableType),
- MAP_ATTRIB(GLX_X_RENDERABLE, xRenderable),
- MAP_ATTRIB(GLX_X_VISUAL_TYPE, visualType),
- MAP_ATTRIB(GLX_CONFIG_CAVEAT, visualRating),
- MAP_ATTRIB(GLX_TRANSPARENT_TYPE, transparentPixel),
- MAP_ATTRIB(GLX_TRANSPARENT_INDEX_VALUE, transparentIndex),
- MAP_ATTRIB(GLX_TRANSPARENT_RED_VALUE, transparentRed),
- MAP_ATTRIB(GLX_TRANSPARENT_GREEN_VALUE, transparentGreen),
- MAP_ATTRIB(GLX_TRANSPARENT_BLUE_VALUE, transparentBlue),
- MAP_ATTRIB(GLX_TRANSPARENT_ALPHA_VALUE, transparentAlpha),
- MAP_ATTRIB(GLX_MAX_PBUFFER_WIDTH, maxPbufferWidth),
- MAP_ATTRIB(GLX_MAX_PBUFFER_HEIGHT, maxPbufferHeight),
- MAP_ATTRIB(GLX_MAX_PBUFFER_PIXELS, maxPbufferPixels),
- MAP_ATTRIB(GLX_VISUAL_ID, visualID),
+ { GLX_BUFFER_SIZE, EGL_BUFFER_SIZE },
+ { GLX_LEVEL, EGL_LEVEL },
+ { GLX_RED_SIZE, EGL_RED_SIZE },
+ { GLX_GREEN_SIZE, EGL_GREEN_SIZE },
+ { GLX_BLUE_SIZE, EGL_BLUE_SIZE },
+ { GLX_ALPHA_SIZE, EGL_ALPHA_SIZE },
+ { GLX_DEPTH_SIZE, EGL_DEPTH_SIZE },
+ { GLX_STENCIL_SIZE, EGL_STENCIL_SIZE },
+ { GLX_SAMPLE_BUFFERS, EGL_SAMPLE_BUFFERS },
+ { GLX_SAMPLES, EGL_SAMPLES },
+ { GLX_RENDER_TYPE, EGL_RENDERABLE_TYPE },
+ { GLX_X_RENDERABLE, EGL_NATIVE_RENDERABLE },
+ { GLX_X_VISUAL_TYPE, EGL_NATIVE_VISUAL_TYPE },
+ { GLX_CONFIG_CAVEAT, EGL_CONFIG_CAVEAT },
+ { GLX_TRANSPARENT_TYPE, EGL_TRANSPARENT_TYPE },
+ { GLX_TRANSPARENT_RED_VALUE, EGL_TRANSPARENT_RED_VALUE },
+ { GLX_TRANSPARENT_GREEN_VALUE, EGL_TRANSPARENT_GREEN_VALUE },
+ { GLX_TRANSPARENT_BLUE_VALUE, EGL_TRANSPARENT_BLUE_VALUE },
+ { GLX_MAX_PBUFFER_WIDTH, EGL_MAX_PBUFFER_WIDTH },
+ { GLX_MAX_PBUFFER_HEIGHT, EGL_MAX_PBUFFER_HEIGHT },
+ { GLX_MAX_PBUFFER_PIXELS, EGL_MAX_PBUFFER_PIXELS },
+ { GLX_VISUAL_ID, EGL_NATIVE_VISUAL_ID },
+ { GLX_X_VISUAL_TYPE, EGL_NATIVE_VISUAL_TYPE },
};
convert_fbconfig(Display *dpy, GLXFBConfig fbconfig,
struct GLX_egl_config *GLX_conf)
{
- __GLcontextModes mode;
- int err = 0, attr, val, i;
-
- memset(&mode, 0, sizeof(mode));
+ int err = 0, attr, egl_attr, val, i;
+ EGLint conformant, config_caveat, surface_type;
for (i = 0; i < ARRAY_SIZE(fbconfig_attributes); i++) {
- int offset = fbconfig_attributes[i].offset;
attr = fbconfig_attributes[i].attr;
+ egl_attr = fbconfig_attributes[i].egl_attr;
err = glXGetFBConfigAttrib(dpy, fbconfig, attr, &val);
if (err) {
if (err == GLX_BAD_ATTRIBUTE) {
}
break;
}
- *((int *) ((char *) &mode + offset)) = val;
+
+ _eglSetConfigKey(&GLX_conf->Base, egl_attr, val);
}
if (err)
return EGL_FALSE;
/* must have rgba bit */
- if (!(mode.renderType & GLX_RGBA_BIT))
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_RENDER_TYPE, &val);
+ if (!(val & GLX_RGBA_BIT))
return EGL_FALSE;
+ conformant = EGL_OPENGL_BIT;
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_CONFIG_CAVEAT, &val);
+ if (val == GLX_SLOW_CONFIG)
+ config_caveat = EGL_SLOW_CONFIG;
+ if (val == GLX_NON_CONFORMANT_CONFIG)
+ conformant &= ~EGL_OPENGL_BIT;
+ if (!(conformant & EGL_OPENGL_ES_BIT))
+ config_caveat = EGL_NON_CONFORMANT_CONFIG;
+
+ _eglSetConfigKey(&GLX_conf->Base, EGL_CONFIG_CAVEAT, config_caveat);
+
+ surface_type = 0;
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_DRAWABLE_TYPE, &val);
+ if (val & GLX_WINDOW_BIT)
+ surface_type |= EGL_WINDOW_BIT;
+ if (val & GLX_PIXMAP_BIT)
+ surface_type |= EGL_PIXMAP_BIT;
+ if (val & GLX_PBUFFER_BIT)
+ surface_type |= EGL_PBUFFER_BIT;
+
/* pixmap and pbuffer surfaces must be single-buffered in EGL */
- if (mode.doubleBufferMode) {
- mode.drawableType &= ~(GLX_PIXMAP_BIT | GLX_PBUFFER_BIT);
- if (!mode.drawableType)
+ glXGetFBConfigAttrib(dpy, fbconfig, GLX_DOUBLEBUFFER, &val);
+ GLX_conf->double_buffered = val;
+ if (GLX_conf->double_buffered) {
+ surface_type &= ~(EGL_PIXMAP_BIT | EGL_PBUFFER_BIT);
+ if (!surface_type)
return EGL_FALSE;
}
- mode.rgbMode = GL_TRUE;
- mode.haveAccumBuffer = (mode.accumRedBits +
- mode.accumGreenBits +
- mode.accumBlueBits +
- mode.accumAlphaBits > 0);
- mode.haveDepthBuffer = (mode.depthBits > 0);
- mode.haveStencilBuffer = (mode.stencilBits > 0);
+ _eglSetConfigKey(&GLX_conf->Base, EGL_SURFACE_TYPE, surface_type);
- GLX_conf->double_buffered = (mode.doubleBufferMode != 0);
- return _eglConfigFromContextModesRec(&GLX_conf->Base, &mode,
- EGL_OPENGL_BIT, EGL_OPENGL_BIT);
+ return EGL_TRUE;
}
-
static const struct {
int attr;
- int offset;
+ int egl_attr;
} visual_attributes[] = {
/* table 3.7 of GLX 1.4 */
/* no GLX_USE_GL */
- MAP_ATTRIB(GLX_BUFFER_SIZE, rgbBits),
- MAP_ATTRIB(GLX_LEVEL, level),
- MAP_ATTRIB(GLX_RGBA, rgbMode),
- MAP_ATTRIB(GLX_DOUBLEBUFFER, doubleBufferMode),
- MAP_ATTRIB(GLX_STEREO, stereoMode),
- MAP_ATTRIB(GLX_AUX_BUFFERS, numAuxBuffers),
- MAP_ATTRIB(GLX_RED_SIZE, redBits),
- MAP_ATTRIB(GLX_GREEN_SIZE, greenBits),
- MAP_ATTRIB(GLX_BLUE_SIZE, blueBits),
- MAP_ATTRIB(GLX_ALPHA_SIZE, alphaBits),
- MAP_ATTRIB(GLX_DEPTH_SIZE, depthBits),
- MAP_ATTRIB(GLX_STENCIL_SIZE, stencilBits),
- MAP_ATTRIB(GLX_ACCUM_RED_SIZE, accumRedBits),
- MAP_ATTRIB(GLX_ACCUM_GREEN_SIZE, accumGreenBits),
- MAP_ATTRIB(GLX_ACCUM_BLUE_SIZE, accumBlueBits),
- MAP_ATTRIB(GLX_ACCUM_ALPHA_SIZE, accumAlphaBits),
- MAP_ATTRIB(GLX_SAMPLE_BUFFERS, sampleBuffers),
- MAP_ATTRIB(GLX_SAMPLES, samples),
- MAP_ATTRIB(GLX_FBCONFIG_ID, fbconfigID),
- /* GLX_EXT_visual_rating */
- MAP_ATTRIB(GLX_VISUAL_CAVEAT_EXT, visualRating),
+ { GLX_BUFFER_SIZE, EGL_BUFFER_SIZE },
+ { GLX_LEVEL, EGL_LEVEL },
+ { GLX_RED_SIZE, EGL_RED_SIZE },
+ { GLX_GREEN_SIZE, EGL_GREEN_SIZE },
+ { GLX_BLUE_SIZE, EGL_BLUE_SIZE },
+ { GLX_ALPHA_SIZE, EGL_ALPHA_SIZE },
+ { GLX_DEPTH_SIZE, EGL_DEPTH_SIZE },
+ { GLX_STENCIL_SIZE, EGL_STENCIL_SIZE },
+ { GLX_SAMPLE_BUFFERS, EGL_SAMPLE_BUFFERS },
+ { GLX_SAMPLES, EGL_SAMPLES },
};
-
-static int
-get_visual_type(const XVisualInfo *vis)
-{
- int klass;
-
-#if defined(__cplusplus) || defined(c_plusplus)
- klass = vis->c_class;
-#else
- klass = vis->class;
-#endif
-
- switch (klass) {
- case TrueColor:
- return GLX_TRUE_COLOR;
- case DirectColor:
- return GLX_DIRECT_COLOR;
- case PseudoColor:
- return GLX_PSEUDO_COLOR;
- case StaticColor:
- return GLX_STATIC_COLOR;
- case GrayScale:
- return GLX_GRAY_SCALE;
- case StaticGray:
- return GLX_STATIC_GRAY;
- default:
- return GLX_NONE;
- }
-}
-
-
static EGLBoolean
convert_visual(Display *dpy, XVisualInfo *vinfo,
struct GLX_egl_config *GLX_conf)
{
- __GLcontextModes mode;
- int err, attr, val, i;
+ int err, attr, egl_attr, val, i;
+ EGLint conformant, config_caveat, surface_type;
/* the visual must support OpenGL */
err = glXGetConfig(dpy, vinfo, GLX_USE_GL, &val);
if (err || !val)
return EGL_FALSE;
- memset(&mode, 0, sizeof(mode));
-
for (i = 0; i < ARRAY_SIZE(visual_attributes); i++) {
- int offset = visual_attributes[i].offset;
attr = visual_attributes[i].attr;
+ egl_attr = fbconfig_attributes[i].egl_attr;
err = glXGetConfig(dpy, vinfo, attr, &val);
if (err) {
if (err == GLX_BAD_ATTRIBUTE) {
}
break;
}
- *((int *) ((char *) &mode + offset)) = val;
+
+ _eglSetConfigKey(&GLX_conf->Base, egl_attr, val);
}
if (err)
return EGL_FALSE;
- /* must be RGB mode */
- if (!mode.rgbMode)
+ glXGetConfig(dpy, vinfo, GLX_RGBA, &val);
+ if (!val)
return EGL_FALSE;
- mode.visualID = vinfo->visualid;
- mode.visualType = get_visual_type(vinfo);
- mode.redMask = vinfo->red_mask;
- mode.greenMask = vinfo->green_mask;
- mode.blueMask = vinfo->blue_mask;
+ conformant = EGL_OPENGL_BIT;
+ glXGetConfig(dpy, vinfo, GLX_VISUAL_CAVEAT_EXT, &val);
+ if (val == GLX_SLOW_CONFIG)
+ config_caveat = EGL_SLOW_CONFIG;
+ if (val == GLX_NON_CONFORMANT_CONFIG)
+ conformant &= ~EGL_OPENGL_BIT;
+ if (!(conformant & EGL_OPENGL_ES_BIT))
+ config_caveat = EGL_NON_CONFORMANT_CONFIG;
- mode.drawableType = GLX_WINDOW_BIT;
+ _eglSetConfigKey(&GLX_conf->Base, EGL_CONFIG_CAVEAT, config_caveat);
+ _eglSetConfigKey(&GLX_conf->Base, EGL_NATIVE_VISUAL_ID, vinfo->visualid);
+ _eglSetConfigKey(&GLX_conf->Base, EGL_NATIVE_VISUAL_TYPE, vinfo->class);
+
+ /* pixmap and pbuffer surfaces must be single-buffered in EGL */
+ glXGetConfig(dpy, vinfo, GLX_DOUBLEBUFFER, &val);
+ GLX_conf->double_buffered = val;
+ surface_type = EGL_WINDOW_BIT;
/* pixmap surfaces must be single-buffered in EGL */
- if (!mode.doubleBufferMode)
- mode.drawableType |= GLX_PIXMAP_BIT;
-
- mode.renderType = GLX_RGBA_BIT;
- mode.xRenderable = GL_TRUE;
- mode.haveAccumBuffer = (mode.accumRedBits +
- mode.accumGreenBits +
- mode.accumBlueBits +
- mode.accumAlphaBits > 0);
- mode.haveDepthBuffer = (mode.depthBits > 0);
- mode.haveStencilBuffer = (mode.stencilBits > 0);
-
- GLX_conf->double_buffered = (mode.doubleBufferMode != 0);
- return _eglConfigFromContextModesRec(&GLX_conf->Base, &mode,
- EGL_OPENGL_BIT, EGL_OPENGL_BIT);
+ if (!GLX_conf->double_buffered)
+ surface_type |= EGL_PIXMAP_BIT;
+
+ _eglSetConfigKey(&GLX_conf->Base, EGL_SURFACE_TYPE, surface_type);
+
+ _eglSetConfigKey(&GLX_conf->Base, EGL_NATIVE_RENDERABLE, EGL_TRUE);
+
+ return EGL_TRUE;
}
+++ /dev/null
-/**
- * Extra utility functions related to EGL configs.
- */
-
-
-#include <stdlib.h>
-#include <string.h>
-#include "eglconfigutil.h"
-
-
-/**
- * Convert an _EGLConfig to a __GLcontextModes object.
- * NOTE: This routine may be incomplete - we're only making sure that
- * the fields needed by Mesa (for _mesa_create_context/framebuffer) are
- * set correctly.
- */
-void
-_eglConfigToContextModesRec(const _EGLConfig *config, __GLcontextModes *mode)
-{
- memset(mode, 0, sizeof(*mode));
-
- mode->rgbMode = GL_TRUE; /* no color index */
- mode->colorIndexMode = GL_FALSE;
- mode->doubleBufferMode = GL_TRUE; /* always DB for now */
- mode->stereoMode = GL_FALSE;
-
- mode->redBits = GET_CONFIG_ATTRIB(config, EGL_RED_SIZE);
- mode->greenBits = GET_CONFIG_ATTRIB(config, EGL_GREEN_SIZE);
- mode->blueBits = GET_CONFIG_ATTRIB(config, EGL_BLUE_SIZE);
- mode->alphaBits = GET_CONFIG_ATTRIB(config, EGL_ALPHA_SIZE);
- mode->rgbBits = GET_CONFIG_ATTRIB(config, EGL_BUFFER_SIZE);
-
- /* no rgba masks - fix? */
-
- mode->depthBits = GET_CONFIG_ATTRIB(config, EGL_DEPTH_SIZE);
- mode->haveDepthBuffer = mode->depthBits > 0;
-
- mode->stencilBits = GET_CONFIG_ATTRIB(config, EGL_STENCIL_SIZE);
- mode->haveStencilBuffer = mode->stencilBits > 0;
-
- /* no accum */
-
- mode->level = GET_CONFIG_ATTRIB(config, EGL_LEVEL);
- mode->samples = GET_CONFIG_ATTRIB(config, EGL_SAMPLES);
- mode->sampleBuffers = GET_CONFIG_ATTRIB(config, EGL_SAMPLE_BUFFERS);
-
- /* surface type - not really needed */
- mode->visualType = GLX_TRUE_COLOR;
- mode->renderType = GLX_RGBA_BIT;
-}
-
-
-/**
- * Convert a __GLcontextModes object to an _EGLConfig.
- */
-EGLBoolean
-_eglConfigFromContextModesRec(_EGLConfig *conf, const __GLcontextModes *m,
- EGLint conformant, EGLint renderable_type)
-{
- EGLint config_caveat, surface_type;
-
- /* must be RGBA */
- if (!m->rgbMode || !(m->renderType & GLX_RGBA_BIT))
- return EGL_FALSE;
-
- config_caveat = EGL_NONE;
- if (m->visualRating == GLX_SLOW_CONFIG)
- config_caveat = EGL_SLOW_CONFIG;
-
- if (m->visualRating == GLX_NON_CONFORMANT_CONFIG)
- conformant &= ~EGL_OPENGL_BIT;
- if (!(conformant & EGL_OPENGL_ES_BIT))
- config_caveat = EGL_NON_CONFORMANT_CONFIG;
-
- surface_type = 0;
- if (m->drawableType & GLX_WINDOW_BIT)
- surface_type |= EGL_WINDOW_BIT;
- if (m->drawableType & GLX_PIXMAP_BIT)
- surface_type |= EGL_PIXMAP_BIT;
- if (m->drawableType & GLX_PBUFFER_BIT)
- surface_type |= EGL_PBUFFER_BIT;
-
- SET_CONFIG_ATTRIB(conf, EGL_BUFFER_SIZE, m->rgbBits);
- SET_CONFIG_ATTRIB(conf, EGL_RED_SIZE, m->redBits);
- SET_CONFIG_ATTRIB(conf, EGL_GREEN_SIZE, m->greenBits);
- SET_CONFIG_ATTRIB(conf, EGL_BLUE_SIZE, m->blueBits);
- SET_CONFIG_ATTRIB(conf, EGL_ALPHA_SIZE, m->alphaBits);
-
- SET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGB, m->bindToTextureRgb);
- SET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGBA, m->bindToTextureRgba);
- SET_CONFIG_ATTRIB(conf, EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER);
- SET_CONFIG_ATTRIB(conf, EGL_CONFIG_CAVEAT, config_caveat);
-
- SET_CONFIG_ATTRIB(conf, EGL_CONFORMANT, conformant);
- SET_CONFIG_ATTRIB(conf, EGL_DEPTH_SIZE, m->depthBits);
- SET_CONFIG_ATTRIB(conf, EGL_LEVEL, m->level);
- SET_CONFIG_ATTRIB(conf, EGL_MAX_PBUFFER_WIDTH, m->maxPbufferWidth);
- SET_CONFIG_ATTRIB(conf, EGL_MAX_PBUFFER_HEIGHT, m->maxPbufferHeight);
- SET_CONFIG_ATTRIB(conf, EGL_MAX_PBUFFER_PIXELS, m->maxPbufferPixels);
-
- SET_CONFIG_ATTRIB(conf, EGL_NATIVE_RENDERABLE, m->xRenderable);
- SET_CONFIG_ATTRIB(conf, EGL_NATIVE_VISUAL_ID, m->visualID);
-
- if (m->visualType != GLX_NONE)
- SET_CONFIG_ATTRIB(conf, EGL_NATIVE_VISUAL_TYPE, m->visualType);
- else
- SET_CONFIG_ATTRIB(conf, EGL_NATIVE_VISUAL_TYPE, EGL_NONE);
-
- SET_CONFIG_ATTRIB(conf, EGL_RENDERABLE_TYPE, renderable_type);
- SET_CONFIG_ATTRIB(conf, EGL_SAMPLE_BUFFERS, m->sampleBuffers);
- SET_CONFIG_ATTRIB(conf, EGL_SAMPLES, m->samples);
- SET_CONFIG_ATTRIB(conf, EGL_STENCIL_SIZE, m->stencilBits);
-
- SET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE, surface_type);
-
- /* what to do with GLX_TRANSPARENT_INDEX? */
- if (m->transparentPixel == GLX_TRANSPARENT_RGB) {
- SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_TYPE, EGL_TRANSPARENT_RGB);
- SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_RED_VALUE, m->transparentRed);
- SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_GREEN_VALUE, m->transparentGreen);
- SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_BLUE_VALUE, m->transparentBlue);
- }
- else {
- SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_TYPE, EGL_NONE);
- }
-
- return EGL_TRUE;
-}