iMSTK
Interactive Medical Simulation Toolkit
imstkTextureManager.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkTexture.h"
10 #include "imstkTextureDelegate.h"
11 
12 #include <unordered_map>
13 
14 namespace imstk
15 {
22 template<class T>
24 {
25 static_assert(std::is_base_of<TextureDelegate, T>::value, "T isn't a subclass of TextureDelegate");
26 
27 public:
28  TextureManager() = default;
29 
30  std::shared_ptr<T> getTextureDelegate(std::shared_ptr<Texture> texture);
31 
32 protected:
33  std::unordered_map<std::shared_ptr<Texture>, std::shared_ptr<T>> m_textureMap;
34 };
35 
36 template<class T> std::shared_ptr<T>
37 TextureManager<T>::getTextureDelegate(std::shared_ptr<Texture> texture)
38 {
39  // If doesn't exist, create new delegate for the texture
40  if (m_textureMap.count(texture) == 0)
41  {
42  m_textureMap[texture] = std::make_shared<T>();
43  m_textureMap[texture]->initialize(texture);
44  }
45  return m_textureMap[texture];
46 }
47 } // namespace imstk
Compound Geometry.
The TextureManager provides delegates for textures, it will create new ones and cache old ones...