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

Method createContext

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

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

Source from the content-addressed store, hash-verified

693
694////////////////////////////////////////////////////////////
695void WglContext::createContext(WglContext* shared)
696{
697 // We can't create an OpenGL context if we don't have a DC
698 if (!m_deviceContext)
699 return;
700
701 // Get a working copy of the context settings
702 const ContextSettings settings = m_settings;
703
704 // Get the context to share display lists with
705 HGLRC sharedContext = shared ? shared->m_context : nullptr;
706
707 // Create the OpenGL context -- first try using wglCreateContextAttribsARB
708 while (!m_context && m_settings.majorVersion)
709 {
710 if (SF_GLAD_WGL_ARB_create_context)
711 {
712 std::vector<int> attributes;
713
714 // Check if the user requested a specific context version (anything > 1.1)
715 if ((m_settings.majorVersion > 1) || ((m_settings.majorVersion == 1) && (m_settings.minorVersion > 1)))
716 {
717 attributes.push_back(WGL_CONTEXT_MAJOR_VERSION_ARB);
718 attributes.push_back(static_cast<int>(m_settings.majorVersion));
719 attributes.push_back(WGL_CONTEXT_MINOR_VERSION_ARB);
720 attributes.push_back(static_cast<int>(m_settings.minorVersion));
721 }
722
723 // Check if setting the profile is supported
724 if (SF_GLAD_WGL_ARB_create_context_profile)
725 {
726 const int profile = (m_settings.attributeFlags & ContextSettings::Core)
727 ? WGL_CONTEXT_CORE_PROFILE_BIT_ARB
728 : WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
729 const int debug = (m_settings.attributeFlags & ContextSettings::Debug) ? WGL_CONTEXT_DEBUG_BIT_ARB : 0;
730
731 attributes.push_back(WGL_CONTEXT_PROFILE_MASK_ARB);
732 attributes.push_back(profile);
733 attributes.push_back(WGL_CONTEXT_FLAGS_ARB);
734 attributes.push_back(debug);
735 }
736 else
737 {
738 if ((m_settings.attributeFlags & ContextSettings::Core) ||
739 (m_settings.attributeFlags & ContextSettings::Debug))
740 err() << "Selecting a profile during context creation is not supported,"
741 << "disabling compatibility and debug" << std::endl;
742
743 m_settings.attributeFlags = ContextSettings::Default;
744 }
745
746 // Append the terminating 0
747 attributes.push_back(0);
748 attributes.push_back(0);
749
750 if (sharedContext)
751 {
752 static std::recursive_mutex mutex;

Callers

nothing calls this directly

Calls 2

getErrorStringFunction · 0.85
ensureExtensionsInitFunction · 0.70

Tested by

no test coverage detected