///////////////////////////////////////////////////////
| 874 | |
| 875 | //////////////////////////////////////////////////////////// |
| 876 | void GlContext::initialize(const ContextSettings& requestedSettings) |
| 877 | { |
| 878 | // Activate the context |
| 879 | setActive(true); |
| 880 | |
| 881 | // Retrieve the context version number |
| 882 | int majorVersion = 0; |
| 883 | int minorVersion = 0; |
| 884 | |
| 885 | // Try the new way first |
| 886 | auto glGetIntegervFunc = reinterpret_cast<glGetIntegervFuncType>(getFunction("glGetIntegerv")); |
| 887 | auto glGetErrorFunc = reinterpret_cast<glGetErrorFuncType>(getFunction("glGetError")); |
| 888 | auto glGetStringFunc = reinterpret_cast<glGetStringFuncType>(getFunction("glGetString")); |
| 889 | auto glEnableFunc = reinterpret_cast<glEnableFuncType>(getFunction("glEnable")); |
| 890 | auto glIsEnabledFunc = reinterpret_cast<glIsEnabledFuncType>(getFunction("glIsEnabled")); |
| 891 | |
| 892 | if (!glGetIntegervFunc || !glGetErrorFunc || !glGetStringFunc || !glEnableFunc || !glIsEnabledFunc) |
| 893 | { |
| 894 | err() << "Could not load necessary function to initialize OpenGL context" << std::endl; |
| 895 | return; |
| 896 | } |
| 897 | |
| 898 | glGetIntegervFunc(GL_MAJOR_VERSION, &majorVersion); |
| 899 | glGetIntegervFunc(GL_MINOR_VERSION, &minorVersion); |
| 900 | |
| 901 | if (glGetErrorFunc() != GL_INVALID_ENUM) |
| 902 | { |
| 903 | m_settings.majorVersion = static_cast<unsigned int>(majorVersion); |
| 904 | m_settings.minorVersion = static_cast<unsigned int>(minorVersion); |
| 905 | } |
| 906 | else |
| 907 | { |
| 908 | // Try the old way |
| 909 | |
| 910 | // If we can't get the version number, assume 1.1 |
| 911 | m_settings.majorVersion = 1; |
| 912 | m_settings.minorVersion = 1; |
| 913 | |
| 914 | if (const char* version = reinterpret_cast<const char*>(glGetStringFunc(GL_VERSION))) |
| 915 | { |
| 916 | // OpenGL ES Common Lite profile: The beginning of the returned string is "OpenGL ES-CL major.minor" |
| 917 | // OpenGL ES Common profile: The beginning of the returned string is "OpenGL ES-CM major.minor" |
| 918 | // OpenGL ES Full profile: The beginning of the returned string is "OpenGL ES major.minor" |
| 919 | // Desktop OpenGL: The beginning of the returned string is "major.minor" |
| 920 | |
| 921 | // Helper to parse OpenGL version strings |
| 922 | static const auto parseVersionString = |
| 923 | [](const char* versionString, const char* prefix, unsigned int& major, unsigned int& minor) |
| 924 | { |
| 925 | const std::size_t prefixLength = std::strlen(prefix); |
| 926 | |
| 927 | if ((std::strlen(versionString) >= (prefixLength + 3)) && |
| 928 | (std::strncmp(versionString, prefix, prefixLength) == 0) && std::isdigit(versionString[prefixLength]) && |
| 929 | (versionString[prefixLength + 1] == '.') && std::isdigit(versionString[prefixLength + 2])) |
| 930 | { |
| 931 | major = static_cast<unsigned int>(versionString[prefixLength] - '0'); |
| 932 | minor = static_cast<unsigned int>(versionString[prefixLength + 2] - '0'); |
| 933 |
no test coverage detected