///////////////////////////////////////////////////////
| 552 | |
| 553 | //////////////////////////////////////////////////////////// |
| 554 | void GlxContext::createContext(GlxContext* shared) |
| 555 | { |
| 556 | // Get a working copy of the context settings |
| 557 | const ContextSettings settings = m_settings; |
| 558 | |
| 559 | X11Ptr<XVisualInfo> visualInfo; |
| 560 | |
| 561 | if (m_pbuffer) |
| 562 | { |
| 563 | unsigned int fbConfigId = 0; |
| 564 | |
| 565 | glXQueryDrawable(m_display.get(), m_pbuffer, GLX_FBCONFIG_ID, &fbConfigId); |
| 566 | |
| 567 | const std::array attributes = {GLX_FBCONFIG_ID, static_cast<int>(fbConfigId), 0, 0}; |
| 568 | |
| 569 | int count = 0; |
| 570 | const auto fbconfig = X11Ptr<GLXFBConfig>( |
| 571 | glXChooseFBConfig(m_display.get(), DefaultScreen(m_display.get()), attributes.data(), &count)); |
| 572 | |
| 573 | if (count == 1) |
| 574 | visualInfo = X11Ptr<XVisualInfo>(glXGetVisualFromFBConfig(m_display.get(), *fbconfig)); |
| 575 | } |
| 576 | else |
| 577 | { |
| 578 | // Retrieve the attributes of the target window |
| 579 | XWindowAttributes windowAttributes; |
| 580 | if (XGetWindowAttributes(m_display.get(), m_window, &windowAttributes) == 0) |
| 581 | { |
| 582 | err() << "Failed to get the window attributes" << std::endl; |
| 583 | return; |
| 584 | } |
| 585 | |
| 586 | // Get its visuals |
| 587 | XVisualInfo tpl; |
| 588 | tpl.screen = DefaultScreen(m_display.get()); |
| 589 | tpl.visualid = XVisualIDFromVisual(windowAttributes.visual); |
| 590 | int nbVisuals = 0; |
| 591 | visualInfo = X11Ptr<XVisualInfo>(XGetVisualInfo(m_display.get(), VisualIDMask | VisualScreenMask, &tpl, &nbVisuals)); |
| 592 | } |
| 593 | |
| 594 | if (!visualInfo) |
| 595 | { |
| 596 | err() << "Failed to get visual info" << std::endl; |
| 597 | return; |
| 598 | } |
| 599 | |
| 600 | // Get the context to share display lists with |
| 601 | GLXContext toShare = shared ? shared->m_context : nullptr; |
| 602 | |
| 603 | // There are no GLX versions prior to 1.0 |
| 604 | int major = 0; |
| 605 | int minor = 0; |
| 606 | |
| 607 | if (!glXQueryVersion(m_display.get(), &major, &minor)) |
| 608 | err() << "Failed to query GLX version, limited to legacy context creation" << std::endl; |
| 609 | |
| 610 | // Check if glXCreateContextAttribsARB is available (requires GLX 1.3 or greater) |
| 611 | const bool hasCreateContextArb = SF_GLAD_GLX_ARB_create_context && ((major > 1) || (minor >= 3)); |