Merge pull request #2764 from Sonicadvance1/pvr_workaround3

Work around devices that choose to only return the default EGL_RENDERABLE_TYPE
This commit is contained in:
Ryan Houdek 2015-07-22 16:47:11 -05:00
commit c81bd32720
1 changed files with 46 additions and 34 deletions

View File

@ -29,52 +29,64 @@ void cInterfaceEGL::DetectMode()
EGLint num_configs; EGLint num_configs;
EGLConfig *config = nullptr; EGLConfig *config = nullptr;
bool supportsGL = false, supportsGLES2 = false, supportsGLES3 = false; bool supportsGL = false, supportsGLES2 = false, supportsGLES3 = false;
std::array<int, 3> renderable_types = {
EGL_OPENGL_BIT,
(1 << 6), /* EGL_OPENGL_ES3_BIT_KHR */
EGL_OPENGL_ES2_BIT,
};
// attributes for a visual in RGBA format with at least for (auto renderable_type : renderable_types)
// 8 bits per color
int attribs[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_NONE };
// Get how many configs there are
if (!eglChooseConfig( egl_dpy, attribs, nullptr, 0, &num_configs))
{ {
INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n"); // attributes for a visual in RGBA format with at least
goto err_exit; // 8 bits per color
} int attribs[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_RENDERABLE_TYPE, renderable_type,
EGL_NONE
};
config = new EGLConfig[num_configs]; // Get how many configs there are
if (!eglChooseConfig( egl_dpy, attribs, nullptr, 0, &num_configs))
// Get all the configurations
if (!eglChooseConfig(egl_dpy, attribs, config, num_configs, &num_configs))
{
INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n");
goto err_exit;
}
for (int i = 0; i < num_configs; ++i)
{
EGLint attribVal;
bool ret;
ret = eglGetConfigAttrib(egl_dpy, config[i], EGL_RENDERABLE_TYPE, &attribVal);
if (ret)
{ {
if (attribVal & EGL_OPENGL_BIT) INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n");
supportsGL = true; goto err_exit;
if (attribVal & (1 << 6)) /* EGL_OPENGL_ES3_BIT_KHR */ }
supportsGLES3 = true;
if (attribVal & EGL_OPENGL_ES2_BIT) config = new EGLConfig[num_configs];
supportsGLES2 = true;
// Get all the configurations
if (!eglChooseConfig(egl_dpy, attribs, config, num_configs, &num_configs))
{
INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n");
goto err_exit;
}
for (int i = 0; i < num_configs; ++i)
{
EGLint attribVal;
bool ret;
ret = eglGetConfigAttrib(egl_dpy, config[i], EGL_RENDERABLE_TYPE, &attribVal);
if (ret)
{
if (attribVal & EGL_OPENGL_BIT)
supportsGL = true;
if (attribVal & (1 << 6)) /* EGL_OPENGL_ES3_BIT_KHR */
supportsGLES3 = true;
if (attribVal & EGL_OPENGL_ES2_BIT)
supportsGLES2 = true;
}
} }
} }
if (supportsGL) if (supportsGL)
s_opengl_mode = GLInterfaceMode::MODE_OPENGL; s_opengl_mode = GLInterfaceMode::MODE_OPENGL;
else if (supportsGLES3) else if (supportsGLES3)
s_opengl_mode = GLInterfaceMode::MODE_OPENGLES3; s_opengl_mode = GLInterfaceMode::MODE_OPENGLES3;
else if (supportsGLES2) else if (supportsGLES2)
s_opengl_mode = GLInterfaceMode::MODE_OPENGLES2; s_opengl_mode = GLInterfaceMode::MODE_OPENGLES2;
err_exit: err_exit:
if (s_opengl_mode == GLInterfaceMode::MODE_DETECT) // Errored before we found a mode if (s_opengl_mode == GLInterfaceMode::MODE_DETECT) // Errored before we found a mode
s_opengl_mode = GLInterfaceMode::MODE_OPENGL; // Fall back to OpenGL s_opengl_mode = GLInterfaceMode::MODE_OPENGL; // Fall back to OpenGL