RigsofRods
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RttManager.cpp
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 #pragma warning(disable:4267)
26 
27 #include "RttManager.h"
28 
29 #include "Hydrax.h"
30 
31 #define _def_Hydrax_Reflection_Rtt_Name "HydraxReflectionMap"
32 #define _def_Hydrax_Refraction_Rtt_Name "HydraxRefractionMap"
33 #define _def_Hydrax_Depth_Rtt_Name "HydraxDepthMap"
34 #define _def_Hydrax_Depth_Reflection_Rtt_Name "HydraxDepthReflectionMap"
35 #define _def_Hydrax_API_Rtt_Name "HydraxAPIMap"
36 #define _def_Hydrax_GPU_Normal_Map_Rtt_Name "HydraxNormalMap"
37 
38 namespace Hydrax
39 {
41  : mHydrax(h)
42  , mPlanesSceneNode(0)
43  , mReflectionDisplacementError(0.5f)
44  {
45  Ogre::String RttNames[6] =
52 
53  for (int k = 0; k < 6; k++)
54  {
55  mPlanes[k] = static_cast<Ogre::MovablePlane*>(NULL);
56  mTextures[k].reset();
57  mRttOptions[k].Name = RttNames[k];
58  mRttOptions[k].Size_ = Size(0);
61  }
62 
71  }
72 
74  {
75  removeAll();
76  }
77 
79  {
80  if (!mPlanesSceneNode)
81  {
82  mPlanesSceneNode = mHydrax->getSceneManager()->getRootSceneNode()->createChildSceneNode();
84  }
85 
86  switch(Rtt)
87  {
88  case RTT_REFLECTION:
89  {
90  const Ogre::Vector3& WC = mHydrax->getWaterColor();
91 
92  bool RenderSkyBox = !mHydrax->_isCurrentFrameUnderwater();
93 
94  _initializeRtt(Rtt, Ogre::Vector3::UNIT_Y, Ogre::ColourValue(WC.x, WC.y, WC.z), RenderSkyBox, &mReflectionListener);
95  }
96  break;
97 
98  case RTT_REFRACTION:
99  {
100  const Ogre::Vector3& WC = mHydrax->getWaterColor();
101 
102  bool RenderSkyBox = mHydrax->_isCurrentFrameUnderwater();
103 
104  _initializeRtt(Rtt, Ogre::Vector3::NEGATIVE_UNIT_Y, Ogre::ColourValue(WC.x, WC.y, WC.z), RenderSkyBox, &mRefractionListener);
105  }
106  break;
107 
108  case RTT_DEPTH:
109  {
110  _initializeRtt(Rtt, Ogre::Vector3::NEGATIVE_UNIT_Y, Ogre::ColourValue::Black, false, &mDepthListener, "HydraxDepth", false);
111  }
112  break;
113 
115  {
116  _initializeRtt(Rtt, Ogre::Vector3::NEGATIVE_UNIT_Y, Ogre::ColourValue::Black, false, &mDepthReflectionListener, "HydraxDepth", false);
117  }
118  break;
119 
120  case RTT_GPU_NORMAL_MAP:
121  {
122  _initializeRtt(Rtt, Ogre::Vector3::NEGATIVE_UNIT_Y, Ogre::ColourValue(0.5,1,0.5), false, &mGPUNormalMapListener, "", false);
123  }
124  break;
125  }
126  }
127 
128  void RttManager::remove(const RttType& Rtt)
129  {
130  Ogre::TexturePtr &Tex = mTextures[Rtt];
131 
132  if (Tex)
133  {
134  Ogre::RenderTarget* RT = Tex->getBuffer()->getRenderTarget();
135  RT->removeAllListeners();
136  RT->removeAllViewports();
137 
138  Ogre::TextureManager::getSingleton().remove(mRttOptions[Rtt].Name);
139  Ogre::MeshManager::getSingleton().remove(mRttOptions[Rtt].Name + "ClipPlane");
140 
141  Tex.reset();
142  delete mPlanes[Rtt];
143  mPlanes[Rtt] = static_cast<Ogre::MovablePlane*>(NULL);
144  }
145 
146  // Check it to avoid any possible problem(texture initializated by createTextureUnit(Name..))
147  if (Ogre::TextureManager::getSingleton().resourceExists(mRttOptions[Rtt].Name))
148  {
149  Ogre::TextureManager::getSingleton().remove(mRttOptions[Rtt].Name);
150  }
151  }
152 
154  {
155  for (int k = 0; k < 6; k++)
156  {
157  remove(static_cast<RttType>(k));
158  }
159 
160  if (mPlanesSceneNode)
161  {
162  mPlanesSceneNode->detachAllObjects();
163  mPlanesSceneNode->getParentSceneNode()->removeAndDestroyChild(mPlanesSceneNode);
164  mPlanesSceneNode = 0;
165  }
166  }
167 
168  void RttManager::_initializeRtt(const RttType& Rtt, const Ogre::Vector3& PlaneNormal,
169  const Ogre::ColourValue& BackgroundColour, const bool& RenderSky,
170  Ogre::RenderTargetListener* RTListener, const Ogre::String& MaterialScheme,
171  const bool& ShadowsEnabled)
172  {
173  remove(Rtt);
174 
175  mPlanes[Rtt] = new Ogre::MovablePlane(mRttOptions[Rtt].Name + "Plane");
176 
177  mPlanes[Rtt]->d = 0;
178  mPlanes[Rtt]->normal = PlaneNormal;
179 
180  Ogre::MeshManager::getSingleton().
181  createPlane(mRttOptions[Rtt].Name + "ClipPlane", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
182  *mPlanes[Rtt],
183  mHydrax->getMesh()->getSize().Width,mHydrax->getMesh()->getSize().Height, // PG grid.. <-- look into
184  10,10, true, 1,5,5, Ogre::Vector3::UNIT_Z);
185 
186  mPlanes[Rtt]->setCastShadows(false);
187  mPlanesSceneNode->attachObject(mPlanes[Rtt]);
188 
189  Size TSize = mRttOptions[Rtt].Size_;
190 
191  if (TSize.Width == 0 || TSize.Height == 0)
192  {
193  TSize.Width = mHydrax->getViewport()->getActualWidth();
194  TSize.Height = mHydrax->getViewport()->getActualHeight();
195  }
196 
197  mTextures[Rtt] = Ogre::TextureManager::getSingleton()
198  .createManual(mRttOptions[Rtt].Name,
199  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
200  Ogre::TEX_TYPE_2D,
201  TSize.Width,
202  TSize.Height,
203  0,
204  getPixelFormat(Rtt),
205  Ogre::TU_RENDERTARGET);
206 
207  Ogre::RenderTarget* RT_Texture = mTextures[Rtt]->getBuffer()->getRenderTarget();
208 
209  Ogre::Viewport *RT_Texture_Viewport = RT_Texture->addViewport(mHydrax->getCamera());
210  RT_Texture_Viewport->setClearEveryFrame(true);
211  RT_Texture_Viewport->setBackgroundColour(BackgroundColour);
212  RT_Texture_Viewport->setOverlaysEnabled(false);
213  RT_Texture_Viewport->setShadowsEnabled(ShadowsEnabled);
214  if (MaterialScheme != "")
215  {
216  RT_Texture_Viewport->setMaterialScheme(MaterialScheme);
217  }
218  RT_Texture_Viewport->setSkiesEnabled(RenderSky);
219 
220  RT_Texture->addListener(RTListener);
221  }
222 
223  void RttManager::setTextureSize(const RttType& Rtt, const Size& S)
224  {
225  mRttOptions[static_cast<int>(Rtt)].Size_ = S;
226 
227  if (getTexture(Rtt))
228  {
229  initialize(Rtt);
230 
232 
234  {
236 
238  {
240  }
241  }
242  }
243  }
244 
246  {
247  bool ReloadMaterialsNeeded = false;
248 
249  for(int k = 0; k < 5; k++)
250  {
251  mRttOptions[static_cast<RttType>(k)].Size_ = S;
252 
253  Ogre::TexturePtr& Tex = mTextures[static_cast<RttType>(k)];
254  if (Tex)
255  {
256  initialize(static_cast<RttType>(k));
257 
258  ReloadMaterialsNeeded = true;
259  }
260  }
261 
262  if (ReloadMaterialsNeeded)
263  {
265 
267  {
269 
271  {
273  }
274  }
275  }
276  }
277 
278  const Ogre::PixelFormat RttManager::getPixelFormat(const RttType& Rtt) const
279  {
280  switch (mRttOptions[Rtt].NumberOfChannels_)
281  {
282  // One channel (R)
283  case NOC_1 :
284  {
285  switch (mRttOptions[Rtt].BitsPerChannel_)
286  {
287  // 8 bits
288  case BPC_8 :
289  {
290  return Ogre::PF_L8;
291  }
292  break;
293 
294  // 16 bits
295  case BPC_16 :
296  {
297  return Ogre::PF_FLOAT16_R;
298  }
299  break;
300 
301  // 32 bits
302  case BPC_32 :
303  {
304  return Ogre::PF_FLOAT32_R;
305  }
306  break;
307  }
308  }
309  break;
310 
311  // Two channels (RG)
312  case NOC_2 :
313  {
314  switch (mRttOptions[Rtt].BitsPerChannel_)
315  {
316  // 8 bits
317  case BPC_8 :
318  {
319  //...
320  }
321  break;
322 
323  // 16 bits
324  case BPC_16 :
325  {
326  return Ogre::PF_FLOAT16_GR;
327  }
328  break;
329 
330  // 32 bits
331  case BPC_32 :
332  {
333  return Ogre::PF_FLOAT32_GR;
334  }
335  break;
336  }
337  }
338  break;
339 
340  // Three channels (RGB)
341  case NOC_3 :
342  {
343  switch (mRttOptions[Rtt].BitsPerChannel_)
344  {
345  // 8 bits
346  case BPC_8 :
347  {
348  return Ogre::PF_B8G8R8;
349  }
350  break;
351 
352  // 16 bits
353  case BPC_16 :
354  {
355  return Ogre::PF_FLOAT16_RGB;
356  }
357  break;
358 
359  // 32 bits
360  case BPC_32 :
361  {
362  return Ogre::PF_FLOAT32_RGB;
363  }
364  break;
365  }
366  }
367  break;
368 
369  // Four channels (RGBA)
370  case NOC_4 :
371  {
372  switch (mRttOptions[Rtt].BitsPerChannel_)
373  {
374  // 8 bits
375  case BPC_8 :
376  {
377  return Ogre::PF_B8G8R8A8;
378  }
379  break;
380 
381  // 16 bits
382  case BPC_16 :
383  {
384  return Ogre::PF_FLOAT16_RGBA;
385  }
386  break;
387 
388  // 32 bits
389  case BPC_32 :
390  {
391  return Ogre::PF_FLOAT32_RGBA;
392  }
393  break;
394  }
395  }
396  break;
397 
398  }
399 
400  // >= than needed
401  return Ogre::PF_FLOAT32_RGBA;
402  }
403 
405 
406  void RttManager::CReflectionListener::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
407  {
409 
411 
412  mHydrax->getMesh()->getEntity()->setVisible(false);
413 
415  {
416  mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->translate(0,-mHydrax->getPlanesError(),0);
417  }
418  else
419  {
420  mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->translate(0,+mHydrax->getPlanesError(),0);
421  }
422 
423  bool IsInUnderwaterError = false;
424 
425  // Underwater
427  (mHydrax->getCamera()->getDerivedPosition().y > mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->getPosition().y))
428  {
429  mCameraPlaneDiff = 0;
430  IsInUnderwaterError = true;
431  }
432  // Overwater
433  else if ((!mHydrax->_isCurrentFrameUnderwater()) &&
434  (mHydrax->getCamera()->getDerivedPosition().y < mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->getPosition().y))
435  {
436  mCameraPlaneDiff = mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->getPosition().y-mHydrax->getCamera()->getDerivedPosition().y+mRttManager->mReflectionDisplacementError;
437  mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->translate(0,-mCameraPlaneDiff,0);
438  }
439  else
440  {
441  mCameraPlaneDiff = 0;
442  }
443 
445  {
447  {
449  }
450  }
451 
452  mHydrax->getCamera()->enableReflection(mRttManager->mPlanes[RTT_REFLECTION]);
453 
454  if (IsInUnderwaterError)
455  {
457  }
458  else
459  {
460  mHydrax->getCamera()->enableCustomNearClipPlane(mRttManager->mPlanes[RTT_REFLECTION]);
461  }
462  }
463 
464  void RttManager::CReflectionListener::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
465  {
466  Hydrax *mHydrax = mRttManager->mHydrax;
467 
468  mHydrax->getMesh()->getEntity()->setVisible(true);
469 
470  if (mCameraPlaneDiff != 0)
471  {
472  mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->translate(0,mCameraPlaneDiff,0);
473  }
474 
476  {
477  mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->translate(0,mHydrax->getPlanesError(),0);
478  }
479  else
480  {
481  mRttManager->mPlanes[RTT_REFLECTION]->getParentNode()->translate(0,-mHydrax->getPlanesError(),0);
482  }
483 
484  mHydrax->getCamera()->disableReflection();
485  mHydrax->getCamera()->disableCustomNearClipPlane();
486 
488  {
490  {
491  mRttManager->mPlanes[RTT_REFLECTION]->normal = -mRttManager->mPlanes[RTT_REFLECTION]->normal;
492  }
493  }
494 
495  mCReflectionQueueListener.mActive = false;
496  }
497 
498  void RttManager::CReflectionListener::CReflectionQueueListener::renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool
499 
500  &skipThisInvocation)
501  {
502  if ((queueGroupId == Ogre::RENDER_QUEUE_SKIES_EARLY || queueGroupId == Ogre::RENDER_QUEUE_SKIES_LATE || queueGroupId ==
503 
504  (Ogre::RENDER_QUEUE_SKIES_EARLY + 2))
505  && mActive)
506  {
507  mRttManager->mHydrax->getCamera()->disableCustomNearClipPlane();
508  Ogre::Root::getSingleton().getRenderSystem()->_setProjectionMatrix(mRttManager->mHydrax->getCamera()->getProjectionMatrixRS());
509  }
510  }
511 
512  void RttManager::CReflectionListener::CReflectionQueueListener::renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool
513 
514  &skipThisInvocation)
515  {
516  if ((queueGroupId == Ogre::RENDER_QUEUE_SKIES_EARLY || queueGroupId == Ogre::RENDER_QUEUE_SKIES_LATE || queueGroupId ==
517 
518  (Ogre::RENDER_QUEUE_SKIES_EARLY + 2))
519  && mActive)
520  {
521  mRttManager->mHydrax->getCamera()->enableCustomNearClipPlane(mRttManager->mPlanes[RTT_REFLECTION]);
522  Ogre::Root::getSingleton().getRenderSystem()->_setProjectionMatrix(mRttManager->mHydrax->getCamera()->getProjectionMatrixRS());
523  }
524  }
525 
526  void RttManager::CRefractionListener::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
527  {
528  Hydrax *mHydrax = mRttManager->mHydrax;
529 
530  mHydrax->getMesh()->getEntity()->setVisible(false);
531 
532  if (Ogre::Math::Abs(mHydrax->getPosition().y - mHydrax->getCamera()->getDerivedPosition().y) > mHydrax->getPlanesError())
533  {
535  {
536  mRttManager->mPlanes[RTT_REFRACTION]->normal = -mRttManager->mPlanes[RTT_REFRACTION]->normal;
537  mRttManager->mPlanes[RTT_REFRACTION]->getParentNode()->translate(0,-mHydrax->getPlanesError(),0);
538  }
539  else
540  {
541  mRttManager->mPlanes[RTT_REFRACTION]->getParentNode()->translate(0,mHydrax->getPlanesError(),0);
542  }
543 
544  mHydrax->getCamera()->enableCustomNearClipPlane(mRttManager->mPlanes[RTT_REFRACTION]);
545  }
546  }
547 
548  void RttManager::CRefractionListener::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
549  {
550  Hydrax *mHydrax = mRttManager->mHydrax;
551 
552  mHydrax->getMesh()->getEntity()->setVisible(true);
553 
554  if (Ogre::Math::Abs(mHydrax->getPosition().y - mHydrax->getCamera()->getDerivedPosition().y) > mHydrax->getPlanesError())
555  {
557  {
558  mRttManager->mPlanes[RTT_REFRACTION]->normal = -mRttManager->mPlanes[RTT_REFRACTION]->normal;
559  mRttManager->mPlanes[RTT_REFRACTION]->getParentNode()->translate(0,+mHydrax->getPlanesError(),0);
560  }
561  else
562  {
563  mRttManager->mPlanes[RTT_REFRACTION]->getParentNode()->translate(0,-mHydrax->getPlanesError(),0);
564  }
565 
566  mHydrax->getCamera()->disableCustomNearClipPlane();
567  }
568  }
569 
570  void RttManager::CDepthListener::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
571  {
572  Hydrax *mHydrax = mRttManager->mHydrax;
573 
574  Ogre::SceneManager::MovableObjectIterator EntityIterator =
575  mHydrax->getSceneManager()->getMovableObjectIterator("Entity");
576  Ogre::Entity* CurrentEntity;
577  unsigned int k;
578 
579  while (EntityIterator.hasMoreElements())
580  {
581  CurrentEntity = static_cast<Ogre::Entity*>(EntityIterator.peekNextValue());
582 
583  for(k = 0; k < CurrentEntity->getNumSubEntities(); k++)
584  {
585  mMaterials.push(CurrentEntity->getSubEntity(k)->getMaterialName());
586 
587  CurrentEntity->getSubEntity(k)->setMaterialName(mHydrax->getMaterialManager()->getMaterial(MaterialManager::MAT_DEPTH)->getName());
588  }
589 
590  EntityIterator.moveNext();
591  }
592 
593  if (Ogre::Math::Abs(mHydrax->getPosition().y - mHydrax->getCamera()->getDerivedPosition().y) > mHydrax->getPlanesError())
594  {
596  {
597  mRttManager->mPlanes[RTT_DEPTH]->normal = -mRttManager->mPlanes[RTT_DEPTH]->normal;
598  mRttManager->mPlanes[RTT_DEPTH]->getParentNode()->translate(0,-mHydrax->getPlanesError(),0);
599  }
600  else
601  {
602  mRttManager->mPlanes[RTT_DEPTH]->getParentNode()->translate(0,mHydrax->getPlanesError(),0);
603  mHydrax->getCamera()->enableCustomNearClipPlane(mRttManager->mPlanes[RTT_DEPTH]);
604  }
605  }
606 
608  {
609  mHydrax->getMesh()->getEntity()->setVisible(true);
610  mHydrax->getMesh()->getEntity()->setMaterialName(
612  getName());
613  mHydrax->getMesh()->getEntity()->setRenderQueueGroup(Ogre::RENDER_QUEUE_SKIES_EARLY);
615  }
616  else
617  {
618  mHydrax->getMesh()->getEntity()->setVisible(false);
619  }
620  }
621 
622  void RttManager::CDepthListener::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
623  {
624  Hydrax *mHydrax = mRttManager->mHydrax;
625 
626  Ogre::SceneManager::MovableObjectIterator EntityIterator =
627  mHydrax->getSceneManager()->getMovableObjectIterator("Entity");
628  Ogre::Entity* CurrentEntity;
629  unsigned int k;
630 
631  while (EntityIterator.hasMoreElements())
632  {
633  CurrentEntity = static_cast<Ogre::Entity*>(EntityIterator.peekNextValue());
634 
635  for(k = 0; k < CurrentEntity->getNumSubEntities(); k++)
636  {
637  CurrentEntity->getSubEntity(k)->setMaterialName(mMaterials.front());
638 
639  mMaterials.pop();
640  }
641 
642  EntityIterator.moveNext();
643  }
644 
645  mHydrax->getMesh()->getEntity()->setVisible(true);
647  mHydrax->getMesh()->getEntity()->setRenderQueueGroup(Ogre::RENDER_QUEUE_1);
648 
649  if (Ogre::Math::Abs(mHydrax->getPosition().y - mHydrax->getCamera()->getDerivedPosition().y) > mHydrax->getPlanesError())
650  {
652  {
653  mRttManager->mPlanes[RTT_DEPTH]->normal = -mRttManager->mPlanes[RTT_DEPTH]->normal;
654  mRttManager->mPlanes[RTT_DEPTH]->getParentNode()->translate(0,+mHydrax->getPlanesError(),0);
655  }
656  else
657  {
658  mRttManager->mPlanes[RTT_DEPTH]->getParentNode()->translate(0,-mHydrax->getPlanesError(),0);
659  }
660 
661  mHydrax->getCamera()->disableCustomNearClipPlane();
662  }
663  }
664 
665  void RttManager::CDepthReflectionListener::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
666  {
667  Hydrax *mHydrax = mRttManager->mHydrax;
668 
669  mHydrax->getMesh()->getEntity()->setVisible(false);
670 
671  Ogre::SceneManager::MovableObjectIterator EntityIterator =
672  mHydrax->getSceneManager()->getMovableObjectIterator("Entity");
673  Ogre::Entity* CurrentEntity;
674  unsigned int k;
675 
676  while (EntityIterator.hasMoreElements())
677  {
678  CurrentEntity = static_cast<Ogre::Entity*>(EntityIterator.peekNextValue());
679 
680  for(k = 0; k < CurrentEntity->getNumSubEntities(); k++)
681  {
682  mMaterials.push(CurrentEntity->getSubEntity(k)->getMaterialName());
683 
684  CurrentEntity->getSubEntity(k)->setMaterialName(mHydrax->getMaterialManager()->getMaterial(MaterialManager::MAT_DEPTH)->getName());
685  }
686 
687  EntityIterator.moveNext();
688  }
689 
690  mRttManager->mPlanes[RTT_DEPTH_REFLECTION]->getParentNode()->translate(0,-mHydrax->getPlanesError(),0);
691 
692  bool IsInUnderwaterError = false;
693 
694  if (mHydrax->getCamera()->getDerivedPosition().y > mRttManager->mPlanes[RTT_DEPTH_REFLECTION]->getParentNode()->getPosition().y)
695  {
696  mCameraPlaneDiff = 0;
697  IsInUnderwaterError = true;
698  }
699  else
700  {
701  mCameraPlaneDiff = 0;
702  }
703 
704  mHydrax->getCamera()->enableReflection(mRttManager->mPlanes[RTT_DEPTH_REFLECTION]);
705 
706  if (!IsInUnderwaterError)
707  {
708  mHydrax->getCamera()->enableCustomNearClipPlane(mRttManager->mPlanes[RTT_DEPTH_REFLECTION]);
709  }
710  }
711 
712  void RttManager::CDepthReflectionListener::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
713  {
714  Hydrax *mHydrax = mRttManager->mHydrax;
715 
716  Ogre::SceneManager::MovableObjectIterator EntityIterator =
717  mHydrax->getSceneManager()->getMovableObjectIterator("Entity");
718  Ogre::Entity* CurrentEntity;
719  unsigned int k;
720 
721  while (EntityIterator.hasMoreElements())
722  {
723  CurrentEntity = static_cast<Ogre::Entity*>(EntityIterator.peekNextValue());
724 
725  for(k = 0; k < CurrentEntity->getNumSubEntities(); k++)
726  {
727  CurrentEntity->getSubEntity(k)->setMaterialName(mMaterials.front());
728 
729  mMaterials.pop();
730  }
731 
732  EntityIterator.moveNext();
733  }
734 
735  mHydrax->getMesh()->getEntity()->setVisible(true);
736 
737  if (mCameraPlaneDiff != 0)
738  {
739  mRttManager->mPlanes[RTT_DEPTH_REFLECTION]->getParentNode()->translate(0,mCameraPlaneDiff,0);
740  }
741 
742  mRttManager->mPlanes[RTT_DEPTH_REFLECTION]->getParentNode()->translate(0,mHydrax->getPlanesError(),0);
743 
744  mHydrax->getCamera()->disableReflection();
745  mHydrax->getCamera()->disableCustomNearClipPlane();
746  }
747 
748  void RttManager::CGPUNormalMapListener::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
749  {
750  mOldMaterialName = mRttManager->mHydrax->getMesh()->getMaterialName();
751  mRttManager->mHydrax->getMesh()->setMaterialName(mRttManager->mHydrax->getGPUNormalMapManager()->getNormalMapMaterial()->getName());
752 
753  Ogre::SceneManager *mSceneMgr = mRttManager->mHydrax->getSceneManager();
754 
755  // Render only the Hydrax mesh(Ogre::RENDER_QUEUE_1)
756  mSceneMgr->clearSpecialCaseRenderQueues();
757  mSceneMgr->addSpecialCaseRenderQueue(Ogre::RENDER_QUEUE_1);
758  mSceneMgr->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_INCLUDE);
759  }
760 
761  void RttManager::CGPUNormalMapListener::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
762  {
763  mRttManager->mHydrax->getMesh()->setMaterialName(mOldMaterialName);
764 
765  Ogre::SceneManager *mSceneMgr = mRttManager->mHydrax->getSceneManager();
766 
767  // Render all
768  mSceneMgr->clearSpecialCaseRenderQueues();
769  mSceneMgr->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_EXCLUDE);
770  }
771 }
Hydrax::MaterialManager::MAT_UNDERWATER
@ MAT_UNDERWATER
Definition: MaterialManager.h:57
Hydrax::RttManager::CDepthListener::postRenderTargetUpdate
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:622
Hydrax::Hydrax::getGodRaysManager
GodRaysManager * getGodRaysManager()
Get Hydrax::GodRaysManager.
Definition: Hydrax.h:349
Hydrax::RttManager::CReflectionListener::CReflectionQueueListener::mActive
bool mActive
Is the reflection Rtt active?
Definition: RttManager.h:272
Hydrax::Hydrax::getWaterColor
const Ogre::Vector3 & getWaterColor() const
Get water color.
Definition: Hydrax.h:476
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::Hydrax::getPosition
const Ogre::Vector3 & getPosition() const
Get water position.
Definition: Hydrax.h:413
Hydrax::MaterialManager::getMaterial
Ogre::MaterialPtr & getMaterial(const MaterialType &Material)
Get material.
Definition: MaterialManager.h:221
Hydrax::RttManager::RttOptions::BitsPerChannel_
BitsPerChannel BitsPerChannel_
Bits per channel.
Definition: RttManager.h:90
Hydrax::Hydrax::getPlanesError
const Ogre::Real & getPlanesError() const
Get current clip planes error.
Definition: Hydrax.h:421
Hydrax::Hydrax::getMesh
Mesh * getMesh()
Get Hydrax::Mesh.
Definition: Hydrax.h:317
Hydrax
Definition: CfgFileManager.cpp:28
Hydrax::RttManager::RttType
RttType
Rtt enumeration.
Definition: RttManager.h:50
Hydrax::RttManager::mRefractionListener
CRefractionListener mRefractionListener
Definition: RttManager.h:367
Hydrax::RttManager::CRefractionListener::preRenderTargetUpdate
void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:526
_def_Hydrax_Depth_Rtt_Name
#define _def_Hydrax_Depth_Rtt_Name
Definition: RttManager.cpp:33
Hydrax::Hydrax::getMaterialManager
MaterialManager * getMaterialManager()
Get Hydrax::MaterialManager.
Definition: Hydrax.h:325
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.h
Hydrax::RttManager::mHydrax
Hydrax * mHydrax
Hydrax parent pointer.
Definition: RttManager.h:353
Hydrax::RttManager::RTT_REFLECTION
@ RTT_REFLECTION
Definition: RttManager.h:52
Hydrax::RttManager::removeAll
void removeAll()
Remove all RttManager resources.
Definition: RttManager.cpp:153
Hydrax::MaterialManager::MAT_DEPTH
@ MAT_DEPTH
Definition: MaterialManager.h:55
_def_Hydrax_API_Rtt_Name
#define _def_Hydrax_API_Rtt_Name
Definition: RttManager.cpp:35
Hydrax::RttManager::CGPUNormalMapListener::postRenderTargetUpdate
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:761
Hydrax::RttManager::RttManager
RttManager(Hydrax *h)
Constructor.
Definition: RttManager.cpp:40
Hydrax::RttManager::CReflectionListener::mRttManager
RttManager * mRttManager
Rtt manager pointer.
Definition: RttManager.h:279
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::mTextures
Ogre::TexturePtr mTextures[6]
Rtt textures vector.
Definition: RttManager.h:361
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::CGPUNormalMapListener::preRenderTargetUpdate
void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:748
Hydrax::Hydrax::isComponent
bool isComponent(const HydraxComponent &Component)
Returns if the especified component is active.
Definition: Hydrax.cpp:612
Hydrax::RttManager::RTT_DEPTH
@ RTT_DEPTH
Definition: RttManager.h:54
Hydrax::Hydrax::getSceneManager
Ogre::SceneManager * getSceneManager()
Get scene manager.
Definition: Hydrax.h:309
Hydrax::Hydrax::getCamera
Ogre::Camera * getCamera()
Get rendering camera.
Definition: Hydrax.h:293
Hydrax::RttManager::mReflectionListener
CReflectionListener mReflectionListener
Rtt listener objects.
Definition: RttManager.h:366
Hydrax::RttManager::mPlanes
Ogre::MovablePlane * mPlanes[6]
Rtt planes vector.
Definition: RttManager.h:358
RttManager.h
Hydrax::RttManager::mReflectionDisplacementError
Ogre::Real mReflectionDisplacementError
Reflection displacement error, range [0.01, ~2].
Definition: RttManager.h:378
Hydrax::RttManager::mRttOptions
RttOptions mRttOptions[6]
Rtt options.
Definition: RttManager.h:363
_def_Hydrax_Refraction_Rtt_Name
#define _def_Hydrax_Refraction_Rtt_Name
Definition: RttManager.cpp:32
Hydrax::RttManager::RttOptions::Size_
Size Size_
Size; Size(0,0) to get main viewport size.
Definition: RttManager.h:86
Hydrax::RttManager::BPC_8
@ BPC_8
Definition: RttManager.h:64
Hydrax::Hydrax::getViewport
Ogre::Viewport * getViewport()
Get main window viewport.
Definition: Hydrax.h:301
_def_Hydrax_Depth_Reflection_Rtt_Name
#define _def_Hydrax_Depth_Reflection_Rtt_Name
Definition: RttManager.cpp:34
Hydrax::MaterialManager::MAT_SIMPLE_RED
@ MAT_SIMPLE_RED
Definition: MaterialManager.h:61
Hydrax::MaterialManager::reload
void reload(const MaterialType &Material)
Reload material.
Definition: MaterialManager.cpp:3170
Hydrax::RttManager::CReflectionListener::postRenderTargetUpdate
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:464
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:570
Hydrax::RttManager::NOC_4
@ NOC_4
Definition: RttManager.h:76
Hydrax::RttManager::CReflectionListener::CReflectionQueueListener::mRttManager
RttManager * mRttManager
Definition: RttManager.h:270
Hydrax::RttManager::getPixelFormat
const Ogre::PixelFormat getPixelFormat(const RttType &Rtt) const
Definition: RttManager.cpp:278
Hydrax::RttManager::CGPUNormalMapListener::mRttManager
RttManager * mRttManager
Rtt manager pointer.
Definition: RttManager.h:324
Hydrax::RttManager::mGPUNormalMapListener
CGPUNormalMapListener mGPUNormalMapListener
Definition: RttManager.h:370
Hydrax::RttManager::CReflectionListener::mCameraPlaneDiff
Ogre::Real mCameraPlaneDiff
Camera.y - Plane.y difference.
Definition: RttManager.h:282
Hydrax::RttManager::CDepthListener::mRttManager
RttManager * mRttManager
Rtt manager pointer.
Definition: RttManager.h:292
_def_Hydrax_GPU_Normal_Map_Rtt_Name
#define _def_Hydrax_GPU_Normal_Map_Rtt_Name
Definition: RttManager.cpp:36
Hydrax::RttManager::NOC_2
@ NOC_2
Definition: RttManager.h:74
Hydrax::Size::Width
int Width
Width value.
Definition: Help.h:43
Hydrax::MaterialManager::MAT_WATER
@ MAT_WATER
Definition: MaterialManager.h:53
Hydrax::RttManager::mDepthReflectionListener
CDepthReflectionListener mDepthReflectionListener
Definition: RttManager.h:369
Hydrax::RttManager::BPC_16
@ BPC_16
Definition: RttManager.h:65
AngelOgre::getName
class AngelOgre::OverlayManager & getName
Hydrax::RttManager::initialize
void initialize(const RttType &Rtt)
Initialize a RTT.
Definition: RttManager.cpp:78
Hydrax::HYDRAX_COMPONENT_UNDERWATER
@ HYDRAX_COMPONENT_UNDERWATER
Definition: Enums.h:65
Hydrax::RttManager::setTextureSize
void setTextureSize(const RttType &Rtt, const Size &S)
Set Rtt texture size.
Definition: RttManager.cpp:223
_def_Hydrax_Reflection_Rtt_Name
#define _def_Hydrax_Reflection_Rtt_Name
Definition: RttManager.cpp:31
Hydrax::RttManager::CReflectionListener::mCReflectionQueueListener
CReflectionQueueListener mCReflectionQueueListener
CReflectionQueueListener.
Definition: RttManager.h:276
Hydrax::RttManager::RttOptions::NumberOfChannels_
NumberOfChannels NumberOfChannels_
Number of channels.
Definition: RttManager.h:88
Hydrax::MaterialManager::MAT_UNDERWATER_COMPOSITOR
@ MAT_UNDERWATER_COMPOSITOR
Definition: MaterialManager.h:59
Hydrax::RttManager::CDepthReflectionListener::postRenderTargetUpdate
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:712
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:665
Hydrax::RttManager::CRefractionListener::postRenderTargetUpdate
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:548
Hydrax::RttManager::RTT_REFRACTION
@ RTT_REFRACTION
Definition: RttManager.h:53
Hydrax::RttManager::CRefractionListener::mRttManager
RttManager * mRttManager
Rtt manager pointer.
Definition: RttManager.h:248
Hydrax::RttManager::mPlanesSceneNode
Ogre::SceneNode * mPlanesSceneNode
SceneNode to attach our planes.
Definition: RttManager.h:356
Hydrax::Hydrax::_isCurrentFrameUnderwater
const bool & _isCurrentFrameUnderwater() const
Is current frame underwater?
Definition: Hydrax.h:621
Hydrax::RttManager::CReflectionListener::CReflectionQueueListener::renderQueueEnded
void renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &skipThisInvocation) override
Definition: RttManager.cpp:512
Hydrax::RttManager::getTexture
Ogre::TexturePtr getTexture(RttType Rtt)
Get Rtt texture.
Definition: RttManager.h:145
Hydrax::Size::Height
int Height
Height value.
Definition: Help.h:45
Hydrax::RttManager::CReflectionListener::CReflectionQueueListener::renderQueueStarted
void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &skipThisInvocation) override
Definition: RttManager.cpp:498
Hydrax::Mesh::getEntity
Ogre::Entity * getEntity()
Get entity.
Definition: Mesh.h:221
Hydrax::GodRaysManager::setVisible
void setVisible(const bool &Visible)
Set visible.
Definition: GodRaysManager.h:165
Hydrax::RttManager::mDepthListener
CDepthListener mDepthListener
Definition: RttManager.h:368
Hydrax::RttManager::CDepthReflectionListener::mRttManager
RttManager * mRttManager
Rtt manager pointer.
Definition: RttManager.h:308
Hydrax::RttManager::CReflectionListener::preRenderTargetUpdate
void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: RttManager.cpp:406
Hydrax::Mesh::getSize
const Size & getSize() const
Get mesh size.
Definition: Mesh.h:237