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 "Renderer/BsRendererManager.h"
4#include "Renderer/BsRenderer.h"
5#include "Error/BsException.h"
6#include "Renderer/BsRendererFactory.h"
7
8namespace bs
9{
10 RendererManager::~RendererManager()
11 {
12 if (mActiveRenderer != nullptr)
13 mActiveRenderer->destroy();
14 }
15
16 void RendererManager::setActive(const String& name)
17 {
18 for(auto iter = mAvailableFactories.begin(); iter != mAvailableFactories.end(); ++iter)
19 {
20 if((*iter)->name() == name)
21 {
22 SPtr<ct::Renderer> newRenderer = (*iter)->create();
23 if(newRenderer != nullptr)
24 {
25 if (mActiveRenderer != nullptr)
26 mActiveRenderer->destroy();
27
28 mActiveRenderer = newRenderer;
29 }
30 }
31 }
32
33 if(mActiveRenderer == nullptr)
34 {
35 BS_EXCEPT(InternalErrorException,
36 "Cannot initialize renderer. Renderer with the name '" + name + "' cannot be found.")
37 }
38 }
39
40 void RendererManager::initialize()
41 {
42 if (mActiveRenderer != nullptr)
43 mActiveRenderer->initialize();
44 }
45
46 void RendererManager::_registerFactory(SPtr<RendererFactory> factory)
47 {
48 assert(factory != nullptr);
49
50 mAvailableFactories.push_back(factory);
51 }
52}