GlfQGLPlatformDebugContextPrivate::GlfQGLPlatformDebugContextPrivate( int majorVersion, int minorVersion, bool coreProfile, bool directRendering) : _dpy(NULL) , _ctx(NULL) { Display *shareDisplay = glXGetCurrentDisplay(); GLXContext shareContext = glXGetCurrentContext(); int fbConfigId = 0; glXQueryContext(shareDisplay, shareContext, GLX_FBCONFIG_ID, &fbConfigId); int screen = 0; glXQueryContext(shareDisplay, shareContext, GLX_SCREEN, &screen); int configSpec[] = { GLX_FBCONFIG_ID, fbConfigId, None, }; GLXFBConfig *configs = NULL; int configCount = 0; configs = glXChooseFBConfig(shareDisplay, screen, configSpec, &configCount); if (not TF_VERIFY(configCount > 0)) { return; } const int profile = coreProfile ? GLX_CONTEXT_CORE_PROFILE_BIT_ARB : GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, majorVersion, GLX_CONTEXT_MINOR_VERSION_ARB, minorVersion, GLX_CONTEXT_PROFILE_MASK_ARB, profile, GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB, 0, }; // Extension entry points must be resolved at run-time. PFNGLXCREATECONTEXTATTRIBSARBPROC createContextAttribs = (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddressARB((const GLubyte*)"glXCreateContextAttribsARB"); // Create a GL context with the requested capabilities. if (createContextAttribs) { _ctx = (*createContextAttribs)(shareDisplay, configs[0], shareContext, directRendering, attribs); } else { TF_WARN("Unable to create GL debug context."); XVisualInfo *vis = glXGetVisualFromFBConfig(shareDisplay, configs[0]); _ctx = glXCreateContext(shareDisplay, vis, shareContext, directRendering); } if (not TF_VERIFY(_ctx)) { return; } _dpy = shareDisplay; }
DECLEXPORT(EGLBoolean) eglQueryContext(EGLDisplay hDisplay, EGLContext hContext, EGLint cAttribute, EGLint *pcValue) { Display *pDisplay = (Display *)hDisplay; if (!VALID_PTR(hDisplay)) return setEGLError(EGL_NOT_INITIALIZED); if (!VALID_PTR(pcValue)) return setEGLError(EGL_BAD_PARAMETER); switch (cAttribute) { case EGL_CONFIG_ID: { int cValue = 0; if (glXQueryContext(pDisplay, (GLXContext)hContext, GLX_FBCONFIG_ID, &cValue) == Success) { *pcValue = cValue; return clearEGLError(); } return setEGLError(EGL_BAD_MATCH); } case EGL_CONTEXT_CLIENT_TYPE: *pcValue = EGL_OPENGL_API; return clearEGLError(); case EGL_CONTEXT_CLIENT_VERSION: *pcValue = 0; return clearEGLError(); case EGL_RENDER_BUFFER: *pcValue = EGL_BACK_BUFFER; return clearEGLError(); default: return setEGLError(EGL_BAD_ATTRIBUTE); } }
GLXFBConfig GLXGLSupport::getFBConfigFromContext(::GLXContext context) { GLXFBConfig fbConfig = 0; if (GLXEW_VERSION_1_3) { int fbConfigAttrib[] = { GLX_FBCONFIG_ID, 0, None }; GLXFBConfig *fbConfigs; int nElements = 0; glXQueryContext(mGLDisplay, context, GLX_FBCONFIG_ID, &fbConfigAttrib[1]); fbConfigs = glXChooseFBConfig(mGLDisplay, DefaultScreen(mGLDisplay), fbConfigAttrib, &nElements); if (nElements) { fbConfig = fbConfigs[0]; XFree(fbConfigs); } } else if (GLXEW_EXT_import_context && GLXEW_SGIX_fbconfig) { VisualID visualid; if (glXQueryContextInfoEXT(mGLDisplay, context, GLX_VISUAL_ID, (int*)&visualid)) { fbConfig = getFBConfigFromVisualID(visualid); } } return fbConfig; }
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_GLX13_nglXQueryContext(JNIEnv *__env, jclass clazz, jlong displayAddress, jlong ctxAddress, jint attribute, jlong valueAddress, jlong __functionAddress) { Display *display = (Display *)(intptr_t)displayAddress; GLXContext ctx = (GLXContext)(intptr_t)ctxAddress; int *value = (int *)(intptr_t)valueAddress; glXQueryContextPROC glXQueryContext = (glXQueryContextPROC)(intptr_t)__functionAddress; UNUSED_PARAMS(__env, clazz) return (jint)glXQueryContext(display, ctx, attribute, value); }
WineWindow::WineWindow() : m_xdpy(glXGetCurrentDisplay()), m_xctx(glXGetCurrentContext()), m_xdrawable(glXGetCurrentDrawable()), m_local_xctx(0) { int screen = -1; int attribs[] = {GLX_FBCONFIG_ID, -1, None}; int dummy; GLXFBConfig* fb; XVisualInfo* vis; glXQueryContext(m_xdpy, m_xctx, GLX_SCREEN, &screen); glXQueryContext(m_xdpy, m_xctx, GLX_FBCONFIG_ID, &attribs[1]); assert(fb = glXChooseFBConfig(m_xdpy, screen, attribs, &dummy)); assert(vis = glXGetVisualFromFBConfig(m_xdpy, *fb)); assert(m_local_xctx = glXCreateContext(m_xdpy, vis, 0, True)); enter(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); leave(); }
static cairo_status_t _glx_dummy_window (Display *dpy, GLXContext gl_ctx, Window *dummy) { int attr[3] = { GLX_FBCONFIG_ID, 0, None }; GLXFBConfig *config; XVisualInfo *vi; Colormap cmap; XSetWindowAttributes swa; Window win = None; int cnt; /* Create a dummy window created for the target GLX context that we can * use to query the available GL/GLX extensions. */ glXQueryContext (dpy, gl_ctx, GLX_FBCONFIG_ID, &attr[1]); cnt = 0; config = glXChooseFBConfig (dpy, DefaultScreen (dpy), attr, &cnt); if (unlikely (cnt == 0)) return _cairo_error (CAIRO_STATUS_INVALID_FORMAT); vi = glXGetVisualFromFBConfig (dpy, config[0]); XFree (config); if (unlikely (vi == NULL)) return _cairo_error (CAIRO_STATUS_INVALID_FORMAT); cmap = XCreateColormap (dpy, RootWindow (dpy, vi->screen), vi->visual, AllocNone); swa.colormap = cmap; swa.border_pixel = 0; win = XCreateWindow (dpy, RootWindow (dpy, vi->screen), -1, -1, 1, 1, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap, &swa); XFreeColormap (dpy, cmap); XFree (vi); XFlush (dpy); if (unlikely (! glXMakeCurrent (dpy, win, gl_ctx))) { XDestroyWindow (dpy, win); return _cairo_error (CAIRO_STATUS_NO_MEMORY); } *dummy = win; return CAIRO_STATUS_SUCCESS; }
GLXFBConfig GLXGLSupport::getFBConfigFromContext(::GLXContext context) { GLXFBConfig fbConfig = 0; int fbConfigAttrib[] = { GLX_FBCONFIG_ID, 0, None }; GLXFBConfig *fbConfigs; int nElements = 0; glXQueryContext(mGLDisplay, context, GLX_FBCONFIG_ID, &fbConfigAttrib[1]); fbConfigs = glXChooseFBConfig(mGLDisplay, DefaultScreen(mGLDisplay), fbConfigAttrib, &nElements); if (nElements) { fbConfig = fbConfigs[0]; XFree(fbConfigs); } return fbConfig; }
GLboolean glewCreateContext (struct createParams *params) { int attrib[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None }; int erb, evb; XSetWindowAttributes swa; /* open display */ dpy = XOpenDisplay(params->display); if (NULL == dpy) return GL_TRUE; /* query for glx */ if (!glXQueryExtension(dpy, &erb, &evb)) return GL_TRUE; /* choose visual */ if (params->visual == -1) { vi = glXChooseVisual(dpy, DefaultScreen(dpy), attrib); if (NULL == vi) return GL_TRUE; params->visual = (int)XVisualIDFromVisual(vi->visual); } else { int n_vis, i; vis = XGetVisualInfo(dpy, 0, NULL, &n_vis); for (i=0; i<n_vis; i++) { if ((int)XVisualIDFromVisual(vis[i].visual) == params->visual) vi = &vis[i]; } if (vi == NULL) return GL_TRUE; } /* create context */ ctx = glXCreateContext(dpy, vi, None, True); if (NULL == ctx) return GL_TRUE; /* create window */ /*wnd = XCreateSimpleWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 1, 1, 1, 0, 0);*/ cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone); swa.border_pixel = 0; swa.colormap = cmap; wnd = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 1, 1, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap, &swa); /* make context current */ if (!glXMakeCurrent(dpy, wnd, ctx)) return GL_TRUE; if (params->major || params->profile || params->flags) { GLXContext oldCtx = ctx; GLXFBConfig *FBConfigs; int FBConfigAttrs[] = { GLX_FBCONFIG_ID, 0, None }; int contextAttrs[20]; int nelems, i; glxewInit(); if (!glxewGetExtension("GLX_ARB_create_context")) return GL_TRUE; if (glXQueryContext(dpy, oldCtx, GLX_FBCONFIG_ID, &FBConfigAttrs[1])) return GL_TRUE; FBConfigs = glXChooseFBConfig(dpy, vi->screen, FBConfigAttrs, &nelems); if (nelems < 1) return GL_TRUE; i = 0; if (params->major) { contextAttrs[i++] = GLX_CONTEXT_MAJOR_VERSION_ARB; contextAttrs[i++] = params->major; contextAttrs[i++] = GLX_CONTEXT_MINOR_VERSION_ARB; contextAttrs[i++] = params->minor; } if (params->profile) { contextAttrs[i++] = GLX_CONTEXT_PROFILE_MASK_ARB; contextAttrs[i++] = params->profile; } if (params->flags) { contextAttrs[i++] = GLX_CONTEXT_FLAGS_ARB; contextAttrs[i++] = params->flags; } contextAttrs[i++] = None; ctx = glXCreateContextAttribsARB(dpy, *FBConfigs, NULL, True, contextAttrs); if (NULL == ctx) return GL_TRUE; if (!glXMakeCurrent(dpy, wnd, ctx)) return GL_TRUE; glXDestroyContext(dpy, oldCtx); XFree(FBConfigs); } return GL_FALSE; }
//------------------------------------------------------------------------------ // eglQueryContext //------------------------------------------------------------------------------ EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext( EGLDisplay display, EGLContext context, EGLint egl_attribute, EGLint *egl_attrib_value ) { if(!eglplus_egl_valid_display(display)) { eglplus_egl_SetErrorCode(EGL_BAD_DISPLAY); return EGL_FALSE; } if(!display->initialized()) { eglplus_egl_SetErrorCode(EGL_NOT_INITIALIZED); return EGL_FALSE; } if(!eglplus_egl_valid_context(context)) { eglplus_egl_SetErrorCode(EGL_BAD_CONTEXT); return EGL_FALSE; } int glx_attribute = 0; switch(egl_attribute) { case EGL_CONTEXT_CLIENT_TYPE: { if(egl_attrib_value) *egl_attrib_value = EGL_OPENGL_BIT; return EGL_TRUE; } case EGL_CONTEXT_CLIENT_VERSION: { if(egl_attrib_value) *egl_attrib_value = 3; return EGL_TRUE; } case EGL_RENDER_BUFFER: { //TODO if(egl_attrib_value) *egl_attrib_value = EGL_BACK_BUFFER; return EGL_TRUE; } case EGL_CONFIG_ID: { glx_attribute = GLX_FBCONFIG_ID; break; } default: { eglplus_egl_SetErrorCode(EGL_BAD_ATTRIBUTE); return EGL_FALSE; } } int glx_attrib_value = 0; if(glXQueryContext( display->_x_open_display, context->_glx_context, glx_attribute, &glx_attrib_value ) != 0) { return EGL_FALSE; } switch(egl_attribute) { default: { if(egl_attrib_value) *egl_attrib_value = glx_attrib_value; } } return EGL_TRUE; }