diff --git a/src/dawn/native/opengl/BackendGL.cpp b/src/dawn/native/opengl/BackendGL.cpp index 90ffd6195d..ac175f55f8 100644 --- a/src/dawn/native/opengl/BackendGL.cpp +++ b/src/dawn/native/opengl/BackendGL.cpp @@ -97,8 +97,9 @@ ResultOrError>> Backend::DiscoverPhysicalDev DAWN_INVALID_IF(options->getProc == nullptr, "PhysicalDeviceDiscoveryOptions::getProc must be set"); - Ref physicalDevice = AcquireRef(new PhysicalDevice( - GetInstance(), static_cast(optionsBase->backendType))); + Ref physicalDevice = AcquireRef( + new PhysicalDevice(GetInstance(), static_cast(optionsBase->backendType), + options->makeCurrent, options->destroy, options->userData)); DAWN_TRY(physicalDevice->InitializeGLFunctions(options->getProc)); DAWN_TRY(physicalDevice->Initialize()); diff --git a/src/dawn/native/opengl/PhysicalDeviceGL.cpp b/src/dawn/native/opengl/PhysicalDeviceGL.cpp index bdcfc4f52f..942f61b73f 100644 --- a/src/dawn/native/opengl/PhysicalDeviceGL.cpp +++ b/src/dawn/native/opengl/PhysicalDeviceGL.cpp @@ -21,6 +21,7 @@ #include "dawn/common/GPUInfo.h" #include "dawn/native/Instance.h" #include "dawn/native/opengl/ContextEGL.h" +#include "dawn/native/opengl/ContextExternal.h" #include "dawn/native/opengl/DeviceGL.h" namespace dawn::native::opengl { @@ -53,12 +54,21 @@ uint32_t GetVendorIdFromVendors(const char* vendor) { } // anonymous namespace -PhysicalDevice::PhysicalDevice(InstanceBase* instance, wgpu::BackendType backendType) - : PhysicalDeviceBase(instance, backendType) {} +PhysicalDevice::PhysicalDevice(InstanceBase* instance, + wgpu::BackendType backendType, + void (*makeCurrent)(void*), + void (*destroy)(void*), + void* userData) + : PhysicalDeviceBase(instance, backendType), + mMakeCurrent(makeCurrent), + mDestroy(destroy), + mUserData(userData) {} MaybeError PhysicalDevice::InitializeGLFunctions(void* (*getProc)(const char*)) { - // Use getProc to populate the dispatch table - mEGLFunctions.Init(getProc); + if (mMakeCurrent == nullptr) { + // Use getProc to populate the dispatch table + mEGLFunctions.Init(getProc); + } return mFunctions.Initialize(getProc); } @@ -238,7 +248,11 @@ ResultOrError> PhysicalDevice::CreateDeviceImpl(AdapterBase* ada EGLenum api = GetBackendType() == wgpu::BackendType::OpenGL ? EGL_OPENGL_API : EGL_OPENGL_ES_API; std::unique_ptr context; - DAWN_TRY_ASSIGN(context, ContextEGL::Create(mEGLFunctions, api)); + if (mMakeCurrent != nullptr) { + DAWN_TRY_ASSIGN(context, ContextExternal::Create(mMakeCurrent, mDestroy, mUserData)); + } else { + DAWN_TRY_ASSIGN(context, ContextEGL::Create(mEGLFunctions, api)); + } return Device::Create(adapter, descriptor, mFunctions, std::move(context), deviceToggles); } diff --git a/src/dawn/native/opengl/PhysicalDeviceGL.h b/src/dawn/native/opengl/PhysicalDeviceGL.h index 6ef3e2e427..052fe8706f 100644 --- a/src/dawn/native/opengl/PhysicalDeviceGL.h +++ b/src/dawn/native/opengl/PhysicalDeviceGL.h @@ -23,7 +23,11 @@ namespace dawn::native::opengl { class PhysicalDevice : public PhysicalDeviceBase { public: - PhysicalDevice(InstanceBase* instance, wgpu::BackendType backendType); + PhysicalDevice(InstanceBase* instance, + wgpu::BackendType backendType, + void (*makeCurrent)(void*), + void (*destroy)(void*), + void* userData); MaybeError InitializeGLFunctions(void* (*getProc)(const char*)); @@ -48,6 +52,9 @@ class PhysicalDevice : public PhysicalDeviceBase { OpenGLFunctions mFunctions; EGLFunctions mEGLFunctions; + void (*mMakeCurrent)(void*); + void (*mDestroy)(void*); + void* mUserData; }; } // namespace dawn::native::opengl