All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CityThemesTextureUpdater.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "Rendering.h"
7 #include "Helpers.h"
8 #include "Web.h"
9 #include "CityThemes.h"
10 #include "WebLoadRequestCompletionCallback.h"
11 #include "GLHelpers.h"
12 #include <string>
13 #include <vector>
14 #include <map>
15 #include <set>
16 #include "PendingWebRequestsContainer.h"
17 #include "IAsyncCubeTextureRequestor.h"
18 #include "AsyncTexturing.h"
19 #include "AsyncLoadersModule.h"
20 #include "IAsyncTextureObserver.h"
21 #include "PendingAsyncTextureLoadsContainer.h"
22 #include "ICallback.h"
23 #include "ITextureFileLoader.h"
24 #include <cstdint>
25 
26 namespace Eegeo
27 {
28  namespace Resources
29  {
30  namespace CityThemes
31  {
33  {
34  private:
35  Rendering::EnvironmentTextures& m_environmentTextures;
36  Eegeo::Helpers::ITextureFileLoader& m_textureLoader;
37  Web::IWebLoadRequestFactory& m_webRequestFactory;
39  Eegeo::Helpers::IHttpCache& m_httpCache;
40 
41  std::set<std::string> m_inFlightCubeTextures;
42  Eegeo::Modules::Core::AsyncLoadersModule& m_asyncLoadersModule;
43 
44  std::uintptr_t m_themeChangeCount;
45  int m_currentThemeTexturesCount;
46  bool m_textureLoadingFailed;
47 
48  struct TextureInfoRefs
49  {
50  bool used;
52  };
53 
54 
55  std::map<std::string, TextureInfoRefs> m_loadedTextures;
56  Web::PendingWebRequestsContainer m_pendingWebRequestsContainer;
57 
59  Rendering::AsyncTexturing::PendingAsyncTextureLoadsContainer m_pendingAsyncTextureLoadsContainer;
60 
61  public:
63  Web::IWebLoadRequestFactory& webRequestFactory,
65  Eegeo::Helpers::IHttpCache& httpCache,
67  );
68 
69  void DownloadThemeTextures(const CityThemeData& targetTheme);
70  bool IsLoading() const { return NumberOfTexturesInFlight() > 0; }
71  int CurrentThemeTexturesToLoad() const { return m_currentThemeTexturesCount; }
72  int CurrentThemeTexturesLoaded() const { return m_currentThemeTexturesCount - NumberOfTexturesInFlight(); }
73  bool LoadsFailed() const { return m_textureLoadingFailed; }
74  void CleanupRedundantLoads();
75  void ApplyThemeTextures(const CityThemeData& themeData);
76 
77  void OnTextureLoadSuccess(const Eegeo::Rendering::AsyncTexturing::IAsyncTexture& loadedTexture);
78  void OnTextureLoadFail(const Eegeo::Rendering::AsyncTexturing::IAsyncTexture& loadedTexture);
79 
80  private:
81  void ThemeTextureDownloadedHandler(Eegeo::Web::IWebResponse& webResponse);
82  void BeginTextureDownload(const std::string& textureName);
83  void BeginCubeMapTextureDownload(const std::string& textureUrl);
84 
85  void BeginTextureDownloads(const std::vector<std::string>& textureUrls);
86 
87  bool TryLoadTextureFromBufferAsync(
88  const std::string& url,
89  const std::vector<Byte>& buffer);
90 
91  void OnTextureAsyncLoadComplete(const Rendering::AsyncTexturing::AsyncTextureLoadResult& result);
92 
93  void LoadLocalTextureFromResource(const std::string& url);
94 
95  Rendering::AsyncTexturing::IAsyncTexture& GetAndUseEnvironmentTexture(const std::string& textureFilename);
96 
97  int NumberOfTexturesInFlight() const;
98  };
99  }
100  }
101 }