1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#include "Managers/BsRenderAPIManager.h"
4#include "Error/BsException.h"
5#include "RenderAPI/BsRenderAPI.h"
6#include "Utility/BsDynLib.h"
7#include "Utility/BsDynLibManager.h"
8
9namespace bs
10{
11 RenderAPIManager::~RenderAPIManager()
12 {
13 if(mRenderAPIInitialized)
14 {
15 ct::RenderAPI::instance().destroy();
16 ct::RenderAPI::shutDown();
17 }
18 }
19
20 SPtr<RenderWindow> RenderAPIManager::initialize(const String& pluginFilename, RENDER_WINDOW_DESC& primaryWindowDesc)
21 {
22 if(mRenderAPIInitialized)
23 return nullptr;
24
25 DynLib* loadedLibrary = gDynLibManager().load(pluginFilename);
26 const char* name = "";
27
28 if(loadedLibrary != nullptr)
29 {
30 typedef const char* (*GetPluginNameFunc)();
31
32 GetPluginNameFunc getPluginNameFunc = (GetPluginNameFunc)loadedLibrary->getSymbol("getPluginName");
33 name = getPluginNameFunc();
34 }
35
36 for(auto iter = mAvailableFactories.begin(); iter != mAvailableFactories.end(); ++iter)
37 {
38 if(strcmp((*iter)->name(), name) == 0)
39 {
40 (*iter)->create();
41 mRenderAPIInitialized = true;
42 return ct::RenderAPI::instance().initialize(primaryWindowDesc);
43 }
44 }
45
46 return nullptr;
47 }
48
49 void RenderAPIManager::registerFactory(SPtr<RenderAPIFactory> factory)
50 {
51 assert(factory != nullptr);
52
53 mAvailableFactories.push_back(factory);
54 }
55}