bool SceneOpenGL::initRenderingContext() { bool direct_rendering = options->isGlDirect(); KXErrorHandler errs1; ctxbuffer = glXCreateNewContext(display(), fbcbuffer, GLX_RGBA_TYPE, NULL, direct_rendering ? GL_TRUE : GL_FALSE); bool failed = (ctxbuffer == NULL || !glXMakeCurrent(display(), glxbuffer, ctxbuffer)); if (errs1.error(true)) // always check for error( having it all in one if () could skip 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; } glXMakeCurrent(display(), None, NULL); if (ctxbuffer != NULL) glXDestroyContext(display(), ctxbuffer); direct_rendering = false; // try again KXErrorHandler errs2; ctxbuffer = glXCreateNewContext(display(), fbcbuffer, GLX_RGBA_TYPE, NULL, GL_FALSE); bool failed = (ctxbuffer == NULL || !glXMakeCurrent(display(), glxbuffer, ctxbuffer)); if (errs2.error(true)) failed = true; if (failed) { kDebug(1212).nospace() << "Couldn't initialize rendering context (" << KXErrorHandler::errorMessage(errs2.errorEvent()) << ")"; return false; } } return true; }
GLXContext CreateContext(Display *dpy, int screen, FBCONFIG config) { int pbSupport = QueryPbuffers(dpy, screen); #if defined(GLX_VERSION_1_3) if (pbSupport == 1) { /* GLX 1.3 */ GLXContext c; c = glXCreateNewContext(dpy, config, GLX_RGBA_TYPE, NULL, True); if (!c) { /* try indirect */ c = glXCreateNewContext(dpy, config, GLX_RGBA_TYPE, NULL, False); } return c; } #endif #if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) if (pbSupport == 2) { GLXContext c; c = glXCreateContextWithConfigSGIX(dpy, config, GLX_RGBA_TYPE_SGIX, NULL, True); if (!c) { c = glXCreateContextWithConfigSGIX(dpy, config, GLX_RGBA_TYPE_SGIX, NULL, False); } return c; } #endif return 0; }
void HeadlessView::createContext() { xDisplay = display->xDisplay; fbConfigs = display->fbConfigs; if (!glContext) { // Try to create a legacy context glContext = glXCreateNewContext(xDisplay, fbConfigs[0], GLX_RGBA_TYPE, None, True); if (glContext) { if (!glXIsDirect(xDisplay, glContext)) { Log::Error(Event::OpenGL, "failed to create direct OpenGL Legacy context"); glXDestroyContext(xDisplay, glContext); glContext = 0; } } } if (glContext == 0) { throw std::runtime_error("Error creating GL context object."); } // Create a dummy pbuffer. We will render to framebuffers anyway, but we need a pbuffer to // activate the context. int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 8, GLX_PBUFFER_HEIGHT, 8, None }; glxPbuffer = glXCreatePbuffer(xDisplay, fbConfigs[0], pbufferAttributes); }
wxGLContext::wxGLContext( bool WXUNUSED(isRGB), wxWindow *win, const wxPalette& WXUNUSED(palette), const wxGLContext *other /* for sharing display lists */ ) { m_window = win; m_widget = win->m_wxwindow; wxGLCanvas *gc = (wxGLCanvas*) win; if (wxGLCanvas::GetGLXVersion() >= 13) { // GLX >= 1.3 GLXFBConfig *fbc = gc->m_fbc; wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") ); m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE, other ? other->m_glContext : None, GL_TRUE ); } else { // GLX <= 1.2 XVisualInfo *vi = (XVisualInfo *) gc->m_vi; wxCHECK_RET( vi, _T("invalid visual for OpenGl") ); m_glContext = glXCreateContext( GDK_DISPLAY(), vi, other ? other->m_glContext : None, GL_TRUE ); } if ( !m_glContext ) { wxFAIL_MSG( _T("Couldn't create OpenGl context") ); } }
std::unique_ptr<GLContextGLX> GLContextGLX::createPbufferContext(PlatformDisplay& platformDisplay, GLXContext sharingContext) { static const int fbConfigAttributes[] = { GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_ALPHA_SIZE, 1, GLX_DOUBLEBUFFER, GL_FALSE, 0 }; int returnedElements; Display* display = downcast<PlatformDisplayX11>(platformDisplay).native(); XUniquePtr<GLXFBConfig> configs(glXChooseFBConfig(display, 0, fbConfigAttributes, &returnedElements)); if (!returnedElements) return nullptr; // We will be rendering to a texture, so our pbuffer does not need to be large. static const int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 }; XUniqueGLXPbuffer pbuffer(glXCreatePbuffer(display, configs.get()[0], pbufferAttributes)); if (!pbuffer) return nullptr; XUniqueGLXContext context(glXCreateNewContext(display, configs.get()[0], GLX_RGBA_TYPE, sharingContext, GL_TRUE)); if (!context) return nullptr; return std::unique_ptr<GLContextGLX>(new GLContextGLX(platformDisplay, WTFMove(context), WTFMove(pbuffer))); }
bool OglContext::initSharingContext() { int fb_attributes[] = { GLX_SAMPLES_ARB, MAX_MULTISAMPLE_SAMPLES, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 16, GLX_DOUBLEBUFFER, 0, GLX_SAMPLE_BUFFERS_ARB, 1, 0 }; int num_configs = 0; while (num_configs == 0 && fb_attributes[1] >= 0) { configs = glXChooseFBConfig(window, DefaultScreen(window), fb_attributes, &num_configs); fb_attributes[1] -= 2; } if (configs == NULL || num_configs == 0) { msSetError(MS_OGLERR, "glXChooseFBConfig could not find any configs. Likely your video card or drivers are not supported. glError: %d", "OglContext::init()", glGetError()); return false; } sharingContext = glXCreateNewContext(window, *configs, GLX_RGBA_TYPE, NULL, 1); if (sharingContext == NULL) { msSetError(MS_OGLERR, "glXCreateNewContext failed. glError: %d", "OglContext::initSharingContext()", glGetError()); return false; } return true; }
bool GraphicsContext::acquireGLSystem() { m_window = glXCreateWindow(m_display, m_config, m_xWindow, NULL); if (!m_window) { printf("%s: %s (%i): ERROR - Invalid glxWindow\n", __FILE__, __FUNCTION__, __LINE__); return false; } const int pbuffer_attribs[] = { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, None }; m_pbuffer = glXCreatePbuffer(m_display, m_config, pbuffer_attribs); if (!m_window) { printf("%s: %s (%i): ERROR - Invalid glxPbuffer\n", __FILE__, __FUNCTION__, __LINE__); return false; } m_context = glXCreateNewContext(m_display, m_config, GLX_RGBA_TYPE, NULL, true); if (!m_context) { printf("%s: %s (%i): ERROR - Invalid glxContext\n", __FILE__, __FUNCTION__, __LINE__); return false; } return true; }
void TopCanvas::CreateGLX(_XDisplay *_x_display, X11Window x_window, GLXFBConfig *fb_cfg) { x_display = _x_display; glx_context = glXCreateNewContext(_x_display, *fb_cfg, GLX_RGBA_TYPE, nullptr, true); if (glx_context == nullptr) { fprintf(stderr, "Failed to create GLX context\n"); exit(EXIT_FAILURE); } glx_window = glXCreateWindow(_x_display, *fb_cfg, x_window, nullptr); XSync(x_display, false); if (!glXMakeContextCurrent(_x_display, glx_window, glx_window, glx_context)) { fprintf(stderr, "Failed to attach GLX context to GLX window\n"); exit(EXIT_FAILURE); } const PixelSize effective_size = GetNativeSize(); if (effective_size.cx <= 0 || effective_size.cy <= 0) { fprintf(stderr, "Failed to query GLX drawable size\n"); exit(EXIT_FAILURE); } OpenGL::SetupContext(); SetupViewport(effective_size); }
void TopCanvas::CreateGLX(_XDisplay *_x_display, X11Window x_window, GLXFBConfig *fb_cfg) { x_display = _x_display; glx_context = glXCreateNewContext(_x_display, *fb_cfg, GLX_RGBA_TYPE, nullptr, true); if (glx_context == nullptr) { fprintf(stderr, "Failed to create GLX context\n"); exit(EXIT_FAILURE); } glx_window = glXCreateWindow(_x_display, *fb_cfg, x_window, nullptr); XSync(x_display, false); if (!glXMakeContextCurrent(_x_display, glx_window, glx_window, glx_context)) { fprintf(stderr, "Failed to attach GLX context to GLX window\n"); exit(EXIT_FAILURE); } unsigned int glx_width = -1, glx_height = -1; glXQueryDrawable(_x_display, glx_window, GLX_WIDTH, &glx_width); glXQueryDrawable(_x_display, glx_window, GLX_HEIGHT, &glx_height); if ((glx_width <= 0) || (glx_height <= 0)) { fprintf(stderr, "Failed to query GLX drawable size\n"); exit(EXIT_FAILURE); } const PixelSize effective_size = { glx_width, glx_height }; OpenGL::SetupContext(); OpenGL::SetupViewport(UnsignedPoint2D(effective_size.cx, effective_size.cy)); Canvas::Create(effective_size); }
wxGLContext::wxGLContext(wxWindow* win, const wxGLContext* other) { wxGLCanvas *gc = (wxGLCanvas*) win; if (wxGLCanvas::GetGLXVersion() >= 13) { // GLX >= 1.3 GLXFBConfig *fbc = gc->m_fbc; wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGl") ); m_glContext = glXCreateNewContext( GDK_DISPLAY(), fbc[0], GLX_RGBA_TYPE, other ? other->m_glContext : None, GL_TRUE ); } else { // GLX <= 1.2 XVisualInfo *vi = (XVisualInfo *) gc->m_vi; wxCHECK_RET( vi, _T("invalid visual for OpenGl") ); m_glContext = glXCreateContext( GDK_DISPLAY(), vi, other ? other->m_glContext : None, GL_TRUE ); } if ( !m_glContext ) { wxFAIL_MSG( _T("Couldn't create OpenGl context") ); } }
Context * createContext(const Visual *_visual, Context *shareContext, Profile profile) { const GlxVisual *visual = static_cast<const GlxVisual *>(_visual); GLXContext share_context = NULL; GLXContext context; if (profile != PROFILE_COMPAT) { return NULL; } if (shareContext) { share_context = static_cast<GlxContext*>(shareContext)->context; } if (glxVersion >= 0x0104 && has_GLX_ARB_create_context) { Attributes<int> attribs; attribs.add(GLX_RENDER_TYPE, GLX_RGBA_TYPE); if (debug) { attribs.add(GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB); } attribs.end(); context = glXCreateContextAttribsARB(display, visual->fbconfig, share_context, True, attribs); } else if (glxVersion >= 0x103) { context = glXCreateNewContext(display, visual->fbconfig, GLX_RGBA_TYPE, share_context, True); } else { context = glXCreateContext(display, visual->visinfo, share_context, True); } return new GlxContext(visual, profile, context); }
static Window createWindow(Display *dpy, int width, int height) { GLXFBConfig *fbc; XVisualInfo *vi; Colormap cmap; XSetWindowAttributes swa; GLXContext cx; XEvent event; int nElements; int attr[] = { GLX_DOUBLEBUFFER, True, None }; fbc = glXChooseFBConfig(dpy, DefaultScreen(dpy), attr, &nElements); vi = glXGetVisualFromFBConfig(dpy, fbc[0]); cx = glXCreateNewContext(dpy, fbc[0], GLX_RGBA_TYPE, 0, GL_FALSE); cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone); swa.colormap = cmap; swa.border_pixel = 0; swa.event_mask = 0; Window win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask, &swa); XSelectInput(dpy, win, StructureNotifyMask | KeyPressMask | KeyReleaseMask); XMapWindow(dpy, win); XIfEvent(dpy, &event, waitMapNotify, (char *)win); XMoveWindow(dpy, win, 100, 100); XIfEvent(dpy, &event, waitConfigureNotify, (char *)win); glXMakeCurrent(dpy, win, cx); return win; }
DECLEXPORT(EGLContext) eglCreateContext(EGLDisplay hDisplay, EGLConfig hConfig, EGLContext hSharedContext, const EGLint *paAttribs) { Display *pDisplay = (Display *)hDisplay; GLXContext hNewContext; if (!VALID_PTR(hDisplay)) { setEGLError(EGL_NOT_INITIALIZED); return EGL_NO_CONTEXT; } if (paAttribs != NULL && *paAttribs != EGL_NONE) { setEGLError(EGL_BAD_ATTRIBUTE); return EGL_NO_CONTEXT; } hNewContext = glXCreateNewContext(pDisplay, (GLXFBConfig)hConfig, GLX_RGBA_TYPE, (GLXContext)hSharedContext, true); if (hNewContext) { clearEGLError(); return (EGLContext)hNewContext; } setEGLError(EGL_BAD_MATCH); return EGL_NO_CONTEXT; }
bool QGLPixelBuffer::hasOpenGLPbuffers() { bool ret = qt_resolve_pbuffer_extensions(); if (!ret) return false; int attribs[40]; int num_configs = 0; qt_format_to_attrib_list(QGLFormat::defaultFormat(), attribs); GLXFBConfig *configs = glXChooseFBConfig(X11->display, X11->defaultScreen, attribs, &num_configs); GLXPbuffer pbuf = 0; GLXContext ctx = 0; if (configs && num_configs) { int pb_attribs[] = {GLX_PBUFFER_WIDTH, 128, GLX_PBUFFER_HEIGHT, 128, XNone}; pbuf = glXCreatePbuffer(X11->display, configs[0], pb_attribs); ctx = glXCreateNewContext(X11->display, configs[0], GLX_RGBA_TYPE, 0, true); XFree(configs); glXDestroyContext(X11->display, ctx); glXDestroyPbuffer(X11->display, pbuf); } return pbuf && ctx; }
int main(int argc, char **argv) { Display *dpy; Window win; XVisualInfo *visinfo; int i; int (*old_handler)(Display *, XErrorEvent *); GLXContext ctx; int attrib[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, None }; GLXFBConfig config, *configs; int nconfigs; for(i = 1; i < argc; ++i) { if (!strcmp(argv[i], "-auto")) piglit_automatic = 1; else fprintf(stderr, "Unknown option: %s\n", argv[i]); } dpy = XOpenDisplay(NULL); if (dpy == NULL) { fprintf(stderr, "couldn't open display\n"); piglit_report_result(PIGLIT_FAIL); } visinfo = piglit_get_glx_visual(dpy); win = piglit_get_glx_window(dpy, visinfo); configs = glXChooseFBConfig(dpy, DefaultScreen(dpy), attrib, &nconfigs); assert(nconfigs > 0); config = configs[0]; XFree(configs); old_handler = XSetErrorHandler(expect_badvalue); ctx = glXCreateNewContext(dpy, config, 0x1010, NULL, True); XSync(dpy, 0); XSetErrorHandler(old_handler); if (!found_badvalue) { printf("Failed to get BadValue from glXCreateContext().\n"); piglit_report_result(PIGLIT_FAIL); } if (ctx != NULL) { glXMakeCurrent(dpy, win, ctx); piglit_report_result(PIGLIT_PASS); } else { piglit_report_result(PIGLIT_SKIP); } return 0; }
JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_GLX13_nglXCreateNewContext(JNIEnv *__env, jclass clazz, jlong displayAddress, jlong configAddress, jint render_type, jlong share_listAddress, jint direct, jlong __functionAddress) { Display *display = (Display *)(intptr_t)displayAddress; GLXFBConfig config = (GLXFBConfig)(intptr_t)configAddress; GLXContext share_list = (GLXContext)(intptr_t)share_listAddress; glXCreateNewContextPROC glXCreateNewContext = (glXCreateNewContextPROC)(intptr_t)__functionAddress; UNUSED_PARAMS(__env, clazz) return (jlong)(intptr_t)glXCreateNewContext(display, config, render_type, share_list, direct); }
/** * Try to create a GLX context of the newest version. */ static GLXContext create_context_with_config(Display *dpy, GLXFBConfig config, Bool coreProfile, Bool es2Profile, Bool direct) { GLXContext ctx = 0; if (coreProfile) { /* Try to create a core profile, starting with the newest version of * GL that we're aware of. If we don't specify the version */ int i; for (i = NUM_GL_VERSIONS - 2; i > 0 ; i--) { /* don't bother below GL 3.0 */ if (gl_versions[i].major == 3 && gl_versions[i].minor == 0) return 0; ctx = create_context_flags(dpy, config, gl_versions[i].major, gl_versions[i].minor, 0x0, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, direct); if (ctx) return ctx; } /* couldn't get core profile context */ return 0; } if (es2Profile) { #ifdef GLX_CONTEXT_ES2_PROFILE_BIT_EXT if (extension_supported("GLX_EXT_create_context_es2_profile", glXQueryExtensionsString(dpy, 0))) { ctx = create_context_flags(dpy, config, 2, 0, 0x0, GLX_CONTEXT_ES2_PROFILE_BIT_EXT, direct); return ctx; } #endif return 0; } /* GLX should return a context of the latest GL version that supports * the full profile. */ ctx = glXCreateNewContext(dpy, config, GLX_RGBA_TYPE, NULL, direct); /* make sure the context is direct, if direct was requested */ if (ctx && direct) { if (!glXIsDirect(dpy, ctx)) { glXDestroyContext(dpy, ctx); return 0; } } return ctx; }
//----------------------------------------------------------------------------// void OpenGLGLXPBTextureTarget::createContext() { d_context = glXCreateNewContext(d_dpy, d_fbconfig, GLX_RGBA_TYPE, glXGetCurrentContext(), true); if (!d_context) throw RendererException("OpenGLGLXPBTextureTarget::createContext - " "Failed to create GLX context for pbuffer."); }
// Create the OpenGL context using legacy API // static GLXContext createLegacyContextGLX(_GLFWwindow* window, GLXFBConfig fbconfig, GLXContext share) { return glXCreateNewContext(_glfw.x11.display, fbconfig, GLX_RGBA_TYPE, share, True); }
COffscreenGLContext::COffscreenGLContext() { //! Get MainCtx & X11-Display GLXContext mainCtx = glXGetCurrentContext(); //GLXDrawable mainDrawable = glXGetCurrentDrawable(); if(!mainCtx) throw opengl_error("Couldn't create an offscreen GL context: glXGetCurrentContext failed!"); SDL_SysWMinfo info; SDL_VERSION(&info.version); if(!SDL_GetWMInfo(&info)) throw opengl_error("Couldn't create an offscreen GL context: SDL_GetWMInfo failed!"); info.info.x11.lock_func(); display = info.info.x11.display; int scrnum = XDefaultScreen(display); info.info.x11.unlock_func(); if (!display) throw opengl_error("Couldn't create an offscreen GL context: Couldn't determine display!"); //! Create a FBConfig int nelements = 0; const int fbattrib[] = { GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, GLX_BUFFER_SIZE, 32, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, None }; GLXFBConfig* fbcfg = glXChooseFBConfig(display, scrnum, (const int*)fbattrib, &nelements); if (!fbcfg || (nelements == 0)) throw opengl_error("Couldn't create an offscreen GL context: glXChooseFBConfig failed!"); //! Create a pbuffer (each render context needs a drawable) const int pbuf_attrib[] = { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, GLX_PRESERVED_CONTENTS, false, None }; pbuf = glXCreatePbuffer(display, *fbcfg, (const int*)pbuf_attrib); if (!pbuf) throw opengl_error("Couldn't create an offscreen GL context: glXCreatePbuffer failed!"); //! Create render context workerCtx = glXCreateNewContext(display, *fbcfg, GLX_RGBA_TYPE, mainCtx, true); if (!workerCtx) throw opengl_error("Couldn't create an offscreen GL context: glXCreateNewContext failed!"); XFree(fbcfg); }
GLXState * glx_context_new_pbuffer (Display * dpy, int width, int height, GLXState * shared) { GLXState * c; GLXFBConfig * fbconfig; int count; GLXContext context; GLXPbuffer pbdraw; GLXContext sh_context = NULL; if (shared) sh_context = shared->context; int pb_attr[] = { GLX_PBUFFER_WIDTH, width, GLX_PBUFFER_HEIGHT, height, None }; fbconfig = glXChooseFBConfig (dpy, DefaultScreen (dpy), attr_list_pb, &count); if (fbconfig == NULL || count == 0) { fprintf (stderr, "GLX Context Error: No FBConfigs found\n"); return NULL; } pbdraw = glXCreatePbuffer (dpy, fbconfig[0], pb_attr); if (!pbdraw) { fprintf (stderr, "GLX Context Error: Failed to create Pbuffer\n"); XFree (fbconfig); return NULL; } context = glXCreateNewContext (dpy, fbconfig[0], GLX_RGBA_TYPE, sh_context, GL_TRUE); if (!context) { fprintf (stderr, "GLX Context Error: Failed to get GLX PB context\n"); glXDestroyPbuffer (dpy, pbdraw); XFree (fbconfig); return NULL; } c = malloc (sizeof (GLXState)); memset (c, 0, sizeof (GLXState)); c->width = width; c->height = height; c->dpy = dpy; c->fbconfig = fbconfig; c->pbuffer = pbdraw; c->context = context; return c; }
wxGLContext::wxGLContext(wxGLCanvas *gc, const wxGLContext *other) { if ( gc->GetGLXContextAttribs()[0] != 0 ) // OpenGL 3 context creation { XVisualInfo *vi = gc->GetXVisualInfo(); wxCHECK_RET( vi, wxT("invalid visual for OpenGL") ); // We need to create a temporary context to get the // glXCreateContextAttribsARB function GLXContext tempContext = glXCreateContext( wxGetX11Display(), vi, NULL, GL_TRUE ); wxCHECK_RET( tempContext, wxT("Couldn't create OpenGL context") ); PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddress((GLubyte *)"glXCreateContextAttribsARB"); if ( !glXCreateContextAttribsARB ) { wxLogError(_("Core OpenGL profile is not supported by the OpenGL driver.")); return; } GLXFBConfig *fbc = gc->GetGLXFBConfig(); wxCHECK_RET( fbc, wxT("invalid GLXFBConfig for OpenGL") ); m_glContext = glXCreateContextAttribsARB( wxGetX11Display(), fbc[0], other ? other->m_glContext : None, GL_TRUE, gc->GetGLXContextAttribs() ); glXDestroyContext( wxGetX11Display(), tempContext ); } else if ( wxGLCanvas::GetGLXVersion() >= 13 ) { GLXFBConfig *fbc = gc->GetGLXFBConfig(); wxCHECK_RET( fbc, wxT("invalid GLXFBConfig for OpenGL") ); m_glContext = glXCreateNewContext( wxGetX11Display(), fbc[0], GLX_RGBA_TYPE, other ? other->m_glContext : None, GL_TRUE ); } else // GLX <= 1.2 { XVisualInfo *vi = gc->GetXVisualInfo(); wxCHECK_RET( vi, wxT("invalid visual for OpenGL") ); m_glContext = glXCreateContext( wxGetX11Display(), vi, other ? other->m_glContext : None, GL_TRUE ); } wxASSERT_MSG( m_glContext, wxT("Couldn't create OpenGL context") ); }
GLOffscreenBuffer::GLOffscreenBuffer(unsigned width, unsigned height) : m_width(width) , m_height(height) , m_display(XOpenDisplay(0)) , m_pbuffer(0) , m_context(0) { if (!m_display) { std::cerr << "Error: XOpenDisplay()\n"; return; } static const int configAttributes[] = { GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DOUBLEBUFFER, GL_FALSE, 0 }; int configCount; GLXFBConfig* config = glXChooseFBConfig(m_display, 0, configAttributes, &configCount); if (!configCount) { std::cerr << "Error: glXChooseFBConfig()\n"; XFree(config); XCloseDisplay(m_display); return; } static const int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, static_cast<int>(width), GLX_PBUFFER_HEIGHT, static_cast<int>(height), 0 }; m_pbuffer = glXCreatePbuffer(m_display, config[0], pbufferAttributes); if (!m_pbuffer) { std::cerr << "Error: glXCreatePbuffer()\n"; XFree(config); XCloseDisplay(m_display); return; } m_context = glXCreateNewContext(m_display, config[0], GLX_RGBA_TYPE, 0, GL_TRUE); XFree(config); if (!m_context) { std::cerr << "Error: glXCreateNewContext()\n"; glXDestroyPbuffer(m_display, m_pbuffer); XCloseDisplay(m_display); return; } }
QOffscreenX11GLXContext::QOffscreenX11GLXContext(QOffscreenX11Info *x11, QOpenGLContext *context) : d(new QOffscreenX11GLXContextData) { d->x11 = x11; d->format = context->format(); d->shareContext = 0; if (context->shareHandle()) d->shareContext = static_cast<QOffscreenX11GLXContext *>(context->shareHandle())->d->context; GLXFBConfig config = qglx_findConfig(x11->display(), x11->screenNumber(), d->format); if (config) { d->context = glXCreateNewContext(x11->display(), config, GLX_RGBA_TYPE, d->shareContext, true); if (!d->context && d->shareContext) { d->shareContext = 0; // re-try without a shared glx context d->context = glXCreateNewContext(x11->display(), config, GLX_RGBA_TYPE, 0, true); } // Get the basic surface format details if (d->context) qglx_surfaceFormatFromGLXFBConfig(&d->format, x11->display(), config); // Create a temporary window so that we can make the new context current d->window = createDummyWindow(x11, config); } else { XVisualInfo *visualInfo = qglx_findVisualInfo(x11->display(), 0, &d->format); if (!visualInfo) qFatal("Could not initialize GLX"); d->context = glXCreateContext(x11->display(), visualInfo, d->shareContext, true); if (!d->context && d->shareContext) { // re-try without a shared glx context d->shareContext = 0; d->context = glXCreateContext(x11->display(), visualInfo, 0, true); } d->window = createDummyWindow(x11, visualInfo); XFree(visualInfo); } }
GraphicsSurfacePrivate(const PlatformGraphicsContext3D shareContext = 0) : m_display(0) , m_xPixmap(0) , m_glxPixmap(0) , m_glContext(0) , m_detachedContext(0) , m_detachedSurface(0) , m_textureIsYInverted(false) , m_hasAlpha(false) { GLXContext shareContextObject = 0; m_display = XOpenDisplay(0); #if PLATFORM(QT) if (shareContext) { #if 0 // This code path requires QXcbNativeInterface::nativeResourceForContext() which is not availble in Qt5 on the build bots yet. QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface(); shareContextObject = static_cast<GLXContext>(nativeInterface->nativeResourceForContext(QByteArrayLiteral("glxcontext"), shareContext)); if (!shareContextObject) return; #else // This code path should be removed as soon as QXcbNativeInterface::nativeResourceForContext() can provide the GLXContext. QOpenGLContext* previousContext = QOpenGLContext::currentContext(); QSurface* previousSurface = previousContext->surface(); QSurface* currentSurface = shareContext->surface(); shareContext->makeCurrent(currentSurface); shareContextObject = glXGetCurrentContext(); previousContext->makeCurrent(previousSurface); #endif } #endif m_display = m_offScreenWindow.display(); int attributes[] = { GLX_LEVEL, 0, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, True, None }; int numReturned; m_fbConfigs = glXChooseFBConfig(m_display, DefaultScreen(m_display), attributes, &numReturned); // Create a GLX context for OpenGL rendering m_glContext = glXCreateNewContext(m_display, m_fbConfigs[0], GLX_RGBA_TYPE, shareContextObject, true); }
void RenderContextImplGLX::ReadyContext(RenderWindow* gw) { // create context based of fbConfig and set as current // do we have a shared context? GLXContext shared = 0; const RenderDriver::ContextCreationParams& contextCreationParams = baseContext->GetContextParams(); if (contextCreationParams.sharedContextIndex >= 0) { RenderContextPtr ptr = baseContext->GetDriver()->AsyncGetContext( contextCreationParams.sharedContextIndex); if (ptr) { shared = static_cast<RenderContextImplGLX*>(( static_cast<RenderContext_Base_GL*>( ptr.GetPtr()))->GetImpl())->context; } } bool result = true; // int (*oldHandler)(Display*, XErrorEvent*) = XSetErrorHandler([&result](Display*, XErrorEvent*) { result = false; return 0; } ); if (!GlXCreateContextAttribsARB) { Trace("Creating old style context"); context = glXCreateNewContext(display, frameBufferConfig, GLX_RGBA_TYPE, shared, True); } else { int contextAttribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, contextCreationParams.reqOpenGLVersionMajor, GLX_CONTEXT_MINOR_VERSION_ARB, contextCreationParams.reqOpenGLVersionMinor, #ifdef NEX_DEBUG GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_DEBUG_BIT_ARB, #endif None }; Trace("Creating context"); context = GlXCreateContextAttribsARB(display, frameBufferConfig, shared, True, contextAttribs); } // Sync to ensure any errors generated are processed. // XSync( display, False ); // XSetErrorHandler( oldHandler ); if (!context || !result) { Error("Context creation failed!."); NEX_THROW_FatalError(EXCEPT_DEVICE_CREATION_FAILED); } if (glXIsDirect(display, context)) Trace("Direct GLX rendering context created!"); else Trace("Indirect GLX rendering context created!"); baseContext->SetCurrentTarget(static_cast<RenderWindowImpl*>(gw->GetImpl())); }
int InitGLX13( vout_thread_t *p_vout ) { vout_sys_t *p_sys = p_vout->p_sys; int i_nbelem; GLXFBConfig *p_fbconfs, fbconf; XVisualInfo *p_vi; int p_attr[] = { GLX_RED_SIZE, 5, GLX_GREEN_SIZE, 5, GLX_BLUE_SIZE, 5, GLX_DOUBLEBUFFER, True, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, 0 }; /* Get the FB configuration */ p_fbconfs = glXChooseFBConfig( p_sys->p_display, 0, p_attr, &i_nbelem ); if( (i_nbelem <= 0) || !p_fbconfs ) { msg_Err( p_vout, "Cannot get FB configurations"); if( p_fbconfs ) XFree( p_fbconfs ); return VLC_EGENERIC; } fbconf = p_fbconfs[0]; /* Get the X11 visual */ p_vi = glXGetVisualFromFBConfig( p_sys->p_display, fbconf ); if( !p_vi ) { msg_Err( p_vout, "Cannot get X11 visual" ); XFree( p_fbconfs ); return VLC_EGENERIC; } XFree( p_vi ); /* Create the GLX window */ p_sys->gwnd = glXCreateWindow( p_sys->p_display, fbconf, p_sys->p_win->video_window, NULL ); if( p_sys->gwnd == None ) { msg_Err( p_vout, "Cannot create GLX window" ); return VLC_EGENERIC; } /* Create an OpenGL context */ p_sys->gwctx = glXCreateNewContext( p_sys->p_display, fbconf, GLX_RGBA_TYPE, NULL, True ); XFree( p_fbconfs ); if( !p_sys->gwctx ) { msg_Err( p_vout, "Cannot create OpenGL context"); return VLC_EGENERIC; } return VLC_SUCCESS; }
void EnableDrawing( XVisualInfo** vi, GLXContext* ctx ) { // -- Check the GLX version, 1.3+ added FBConfigs if ( ( x11::glx[0] == 1 && x11::glx[1] < 3 ) || ( x11::glx[0] < 1 ) ) { // -- Give us a GL context if ( (*ctx = glXCreateContext( x11::disp, *vi, NULL, True)) == 0 ) { printf( "GL3 Failed to get Legacy context\n" ); exit( EXIT_FAILURE ); } } else { printf( "EnableDrawing() :: GLX 1.3+ Context Creation\n" ); if ( !glXCreateContextAttribsARB ) { printf( "glXCreateContextAttribsARB() not found ... using old-style GLX context\n" ); *ctx = glXCreateNewContext( x11::disp, x11::fbconfig, GLX_RGBA_TYPE, 0, True ); } else { int context_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 0, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, #if defined( _DEBUG ) || defined( DEBUG ) || defined( ENIGMA_DEBUG ) GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB, #endif None }; if ( (*ctx = glXCreateContextAttribsARB( x11::disp, x11::fbconfig, 0, True, context_attribs )) == 0 ) { printf( "GL3 Failed to get Core context\n" ); exit( EXIT_FAILURE ); } } } // -- Make the context current to this thread glXMakeCurrent( x11::disp, x11::win, *ctx ); // -- Clear the back buffers glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_ACCUM_BUFFER_BIT|GL_STENCIL_BUFFER_BIT ); }
void HeadlessView::createContext() { if (!display) { throw std::runtime_error("Display is not set"); } #if MBGL_USE_CGL CGLError error = CGLCreateContext(display->pixelFormat, NULL, &glContext); if (error != kCGLNoError) { throw std::runtime_error(std::string("Error creating GL context object:") + CGLErrorString(error) + "\n"); } error = CGLEnable(glContext, kCGLCEMPEngine); if (error != kCGLNoError) { throw std::runtime_error(std::string("Error enabling OpenGL multithreading:") + CGLErrorString(error) + "\n"); } #endif #if MBGL_USE_GLX xDisplay = display->xDisplay; fbConfigs = display->fbConfigs; if (!glContext) { // Try to create a legacy context glContext = glXCreateNewContext(xDisplay, fbConfigs[0], GLX_RGBA_TYPE, None, True); if (glContext) { if (!glXIsDirect(xDisplay, glContext)) { Log::Error(Event::OpenGL, "failed to create direct OpenGL Legacy context"); glXDestroyContext(xDisplay, glContext); glContext = 0; } } } if (glContext == 0) { throw std::runtime_error("Error creating GL context object."); } // Create a dummy pbuffer. We will render to framebuffers anyway, but we need a pbuffer to // activate the context. int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 8, GLX_PBUFFER_HEIGHT, 8, None }; glxPbuffer = glXCreatePbuffer(xDisplay, fbConfigs[0], pbufferAttributes); #endif }
// Create the OpenGL context using legacy API // static GLXContext createLegacyContext(_GLFWwindow *window, GLXFBConfig fbconfig, GLXContext share) { if (_glfw.glx.SGIX_fbconfig) { return _glfw.glx.CreateContextWithConfigSGIX(_glfw.x11.display, fbconfig, GLX_RGBA_TYPE, share, True); } return glXCreateNewContext(_glfw.x11.display, fbconfig, GLX_RGBA_TYPE, share, True); }