OpenXRVkGladFuncLoader.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/PlatformIncl.h>
  9. #define GLAD_VULKAN_IMPLEMENTATION
  10. #include <OpenXRVk_Platform.h>
  11. #include <OpenXRVk/OpenXRVkGladFuncLoader.h>
  12. #include <AzCore/Module/DynamicModuleHandle.h>
  13. namespace
  14. {
  15. GLADapiproc LoadFunctionFromLibrary(void* userPtr, const char *name)
  16. {
  17. AZ::DynamicModuleHandle* moduleHandle = reinterpret_cast<AZ::DynamicModuleHandle*>(userPtr);
  18. AZ_Assert(moduleHandle, "Invalid module handle");
  19. return moduleHandle->GetFunction<GLADapiproc>(name);
  20. }
  21. }
  22. namespace OpenXRVk
  23. {
  24. AZStd::unique_ptr<FunctionLoader> FunctionLoader::Create()
  25. {
  26. return AZStd::make_unique<GladFunctionLoader>();
  27. }
  28. bool GladFunctionLoader::InitInternal()
  29. {
  30. // Since we don't have the vulkan instance or device yet, we just load the function pointers from the loader
  31. // using dlsym or something similar.
  32. return gladLoadVulkanUserPtr(VK_NULL_HANDLE, &LoadFunctionFromLibrary, m_moduleHandle.get()) != 0;
  33. }
  34. void GladFunctionLoader::ShutdownInternal()
  35. {
  36. gladLoaderUnloadVulkan();
  37. }
  38. }