blob: cc35dad37f9bfd61aa404bae50c83394994bdfbd [file] [log] [blame]
Corentin Wallezdf69f242019-06-13 10:22:32 +00001//* 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/OpenGLFunctionsBase_autogen.h"
16
17namespace dawn_native { namespace opengl {
18
19template<typename T>
20MaybeError OpenGLFunctionsBase::LoadProc(GetProcAddress getProc, T* memberProc, const char* name) {
21 *memberProc = reinterpret_cast<T>(getProc(name));
22 if (DAWN_UNLIKELY(memberProc == nullptr)) {
Corentin Walleza0afd312020-04-01 12:07:43 +000023 return DAWN_INTERNAL_ERROR(std::string("Couldn't load GL proc: ") + name);
Corentin Wallezdf69f242019-06-13 10:22:32 +000024 }
25 return {};
26}
27
28MaybeError OpenGLFunctionsBase::LoadOpenGLESProcs(GetProcAddress getProc, int majorVersion, int minorVersion) {
29 {% for block in gles_blocks %}
30 // OpenGL ES {{block.version.major}}.{{block.version.minor}}
31 if (majorVersion > {{block.version.major}} || (majorVersion == {{block.version.major}} && minorVersion >= {{block.version.minor}})) {
32 {% for proc in block.procs %}
33 DAWN_TRY(LoadProc(getProc, &{{proc.ProcName()}}, "{{proc.glProcName()}}"));
34 {% endfor %}
35 }
36
37 {% endfor %}
Stephen Whited0ebcba2021-05-06 18:34:14 +000038
39 {% for block in extension_gles_blocks %}
40 // {{block.extension}}
41 {% for proc in block.procs %}
42 DAWN_TRY(LoadProc(getProc, &{{proc.ProcName()}}, "{{proc.glProcName()}}"));
43 {% endfor %}
44 {% endfor %}
45
Corentin Wallezdf69f242019-06-13 10:22:32 +000046 return {};
47}
48
49MaybeError OpenGLFunctionsBase::LoadDesktopGLProcs(GetProcAddress getProc, int majorVersion, int minorVersion) {
50 {% for block in desktop_gl_blocks %}
51 // Desktop OpenGL {{block.version.major}}.{{block.version.minor}}
52 if (majorVersion > {{block.version.major}} || (majorVersion == {{block.version.major}} && minorVersion >= {{block.version.minor}})) {
53 {% for proc in block.procs %}
54 DAWN_TRY(LoadProc(getProc, &{{proc.ProcName()}}, "{{proc.glProcName()}}"));
55 {% endfor %}
56 }
57
58 {% endfor %}
Stephen Whited0ebcba2021-05-06 18:34:14 +000059
60 {% for block in extension_desktop_gl_blocks %}
61 // {{block.extension}}
62 {% for proc in block.procs %}
63 DAWN_TRY(LoadProc(getProc, &{{proc.ProcName()}}, "{{proc.glProcName()}}"));
64 {% endfor %}
65 {% endfor %}
66
Corentin Wallezdf69f242019-06-13 10:22:32 +000067 return {};
68}
69
70}} // namespace dawn_native::opengl