From 983e76d57b2748796b62b114446f9337f3709ff5 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 7 Dec 2019 14:17:17 -0800 Subject: Reworked API Unit test to use run-time DLL loading to avoid apparent issue with missing Vulkan library on appveyor; improved implementation of DLL loading on Windows --- .../interface/EngineFactoryVk.h | 54 ++++------------------ 1 file changed, 10 insertions(+), 44 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/interface/EngineFactoryVk.h b/Graphics/GraphicsEngineVulkan/interface/EngineFactoryVk.h index 2b3381ba..c50649b1 100644 --- a/Graphics/GraphicsEngineVulkan/interface/EngineFactoryVk.h +++ b/Graphics/GraphicsEngineVulkan/interface/EngineFactoryVk.h @@ -34,18 +34,19 @@ #include "../../GraphicsEngine/interface/SwapChain.h" #if PLATFORM_ANDROID || PLATFORM_LINUX || PLATFORM_MACOS || PLATFORM_IOS || (PLATFORM_WIN32 && !defined(_MSC_VER)) - // https://gcc.gnu.org/wiki/Visibility # define API_QUALIFIER __attribute__((visibility("default"))) - #elif PLATFORM_WIN32 - # define API_QUALIFIER - #else # error Unsupported platform #endif +#if ENGINE_DLL && PLATFORM_WIN32 && defined(_MSC_VER) +# include "../../GraphicsEngine/interface/LoadEngineDll.h" +# define EXPLICITLY_LOAD_ENGINE_VK_DLL 1 +#endif + namespace Diligent { @@ -74,50 +75,15 @@ public: }; -#if ENGINE_DLL && PLATFORM_WIN32 && defined(_MSC_VER) - -# define EXPLICITLY_LOAD_ENGINE_VK_DLL 1 +#if EXPLICITLY_LOAD_ENGINE_VK_DLL -typedef IEngineFactoryVk* (*GetEngineFactoryVkType)(); +using GetEngineFactoryVkType = IEngineFactoryVk* (*)(); static bool LoadGraphicsEngineVk(GetEngineFactoryVkType& GetFactoryFunc) { - GetFactoryFunc = nullptr; - std::string LibName = "GraphicsEngineVk_"; - -# if _WIN64 - LibName += "64"; -# else - LibName += "32"; -# endif - -# ifdef _DEBUG - LibName += "d"; -# else - LibName += "r"; -# endif - - LibName += ".dll"; - auto hModule = LoadLibraryA(LibName.c_str()); - if (hModule == NULL) - { - std::stringstream ss; - ss << "Failed to load " << LibName << " library.\n"; - OutputDebugStringA(ss.str().c_str()); - return false; - } - - GetFactoryFunc = reinterpret_cast(GetProcAddress(hModule, "GetEngineFactoryVk")); - if (GetFactoryFunc == NULL) - { - std::stringstream ss; - ss << "Failed to load GetEngineFactoryVk() from " << LibName << " library.\n"; - OutputDebugStringA(ss.str().c_str()); - FreeLibrary(hModule); - return false; - } - - return true; + auto ProcAddress = LoadEngineDll("GraphicsEngineVk", "GetEngineFactoryVk"); + GetFactoryFunc = reinterpret_cast(ProcAddress); + return GetFactoryFunc != nullptr; } #else -- cgit v1.2.3