Project

General

Profile

SO3Engine
SO3Root.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
32#ifndef __SO3ROOT_H__
33#define __SO3ROOT_H__
34
37#include <OgreSingleton.h>
38#include <OgreRTShaderSystem.h>
39#include <OgreShaderGenerator.h>
40#include <OgreOverlaySystem.h>
41#include <OgreSTBICodec.h>
42#include <boost/thread/thread.hpp>
43#include <boost/bind/bind.hpp>
44
45namespace SO3
46{
47
48 typedef std::list<std::string> manualGroupList;
49
55class ShaderGeneratorTechniqueResolverListener : public Ogre::MaterialManager::Listener
56{
57public:
58
64 virtual Ogre::Technique* handleSchemeNotFound(unsigned short schemeIndex, const Ogre::String& schemeName, Ogre::Material* originalMaterial, unsigned short lodIndex, const Ogre::Renderable* rend);
65
66 virtual bool afterIlluminationPassesCreated(Ogre::Technique* tech);
67
68 virtual bool beforeIlluminationPassesCleared(Ogre::Technique* tech);
69};
70
71
72class _SO3_Export SRoot : public Ogre::Singleton<SRoot>, public Ogre::LogListener, public Ogre::RenderSystem::Listener
73{
74public:
86protected:
87private:
88 ShaderGeneratorTechniqueResolverListener* mMaterialMgrListener; // Shader generator material manager listener.
89
90 bool mDeviceLost;
91 bool mRootInitialised;
92 unsigned int windowIndex;
93 RenderSystem renderSystem;
94 std::string defaultFsaa;
95 Ogre::RenderSystem* O3Render;
96 Ogre::Root* O3Root;
97 Ogre::RTShader::ShaderGenerator* mShaderGenerator;
98 manualGroupList mManualGroups;
99
100#ifdef SO3_BUILD_DEFERRED
101 SDeferredShading* deferredManager;
102#endif
103
104 SO3ScolFileSystemArchiveFactory* scolFileSystemArchiveFactory;
105 SSceneMap sceneList;
106 SWindowMap windowList;
107 SPluginManager* pluginManager;
108 Ogre::ParticleFXPlugin* staticPluginParticleFX;
109 Ogre::SceneManager* mDummyScene;
110
111#if !defined(ANDROID) && !defined(APPLE_IOS) && !defined(SO3_USE_METAL) && !defined(RPI)
112 Ogre::CgPlugin* staticPluginCG;
113#endif
114
115 Ogre::OctreePlugin* staticPluginOctree;
116 Ogre::OverlaySystem* O3OverlaySystem;
117
118 SWidgetManager* widgetManager;
119
120#ifdef SO3_FLASH_ENABLE
121 SFlashWidgetFactory* flashWidgetFactory;
122#endif
123
124 SBitmapWidgetFactory* bitmapWidgetFactory;
125 SObjWindowWidgetFactory* objWindowWidgetFactory;
126 #if SO3_WEB_NAVIGATOR_BUILD == 1
128 SWebNavigatorWidgetFactory* webNavigatorWidgetFactory;
129 #endif
130 SKeyboardHook* keyboardHook;
131 SWindow* fullScreenWindow;
132 typedef std::set<SLogListener*> LogListenerList;
133 LogListenerList logListenerList;
134 bool mLogEnable;
135 bool mDebugEnable;
136#ifdef SO3_DEVELOPPER_BUILD
137# ifdef _WIN32
138# ifndef SO3_USE_DX11
139 Ogre::D3D9Plugin* staticPluginD3D9;
140# else
141 Ogre::D3D11Plugin* staticPluginD3D11;
142# endif
143# endif
144
145# ifndef SO3_USE_OPENGLES2
146# ifdef SO3_USE_GL3
147 Ogre::GL3PlusPlugin* staticPluginOpenGL3;
148# elif !defined(SO3_USE_METAL)
149 Ogre::GLPlugin* staticPluginOpenGL;
150# endif
151# elif !defined(SO3_USE_METAL)
152 Ogre::GLES2Plugin* staticPluginOpenGLES2;
153# endif
154
155# if defined(__APPLE__) && defined(SO3_USE_METAL)
156 Ogre::MetalPlugin* staticPluginMetal;
157# endif
158
159# if defined(_WIN64)
160 //Ogre::TinyPlugin* staticPluginTiny;
161
162 Ogre::VulkanPlugin* staticPluginVulkan;
163 Ogre::GLSLangPlugin* staticPluginGLSLang;
164# endif
165
166#endif
167 bool mDebugInitialized;
168 bool mPaused;
169 Ogre::RenderWindow* dummyWindow;
170 SResourceLoader* resourceLoader;
171 float quadBufferFocalLength;
172 float quadBufferEyesSeparation;
173 bool useVSync;
174 bool mResourcesReleased;
175 Ogre::GpuSharedParametersPtr mSlicePlaneParams;
176 Ogre::GpuSharedParametersPtr mCommonParams;
177 bool mSlicePlaneState;
178 Ogre::Vector4 mSlicePlane;
179 bool mUpdating;
180 bool mRendering;
181
182#ifdef ANDROID
183 int mMainWidth;
184 int mMainHeight;
185#endif
186public:
190 SRoot(const std::string& firstPartition);
191
195 ~SRoot();
196
197#ifdef _WIN32
198 void* GetD3Ddevice();
199#endif
200
204 void InitRenderer(SWindow* pwin = 0);
205
208 bool IsRenderInitialised();
209
213 bool SetFullScreenState(SWindow* window, const bool& state, const int& width, const int& height);
214
217 void AddLogListener(SLogListener* newLogListener);
218
221 void RemoveLogListener(SLogListener* existingLogListener);
222
225 void SetLogEnable(const bool& state);
226
229 bool GetLogEnable();
230
233 void SetLogMask(const Ogre::LogMessageLevel& level);
234
237 Ogre::Root* GetOgreRootPointer();
238
241 Ogre::RenderSystem* GetOgreRenderSystem();
242
245 bool IsUpdating();
246
249 bool IsRendering();
250
251#ifdef SO3_BUILD_DEFERRED
254 SDeferredShading* GetDeferredManager();
255#endif
256
259 static SRoot& getSingleton();
260
263 static SRoot* getSingletonPtr();
264
268 SScene* CreateScene(const std::string& newSceneName);
269
273 void DeleteScene(SScene* existingScene);
274
278 SScene* GetScene(const std::string& sceneName);
279
280 void AddManualRessourceGroup(std::string name);
281
282 void RemoveManualRessourceGroup(std::string name);
283
284 void ClearManualRessourceGroups();
285
289 const SSceneMap& GetSceneList() const;
290
293 bool checkFSAA(const Ogre::String& val);
294
297 RenderSystem GetRenderSystem();
298
301 std::vector<std::string> GetMultisamplingMode(const RenderSystem& wishedRenderSystem);
302
306 SWindow* CreateRenderWindow(const ScolWindowHandle windowHandle, const std::string& windowName, const int& width, const int& height, const std::string& renderWindowFsaa="default");
307
311 void DeleteRenderWindow(SWindow* existingWindow);
312
316 const SWindowMap& GetRenderWindowList() const;
317
321 SWindow* GetRenderWindow(const std::string& windowName);
322
326 SWindow* GetRenderWindow(const ScolWindowHandle& hwnd);
327
331 bool CheckDirectxVersion();
332
335 void SetDebugEnable(const bool& enable);
336
339 bool GetDebugEnable();
340
343 void SetDebugDisplay(const int& color, const int& posx, const int& posy, const int& width, const int& height, const int& charHeight);
344
347 void SetDebugText(const std::string& text);
348
352 void UpdateCamera(SViewPort* viewport);
353
357 void RegisterViewport(SViewPort* viewport);
358
362 void UnregisterViewport(SViewPort* viewport);
363
366 bool Update();
367
370 void DestroyInternalRessources();
371
374 void ReloadInternalRessources();
375
378 void Pause();
379
382 void Resume();
383
386 bool GetQuadBufferEnable();
387
390 float GetQuadBufferFocalLength();
391
394 float GetQuadBufferEyesSeparation();
395
398 bool GetVSyncEnable();
399
402 bool isDeviceLost();
403
406 bool GetRttPixelFormat(Ogre::PixelFormat &format, bool alpha = false, bool floattex = false);
407
410 void InvalidateGeneratedMaterial(Ogre::Material* mat);
411
414 void RemoveGeneratedMaterial(Ogre::Material* mat);
415
419 void ParseConfigFile();
420
423 void SetSlicePlaneState(bool state);
424
427 void SetSlicePlane(Ogre::Vector4 plane);
428
431 bool GetSlicePlaneState();
432
435 Ogre::Vector4 GetSlicePlane();
436
439 void SetProgramCameraParameter(float fov, float znear, float zfar, float focalLength);
440
441protected:
444 virtual void messageLogged(const Ogre::String& message, Ogre::LogMessageLevel lml, bool maskDebug, const Ogre::String& logName, bool& skipMessage);
445
449 virtual void eventOccurred(const Ogre::String &eventName, const Ogre::NameValuePairList *parameters);
450
454 void AddScene(SScene* existingScene);
455
459 void RemoveScene(SScene* existingScene);
460
464 void RemoveScene(const std::string& sceneName);
465
469 void AddRenderWindow(SWindow* existingWindow);
470
474 void RemoveRenderWindow(SWindow* existingWindow);
475
479 void RemoveRenderWindow(const std::string& windowName);
480
481private:
484 void ClearSceneManagerPassMaps();
485
488 bool LoadOgrePlugins();
489
492 bool UnloadOgrePlugins();
493
496 void CreateBoneHelperMesh();
497
501 void WriteConfigFile(const std::string& filename);
502
507 void SetRenderSystem(const RenderSystem& selectedRenderSystem, const bool& activateQuadBuffer);
508
509 bool initialiseRTShaderSystem();
510 void destroyRTShaderSystem();
511
515 SRoot();
516};
517
518}
519
520#endif
librairies include
std::string firstPartition(((packdir) SCgetExtra("FirstPack")) ->path)
@ SO3_DIRECTX9_RENDERER
Definition SO3Root.h:78
@ SO3_METAL_RENDERER
Definition SO3Root.h:83
@ SO3_DIRECTX11_RENDERER
Definition SO3Root.h:79
@ SO3_OPENGL3_RENDERER
Definition SO3Root.h:81
@ SO3_OPENGL_RENDERER
Definition SO3Root.h:80
@ SO3_VULKAN_RENDERER
Definition SO3Root.h:82
virtual bool afterIlluminationPassesCreated(Ogre::Technique *tech)
Definition SO3Root.cpp:2629
virtual bool beforeIlluminationPassesCleared(Ogre::Technique *tech)
Definition SO3Root.cpp:2641
virtual Ogre::Technique * handleSchemeNotFound(unsigned short schemeIndex, const Ogre::String &schemeName, Ogre::Material *originalMaterial, unsigned short lodIndex, const Ogre::Renderable *rend)
Definition SO3Root.cpp:2358
std::unordered_map< std::string, SScene * > SSceneMap
std::unordered_map< std::string, SWindow * > SWindowMap
std::list< std::string > manualGroupList
Definition SO3Root.h:48