Overte C++ Documentation
RenderableZoneEntityItem.h
1 //
2 // RenderableZoneEntityItem.h
3 //
4 // Created by Clement on 4/22/15.
5 // Copyright 2015 High Fidelity, Inc.
6 //
7 // Distributed under the Apache License, Version 2.0.
8 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
9 //
10 
11 #ifndef hifi_RenderableZoneEntityItem_h
12 #define hifi_RenderableZoneEntityItem_h
13 
14 #include <ZoneEntityItem.h>
15 #include <graphics/Skybox.h>
16 #include <graphics/Haze.h>
17 #include <graphics/Bloom.h>
18 #include <graphics/Stage.h>
19 #include <LightStage.h>
20 #include <BackgroundStage.h>
21 #include <HazeStage.h>
22 #include <BloomStage.h>
23 #include <TonemappingStage.h>
24 #include <AmbientOcclusionStage.h>
25 #include <NormalMapAttenuationStage.h>
26 #include <TextureCache.h>
27 #include "RenderableEntityItem.h"
28 #include <ComponentMode.h>
29 
30 namespace render { namespace entities {
31 
32 class ZoneEntityRenderer : public TypedEntityRenderer<ZoneEntityItem> {
33  using Parent = TypedEntityRenderer<ZoneEntityItem>;
34  friend class EntityRenderer;
35 
36 public:
37  ZoneEntityRenderer(const EntityItemPointer& entity);
38 
39 protected:
40  virtual void onRemoveFromSceneTyped(const TypedEntityPointer& entity) override;
41  virtual ItemKey getKey() override;
42  virtual void doRender(RenderArgs* args) override;
43  virtual bool needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const override;
44  virtual void doRenderUpdateAsynchronousTyped(const TypedEntityPointer& entity) override;
45 
46 private:
47  void updateKeyZoneItemFromEntity(const TypedEntityPointer& entity);
48  void updateKeySunFromEntity(const TypedEntityPointer& entity);
49  void updateAmbientLightFromEntity(const TypedEntityPointer& entity);
50  void updateHazeFromEntity(const TypedEntityPointer& entity);
51  void updateKeyBackgroundFromEntity(const TypedEntityPointer& entity);
52  void updateBloomFromEntity(const TypedEntityPointer& entity);
53  void updateTonemappingFromEntity(const TypedEntityPointer& entity);
54  void updateAmbientOcclusionFromEntity(const TypedEntityPointer& entity);
55  void updateNormalMapAttenuationFromEntity(const TypedEntityPointer& entity);
56  void updateAmbientMap();
57  void updateSkyboxMap();
58  void setAmbientURL(const QString& ambientUrl);
59  void setSkyboxURL(const QString& skyboxUrl);
60 
61  void setSkyboxColor(const glm::vec3& color);
62  void setProceduralUserData(const QString& userData);
63 
64  graphics::LightPointer editSunLight() { _needSunUpdate = true; return _sunLight; }
65  graphics::LightPointer editAmbientLight() { _needAmbientUpdate = true; return _ambientLight; }
66  graphics::SunSkyStagePointer editBackground() { _needBackgroundUpdate = true; return _background; }
67  graphics::SkyboxPointer editSkybox() { return editBackground()->getSkybox(); }
68  graphics::HazePointer editHaze() { _needHazeUpdate = true; return _haze; }
69  graphics::BloomPointer editBloom() { _needBloomUpdate = true; return _bloom; }
70  graphics::TonemappingPointer editTonemapping() { _needTonemappingUpdate = true; return _tonemapping; }
71  graphics::AmbientOcclusionPointer editAmbientOcclusion() { _needAmbientOcclusionUpdate = true; return _ambientOcclusion; }
72  graphics::NormalMapAttenuationPointer editNormalMapAttenuation() { _needNormalMapAttenuationUpdate = true; return _normalMapAttenuation; }
73 
74  glm::vec3 _lastPosition;
75  glm::vec3 _lastDimensions;
76  glm::quat _lastRotation;
77  bool _lastVisible;
78 
79  LightStagePointer _stage;
80  const graphics::LightPointer _sunLight { std::make_shared<graphics::Light>() };
81  const graphics::LightPointer _ambientLight { std::make_shared<graphics::Light>() };
82  const graphics::SunSkyStagePointer _background { std::make_shared<graphics::SunSkyStage>() };
83  const graphics::HazePointer _haze { std::make_shared<graphics::Haze>() };
84  const graphics::BloomPointer _bloom { std::make_shared<graphics::Bloom>() };
85  const graphics::TonemappingPointer _tonemapping { std::make_shared<graphics::Tonemapping>() };
86  const graphics::AmbientOcclusionPointer _ambientOcclusion { std::make_shared<graphics::AmbientOcclusion>() };
87  const graphics::NormalMapAttenuationPointer _normalMapAttenuation { std::make_shared<graphics::NormalMapAttenuation>() };
88 
89  ComponentMode _keyLightMode { COMPONENT_MODE_INHERIT };
90  ComponentMode _ambientLightMode { COMPONENT_MODE_INHERIT };
91  ComponentMode _skyboxMode { COMPONENT_MODE_INHERIT };
92  ComponentMode _hazeMode { COMPONENT_MODE_INHERIT };
93  ComponentMode _bloomMode { COMPONENT_MODE_INHERIT };
94  ComponentMode _tonemappingMode { COMPONENT_MODE_INHERIT };
95  ComponentMode _ambientOcclusionMode { COMPONENT_MODE_INHERIT };
96  ComponentMode _normalMapAttenuationMode { COMPONENT_MODE_INHERIT };
97 
98  indexed_container::Index _sunIndex { LightStage::INVALID_INDEX };
99  indexed_container::Index _ambientIndex { LightStage::INVALID_INDEX };
100 
101  BackgroundStagePointer _backgroundStage;
102  BackgroundStage::Index _backgroundIndex { BackgroundStage::INVALID_INDEX };
103 
104  HazeStagePointer _hazeStage;
105  HazeStage::Index _hazeIndex { HazeStage::INVALID_INDEX };
106 
107  BloomStagePointer _bloomStage;
108  BloomStage::Index _bloomIndex { BloomStage::INVALID_INDEX };
109 
110  TonemappingStagePointer _tonemappingStage;
111  TonemappingStage::Index _tonemappingIndex { TonemappingStage::INVALID_INDEX };
112 
113  AmbientOcclusionStagePointer _ambientOcclusionStage;
114  AmbientOcclusionStage::Index _ambientOcclusionIndex { AmbientOcclusionStage::INVALID_INDEX };
115 
116  NormalMapAttenuationStagePointer _normalMapAttenuationStage;
117  NormalMapAttenuationStage::Index _normalMapAttenuationIndex { NormalMapAttenuationStage::INVALID_INDEX };
118 
119  bool _needUpdate { true };
120  bool _needSunUpdate { true };
121  bool _needAmbientUpdate { true };
122  bool _needBackgroundUpdate { true };
123  bool _needHazeUpdate { true };
124  bool _needBloomUpdate { true };
125  bool _needTonemappingUpdate { true };
126  bool _needAmbientOcclusionUpdate { true };
127  bool _needNormalMapAttenuationUpdate { true };
128 
129  KeyLightPropertyGroup _keyLightProperties;
130  AmbientLightPropertyGroup _ambientLightProperties;
131  HazePropertyGroup _hazeProperties;
132  SkyboxPropertyGroup _skyboxProperties;
133  BloomPropertyGroup _bloomProperties;
134  TonemappingPropertyGroup _tonemappingProperties;
135  AmbientOcclusionPropertyGroup _ambientOcclusionProperties;
136  NormalMapAttenuationPropertyGroup _normalMapAttenuationProperties;
137 
138  // More attributes used for rendering:
139  QString _ambientTextureURL;
140  NetworkTexturePointer _ambientTexture;
141  bool _pendingAmbientTexture { false };
142 
143  QString _skyboxTextureURL;
144  NetworkTexturePointer _skyboxTexture;
145  bool _pendingSkyboxTexture { false };
146 
147  QString _proceduralUserData;
148 };
149 
150 } } // namespace
151 
152 #endif // hifi_RenderableZoneEntityItem_h