RigsofRods
Soft-body Physics Simulation
RttManager.h
Go to the documentation of this file.
1 /*
2 --------------------------------------------------------------------------------
3 This source file is part of Hydrax.
4 Visit ---
5 
6 Copyright (C) 2008 Xavier Verguín González <xavierverguin@hotmail.com>
7  <xavyiy@gmail.com>
8 
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
12 version.
13 
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License along with
19 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21 http://www.gnu.org/copyleft/lesser.txt.
22 --------------------------------------------------------------------------------
23 */
24 
25 #ifndef _Hydrax_RttManager_H_
26 #define _Hydrax_RttManager_H_
27 
28 #include "Prerequisites.h"
29 
30 #include "Enums.h"
31 #include "Help.h"
32 
35 
38 
39 namespace Hydrax
40 {
41  class Hydrax;
42 
45  class RttManager
46  {
47  public:
50  enum RttType
51  {
54  RTT_DEPTH = 2,
58  };
59 
63  {
64  BPC_8 = 8,
65  BPC_16 = 16,
66  BPC_32 = 32
67  };
68 
72  {
73  NOC_1 = 1,
74  NOC_2 = 2,
75  NOC_3 = 3,
76  NOC_4 = 4
77  };
78 
81  struct RttOptions
82  {
84  Ogre::String Name;
91  };
92 
96  {
97  public:
102  virtual void preRenderTargetUpdate(const RttType& Rtt){};
103 
108  virtual void postRenderTargetUpdate(const RttType& Rtt){};
109  };
110 
114  RttManager(Hydrax *h);
115 
118  ~RttManager();
119 
124  void initialize(const RttType& Rtt);
125 
129  void remove(const RttType& Rtt);
130 
134  void removeAll();
135 
138  inline const Ogre::String& getRttName(RttType Rtt) const
139  {
140  return mRttOptions[static_cast<int>(Rtt)].Name;
141  }
142 
145  inline Ogre::TexturePtr getTexture(RttType Rtt)
146  {
147  return mTextures[static_cast<int>(Rtt)];
148  }
149 
150  inline Ogre::SceneNode* getPlanesSceneNode()
151  {
152  return mPlanesSceneNode;
153  }
154 
157  inline Ogre::MovablePlane* getPlane(RttType Rtt)
158  {
159  return mPlanes[static_cast<int>(Rtt)];
160  }
161 
162  inline const Size& getTextureSize(const RttType& Rtt) const
163  {
164  return mRttOptions[static_cast<int>(Rtt)].Size_;
165  }
166 
170  void setTextureSize(const RttType& Rtt, const Size& S);
171 
175  void setTexturesSize(const Size& S);
176 
177  const Ogre::PixelFormat getPixelFormat(const RttType& Rtt) const;
178 
179  inline void setNumberOfChannels(const RttType& Rtt, const NumberOfChannels& NOC)
180  {
181  mRttOptions[Rtt].NumberOfChannels_ = NOC;
182 
183  if (!getTexture(Rtt).isNull())
184  {
185  initialize(Rtt);
186  }
187  }
188 
189  inline const NumberOfChannels& getNumberOfChannels(const RttType& Rtt) const
190  {
191  return mRttOptions[Rtt].NumberOfChannels_;
192  }
193 
194  inline void setBitsPerChannel(const RttType& Rtt, const BitsPerChannel& BPC)
195  {
196  mRttOptions[Rtt].BitsPerChannel_ = BPC;
197 
198  if (!getTexture(Rtt).isNull())
199  {
200  initialize(Rtt);
201  }
202  }
203 
204  inline const BitsPerChannel& getBitsPerChannel(const RttType& Rtt) const
205  {
206  return mRttOptions[Rtt].BitsPerChannel_;
207  }
208 
209  inline const RttOptions& getRttOptions(const RttType& Rtt) const
210  {
211  return mRttOptions[Rtt];
212  }
213 
216  void setReflectionDisplacementError(const Ogre::Real& ReflectionDisplacementError)
217  {
218  mReflectionDisplacementError = ReflectionDisplacementError;
219  }
220 
221  inline const Ogre::Real& getReflectionDisplacementError() const
222  {
224  }
225 
226  inline void setDisableReflectionCustomNearCliplPlaneRenderQueues(const std::vector<Ogre::RenderQueueGroupID>& DisableReflectionCustomNearClipPlaneRenderQueues)
227  {
228  mDisableReflectionCustomNearClipPlaneRenderQueues = DisableReflectionCustomNearClipPlaneRenderQueues;
229  }
230 
231  inline const std::vector<Ogre::RenderQueueGroupID>& getDisableReflectionCustomNearClipPlaneRenderQueues()
232  {
234  }
235 
236  inline void addRttListener(RttListener *l)
237  {
238  mRttListeners.push_back(l);
239  }
240 
241  void removeRttListener(RttListener *l, const bool& releaseMemory = true);
242 
243  void removeAllRttListeners(const bool& releaseMemory = true);
244 
245  private:
248  class CRefractionListener : public Ogre::RenderTargetListener
249  {
250  public:
253 
255  Ogre::Real mCameraPlaneDiff;
256 
257  void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) override;
258  void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) override;
259  };
260 
263  class CReflectionListener : public Ogre::RenderTargetListener
264  {
265  public:
268  class CReflectionQueueListener : public Ogre::RenderQueueListener
269  {
270  public:
271  void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &skipThisInvocation) override;
272  void renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &skipThisInvocation) override;
273 
276  bool mActive;
277  };
278 
281 
284 
286  Ogre::Real mCameraPlaneDiff;
287 
288  void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) override;
289  void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) override;
290  };
291 
292  class CDepthListener : public Ogre::RenderTargetListener
293  {
294  public:
297 
299  std::queue<std::string> mMaterials;
300 
302  Ogre::Real mCameraPlaneDiff;
303 
304  void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) override;
305  void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) override;
306  };
307 
308  class CDepthReflectionListener : public Ogre::RenderTargetListener
309  {
310  public:
313 
315  std::queue<std::string> mMaterials;
316 
318  Ogre::Real mCameraPlaneDiff;
319 
320  void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) override;
321  void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) override;
322  };
323 
324  class CGPUNormalMapListener : public Ogre::RenderTargetListener
325  {
326  public:
329 
331  Ogre::String mOldMaterialName;
332 
333  void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) override;
334  void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) override;
335  };
336 
337 
338  void _initializeRtt(const RttType& Rtt, const Ogre::Vector3& RttPlaneNormal,
339  const Ogre::ColourValue& BackgroundColour, const bool& RenderSky,
340  Ogre::RenderTargetListener* RTListener, const Ogre::String& MaterialScheme = "",
341  const bool& ShadowsEnabled = true);
342 
343  inline const bool _isRenderQueueInList(const std::vector<Ogre::RenderQueueGroupID>& l, const Ogre::RenderQueueGroupID& rq)
344  {
345  for (std::vector<Ogre::RenderQueueGroupID>::const_iterator i = l.begin(); i != l.end(); i++)
346  {
347  if ((*i) == rq)
348  {
349  return true;
350  }
351  }
352 
353  return false;
354  }
355 
360  void _invokeRttListeners(const RttType& Rtt, const bool& pre);
361 
364 
366  Ogre::SceneNode *mPlanesSceneNode;
368  Ogre::MovablePlane *mPlanes[6];
369 
371  Ogre::TexturePtr mTextures[6];
374 
381 
383  std::vector<Ogre::RenderQueueGroupID> mDisableReflectionCustomNearClipPlaneRenderQueues;
385  std::vector<RttListener*> mRttListeners;
386 
389  };
390 };
391 
394 
395 #endif
Hydrax::RttManager::CDepthListener::postRenderTargetUpdate
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:623
Hydrax::RttManager::CDepthListener
Definition: RttManager.h:292
Hydrax::RttManager::CReflectionListener::CReflectionQueueListener::mActive
bool mActive
Is the reflection Rtt active?
Definition: RttManager.h:276
Hydrax::RttManager::CRefractionListener::mCameraPlaneDiff
Ogre::Real mCameraPlaneDiff
Camera.y - Plane.y difference.
Definition: RttManager.h:255
Hydrax::RttManager::NOC_1
@ NOC_1
Definition: RttManager.h:73
Hydrax::RttManager::~RttManager
~RttManager()
Destructor.
Definition: RttManager.cpp:73
Hydrax::RttManager::NOC_3
@ NOC_3
Definition: RttManager.h:75
Hydrax::RttManager::getRttName
const Ogre::String & getRttName(RttType Rtt) const
Get RTT texture name.
Definition: RttManager.h:138
Hydrax::RttManager::setBitsPerChannel
void setBitsPerChannel(const RttType &Rtt, const BitsPerChannel &BPC)
Definition: RttManager.h:194
Hydrax::RttManager::getBitsPerChannel
const BitsPerChannel & getBitsPerChannel(const RttType &Rtt) const
Definition: RttManager.h:204
Hydrax::RttManager::RttOptions::BitsPerChannel_
BitsPerChannel BitsPerChannel_
Bits per channel.
Definition: RttManager.h:90
Hydrax::RttManager::RttListener::postRenderTargetUpdate
virtual void postRenderTargetUpdate(const RttType &Rtt)
Funtion that is called after the Rtt will render.
Definition: RttManager.h:108
Hydrax
Definition: CfgFileManager.cpp:28
Hydrax::RttManager::RttType
RttType
Rtt enumeration.
Definition: RttManager.h:50
Hydrax::RttManager::mRefractionListener
CRefractionListener mRefractionListener
Definition: RttManager.h:377
Hydrax::RttManager::CRefractionListener::preRenderTargetUpdate
void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:525
Hydrax::RttManager::getPlanesSceneNode
Ogre::SceneNode * getPlanesSceneNode()
Definition: RttManager.h:150
Hydrax::Size
Struct wich contains an especific width and height value.
Definition: Help.h:40
Hydrax::RttManager::RttOptions::Name
Ogre::String Name
Texture names.
Definition: RttManager.h:84
Hydrax::RttManager::RTT_GPU_NORMAL_MAP
@ RTT_GPU_NORMAL_MAP
Definition: RttManager.h:57
Hydrax::RttManager::NumberOfChannels
NumberOfChannels
Number of channels.
Definition: RttManager.h:71
Hydrax::RttManager::mHydrax
Hydrax * mHydrax
Hydrax parent pointer.
Definition: RttManager.h:363
Hydrax::RttManager::RTT_REFLECTION
@ RTT_REFLECTION
Definition: RttManager.h:52
Hydrax::RttManager::removeAll
void removeAll()
Remove all RttManager resources.
Definition: RttManager.cpp:153
Hydrax::RttManager::removeRttListener
void removeRttListener(RttListener *l, const bool &releaseMemory=true)
Hydrax::RttManager::CGPUNormalMapListener::postRenderTargetUpdate
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:764
Hydrax::RttManager::getRttOptions
const RttOptions & getRttOptions(const RttType &Rtt) const
Definition: RttManager.h:209
Hydrax::RttManager::removeAllRttListeners
void removeAllRttListeners(const bool &releaseMemory=true)
Hydrax::RttManager::getNumberOfChannels
const NumberOfChannels & getNumberOfChannels(const RttType &Rtt) const
Definition: RttManager.h:189
Enums.h
Hydrax::RttManager::RttManager
RttManager(Hydrax *h)
Constructor.
Definition: RttManager.cpp:40
Hydrax::RttManager::CGPUNormalMapListener::mOldMaterialName
Ogre::String mOldMaterialName
Old Hydrax mesh material name.
Definition: RttManager.h:331
Hydrax::RttManager::CReflectionListener::mRttManager
RttManager * mRttManager
Rtt manager pointer.
Definition: RttManager.h:283
Hydrax::RttManager::RttListener::preRenderTargetUpdate
virtual void preRenderTargetUpdate(const RttType &Rtt)
Funtion that is called before the Rtt will render.
Definition: RttManager.h:102
Hydrax::RttManager::setTexturesSize
void setTexturesSize(const Size &S)
Set Rtt textures size.
Definition: RttManager.cpp:245
Hydrax::RttManager::BPC_32
@ BPC_32
Definition: RttManager.h:66
Hydrax::RttManager::addRttListener
void addRttListener(RttListener *l)
Definition: RttManager.h:236
Hydrax::RttManager::RttListener
Rtt Listener class.
Definition: RttManager.h:95
Help.h
Hydrax::RttManager::mTextures
Ogre::TexturePtr mTextures[6]
Rtt textures vector.
Definition: RttManager.h:371
Hydrax::RttManager::mRttListeners
std::vector< RttListener * > mRttListeners
Rtt listeners.
Definition: RttManager.h:385
Hydrax::RttManager::_initializeRtt
void _initializeRtt(const RttType &Rtt, const Ogre::Vector3 &RttPlaneNormal, const Ogre::ColourValue &BackgroundColour, const bool &RenderSky, Ogre::RenderTargetListener *RTListener, const Ogre::String &MaterialScheme="", const bool &ShadowsEnabled=true)
Definition: RttManager.cpp:168
Hydrax::RttManager::CDepthReflectionListener
Definition: RttManager.h:308
Hydrax::RttManager::CGPUNormalMapListener::preRenderTargetUpdate
void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:751
Hydrax::RttManager::CReflectionListener::CReflectionQueueListener
Used for avoid near clip plane clipping during the reflection Rtt.
Definition: RttManager.h:268
Hydrax::RttManager::RTT_DEPTH
@ RTT_DEPTH
Definition: RttManager.h:54
Hydrax::RttManager::CGPUNormalMapListener
Definition: RttManager.h:324
Hydrax::RttManager::_isRenderQueueInList
const bool _isRenderQueueInList(const std::vector< Ogre::RenderQueueGroupID > &l, const Ogre::RenderQueueGroupID &rq)
Definition: RttManager.h:343
Hydrax::RttManager::mReflectionListener
CReflectionListener mReflectionListener
Rtt listener objects.
Definition: RttManager.h:376
Hydrax::RttManager::mPlanes
Ogre::MovablePlane * mPlanes[6]
Rtt planes vector.
Definition: RttManager.h:368
Hydrax::RttManager::CReflectionListener
RttManager::CReflectionListener class.
Definition: RttManager.h:263
Hydrax::RttManager::CDepthListener::mCameraPlaneDiff
Ogre::Real mCameraPlaneDiff
Camera.y - Plane.y difference.
Definition: RttManager.h:302
Hydrax::RttManager::mReflectionDisplacementError
Ogre::Real mReflectionDisplacementError
Reflection displacement error, range [0.01, ~2].
Definition: RttManager.h:388
Hydrax::RttManager::mRttOptions
RttOptions mRttOptions[6]
Rtt options.
Definition: RttManager.h:373
Hydrax::RttManager::RttOptions::Size_
Size Size_
Size; Size(0,0) to get main viewport size.
Definition: RttManager.h:86
Hydrax::RttManager::CDepthListener::mMaterials
std::queue< std::string > mMaterials
std::string to store entity's original materials name
Definition: RttManager.h:299
Hydrax::RttManager::BPC_8
@ BPC_8
Definition: RttManager.h:64
Hydrax::RttManager
Rtt's manager class.
Definition: RttManager.h:45
Hydrax::RttManager::CReflectionListener::postRenderTargetUpdate
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:463
Hydrax::RttManager::CRefractionListener
RttManager::CRefractionListener class.
Definition: RttManager.h:248
Hydrax::RttManager::RTT_DEPTH_REFLECTION
@ RTT_DEPTH_REFLECTION
Definition: RttManager.h:55
Hydrax::RttManager::CDepthListener::preRenderTargetUpdate
void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:569
Hydrax::RttManager::NOC_4
@ NOC_4
Definition: RttManager.h:76
Hydrax::RttManager::RTT_DEPTH_AIP
@ RTT_DEPTH_AIP
Definition: RttManager.h:56
Hydrax::RttManager::CReflectionListener::CReflectionQueueListener::mRttManager
RttManager * mRttManager
Definition: RttManager.h:274
Prerequisites.h
Hydrax::RttManager::getPixelFormat
const Ogre::PixelFormat getPixelFormat(const RttType &Rtt) const
Definition: RttManager.cpp:277
Hydrax::RttManager::CGPUNormalMapListener::mRttManager
RttManager * mRttManager
Rtt manager pointer.
Definition: RttManager.h:328
Hydrax::RttManager::getReflectionDisplacementError
const Ogre::Real & getReflectionDisplacementError() const
Definition: RttManager.h:221
Hydrax::RttManager::RttOptions
Rtt options struct.
Definition: RttManager.h:81
Hydrax::RttManager::mGPUNormalMapListener
CGPUNormalMapListener mGPUNormalMapListener
Definition: RttManager.h:380
Hydrax::RttManager::CReflectionListener::mCameraPlaneDiff
Ogre::Real mCameraPlaneDiff
Camera.y - Plane.y difference.
Definition: RttManager.h:286
Hydrax::RttManager::setDisableReflectionCustomNearCliplPlaneRenderQueues
void setDisableReflectionCustomNearCliplPlaneRenderQueues(const std::vector< Ogre::RenderQueueGroupID > &DisableReflectionCustomNearClipPlaneRenderQueues)
Definition: RttManager.h:226
Hydrax::RttManager::CDepthListener::mRttManager
RttManager * mRttManager
Rtt manager pointer.
Definition: RttManager.h:296
Hydrax::RttManager::NOC_2
@ NOC_2
Definition: RttManager.h:74
Hydrax::RttManager::mDepthReflectionListener
CDepthReflectionListener mDepthReflectionListener
Definition: RttManager.h:379
Hydrax::RttManager::BPC_16
@ BPC_16
Definition: RttManager.h:65
Hydrax::RttManager::setNumberOfChannels
void setNumberOfChannels(const RttType &Rtt, const NumberOfChannels &NOC)
Definition: RttManager.h:179
Hydrax::RttManager::initialize
void initialize(const RttType &Rtt)
Initialize a RTT.
Definition: RttManager.cpp:78
Hydrax::RttManager::setTextureSize
void setTextureSize(const RttType &Rtt, const Size &S)
Set Rtt texture size.
Definition: RttManager.cpp:223
Hydrax::RttManager::CReflectionListener::mCReflectionQueueListener
CReflectionQueueListener mCReflectionQueueListener
CReflectionQueueListener.
Definition: RttManager.h:280
Hydrax::RttManager::setReflectionDisplacementError
void setReflectionDisplacementError(const Ogre::Real &ReflectionDisplacementError)
Range [0.05, ~2], increase if you experience reflection issues when the camera is near to the water.
Definition: RttManager.h:216
Hydrax::RttManager::RttOptions::NumberOfChannels_
NumberOfChannels NumberOfChannels_
Number of channels.
Definition: RttManager.h:88
Hydrax::RttManager::CDepthReflectionListener::postRenderTargetUpdate
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:715
Hydrax::RttManager::remove
void remove(const RttType &Rtt)
Removes a RTT.
Definition: RttManager.cpp:128
Hydrax::RttManager::CDepthReflectionListener::preRenderTargetUpdate
void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:666
Hydrax::RttManager::CRefractionListener::postRenderTargetUpdate
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:547
Hydrax::RttManager::_invokeRttListeners
void _invokeRttListeners(const RttType &Rtt, const bool &pre)
Invoke Rtt Listeners.
Hydrax::RttManager::RTT_REFRACTION
@ RTT_REFRACTION
Definition: RttManager.h:53
Hydrax::RttManager::CDepthReflectionListener::mCameraPlaneDiff
Ogre::Real mCameraPlaneDiff
Camera.y - Plane.y difference.
Definition: RttManager.h:318
Hydrax::RttManager::CRefractionListener::mRttManager
RttManager * mRttManager
Rtt manager pointer.
Definition: RttManager.h:252
Hydrax::RttManager::mPlanesSceneNode
Ogre::SceneNode * mPlanesSceneNode
SceneNode to attach our planes.
Definition: RttManager.h:366
Hydrax::RttManager::BitsPerChannel
BitsPerChannel
Bits per channel.
Definition: RttManager.h:62
Hydrax::RttManager::CReflectionListener::CReflectionQueueListener::renderQueueEnded
void renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &skipThisInvocation) override
Definition: RttManager.cpp:511
Hydrax::RttManager::getTexture
Ogre::TexturePtr getTexture(RttType Rtt)
Get Rtt texture.
Definition: RttManager.h:145
Hydrax::RttManager::getDisableReflectionCustomNearClipPlaneRenderQueues
const std::vector< Ogre::RenderQueueGroupID > & getDisableReflectionCustomNearClipPlaneRenderQueues()
Definition: RttManager.h:231
Hydrax::RttManager::CDepthReflectionListener::mMaterials
std::queue< std::string > mMaterials
std::string to store entity's original materials name
Definition: RttManager.h:315
Hydrax::RttManager::CReflectionListener::CReflectionQueueListener::renderQueueStarted
void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &skipThisInvocation) override
Definition: RttManager.cpp:497
Hydrax::RttManager::getTextureSize
const Size & getTextureSize(const RttType &Rtt) const
Definition: RttManager.h:162
Hydrax::RttManager::mDepthListener
CDepthListener mDepthListener
Definition: RttManager.h:378
Hydrax::RttManager::CDepthReflectionListener::mRttManager
RttManager * mRttManager
Rtt manager pointer.
Definition: RttManager.h:312
Hydrax::RttManager::mDisableReflectionCustomNearClipPlaneRenderQueues
std::vector< Ogre::RenderQueueGroupID > mDisableReflectionCustomNearClipPlaneRenderQueues
Render queues to exclude of the reflection custom near clip plane.
Definition: RttManager.h:383
Hydrax::RttManager::CReflectionListener::preRenderTargetUpdate
void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:405
Hydrax::RttManager::getPlane
Ogre::MovablePlane * getPlane(RttType Rtt)
Get Rtt plane.
Definition: RttManager.h:157