All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
HttpAsyncTextureLoader.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "IAsyncTextureRequestor.h"
7 #include "Web.h"
8 #include "Helpers.h"
9 #include "GLHelpers.h"
10 #include "IdTypes.h"
11 #include "WebLoadRequestCompletionCallback.h"
12 #include <map>
13 #include <deque>
14 #include <string>
15 #include <vector>
16 #include "PendingWebRequestsContainer.h"
17 #include "PendingAsyncTextureLoadsContainer.h"
18 #include "ICallback.h"
19 #include "ITextureFileLoader.h"
20 
21 namespace Eegeo
22 {
23  namespace Rendering
24  {
25  namespace AsyncTexturing
26  {
27  typedef std::vector<Rendering::AsyncTexturing::IAsyncTexture*> TIAsyncTextures;
28 
30  {
31  public:
33  Web::IWebLoadRequestFactory& webLoadRequestFactory,
34  Eegeo::Helpers::IHttpCache& httpCache,
36  IAsyncTexture& placeholderTexture,
37  ITextureFactory& textureFactory
38  );
39 
41 
42  IAsyncTexture& RequestTexture(const std::string& textureUrl,
43  IAsyncTextureObserver* pObserver,
44  bool generateMipmaps=false,
45  bool tryToUpdateIfModified=false);
46 
47  void Release(const HttpAsyncTexture& textureToRelease);
48  void DestroyTexture(const HttpAsyncTexture& textureToRelease);
49 
50  void IssueNextLoadRequest();
51  bool HasPendingLoadRequests() const;
52  void UpdatePlaceholderEnvironmentTexture(Rendering::AsyncTexturing::IAsyncTexture& texture);
53 
54  int TextureCount() const;
55 
56  int PendingTextureLoadsCount() const;
57 
58  private:
59  Web::IWebLoadRequestFactory& m_webLoadRequestFactory;
60  Eegeo::Helpers::IHttpCache& m_httpCache;
61  Eegeo::Helpers::ITextureFileLoader& m_textureLoader;
62  IAsyncTexture* m_placeholderTexture;
63 
65  Web::PendingWebRequestsContainer m_pendingWebRequestsContainer;
66 
68  Rendering::AsyncTexturing::PendingAsyncTextureLoadsContainer m_pendingAsyncTextureLoadsContainer;
69 
70  bool Contains(const std::string& textureUrl) const;
71 
72  HttpAsyncTexture* CreateTexture(const std::string& textureUrl,
73  IAsyncTextureObserver* pObserver,
74  bool generateMipmaps,
75  bool tryToUpdateIfModified);
76 
77  HttpAsyncTexture* GetTextureByUrl(const std::string& textureUrl) const;
78 
79  void Evict(HttpAsyncTexture* pTexture);
80 
81  void StartLoadingTexture(HttpAsyncTexture* pTexture);
82 
83  void OnTextureWebLoadComplete(Web::IWebResponse& webResponse);
84 
85  void OnTextureAsyncLoadComplete(const Rendering::AsyncTexturing::AsyncTextureLoadResult& result);
86 
87  void BeginLoadTextureFromBuffer(
88  const std::vector<Byte>& buffer,
89  HttpAsyncTexture& texture);
90 
91  typedef std::map<HttpAsyncTexture*, Web::IWebLoadRequest*> TTextureToRequest;
92  typedef std::deque<HttpAsyncTexture*> TTextureDeque;
93  typedef std::map<std::string, HttpAsyncTexture*> TStringToTexture;
94  typedef std::map<HttpAsyncTexture*, Rendering::AsyncTexturing::IAsyncTextureLoad*> TTextureToDecode;
95 
96  TTextureToRequest m_requestByTexture;
97  TTextureDeque m_pendingLoads;
98  TStringToTexture m_texturesByUrl;
99  TTextureToDecode m_decodeByTexture;
100  int m_inFlightLoadCount;
101  ITextureFactory& m_textureFactory;
102  };
103  }
104  }
105 }