RigsofRods
Soft-body Physics Simulation
Renderdash.cpp
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5 
6  For more information, see http://www.rigsofrods.org/
7 
8  Rigs of Rods is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License version 3, as
10  published by the Free Software Foundation.
11 
12  Rigs of Rods is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "Renderdash.h"
22 
23 #include "Actor.h"
24 #include "Application.h"
25 #include "GfxScene.h"
26 #include "GUIManager.h"
27 #include "GUI_DirectionArrow.h"
28 #include "OverlayWrapper.h"
29 
30 #include <Overlay/OgreOverlayManager.h>
31 #include <Overlay/OgreOverlay.h>
32 
33 using namespace RoR;
34 
35 RoR::Renderdash::Renderdash(std::string const& rg_name, std::string const& tex_name, std::string const& cam_name)
36  : m_dash_cam(nullptr)
37  , m_rtt_tex(nullptr)
38  , m_blend_overlay(nullptr)
39  , m_dash_overlay(nullptr)
40  , m_needles_overlay(nullptr)
41 {
42  m_texture = Ogre::TextureManager::getSingleton().createManual(
43  tex_name, rg_name, Ogre::TEX_TYPE_2D, 1024, 512, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);
44 
45  m_rtt_tex = m_texture->getBuffer()->getRenderTarget();
46 
47  static int cam_counter = 0;
48  m_dash_cam = App::GetGfxScene()->GetSceneManager()->createCamera(cam_name);
49  m_dash_cam->setNearClipDistance(1.0);
50  m_dash_cam->setFarClipDistance(10.0);
51  m_dash_cam->setPosition(Ogre::Vector3(0.0, -10000.0, 0.0));
52 
53  m_dash_cam->setAspectRatio(2.0);
54 
55  Ogre::Viewport* v = m_rtt_tex->addViewport(m_dash_cam);
56  v->setClearEveryFrame(true);
57  v->setBackgroundColour(Ogre::ColourValue::Black);
58 
59  // NOTE: The 'renderdash' material is defined as a dummy in file 'ror.material' which is loaded into every actor's resource group.
60  Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName("renderdash", rg_name);
61  mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTexture(m_texture);
62 
63  m_dash_overlay = Ogre::OverlayManager::getSingleton().getByName("tracks/3D_DashboardOverlay");
64  m_needles_overlay = Ogre::OverlayManager::getSingleton().getByName("tracks/3D_NeedlesOverlay");
65  m_blend_overlay = Ogre::OverlayManager::getSingleton().getByName("tracks/3D_BlendOverlay");
66 
67  m_rtt_tex->addListener(this);
68  m_rtt_tex->setActive(false);
69 
70  // IMPORTANT: Must be manually updated as a workaround
71  // Under Windows with DirectX9 rendering, once auto-updated RTT is enabled, all DearIMGUI colors change: blue turns light orange, yellow turns light blue, red turns dark purple etc... looks like a hue shift but I haven't researched further. The moment the RTT is deactivated colors go back to normal.
72  m_rtt_tex->setAutoUpdated(false);
73 }
74 
76 {
77  if (m_rtt_tex != nullptr)
78  m_rtt_tex->removeListener(this);
79  App::GetGfxScene()->GetSceneManager()->destroyCamera(m_dash_cam);
80  Ogre::TextureManager::getSingleton().remove(m_texture);
81 }
82 
84 {
85  m_rtt_tex->setActive(en);
86 }
87 
88 void RoR::Renderdash::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
89 {
90  // hide everything
91  App::GetGfxScene()->GetSceneManager()->setFindVisibleObjects(false);
92 
93  // Disable DearIMGUI overlay
94  App::GetGfxScene()->GetSceneManager()->removeRenderQueueListener(&App::GetGuiManager()->GetImGui());
95 
96  // Disable other overlays
99 
100  //show overlay
101  m_dash_overlay->show();
102  m_needles_overlay->show();
103  m_blend_overlay->show();
104 }
105 
106 void RoR::Renderdash::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
107 {
108  // show everything
109  App::GetGfxScene()->GetSceneManager()->setFindVisibleObjects(true);
110 
111  // Enable DearIMGUI overlay
112  App::GetGfxScene()->GetSceneManager()->addRenderQueueListener(&App::GetGuiManager()->GetImGui());
113 
114  // Overlays 'racing' and 'direction arrow' are re-enabled automatically if needed
115 
116  // hide overlay
117  m_dash_overlay->hide();
118  m_needles_overlay->hide();
119  m_blend_overlay->hide();
120 }
RoR::Renderdash::postRenderTargetUpdate
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: Renderdash.cpp:106
OverlayWrapper.h
RoR::App::GetGuiManager
GUIManager * GetGuiManager()
Definition: Application.cpp:269
RoR::Renderdash::m_rtt_tex
Ogre::RenderTexture * m_rtt_tex
Definition: Renderdash.h:50
Renderdash.h
RoR::Renderdash::m_dash_overlay
Ogre::Overlay * m_dash_overlay
Definition: Renderdash.h:53
RoR::GUI::DirectionArrow::SetVisible
void SetVisible(bool value)
Only effective in main menu, simulation visibility is set in Update()
Definition: GUI_DirectionArrow.cpp:87
RoR::App::GetOverlayWrapper
OverlayWrapper * GetOverlayWrapper()
Definition: Application.cpp:268
RoR::Renderdash::m_blend_overlay
Ogre::Overlay * m_blend_overlay
Definition: Renderdash.h:52
GUI_DirectionArrow.h
Race direction arrow and text info (using OGRE Overlay)
RoR::GUIManager::DirectionArrow
GUI::DirectionArrow DirectionArrow
Definition: GUIManager.h:123
GUIManager.h
Actor.h
RoR::GfxScene::GetSceneManager
Ogre::SceneManager * GetSceneManager()
Definition: GfxScene.h:64
RoR::Renderdash::~Renderdash
~Renderdash()
Definition: Renderdash.cpp:75
RoR::Renderdash::Renderdash
Renderdash(std::string const &rg_name, std::string const &tex_name, std::string const &cam_name)
Definition: Renderdash.cpp:35
RoR::Renderdash::m_needles_overlay
Ogre::Overlay * m_needles_overlay
Definition: Renderdash.h:54
GfxScene.h
RoR::Renderdash::preRenderTargetUpdate
void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt) override
Definition: Renderdash.cpp:88
Application.h
Central state/object manager and communications hub.
RoR::Renderdash::m_texture
Ogre::TexturePtr m_texture
Definition: Renderdash.h:51
RoR::OverlayWrapper::HideRacingOverlay
void HideRacingOverlay()
Definition: OverlayWrapper.cpp:959
RoR::Renderdash::m_dash_cam
Ogre::Camera * m_dash_cam
Definition: Renderdash.h:49
RoR::Renderdash::setEnable
void setEnable(bool en)
Definition: Renderdash.cpp:83
RoR
Definition: AppContext.h:36
RoR::App::GetGfxScene
GfxScene * GetGfxScene()
Definition: Application.cpp:276