All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
HttpAsyncCubeTextureLoader.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "IAsyncCubeTextureRequestor.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  {
28  {
29  public:
31  Eegeo::Helpers::IHttpCache& httpCache,
33  IAsyncTexture& placeholderTexture);
34 
36 
37  IAsyncTexture& RequestCubeTexture(const Helpers::CubeTextureName& cubeTextureName,
38  IAsyncTextureObserver* pObserver,
39  bool tryToUpdateIfModified=false);
40 
41  void Release(const HttpAsyncCubeTexture& textureToRelease);
42  void DestroyTexture(const HttpAsyncCubeTexture& textureToRelease);
43 
44  void IssueNextLoadRequest();
45  bool HasPendingLoadRequests() const;
46 
47  int CubeTextureCount() const;
48 
49  int PendingCubeTextureLoadsCount() const;
50 
51  private:
52  Web::IWebLoadRequestFactory& m_webLoadRequestFactory;
53  Eegeo::Helpers::IHttpCache& m_httpCache;
54  Eegeo::Helpers::ITextureFileLoader& m_textureLoader;
55  IAsyncTexture* m_placeholderTexture;
56 
58  Web::PendingWebRequestsContainer m_pendingCubeWebRequestsContainer;
59 
61  Rendering::AsyncTexturing::PendingAsyncTextureLoadsContainer m_pendingAsyncTextureLoadsContainer;
62 
63 
64  bool Contains(const std::string& textureUrl) const;
65 
66  HttpAsyncCubeTexture* CreateTexture(const Helpers::CubeTextureName& cubeTextureName,
67  IAsyncTextureObserver* pObserver,
68  bool tryToUpdateIfModified);
69 
70  HttpAsyncCubeTexture* GetCubeTextureByUrl(const std::string& textureUrl) const;
71 
72  void Evict(HttpAsyncCubeTexture* textureToRelease);
73 
74  void StartLoadingTexture(HttpAsyncCubeTexture* pTexture);
75 
76  bool TryAttachTextureBufferFromCache(HttpAsyncCubeTexture* pTexture, int faceIndex, const std::string& url);
77 
78  void CreateTextureFileRequest(HttpAsyncCubeTexture* pTexture, int faceIndex, const std::string& url, std::vector<Web::IWebLoadRequest*> &requestsToIssue);
79 
80  void OnCubeTextureWebLoadComplete(Web::IWebResponse& webResponse);
81 
82  void BeginLoadCubeTextureFromBuffers(
83  const std::vector<const std::vector<Byte>*>& cubeFaceBuffers,
84  HttpAsyncCubeTexture& texture);
85 
86  void OnCubeTextureAsyncLoadComplete(const Rendering::AsyncTexturing::AsyncTextureLoadResult& result);
87 
88  void AbandonLoads(HttpAsyncCubeTexture* pTexture);
89 
90  typedef std::map<HttpAsyncCubeTexture*, std::vector<Web::IWebLoadRequest*> > TCubeTextureToRequests;
91  typedef std::deque<HttpAsyncCubeTexture*> TCubeTextureDeque;
92  typedef std::map<std::string, HttpAsyncCubeTexture*> TStringToCubeTexture;
93 
94  TCubeTextureToRequests m_requestsByCubeTexture;
95  TCubeTextureDeque m_pendingCubeLoads;
96  TStringToCubeTexture m_cubeTexturesByUrl;
97  int m_inFlightCubeLoadCount;
98  };
99  }
100  }
101 }