All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
InstancedInteriorFloorRenderable.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Interiors.h"
6 #include "InteriorRenderable.h"
7 #include "LayerIds.h"
8 #include "Rendering.h"
9 #include "Culling.h"
10 #include "VectorMath.h"
11 #include "InteriorsStencilMirrorType.h"
12 #include "SingleSphere.h"
13 #include "InstancedRenderState.h"
14 
15 #include <vector>
16 #include <string>
17 
18 namespace Eegeo
19 {
20  namespace Rendering
21  {
22  namespace Renderables
23  {
25  {
26  public:
27 
28  InstancedInteriorFloorRenderable(LayerIds::Values layerId,
29  int floorIndex,
30  Materials::IMaterial* material,
31  Rendering::Mesh* pMesh,
32  Culling::CullingVolumeTree* pCullingVolumeTree,
33  const VertexLayouts::VertexBinding& vertexBinding,
34  Eegeo::dv3 ecefLocalOrigin,
35  Eegeo::v4 positionBoundsMin,
36  Eegeo::v4 positionBoundsMax,
37  Eegeo::v2 uvBoundsMin,
38  Eegeo::v2 uvBoundsMax,
39  const std::string& renderableId,
40  const Resources::Interiors::IInteriorsMaterialAssignmentObserver& materialAssignmentObserver,
41  const float interiorTerrainHeight,
42  bool ownsMesh,
43  const std::vector<m44>& instanceTransforms,
44  const std::string& interiorIdentifier);
45 
47 
48  void SetInstancedRenderState(const InstancedRenderState& renderState);
49 
50  bool UpdateVisibility(const Eegeo::Geometry::Frustum& viewFrustum, Culling::CullingVolumeVisibilityUpdater& visibilityUpdater, float environmentScale);
51 
52  virtual void Render(Rendering::GLState& glState) const;
53 
54  bool IsHighlighted(int instanceIndex) const;
55 
56  v4 GetHighlightColor(int instanceIndex) const;
57 
58  int GetInstanceCount() const;
59 
60  const m44& GetInstanceTransformAtIndex(int index) const;
61 
62  virtual void SetInstanceTransformAtIndex(int index, const m44& transform);
63 
64  virtual void AddInstanceTransform(const m44& transform);
65 
66  virtual void RemoveInstanceTransformAtIndex(int index);
67 
68  const InstancedRenderState& GetInstancedRenderState() const { return m_instancedRenderState; }
69 
70  virtual void UpdateIndexColor(int index, const v4& color);
71 
72  const Eegeo::Geometry::SingleSphere& GetInstancedBoundingSphere(int index) const { return m_instanceBounds.at(index); }
73 
74  const bool IsInstanceVisible(int index) const { return m_visibleInstances.at(index); }
75 
76  private:
77 
78  void UpdateCullingBounds();
79 
80  // mutable canonical state
81  std::vector<m44> m_instanceTransforms;
82 
83  InstancedRenderState m_instancedRenderState;
84 
85  Eegeo::Geometry::SingleSphere m_overallBounds;
86  std::vector<Eegeo::Geometry::SingleSphere> m_instanceBounds;
87  std::vector<bool> m_visibleInstances;
88  Eegeo::Geometry::SingleSphere m_localBounds;
89  bool m_isCullingBoundsDirty;
90  };
91  }
92  }
93 }