Pick right visual attribs in EGL depending on API.

This commit is contained in:
Themaister 2012-09-25 13:25:03 +02:00
parent d059d3fba2
commit 9c24946ca5
2 changed files with 93 additions and 33 deletions

View File

@ -408,25 +408,48 @@ static bool gfx_ctx_set_video_mode(
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
static const EGLint context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
#define EGL_ATTRIBS_BASE \
EGL_SURFACE_TYPE, EGL_WINDOW_BIT, \
EGL_RED_SIZE, 8, \
EGL_GREEN_SIZE, 8, \
EGL_BLUE_SIZE, 8, \
EGL_DEPTH_SIZE, 0, \
EGL_STENCIL_SIZE, 0
static const EGLint egl_attribs_gl[] = {
EGL_ATTRIBS_BASE,
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
EGL_NONE,
};
static const EGLint config_attribs[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RED_SIZE, 1,
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
EGL_ALPHA_SIZE, 0,
#if defined(HAVE_OPENGLES2)
static const EGLint egl_attribs_gles[] = {
EGL_ATTRIBS_BASE,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
#elif defined(HAVE_OPENGL)
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
#endif
EGL_NONE
EGL_NONE,
};
static const EGLint egl_attribs_vg[] = {
EGL_ATTRIBS_BASE,
EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
EGL_NONE,
};
const EGLint *attrib_ptr;
switch (g_api)
{
case GFX_CTX_OPENGL_API:
attrib_ptr = egl_attribs_gl;
break;
case GFX_CTX_OPENGL_ES_API:
attrib_ptr = egl_attribs_gles;
break;
case GFX_CTX_OPENVG_API:
attrib_ptr = egl_attribs_vg;
break;
default:
attrib_ptr = NULL;
}
g_egl_dpy = eglGetDisplay((EGLNativeDisplayType)g_gbm_dev);
if (!g_egl_dpy)
{
@ -439,10 +462,16 @@ static bool gfx_ctx_set_video_mode(
goto error;
EGLint n;
if (!eglChooseConfig(g_egl_dpy, config_attribs, &g_config, 1, &n) || n != 1)
if (!eglChooseConfig(g_egl_dpy, attrib_ptr, &g_config, 1, &n) || n != 1)
goto error;
g_egl_ctx = eglCreateContext(g_egl_dpy, g_config, EGL_NO_CONTEXT, (g_api == GFX_CTX_OPENGL_ES_API) ? context_attribs : NULL);
// GLES 2.0. Don't use for any other API.
static const EGLint gles_context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
g_egl_ctx = eglCreateContext(g_egl_dpy, g_config, EGL_NO_CONTEXT, (g_api == GFX_CTX_OPENGL_ES_API) ? glsl_context_attribs : NULL);
if (!g_egl_ctx)
goto error;

View File

@ -222,20 +222,48 @@ static bool gfx_ctx_init(void)
if (g_inited)
return false;
const EGLint egl_attribs[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RED_SIZE, 1,
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
EGL_DEPTH_SIZE, 1,
#ifdef HAVE_OPENGLES2
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
#else
#define EGL_ATTRIBS_BASE \
EGL_SURFACE_TYPE, EGL_WINDOW_BIT, \
EGL_RED_SIZE, 8, \
EGL_GREEN_SIZE, 8, \
EGL_BLUE_SIZE, 8, \
EGL_DEPTH_SIZE, 0, \
EGL_STENCIL_SIZE, 0
static const EGLint egl_attribs_gl[] = {
EGL_ATTRIBS_BASE,
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
#endif
EGL_NONE,
};
static const EGLint egl_attribs_gles[] = {
EGL_ATTRIBS_BASE,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE,
};
static const EGLint egl_attribs_vg[] = {
EGL_ATTRIBS_BASE,
EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
EGL_NONE,
};
const EGLint *attrib_ptr;
switch (g_api)
{
case GFX_CTX_OPENGL_API:
attrib_ptr = egl_attribs_gl;
break;
case GFX_CTX_OPENGL_ES_API:
attrib_ptr = egl_attribs_gles;
break;
case GFX_CTX_OPENVG_API:
attrib_ptr = egl_attribs_vg;
break;
default:
attrib_ptr = NULL;
}
g_quit = 0;
g_dpy = XOpenDisplay(NULL);
@ -253,7 +281,7 @@ static bool gfx_ctx_init(void)
RARCH_LOG("[X/EGL]: EGL version: %d.%d\n", egl_major, egl_minor);
EGLint num_configs;
if (!eglChooseConfig(g_egl_dpy, egl_attribs, &g_config, 1, &num_configs)
if (!eglChooseConfig(g_egl_dpy, attrib_ptr, &g_config, 1, &num_configs)
|| num_configs == 0 || !g_config)
goto error;
@ -281,11 +309,6 @@ static bool gfx_ctx_set_video_mode(
XSetWindowAttributes swa = {0};
XVisualInfo *vi = NULL;
const EGLint egl_ctx_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE,
};
EGLint vid;
if (!eglGetConfigAttrib(g_egl_dpy, g_config, EGL_NATIVE_VISUAL_ID, &vid))
goto error;
@ -307,7 +330,15 @@ static bool gfx_ctx_set_video_mode(
CWBorderPixel | CWColormap | CWEventMask, &swa);
XSetWindowBackground(g_dpy, g_win, 0);
g_egl_ctx = eglCreateContext(g_egl_dpy, g_config, EGL_NO_CONTEXT, (g_api == GFX_CTX_OPENGL_ES_API) ? egl_ctx_attribs : NULL);
// GLES 2.0. Don't use for any other API.
static const EGLint egl_ctx_gles_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE,
};
g_egl_ctx = eglCreateContext(g_egl_dpy, g_config, EGL_NO_CONTEXT,
(g_api == GFX_CTX_OPENGL_ES_API) ? egl_ctx_gles_attribs : NULL);
if (!g_egl_ctx)
goto error;