MCPcopy Create free account
hub / github.com/SFML/SFML / createSurface

Method createSurface

src/SFML/Window/Win32/WglContext.cpp:610–677  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

608
609////////////////////////////////////////////////////////////
610void WglContext::createSurface(WglContext* shared, Vector2u size, unsigned int bitsPerPixel)
611{
612 // Check if the shared context already exists and pbuffers are supported
613 if (shared && shared->m_deviceContext && SF_GLAD_WGL_ARB_pbuffer)
614 {
615 const int bestFormat = selectBestPixelFormat(shared->m_deviceContext, bitsPerPixel, m_settings, true);
616
617 if (bestFormat > 0)
618 {
619 static constexpr std::array attributes = {0, 0};
620
621 m_pbuffer = wglCreatePbufferARB(shared->m_deviceContext,
622 bestFormat,
623 static_cast<int>(size.x),
624 static_cast<int>(size.y),
625 attributes.data());
626
627 if (m_pbuffer)
628 {
629 m_window = shared->m_window;
630 m_deviceContext = wglGetPbufferDCARB(m_pbuffer);
631
632 if (!m_deviceContext)
633 {
634 err() << "Failed to retrieve pixel buffer device context: " << getErrorString(GetLastError())
635 << std::endl;
636
637 wglDestroyPbufferARB(m_pbuffer);
638 m_pbuffer = nullptr;
639 }
640 }
641 else
642 {
643 err() << "Failed to create pixel buffer: " << getErrorString(GetLastError()) << std::endl;
644 }
645 }
646 }
647
648 // If pbuffers are not available we use a hidden window as the off-screen surface to draw to
649 if (!m_deviceContext)
650 {
651 // We can't create a memory DC, the resulting context wouldn't be compatible
652 // with other contexts and thus wglShareLists would always fail
653
654 // Create the hidden window
655 m_window = CreateWindowA("STATIC",
656 "",
657 WS_POPUP | WS_DISABLED,
658 0,
659 0,
660 static_cast<int>(size.x),
661 static_cast<int>(size.y),
662 nullptr,
663 nullptr,
664 GetModuleHandle(nullptr),
665 nullptr);
666 ShowWindow(m_window, SW_HIDE);
667 m_deviceContext = GetDC(m_window);

Callers

nothing calls this directly

Calls 1

getErrorStringFunction · 0.85

Tested by

no test coverage detected