Geoff Lang | 56cf9af | 2015-02-17 10:16:49 -0500 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2015 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // FunctionsGL.cpp: Implements the FuntionsGL class to contain loaded GL functions |
| 8 | |
| 9 | #include "libANGLE/renderer/gl/FunctionsGL.h" |
Jacek Caban | fa60f69 | 2015-04-27 18:23:44 +0200 | [diff] [blame] | 10 | |
| 11 | #include <algorithm> |
| 12 | |
Jamie Madill | 8c5aeb6 | 2015-05-21 08:17:18 -0400 | [diff] [blame] | 13 | #include "common/string_utils.h" |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 14 | #include "libANGLE/renderer/gl/renderergl_utils.h" |
Geoff Lang | 56cf9af | 2015-02-17 10:16:49 -0500 | [diff] [blame] | 15 | |
| 16 | namespace rx |
| 17 | { |
| 18 | |
Geoff Lang | 08dcfed | 2015-05-25 13:38:42 -0400 | [diff] [blame] | 19 | static void GetGLVersion(PFNGLGETSTRINGPROC getStringFunction, gl::Version *outVersion, StandardGL *outStandard) |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 20 | { |
| 21 | const std::string version = reinterpret_cast<const char*>(getStringFunction(GL_VERSION)); |
| 22 | if (version.find("OpenGL ES") == std::string::npos) |
| 23 | { |
Corentin Wallez | fee0350 | 2015-05-05 15:08:24 -0400 | [diff] [blame] | 24 | // OpenGL spec states the GL_VERSION string will be in the following format: |
| 25 | // <version number><space><vendor-specific information> |
| 26 | // The version number is either of the form major number.minor number or major |
| 27 | // number.minor number.release number, where the numbers all have one or more |
| 28 | // digits |
Geoff Lang | 08dcfed | 2015-05-25 13:38:42 -0400 | [diff] [blame] | 29 | *outStandard = STANDARD_GL_DESKTOP; |
| 30 | *outVersion = gl::Version(version[0] - '0', version[2] - '0'); |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 31 | } |
| 32 | else |
| 33 | { |
Corentin Wallez | fee0350 | 2015-05-05 15:08:24 -0400 | [diff] [blame] | 34 | // ES spec states that the GL_VERSION string will be in the following format: |
| 35 | // "OpenGL ES N.M vendor-specific information" |
Geoff Lang | 08dcfed | 2015-05-25 13:38:42 -0400 | [diff] [blame] | 36 | *outStandard = STANDARD_GL_ES; |
| 37 | *outVersion = gl::Version(version[10] - '0', version[12] - '0'); |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 41 | static std::vector<std::string> GetIndexedExtensions(PFNGLGETINTEGERVPROC getIntegerFunction, PFNGLGETSTRINGIPROC getStringIFunction) |
| 42 | { |
| 43 | std::vector<std::string> result; |
| 44 | |
| 45 | GLint numExtensions; |
| 46 | getIntegerFunction(GL_NUM_EXTENSIONS, &numExtensions); |
| 47 | |
| 48 | result.reserve(numExtensions); |
| 49 | |
| 50 | for (GLint i = 0; i < numExtensions; i++) |
| 51 | { |
| 52 | result.push_back(reinterpret_cast<const char*>(getStringIFunction(GL_EXTENSIONS, i))); |
| 53 | } |
| 54 | |
| 55 | return result; |
| 56 | } |
| 57 | |
Jamie Madill | 60c6555 | 2017-05-02 14:34:05 -0400 | [diff] [blame] | 58 | #define ASSIGN(NAME, FP) *reinterpret_cast<void **>(&FP) = loadProcAddress(NAME) |
| 59 | |
Jamie Madill | 29ddcc9 | 2017-10-21 16:10:02 -0400 | [diff] [blame^] | 60 | FunctionsGL::FunctionsGL() : version(), standard(), extensions() |
Geoff Lang | 56cf9af | 2015-02-17 10:16:49 -0500 | [diff] [blame] | 61 | { |
| 62 | } |
| 63 | |
| 64 | FunctionsGL::~FunctionsGL() |
| 65 | { |
| 66 | } |
| 67 | |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 68 | void FunctionsGL::initialize() |
Geoff Lang | 56cf9af | 2015-02-17 10:16:49 -0500 | [diff] [blame] | 69 | { |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 70 | // Grab the version number |
Jamie Madill | 60c6555 | 2017-05-02 14:34:05 -0400 | [diff] [blame] | 71 | ASSIGN("glGetString", getString); |
| 72 | ASSIGN("glGetIntegerv", getIntegerv); |
Geoff Lang | 08dcfed | 2015-05-25 13:38:42 -0400 | [diff] [blame] | 73 | GetGLVersion(getString, &version, &standard); |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 74 | |
| 75 | // Grab the GL extensions |
Geoff Lang | b2d9ab6 | 2016-01-20 10:50:09 -0500 | [diff] [blame] | 76 | if (isAtLeastGL(gl::Version(3, 0)) || isAtLeastGLES(gl::Version(3, 0))) |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 77 | { |
Jamie Madill | 60c6555 | 2017-05-02 14:34:05 -0400 | [diff] [blame] | 78 | ASSIGN("glGetStringi", getStringi); |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 79 | extensions = GetIndexedExtensions(getIntegerv, getStringi); |
| 80 | } |
| 81 | else |
| 82 | { |
Jamie Madill | 29ddcc9 | 2017-10-21 16:10:02 -0400 | [diff] [blame^] | 83 | const char *exts = reinterpret_cast<const char *>(getString(GL_EXTENSIONS)); |
Jamie Madill | 8c5aeb6 | 2015-05-21 08:17:18 -0400 | [diff] [blame] | 84 | angle::SplitStringAlongWhitespace(std::string(exts), &extensions); |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Jamie Madill | 29ddcc9 | 2017-10-21 16:10:02 -0400 | [diff] [blame^] | 87 | std::set<std::string> extensionSet; |
| 88 | for (const auto &extension : extensions) |
| 89 | { |
| 90 | extensionSet.insert(extension); |
| 91 | } |
| 92 | |
| 93 | // Note: |
| 94 | // Even though extensions are written against specific versions of GL, many drivers expose the |
| 95 | // extensions in even older versions. Always try loading the extensions regardless of GL |
| 96 | // version. |
| 97 | |
Geoff Lang | b2d9ab6 | 2016-01-20 10:50:09 -0500 | [diff] [blame] | 98 | // Load the entry points |
| 99 | switch (standard) |
| 100 | { |
| 101 | case STANDARD_GL_DESKTOP: |
Jamie Madill | 29ddcc9 | 2017-10-21 16:10:02 -0400 | [diff] [blame^] | 102 | { |
| 103 | // Check the context profile |
| 104 | profile = 0; |
| 105 | if (isAtLeastGL(gl::Version(3, 2))) |
| 106 | { |
| 107 | getIntegerv(GL_CONTEXT_PROFILE_MASK, &profile); |
| 108 | } |
| 109 | |
| 110 | initProcsDesktopGL(version, extensionSet); |
Geoff Lang | b2d9ab6 | 2016-01-20 10:50:09 -0500 | [diff] [blame] | 111 | break; |
Jamie Madill | 29ddcc9 | 2017-10-21 16:10:02 -0400 | [diff] [blame^] | 112 | } |
Geoff Lang | b2d9ab6 | 2016-01-20 10:50:09 -0500 | [diff] [blame] | 113 | |
| 114 | case STANDARD_GL_ES: |
Jamie Madill | 29ddcc9 | 2017-10-21 16:10:02 -0400 | [diff] [blame^] | 115 | // No profiles in GLES |
| 116 | profile = 0; |
| 117 | |
| 118 | initProcsGLES(version, extensionSet); |
Geoff Lang | b2d9ab6 | 2016-01-20 10:50:09 -0500 | [diff] [blame] | 119 | break; |
| 120 | |
| 121 | default: |
| 122 | UNREACHABLE(); |
| 123 | break; |
| 124 | } |
Geoff Lang | b2d9ab6 | 2016-01-20 10:50:09 -0500 | [diff] [blame] | 125 | |
Jamie Madill | 29ddcc9 | 2017-10-21 16:10:02 -0400 | [diff] [blame^] | 126 | initProcsSharedExtensions(extensionSet); |
Geoff Lang | b2d9ab6 | 2016-01-20 10:50:09 -0500 | [diff] [blame] | 127 | } |
| 128 | |
Geoff Lang | 08dcfed | 2015-05-25 13:38:42 -0400 | [diff] [blame] | 129 | bool FunctionsGL::isAtLeastGL(const gl::Version &glVersion) const |
| 130 | { |
| 131 | return standard == STANDARD_GL_DESKTOP && version >= glVersion; |
| 132 | } |
| 133 | |
Corentin Wallez | f741780 | 2016-10-12 17:59:31 -0400 | [diff] [blame] | 134 | bool FunctionsGL::isAtMostGL(const gl::Version &glVersion) const |
| 135 | { |
| 136 | return standard == STANDARD_GL_DESKTOP && glVersion >= version; |
| 137 | } |
| 138 | |
Geoff Lang | 08dcfed | 2015-05-25 13:38:42 -0400 | [diff] [blame] | 139 | bool FunctionsGL::isAtLeastGLES(const gl::Version &glesVersion) const |
| 140 | { |
| 141 | return standard == STANDARD_GL_ES && version >= glesVersion; |
| 142 | } |
| 143 | |
Corentin Wallez | f741780 | 2016-10-12 17:59:31 -0400 | [diff] [blame] | 144 | bool FunctionsGL::isAtMostGLES(const gl::Version &glesVersion) const |
| 145 | { |
| 146 | return standard == STANDARD_GL_ES && glesVersion >= version; |
| 147 | } |
| 148 | |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 149 | bool FunctionsGL::hasExtension(const std::string &ext) const |
| 150 | { |
| 151 | return std::find(extensions.begin(), extensions.end(), ext) != extensions.end(); |
| 152 | } |
| 153 | |
Geoff Lang | 862c0ba | 2015-05-25 15:31:16 -0400 | [diff] [blame] | 154 | bool FunctionsGL::hasGLExtension(const std::string &ext) const |
| 155 | { |
| 156 | return standard == STANDARD_GL_DESKTOP && hasExtension(ext); |
| 157 | } |
| 158 | |
| 159 | bool FunctionsGL::hasGLESExtension(const std::string &ext) const |
| 160 | { |
| 161 | return standard == STANDARD_GL_ES && hasExtension(ext); |
| 162 | } |
| 163 | |
Jamie Madill | 60c6555 | 2017-05-02 14:34:05 -0400 | [diff] [blame] | 164 | } // namespace gl |