bool EGLOffScreenContext::initialize(GLPlatformSurface* surface, PlatformContext sharedContext) { if (!surface) return false; if (!eglBindAPI(eglAPIVersion)) { LOG_ERROR("Failed to set EGL API(%d).", eglGetError()); return false; } m_display = surface->sharedDisplay(); if (!m_display) return false; EGLConfig config = surface->configuration(); if (!config) return false; if (isRobustnessExtSupported(m_display)) m_contextHandle = eglCreateContext(m_display, config, sharedContext, contextRobustnessAttributes); if (m_contextHandle != EGL_NO_CONTEXT) { // The EGL_EXT_create_context_robustness spec requires that a context created with // EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT bit set must also support GL_EXT_robustness or // a version of OpenGL incorporating equivalent functionality. // The spec also defines similar requirements for attribute EGL_LOSE_CONTEXT_ON_RESET_EXT. if (platformMakeCurrent(surface) && (GLPlatformContext::supportsGLExtension("GL_EXT_robustness"))) m_resetLostContext = true; else eglDestroyContext(m_display, m_contextHandle); } if (m_contextHandle == EGL_NO_CONTEXT) { m_contextHandle = eglCreateContext(m_display, config, sharedContext, contextAttributes); if (!platformMakeCurrent(surface)) eglDestroyContext(m_display, m_contextHandle); } if (m_contextHandle != EGL_NO_CONTEXT) return true; return false; }
bool GLPlatformContext::makeCurrent(GLPlatformSurface* surface) { m_contextLost = false; if (m_currentContext == this && (!surface || surface->isCurrentDrawable())) return true; m_currentContext = 0; if (!surface || (surface && !surface->drawable())) platformReleaseCurrent(); else if (platformMakeCurrent(surface)) { m_currentContext = this; surface->onMakeCurrent(); } if (m_resetLostContext) { resolveResetStatusExtension(); if (glGetGraphicsResetStatus) { GLenum status = glGetGraphicsResetStatus(); switch (status) { case PLATFORMCONTEXT_NO_ERROR: break; case PLATFORMCONTEXT_GUILTY_CONTEXT_RESET: m_contextLost = true; break; case PLATFORMCONTEXT_INNOCENT_CONTEXT_RESET: break; case PLATFORMCONTEXT_UNKNOWN_CONTEXT_RESET: m_contextLost = true; break; default: break; } } } return m_currentContext; }
bool GLXOffScreenContext::initialize(GLPlatformSurface* surface, PlatformContext sharedContext) { if (!surface) return false; Display* x11Display = X11Helper::nativeDisplay(); if (!x11Display) return false; GLXFBConfig config = surface->configuration(); if (config) { initializeARBExtensions(); if (glXCreateContextAttribsARB) m_contextHandle = glXCreateContextAttribsARB(x11Display, config, sharedContext, true, Attribs); if (m_contextHandle) { // The GLX_ARB_create_context_robustness spec requires that a context created with // GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB bit set must also support GL_ARB_robustness or // a version of OpenGL incorporating equivalent functionality. // The spec also defines similar requirements for attribute GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB. if (platformMakeCurrent(surface) && GLPlatformContext::supportsGLExtension("GL_ARB_robustness")) m_resetLostContext = true; else glXDestroyContext(x11Display, m_contextHandle); } bool supportsAlpha = surface->attributes() & GLPlatformSurface::SupportAlpha; if (!m_contextHandle) m_contextHandle = glXCreateNewContext(x11Display, config, supportsAlpha ? GLX_RGBA_TYPE : 0, sharedContext, true); if (m_contextHandle) return true; } return false; }