All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CustomLandmarkRenderable.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "PackedRenderable.h"
6 #include "LayerIds.h"
7 #include "Rendering.h"
8 #include "CullingVolume.h"
9 #include "VectorMathDecl.h"
10 #include "AsyncTexturing.h"
11 #include "IAsyncTexture.h"
12 #include <string>
13 #include <map>
14 
15 namespace Eegeo
16 {
17  namespace Rendering
18  {
19  namespace Renderables
20  {
22  {
23  public:
25  LayerIds::Values layerId,
26  Materials::IMaterial* material,
27  Rendering::Mesh* pMesh,
28  Culling::CullingVolumeTree* pCullingVolumeTree,
29  const VertexLayouts::VertexBinding& vertexBinding,
30  Eegeo::dv3 ecefPosition,
31  Eegeo::v4 positionBoundsMin,
32  Eegeo::v4 positionBoundsMax,
33  Eegeo::v2 uvBoundsMin,
34  Eegeo::v2 uvBoundsMax,
35  const std::string& landmarkTextureName,
36  const std::string& renderableName)
38  layerId,
39  material,
40  pMesh,
41  pCullingVolumeTree,
42  vertexBinding,
43  ecefPosition,
44  positionBoundsMin,
45  positionBoundsMax,
46  uvBoundsMin,
47  uvBoundsMax)
48  , m_landmarkTextureName(landmarkTextureName)
49  , m_renderableName(renderableName)
50  , m_alpha(1.f)
51  , m_originalEcefPosition(ecefPosition)
52  {
53  }
54 
55  virtual ~CustomLandmarkRenderable()
56  {
57  ClearTextures();
58  }
59 
60  virtual void ClearTextures()
61  {
62  for (std::map<std::string, Rendering::AsyncTexturing::IAsyncTexture*>::iterator it = m_textureIdsByState.begin();
63  it != m_textureIdsByState.end();
64  ++it)
65  {
66  it->second->Release();
67  }
68  m_textureIdsByState.clear();
69  }
70 
71  const std::string& GetLandmarkTextureName() const
72  {
73  return m_landmarkTextureName;
74  }
75 
76  const std::string& GetRenderableName() const
77  {
78  return m_renderableName;
79  }
80 
81  void RegisterTextureForState(const std::string& stateName, Rendering::AsyncTexturing::IAsyncTexture& asyncTexture)
82  {
83  Eegeo_ASSERT(m_textureIdsByState.find(stateName) == m_textureIdsByState.end(), "state already registered");
84  m_textureIdsByState[stateName] = &asyncTexture;
85  }
86 
87  TTextureId GetTextureForState(const std::string& stateName) const
88  {
89  Rendering::AsyncTexturing::IAsyncTexture* pAsyncTexture = m_textureIdsByState.at(stateName);
90  return pAsyncTexture->GetTextureInfo().textureId;
91  }
92 
93  bool ShouldRender() const
94  {
95  const float MinimumAlphaForRendering = 1.0f / 256.0f;
96  return m_alpha > MinimumAlphaForRendering;
97  }
98 
99  const dv3& GetOriginalEcefPosition() const { return m_originalEcefPosition; }
100 
101  virtual void SetAlpha(float alpha) { m_alpha = alpha; }
102  float GetAlpha() const { return m_alpha; }
103 
104  protected:
105  const std::string m_landmarkTextureName;
106  const std::string m_renderableName;
107  std::map<std::string, Rendering::AsyncTexturing::IAsyncTexture*> m_textureIdsByState;
108  float m_alpha;
109 
110  const dv3 m_originalEcefPosition;
111 
112 
113  };
114  }
115  }
116 }