• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "dawn_native/opengl/OpenGLFunctions.h"
16 
17 #include <cctype>
18 
19 namespace dawn_native { namespace opengl {
20 
Initialize(GetProcAddress getProc)21     MaybeError OpenGLFunctions::Initialize(GetProcAddress getProc) {
22         DAWN_TRY(mVersion.Initialize(getProc));
23         if (mVersion.IsES()) {
24             DAWN_TRY(LoadOpenGLESProcs(getProc, mVersion.GetMajor(), mVersion.GetMinor()));
25         } else {
26             DAWN_TRY(LoadDesktopGLProcs(getProc, mVersion.GetMajor(), mVersion.GetMinor()));
27         }
28 
29         InitializeSupportedGLExtensions();
30 
31         return {};
32     }
33 
InitializeSupportedGLExtensions()34     void OpenGLFunctions::InitializeSupportedGLExtensions() {
35         int32_t numExtensions;
36         GetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
37 
38         for (int32_t i = 0; i < numExtensions; ++i) {
39             const char* extensionName = reinterpret_cast<const char*>(GetStringi(GL_EXTENSIONS, i));
40             mSupportedGLExtensionsSet.insert(extensionName);
41         }
42     }
43 
IsGLExtensionSupported(const char * extension) const44     bool OpenGLFunctions::IsGLExtensionSupported(const char* extension) const {
45         ASSERT(extension != nullptr);
46         return mSupportedGLExtensionsSet.count(extension) != 0;
47     }
48 
GetVersion() const49     const OpenGLVersion& OpenGLFunctions::GetVersion() const {
50         return mVersion;
51     }
52 
IsAtLeastGL(uint32_t majorVersion,uint32_t minorVersion) const53     bool OpenGLFunctions::IsAtLeastGL(uint32_t majorVersion, uint32_t minorVersion) const {
54         return mVersion.IsDesktop() && mVersion.IsAtLeast(majorVersion, minorVersion);
55     }
56 
IsAtLeastGLES(uint32_t majorVersion,uint32_t minorVersion) const57     bool OpenGLFunctions::IsAtLeastGLES(uint32_t majorVersion, uint32_t minorVersion) const {
58         return mVersion.IsES() && mVersion.IsAtLeast(majorVersion, minorVersion);
59     }
60 
61 }}  // namespace dawn_native::opengl
62