mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 07:36:15 +00:00
OpenGL: Don't use glad to load OpenGL entrypoints
This makes the OpenGL entry points loaded at Adapter creation from the getProcAddress passed in the DiscoveryOptions and update all GL calls in the backend to go through the new OpenGLFunctions object. A code generator is added that generates the function loader and list of GL procs from Khronos' gl.xml file but we can't get rid of glad yet because it is used to have the PROC typedefs and enum values. BUG=dawn:165 Change-Id: I2a583d79752f55877fa4190846f5be16cf91651a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/7983 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
87ab2f96d9
commit
df69f24824
59
src/dawn_native/opengl/OpenGLFunctions.cpp
Normal file
59
src/dawn_native/opengl/OpenGLFunctions.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright 2019 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "dawn_native/opengl/OpenGLFunctions.h"
|
||||
|
||||
#include <cctype>
|
||||
|
||||
namespace dawn_native { namespace opengl {
|
||||
|
||||
MaybeError OpenGLFunctions::Initialize(GetProcAddress getProc) {
|
||||
PFNGLGETSTRINGPROC getString = reinterpret_cast<PFNGLGETSTRINGPROC>(getProc("glGetString"));
|
||||
if (getString == nullptr) {
|
||||
return DAWN_CONTEXT_LOST_ERROR("Couldn't load glGetString");
|
||||
}
|
||||
|
||||
std::string version = reinterpret_cast<const char*>(getString(GL_VERSION));
|
||||
|
||||
if (version.find("OpenGL ES") != std::string::npos) {
|
||||
// ES spec states that the GL_VERSION string will be in the following format:
|
||||
// "OpenGL ES N.M vendor-specific information"
|
||||
mStandard = Standard::ES;
|
||||
mMajorVersion = version[10] - '0';
|
||||
mMinorVersion = version[12] - '0';
|
||||
|
||||
// The minor version shouldn't get to two digits.
|
||||
ASSERT(version.size() <= 13 || !isdigit(version[13]));
|
||||
|
||||
DAWN_TRY(LoadOpenGLESProcs(getProc, mMajorVersion, mMinorVersion));
|
||||
} else {
|
||||
// OpenGL spec states the GL_VERSION string will be in the following format:
|
||||
// <version number><space><vendor-specific information>
|
||||
// The version number is either of the form major number.minor number or major
|
||||
// number.minor number.release number, where the numbers all have one or more
|
||||
// digits
|
||||
mStandard = Standard::Desktop;
|
||||
mMajorVersion = version[0] - '0';
|
||||
mMinorVersion = version[2] - '0';
|
||||
|
||||
// The minor version shouldn't get to two digits.
|
||||
ASSERT(version.size() <= 3 || !isdigit(version[3]));
|
||||
|
||||
DAWN_TRY(LoadDesktopGLProcs(getProc, mMajorVersion, mMinorVersion));
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
}} // namespace dawn_native::opengl
|
||||
Reference in New Issue
Block a user