kwin: Simplify GLXBackend::initRenderingContext()

glXCreateNewContext() is supposed to return NULL on failure, so let's
assume that it does. Don't try to create an indirect context when
creating a direct context failed. glXCreateNewContext() should return
an indirect context when a direct context cannot be created.
This commit is contained in:
Fredrik Höglund 2013-03-11 16:19:45 +01:00
parent 96ed29497c
commit baeeb1b90b

View file

@ -138,34 +138,22 @@ void GlxBackend::init()
bool GlxBackend::initRenderingContext() bool GlxBackend::initRenderingContext()
{ {
bool direct_rendering = options->isGlDirect(); bool direct = options->isGlDirect();
KXErrorHandler errs1;
ctx = glXCreateNewContext(display(), fbconfig, GLX_RGBA_TYPE, NULL, ctx = glXCreateNewContext(display(), fbconfig, GLX_RGBA_TYPE, NULL, direct);
direct_rendering ? GL_TRUE : GL_FALSE);
bool failed = (ctx == NULL || !glXMakeCurrent(display(), glxDrawable, ctx)); if (!ctx) {
if (errs1.error(true)) // always check for error( having it all in one if () could skip kDebug(1212) << "Failed to create an OpenGL context.";
failed = true; // it due to evaluation short-circuiting
if (failed) {
if (!direct_rendering) {
kDebug(1212).nospace() << "Couldn't initialize rendering context ("
<< KXErrorHandler::errorMessage(errs1.errorEvent()) << ")";
return false; return false;
} }
glXMakeCurrent(display(), None, NULL);
if (ctx != NULL) if (!glXMakeCurrent(display(), glxDrawable, ctx)) {
kDebug(1212) << "Failed to make the OpenGL context current.";
glXDestroyContext(display(), ctx); glXDestroyContext(display(), ctx);
direct_rendering = false; // try again ctx = 0;
KXErrorHandler errs2;
ctx = glXCreateNewContext(display(), fbconfig, GLX_RGBA_TYPE, NULL, GL_FALSE);
bool failed = (ctx == NULL || !glXMakeCurrent(display(), glxDrawable, ctx));
if (errs2.error(true))
failed = true;
if (failed) {
kDebug(1212).nospace() << "Couldn't initialize rendering context ("
<< KXErrorHandler::errorMessage(errs2.errorEvent()) << ")";
return false; return false;
} }
}
return true; return true;
} }