Spinning Topp Logo BlackTopp Studios
inc
graphicsmanager.cpp
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _graphicsmanager_cpp
41 #define _graphicsmanager_cpp
42 
43 #include "Graphics/graphicsmanager.h"
44 #include "Graphics/texturemanager.h"
45 #include "Graphics/cameraproxy.h"
46 #include "Graphics/viewport.h"
47 
49 
50 #include "UI/uimanager.h"
51 
52 #include "eventmanager.h"
53 #include "crossplatform.h"
54 #include "stringtool.h"
55 #include "entresol.h"
56 
57 #include <SDL.h>
58 #include <Ogre.h>
59 
60 #ifdef MEZZ_BUILD_DIRECTX9_SUPPORT
61 #include "d3d9rendersyshelper.h.cpp"
62 #endif
63 #ifdef MEZZ_BUILD_DIRECTX11_SUPPORT
64 #include "d3d11rendersyshelper.h.cpp"
65 #endif
66 #ifdef MEZZ_BUILD_OPENGL_SUPPORT
67 #include "oglrendersyshelper.h.cpp"
68 #endif
69 #ifdef MEZZ_BUILD_OPENGL3PLUS_SUPPORT
70 #include "ogl3plusrendersyshelper.h.cpp"
71 #endif
72 #ifdef MEZZ_BUILD_OPENGLES_SUPPORT
73 #include "oglesrendersyshelper.h.cpp"
74 #endif
75 #ifdef MEZZ_BUILD_OPENGLES2_SUPPORT
76 #include "ogles2rendersyshelper.h.cpp"
77 #endif
78 
79 #include <cstdlib>
80 #include <algorithm>
81 
82 namespace Mezzanine
83 {
84  template<> Graphics::GraphicsManager* Singleton<Graphics::GraphicsManager>::SingletonPtr = NULL;
85 
86  namespace Graphics
87  {
88  ///////////////////////////////////////////////////////////////////////////
89  // RenderWorkUnit Methods
90 
91  RenderWorkUnit::RenderWorkUnit(GraphicsManager* Target) :
92  TargetManager(Target)
93  { }
94 
96  { }
97 
98  void RenderWorkUnit::UseThreads(const Whole& AmountToUse)
99  {
100  //TargetGraphicsManager->SomehowTellOgreHowManyThread(AmountToUse);
101  }
102 
104  {
105  //return TargetGraphicsManager->GetThreadCountFromOgreSomehow();
106  return 1;
107  }
108 
110  {
111  this->TargetManager->ThreadResources = &CurrentThreadStorage; // Allow this full access to any thread specific resources it needs
112  Ogre::WindowEventUtilities::messagePump();
113  this->TargetManager->RenderOneFrame();
114  this->TargetManager->ThreadResources = NULL; // Take it all away.
115  }
116 
117  ///////////////////////////////////////////////////////////////////////////
118  // GraphicsManager Methods
119 
120  //template<> GraphicsManager* Singleton<GraphicsManager>::SingletonPtr = NULL;
121  const String GraphicsManager::ImplementationName = "DefaultGraphicsManager";
122  const ManagerBase::ManagerType GraphicsManager::InterfaceType = ManagerBase::MT_GraphicsManager;
123 
125  PrimaryGameWindow(NULL),
126  RenderWork(NULL),
127  ThreadResources(NULL),
128  CurrRenderSys(Graphics::RS_OpenGL2),
129  OgreBeenInitialized(false)
130  {
131  this->Construct();
132  this->AutoGenFiles = false;
133  }
134 
136  PrimaryGameWindow(NULL),
137  RenderWork(NULL),
138  ThreadResources(NULL),
139  CurrRenderSys(Graphics::RS_OpenGL2),
140  OgreBeenInitialized(false)
141  {
142  this->Construct();
143 
145 
146  /// @todo This is currently necessary because a render window of some kind needs to exist for the loading
147  /// of resources that occurs later in world construction (when this is constructed by the world, which this
148  /// assumes. If possible this should be removed, to keep construction more flexible.
149  this->InitOgreRenderSystem();
150  }
151 
152 
154  {
155  this->Deinitialize();
156  this->DestroyAllGameWindows(false);
157 
158  #ifdef MEZZ_BUILD_DIRECTX9_SUPPORT
160  #endif
161  #ifdef MEZZ_BUILD_DIRECTX11_SUPPORT
163  #endif
164  #ifdef MEZZ_BUILD_OPENGL_SUPPORT
166  #endif
167  #ifdef MEZZ_BUILD_OPENGL3PLUS_SUPPORT
169  #endif
170  #ifdef MEZZ_BUILD_OPENGLES_SUPPORT
172  #endif
173  #ifdef MEZZ_BUILD_OPENGLES2_SUPPORT
175  #endif
176 
177  //UInt32 InitSDLSystems = SDL_WasInit(0);
178  //if( SDL_INIT_VIDEO | InitSDLSystems ) {
179  // SDL_QuitSubSystem(SDL_INIT_VIDEO);
180  //}
181 
182  delete RenderWork;
183  }
184 
186  {
187  this->PrimaryGameWindow = NULL;
188  this->RenderWork = new RenderWorkUnit(this);
189 
190  UInt32 InitSDLSystems = SDL_WasInit(0);
191  if( (SDL_INIT_VIDEO & InitSDLSystems) == 0 ) {
192  if( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0 ) {
193  MEZZ_EXCEPTION(ExceptionBase::INTERNAL_EXCEPTION,String("Failed to Initialize SDL for Video/Windowing, SDL Error: ") + SDL_GetError());
194  }
195  }
196 
197  SDL_DisplayMode DeskMode;
198  SDL_GetDesktopDisplayMode(0,&DeskMode);
199  DesktopSettings.WinRes.Width = DeskMode.w;
200  DesktopSettings.WinRes.Height = DeskMode.h;
201  DesktopSettings.RefreshRate = DeskMode.refresh_rate;
202 
203  #ifdef MEZZ_BUILD_DIRECTX9_SUPPORT
205  #endif
206  #ifdef MEZZ_BUILD_DIRECTX11_SUPPORT
208  #endif
209  #ifdef MEZZ_BUILD_OPENGL_SUPPORT
211  #endif
212  #ifdef MEZZ_BUILD_OPENGL3PLUS_SUPPORT
214  #endif
215  #ifdef MEZZ_BUILD_OPENGLES_SUPPORT
217  #endif
218  #ifdef MEZZ_BUILD_OPENGLES2_SUPPORT
220  #endif
221  }
222 
224  {
225  if( !this->OgreBeenInitialized ) {
226  Ogre::Root* OgreCore = Ogre::Root::getSingletonPtr();
227  const Ogre::RenderSystemList& RSList = OgreCore->getAvailableRenderers();
228  if( RSList.size() == 1 ) {
229  //Ogre::RenderSystem* temp = OgreCore->getRenderSystemByName( this->GetRenderSystemName( this->RenderSystemTypes[0] ) );
230  OgreCore->setRenderSystem( RSList[0] );
231  }else{
232  //Ogre::RenderSystem* temp = OgreCore->getRenderSystemByName( this->GetRenderSystemName( this->CurrRenderSys ) );
233  OgreCore->setRenderSystem( OgreCore->getRenderSystemByName( this->GetRenderSystemName( this->CurrRenderSys ) ) );
234  }
235 
236  OgreCore->initialise(false,"");
237  this->OgreBeenInitialized = true;
238 
239  this->PrimaryGameWindow = new GameWindow("Primary",1,1,GameWindow::WF_Hidden);
240  }
241  }
242 
243 
245  {
246  return "DefaultGraphicsManagerSettings";
247  }
248 
250  {
251  // Create the Group node to be returned
252  XML::Node CurrentSettings = SettingsRootNode.AppendChild("Current");
253  // Create and initialize the rendersystem settings
254  XML::Node RenderSystemNode = CurrentSettings.AppendChild("RenderSystem");
255  RenderSystemNode.AppendAttribute("Name").SetValue( this->GetShortenedRenderSystemName(CurrRenderSys) );
256  // Create and initialize the window configuration
257  for( GameWindowIterator WinIt = this->BeginGameWindow() ; WinIt != this->EndGameWindow() ; ++WinIt )
258  { (*WinIt)->ProtoSerialize(CurrentSettings); }
259  }
260 
262  {
263  for( ObjectSettingSetContainer::SubSetIterator SubSetIt = Group->SubSetBegin() ; SubSetIt != Group->SubSetEnd() ; ++SubSetIt )
264  {
265  String CurrSettingValue;
266  if( "RenderSystem" == (*SubSetIt)->GetName() ) {
267  Graphics::RenderSystem RenderSys = Graphics::RS_OpenGL2;
268  CurrSettingValue = (*SubSetIt)->GetSettingValue("Name");
269  if( GetShortenedRenderSystemName(Graphics::RS_DirectX9) == CurrSettingValue )
270  RenderSys = Graphics::RS_DirectX9;
271  else if( GetShortenedRenderSystemName(Graphics::RS_DirectX11) == CurrSettingValue )
272  RenderSys = Graphics::RS_DirectX11;
273  else if( GetShortenedRenderSystemName(Graphics::RS_OpenGL2) == CurrSettingValue )
274  RenderSys = Graphics::RS_OpenGL2;
275  else if( GetShortenedRenderSystemName(Graphics::RS_OpenGLES1) == CurrSettingValue )
276  RenderSys = Graphics::RS_OpenGLES1;
277  else if( GetShortenedRenderSystemName(Graphics::RS_OpenGLES2) == CurrSettingValue )
278  RenderSys = Graphics::RS_OpenGLES2;
279 
280  this->CurrRenderSys = RenderSys;
281 
282  if( !this->OgreBeenInitialized ) {
283  this->SetRenderSystem(this->CurrRenderSys,true);
284  }else{
285  /// @todo May want to make some other data member so that people can accurately get what is set now, instead of what will be set.
286  Entresol::GetSingletonPtr()->_Log("WARNING: Attempting to apply new RenderSystem settings after the GraphicsManager has been initialized. "
287  "These Settings will be applied the next time settings are loaded during manager construction if current settings are saved.");
288  }
289  }
290  else if( "GameWindow" == (*SubSetIt)->GetName() )
291  {
292  GameWindow* CurrWindow = NULL;
293  String WinCaption("Mezzanine Window");
294  Whole WinWidth = 800;
295  Whole WinHeight = 600;
296  Whole WinFlags = 0;
297 
298  ObjectSettingSet* PropertiesSet = (*SubSetIt)->GetChildObjectSettingSet("GameWindowProperties");
299  if( PropertiesSet != NULL ) {
300  // Get the caption.
301  CurrSettingValue = PropertiesSet->GetSettingValue("Caption");
302  if(!CurrSettingValue.empty())
303  WinCaption = CurrSettingValue;
304  // Get the width.
305  CurrSettingValue = PropertiesSet->GetSettingValue("Width");
306  if(!CurrSettingValue.empty())
307  WinWidth = StringTools::ConvertToUInt32(CurrSettingValue);
308  // Get the height.
309  CurrSettingValue = PropertiesSet->GetSettingValue("Height");
310  if(!CurrSettingValue.empty())
311  WinHeight = StringTools::ConvertToUInt32(CurrSettingValue);
312  // Get fullscreen.
313  CurrSettingValue = PropertiesSet->GetSettingValue("Fullscreen");
314  if(!CurrSettingValue.empty()) {
315  if(StringTools::ConvertToBool(CurrSettingValue))
316  WinFlags = (WinFlags | GameWindow::WF_Fullscreen);
317  }
318  // Get hidden.
319  CurrSettingValue = PropertiesSet->GetSettingValue("Hidden");
320  if(!CurrSettingValue.empty()) {
321  if(StringTools::ConvertToBool(CurrSettingValue))
322  WinFlags = (WinFlags | GameWindow::WF_Hidden);
323  }
324  // Get vsync.
325  CurrSettingValue = PropertiesSet->GetSettingValue("Vsync");
326  if(!CurrSettingValue.empty()) {
327  if(StringTools::ConvertToBool(CurrSettingValue))
328  WinFlags = (WinFlags | GameWindow::WF_VsyncEnabled);
329  }
330  // Get resizable.
331  CurrSettingValue = PropertiesSet->GetSettingValue("Resizeable");
332  if(!CurrSettingValue.empty()) {
333  if(StringTools::ConvertToBool(CurrSettingValue))
334  WinFlags = (WinFlags | GameWindow::WF_Resizeable);
335  }
336  // Get maximized.
337  CurrSettingValue = PropertiesSet->GetSettingValue("Maximized");
338  if(!CurrSettingValue.empty()) {
339  if(StringTools::ConvertToBool(CurrSettingValue))
340  WinFlags = (WinFlags | GameWindow::WF_Maximized);
341  }
342  // Get borderless.
343  CurrSettingValue = PropertiesSet->GetSettingValue("Borderless");
344  if(!CurrSettingValue.empty()) {
345  if(StringTools::ConvertToBool(CurrSettingValue))
346  WinFlags = (WinFlags | GameWindow::WF_Borderless);
347  }
348  // Get the FSAA level
349  CurrSettingValue = PropertiesSet->GetSettingValue("FSAA");
350  if(!CurrSettingValue.empty()) {
351  switch( StringTools::ConvertToUInt32(CurrSettingValue) )
352  {
353  case 2:
354  WinFlags = (WinFlags | GameWindow::WF_FSAA_2);
355  break;
356  case 4:
357  WinFlags = (WinFlags | GameWindow::WF_FSAA_4);
358  break;
359  case 8:
360  WinFlags = (WinFlags | GameWindow::WF_FSAA_8);
361  break;
362  case 16:
363  WinFlags = (WinFlags | GameWindow::WF_FSAA_16);
364  break;
365  }
366  }
367  // Finally, construct the window.
368  CurrWindow = this->CreateGameWindow(WinCaption,WinWidth,WinHeight,WinFlags);
369  }
370  // Set up the viewports
371  ObjectSettingSet* ViewportsSet = (*SubSetIt)->GetChildObjectSettingSet("Viewports");
372  if( ViewportsSet != NULL && CurrWindow != NULL ) {
373  for( ObjectSettingSetContainer::SubSetIterator VPIt = ViewportsSet->SubSetBegin() ; VPIt != ViewportsSet->SubSetEnd() ; ++VPIt )
374  {
375  if( "Viewport" == (*VPIt)->GetName() ) {
376  Integer ZO = 0;
377  Vector2 Position(0,0);
378  Vector2 Size(1,1);
379 
380  CurrSettingValue = (*VPIt)->GetSettingValue("ZOrder");
381  if( !CurrSettingValue.empty() ) {
382  ZO = StringTools::ConvertToInteger( CurrSettingValue );
383  }
384 
385  ObjectSettingSet* PositionSet = (*VPIt)->GetChildObjectSettingSet("Position");
386  if( PositionSet != NULL ) {
387  ObjectSettingSet* PositionVector = PositionSet->GetChildObjectSettingSet("Vector2");
388 
389  CurrSettingValue = PositionVector->GetSettingValue("X");
390  if( !CurrSettingValue.empty() ) {
391  Position.X = StringTools::ConvertToReal( CurrSettingValue );
392  }
393  CurrSettingValue = PositionVector->GetSettingValue("Y");
394  if( !CurrSettingValue.empty() ) {
395  Position.Y = StringTools::ConvertToReal( CurrSettingValue );
396  }
397  }
398 
399  ObjectSettingSet* SizeSet = (*VPIt)->GetChildObjectSettingSet("Size");
400  if( SizeSet != NULL ) {
401  ObjectSettingSet* SizeVector = SizeSet->GetChildObjectSettingSet("Vector2");
402 
403  CurrSettingValue = SizeVector->GetSettingValue("X");
404  if( !CurrSettingValue.empty() ) {
405  Size.X = StringTools::ConvertToReal( CurrSettingValue );
406  }
407  CurrSettingValue = SizeVector->GetSettingValue("Y");
408  if( !CurrSettingValue.empty() ) {
409  Size.Y = StringTools::ConvertToReal( CurrSettingValue );
410  }
411  }
412 
413  Viewport* CurrViewport = CurrWindow->CreateViewport(NULL,ZO);
414  CurrViewport->SetDimensions(Position,Size);
415  }// if - Viewport
416  }// for - Viewports
417  }// if - ViewportsSet
418  }// if - RS || GameWindow
419  }// for - SubSets
420  }
421 
422  ///////////////////////////////////////////////////////////////////////////////
423  // Window Management
424 
425  GameWindow* GraphicsManager::CreateGameWindow(const String& WindowCaption, const Whole& Width, const Whole& Height, const Whole& Flags)
426  {
427  if( !this->OgreBeenInitialized )
428  this->InitOgreRenderSystem();
429 
430  GameWindow* NewWindow = new GameWindow(WindowCaption,Width,Height,Flags);
431  this->GameWindows.push_back(NewWindow);
432  return NewWindow;
433  }
434 
436  {
437  return this->GameWindows.at(Index);
438  }
439 
441  {
442  for( ConstGameWindowIterator WinIt = this->GameWindows.begin() ; WinIt != this->GameWindows.end() ; ++WinIt )
443  {
444  if( (*WinIt)->GetWindowCaption() == Caption ) {
445  return (*WinIt);
446  }
447  }
448  return NULL;
449  }
450 
452  {
453  return this->GameWindows.size();
454  }
455 
457  {
458  for( GameWindowIterator it = this->GameWindows.begin() ; it != this->GameWindows.end() ; it++ )
459  {
460  if( ToBeDestroyed == (*it) ) {
461  delete ToBeDestroyed;
462  this->GameWindows.erase(it);
463  return;
464  }
465  }
466  }
467 
469  {
470  for( GameWindowIterator Iter = this->GameWindows.begin() ; Iter != this->GameWindows.end() ; ++Iter )
471  { delete *Iter; }
472  this->GameWindows.clear();
473 
474  if(!ExcludePrimary) {
475  delete this->PrimaryGameWindow;
476  this->PrimaryGameWindow = NULL;
477  }
478  }
479 
481  {
482  return this->PrimaryGameWindow;
483  }
484 
486  {
487  return this->GameWindows.begin();
488  }
489 
491  {
492  return this->GameWindows.end();
493  }
494 
496  {
497  return this->GameWindows.begin();
498  }
499 
501  {
502  return this->GameWindows.end();
503  }
504 
505  ///////////////////////////////////////////////////////////////////////////////
506  // RenderSystem Management
507 
508  void GraphicsManager::SetRenderSystem(const Graphics::RenderSystem& RenderSys, Boole InitializeRenderSystem)
509  {
510  if(!this->OgreBeenInitialized) this->CurrRenderSys = RenderSys;
511  else { MEZZ_EXCEPTION(ExceptionBase::INVALID_STATE_EXCEPTION,"Attempting to set RenderSystem after graphics has been initialized. This is not supported."); }
512 
513  if( InitializeRenderSystem )
514  this->InitOgreRenderSystem();
515  }
516 
518  {
519  return this->CurrRenderSys;
520  }
521 
523  {
524  switch(RenderSys)
525  {
526  case Graphics::RS_DirectX9: return "Direct3D9 Rendering Subsystem"; break;
527  case Graphics::RS_DirectX11: return "Direct3D11 Rendering Subsystem"; break;
528  case Graphics::RS_OpenGL2: return "OpenGL Rendering Subsystem"; break;
529  case Graphics::RS_OpenGL3Plus: return "OpenGL 3+ Rendering Subsystem (ALPHA)"; break;
530  case Graphics::RS_OpenGLES1: return "OpenGL ES 1.x Rendering Subsystem"; break;
531  case Graphics::RS_OpenGLES2: return "OpenGL ES 2.x Rendering Subsystem"; break;
532  default: return ""; break;
533  }
534  return "";
535  }
536 
538  {
539  switch(RenderSys)
540  {
541  case Graphics::RS_DirectX9: return "Direct3D9"; break;
542  case Graphics::RS_DirectX11: return "Direct3D11"; break;
543  case Graphics::RS_OpenGL2: return "OpenGL"; break;
544  case Graphics::RS_OpenGL3Plus: return "OpenGL3+"; break;
545  case Graphics::RS_OpenGLES1: return "OpenGLES1.x"; break;
546  case Graphics::RS_OpenGLES2: return "OpenGLES2.x"; break;
547  default: return ""; break;
548  }
549  return "";
550  }
551 
552  ///////////////////////////////////////////////////////////////////////////////
553  // Query Methods
554 
556  {
557  return this->SupportedResolutions;
558  }
559 
561  {
562  return this->SupportedDevices;
563  }
564 
566  {
567  return this->DesktopSettings;
568  }
569 
570  ///////////////////////////////////////////////////////////////////////////////
571  // Utility Methods
572 
574  {
575  // Do the actual frame
576  Ogre::Root::getSingleton().renderOneFrame();
577  // This fixes an undocumented error of some kind
578  if( !this->GetPrimaryGameWindow()->_GetOgreWindowPointer()->isVisible() ) {
579  Ogre::Root::getSingleton().clearEventTimes();
580  }
581  // Do the Logging aggregation
582  /*Ogre::Log* DefaultLog = Ogre::LogManager::getSingleton().getDefaultLog();
583  if( DefaultLog != NULL ) {
584  if( this->ThreadResources != NULL ) {
585  //this->ThreadResources->GetUsableLogger() << DefaultLog->stream();
586  }else{
587  //Entresol::GetSingletonPtr()->_GetLogStream() << DefaultLog->stream();
588  }
589  DefaultLog->stream().flush();
590  }// */
591  }
592 
594  {
595  for( Whole X = 0 ; X < this->GetNumGameWindows() ; X++ )
596  this->GetGameWindow(X)->_GetOgreWindowPointer()->swapBuffers();
597  }
598 
600  {
601  if( !this->Initialized ) {
602  this->TheEntresol->GetScheduler().AddWorkUnitMonopoly(this->RenderWork, "RenderWork");
603 
604  if( !this->OgreBeenInitialized ) {
605  this->InitOgreRenderSystem();
606  }
607 
608  Ogre::ConfigOptionMap& CurrentRendererOptions = Ogre::Root::getSingleton().getRenderSystem()->getConfigOptions();
609  for( Ogre::ConfigOptionMap::iterator configItr = CurrentRendererOptions.begin() ; configItr != CurrentRendererOptions.end() ; configItr++ )
610  {
611  if( (configItr)->first == "Video Mode" ) {
612  for( Whole X = 0 ; X < (configItr)->second.possibleValues.size() ; X++ )
613  {
614  String NewRes = (configItr)->second.possibleValues[X];
615  String ResWidth = NewRes.substr(0,NewRes.find_first_of('x'));
616  String ResHeight = NewRes.substr(NewRes.find_first_of('x')+1);
617  StringTools::Trim( ResWidth );
618  StringTools::Trim( ResHeight );
619  this->SupportedResolutions.push_back( Resolution( StringTools::ConvertToWhole( ResWidth ) , StringTools::ConvertToWhole( ResHeight ) ) );
620  }
621  std::sort(this->SupportedResolutions.begin(),this->SupportedResolutions.end());
622  }else if( (configItr)->first == "Rendering Device" ) {
623  for( Whole Y = 0 ; Y < (configItr)->second.possibleValues.size() ; Y++ )
624  { this->SupportedDevices.push_back( (configItr)->second.possibleValues[Y] ); }
625  }
626  }
627 
628  if( this->AutoGenFiles ) {
629  this->SaveAllSettings();
630  }
631 
632  this->Initialized = true;
633  }
634  }
635 
637  {
638  if( this->Initialized ) {
640 
641  // Textures are loaded into video memory, which we can only do with a valid and initialized rendering context.
642  // If the context goes away, such as is the case when the rendersystem is shut down then we can't have textures loaded.
643  // So deinitialize the TextureManager.
644  this->TheEntresol->GetManager(ManagerBase::MT_TextureManager)->Deinitialize();
645 
646  /// @todo Here is where we should be shutting down the rendersystem, but Ogre in it's poorly coded ways wasn't
647  /// designed for that unless you are also deleting Ogre::Root. Take it up with them if you don't like it.
648  /// (tell me where the thread is when you do, I'll join in)
649  /// Related: http://www.ogre3d.org/forums/viewtopic.php?f=4&t=77036&sid=a7ce7512032eb851d50da083795198f3
650 
651  if( this->AutoGenFiles )
652  this->SaveAllSettings();
653 
654  this->Initialized = false;
655  }
656  }
657 
659  { return this->RenderWork; }
660 
661  ///////////////////////////////////////////////////////////////////////////////
662  // SubSystem Initialization
663 
665  {
666  return SDL_WasInit(SDL_INIT_VIDEO);
667  }
668 
670  {
671  return this->OgreBeenInitialized;
672  }
673 
674  ///////////////////////////////////////////////////////////////////////////////
675  // Type Identifier Methods
676 
679 
682 
683  ///////////////////////////////////////////////////////////////////////////////
684  // DefaultGraphicsManagerFactory Methods
685 
687  { }
688 
690  { }
691 
694 
697 
699  {
701  /// @todo Add something to log a warning that the manager exists and was requested to be constructed when we have a logging manager set up.
703  }else{
704  return new GraphicsManager();
705  }
706  }
707 
709  {
711  /// @todo Add something to log a warning that the manager exists and was requested to be constructed when we have a logging manager set up.
713  }else{
714  return new GraphicsManager(XMLNode);
715  }
716  }
717 
719  { delete ToBeDestroyed; }
720  } // Graphics Namespace
721 } //Mezzanine
722 
723 #endif
Creates a window with resizable borders, otherwise it is fixed size.
Definition: gamewindow.h:87
virtual void AddWorkUnitMonopoly(MonopolyWorkUnit *MoreWork, const String &WorkUnitName)
Add a MonopolyWorkUnit for execution at the beginning of the frame.
Attribute AppendAttribute(const Char8 *Name)
Creates an Attribute and puts it at the end of this Nodes attributes.
friend class RenderWorkUnit
The RenderWorkUnit really is an extension of the GraphicsManager, it just exists as a Functor for the...
ResolutionContainer SupportedResolutions
A container of strings storing all the detected supported resolutions on the current hardware...
GameWindowContainer GameWindows
A container storing all the game windows created by this manager.
std::vector< String > StringVector
This is a simple datatype for a vector container of strings.
Definition: datatypes.h:212
Thrown when an unknown internal error occurred.
Definition: exception.h:116
Enables Fullscreen Anti-Aliasing level 4 for the window.
Definition: gamewindow.h:84
UInt32 ConvertToUInt32(const String &ToConvert)
Converts a string into a UInt32.
Definition: stringtool.cpp:456
void DestroyManager(EntresolManager *ToBeDestroyed)
Destroys a Manager created by this factory.
void CreateGLES2RenderSystem()
Creates the rendersystem and populates internal structures appropriately for use. ...
void CreateGLRenderSystem()
Creates the rendersystem and populates internal structures appropriately for use. ...
virtual void Deinitialize()
Removes this manager from any necessary configuration so it can be safely disposed of...
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
RenderSystem
Used primarily by the graphics manager class during initialization.
Enables Fullscreen Anti-Aliasing level 16 for the window.
Definition: gamewindow.h:86
SubSetVector::iterator SubSetIterator
Iterator type for ObjectSettingSet instances stored by this class.
StringVector SupportedDevices
A container of strings storing all the detected names of video devices on the current hardware...
ManagerType
A listing of Manager Types.
Definition: managerbase.h:65
Whole Height
The pixel height of the window.
Definition: resolution.h:66
void DestroyGLES2RenderSystem()
Shutsdown the rendersystem and removes it from internal structures.
static const String ImplementationName
A String containing the name of this manager implementation.
void CreateGL3PlusRenderSystem()
Creates the rendersystem and populates internal structures appropriately for use. ...
Removes all window decorations from the window(titlebar, borders, etc.).
Definition: gamewindow.h:89
GameWindow * GetGameWindow(const Whole &Index) const
Gets a game window by index.
void DestroyGameWindow(GameWindow *ToBeDestroyed)
Destroys a created game window by index.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Definition: exception.h:3048
This stores all the basic configuration options a game window supports.
Definition: resolution.h:57
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
A class that store's a named set of settings for an object.
void DestroyGLESRenderSystem()
Shutsdown the rendersystem and removes it from internal structures.
Threading::DefaultThreadSpecificStorage::Type * ThreadResources
Can be used for thread safe logging and other thread Specific resources.
Boole HasSDLBeenInitialized()
Gets whether or not SDL has been started.
void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
Threading::FrameScheduler & GetScheduler()
Gets the core structure responsible for scheduling work in the Entresol main loop.
Definition: entresol.cpp:495
This stores all the basic configuration options a game window supports.
void _Log(const T &Message)
Runtime event and message logging.
Definition: entresol.h:686
Ogre::RenderWindow * _GetOgreWindowPointer()
This will get a pointer to the Ogre RenderWindow.
Definition: gamewindow.cpp:580
void Trim(String &Source, Boole Left, Boole Right)
Trims all whitespaces and tabs from a one or both sides of a String.
Definition: stringtool.cpp:128
virtual String GetImplementationTypeName() const
This Allows any manager name to be sent to a stream. Primarily used for logging.
SubSetIterator SubSetEnd()
Gets an iterator to one passed the last subset of settings in this set.
static const ManagerBase::ManagerType InterfaceType
A ManagerType enum value used to describe the type of interface/functionality this manager provides...
virtual ~RenderWorkUnit()
virtual deconstructor
GameWindowContainer::iterator GameWindowIterator
Iterator type for GameWindow instances stored by this class.
virtual String GetObjectRootNodeName() const
Gets the name to be given to a Node with this handlers serialized data.
EntresolManager * CreateManager(const NameValuePairList &Params)
Creates a manager of the type represented by this factory.
GameWindowIterator BeginGameWindow()
Gets an iterator to the first GameWindow stored in this manager.
void CreateGLESRenderSystem()
Creates the rendersystem and populates internal structures appropriately for use. ...
A thread specific collection of double-buffered and algorithm specific resources. ...
Enables Fullscreen Anti-Aliasing level 2 for the window.
Definition: gamewindow.h:83
bool SetValue(const Char8 *rhs)
Set the value of this.
virtual ~DefaultGraphicsManagerFactory()
Class destructor.
const ResolutionContainer & GetSupportedResolutions() const
Gets a vector containing all the resolutions supported by this render system on the current hardware...
Boole AutoGenFiles
Stores whether or not this handler will attempt to automatically generate a file if it doesn't exist...
static Boole SingletonValid()
Checks to see if the singleton pointer is valid.
Definition: singleton.h:110
Integer ConvertToInteger(const String &ToConvert)
Converts a string into an Integer.
Definition: stringtool.cpp:400
This enables vsync for the window.
Definition: gamewindow.h:82
Viewport * CreateViewport(CameraProxy *ViewportCamera, const Integer ZOrder)
Creates an additional Viewport within a created render window.
Definition: gamewindow.cpp:201
static Entresol * GetSingletonPtr()
Fetches a pointer to the singleton.
Definition: singleton.h:97
This class is for creating and managing viewports within a game window.
Definition: viewport.h:65
Boole ConvertToBool(const String &ToConvert, const Boole Default)
Converts a string into a Boole.
Definition: stringtool.cpp:379
virtual void DoWork(Threading::DefaultThreadSpecificStorage::Type &CurrentThreadStorage)
This does any required update of the Graphical Scene graph and REnders one frame. ...
Whole Width
The pixel width of the window.
Definition: resolution.h:64
Real Y
Coordinate on the Y vector.
Definition: vector2.h:69
This is the base class for all managers that do no describe properties of a single world...
const StringVector & GetSupportedDevices() const
Gets a vector containing all the devices supported by this render system on the current hardware...
WindowSettings DesktopSettings
A struct storing the dimensions of the desktop on the current hardware.
This file contains the declaration for the World proxy wrapping camera functionality.
GameWindow * CreateGameWindow(const String &WindowCaption, const Whole &Width, const Whole &Height, const Whole &Flags)
Creates a new game window to be rendered to.
GameWindowContainer::const_iterator ConstGameWindowIterator
Const Iterator type for GameWindow instances stored by this class.
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
Real X
Coordinate on the X vector.
Definition: vector2.h:67
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
GameWindow * GetPrimaryGameWindow()
Gets the primary(first) game window.
This is used to represent a point on a 2 dimentional area, such as a screen.
Definition: vector2.h:63
String GetSettingValue(const String &SettingName) const
Gets a String representing the Value currently assigned to the existing setting.
virtual void RenderOneFrame()
Renders one frame of the scene.
void DestroyAllGameWindows(Boole ExcludePrimary=true)
Destroys every game window created.
virtual ~GraphicsManager()
Class Destructor.
Whole GetNumGameWindows() const
Gets the number of game windows within this manager.
void CreateD3D11RenderSystem()
Creates the rendersystem and populates internal structures appropriately for use. ...
Entresol * TheEntresol
The actual pointer to the Entresol core class.
Definition: managerbase.h:108
The defintion of the Resource Manager.
RenderWorkUnit * GetRenderWork()
Gets the work unit responsible for performing the graphics render of all scenes.
SubSetIterator SubSetBegin()
Gets an iterator to the first subset of settings in this set.
This enables fullscreen on the window.
Definition: gamewindow.h:80
ObjectSettingSet * GetChildObjectSettingSet(const String &Name, UInt16 Which=0) const
Gets a Sub-Set of this container by name.
std::list< NameValuePair > NameValuePairList
This is a datatype mostly used for describing settings or parameters that can't be declared in advanc...
Definition: datatypes.h:206
Thrown when the available information should have worked but failed for unknown reasons.
Definition: exception.h:113
ManagerBase::ManagerType GetManagerType() const
Gets the type of manager that is created by this factory.
String GetShortenedRenderSystemName(const Graphics::RenderSystem &RenderSys)
Gets a short hand name of the provided render system.
GameWindow * PrimaryGameWindow
A pointer to the hidden window storing the context and render resources.
This does the main loop processing for required to make the Graphics Manager function.
EntresolManager * GetManager(const Whole RetrieveType, UInt16 WhichOne=0)
This is will find the manager of a given type.
Definition: entresol.cpp:792
virtual void RemoveWorkUnitMonopoly(MonopolyWorkUnit *LessWork)
Remove a WorkUnit from the Monopoly pool of WorkUnits (and not from the Main or Affinity group)...
This hides the window so that it isn't visible.
Definition: gamewindow.h:81
Boole OgreBeenInitialized
Stores whether the internal graphics subsystem has been initialized.
Graphics::RenderSystem CurrRenderSys
A RenderSystem enum value storing the RenderSystem type currently in use.
void DestroyGL3PlusRenderSystem()
Shutsdown the rendersystem and removes it from internal structures.
GameWindowIterator EndGameWindow()
Gets an iterator to one passed the last GameWindow stored in this manager.
void SetRenderSystem(const Graphics::RenderSystem &RenderSys, Boole InitializeRenderSystem=false)
Sets the render system to be used.
String GetRenderSystemName(const Graphics::RenderSystem &RenderSys)
Gets the name of the provided render system.
void DestroyGLRenderSystem()
Shutsdown the rendersystem and removes it from internal structures.
Whole ConvertToWhole(const String &ToConvert)
Converts a string into an Whole.
Definition: stringtool.cpp:408
virtual void ApplySettingGroupImpl(ObjectSettingGroup *Group)
Applies all the settings stored by a ObjectSettingGroup.
This is intended to store basic graphics setting for the user.
virtual ManagerType GetInterfaceType() const
This returns the type of this manager.
void SaveAllSettings()
Saves all settings that need saving.
Graphics::RenderSystem GetCurrRenderSystem()
Gets the current rendersystem being used.
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
virtual void UseThreads(const Whole &AmountToUse)
Once The graphics is properly multithread, this will set the amount of threads it should use...
Whole RefreshRate
This stores the device refresh rate in Hz.
void InitOgreRenderSystem()
Initializes the internal graphics subsystem with the currently set configuration. ...
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
void DestroyD3D9RenderSystem()
Shutsdown the rendersystem and removes it from internal structures.
virtual Whole UsingThreadCount()
Get the amount of threads this will attempt to sue.
std::vector< Resolution > ResolutionContainer
Basic container type for storing the detected supported fullscreen resolutions on the current system...
String GetManagerImplName() const
Gets the name of the manager that is created by this factory.
const WindowSettings & GetDesktopSettings() const
Gets the desktop display settings.
void Construct()
Construct the manager and set sane defaults.
Resolution WinRes
This stores the Height and Width of the render window.
Boole HasOgreBeenInitialized()
Gets whether or not Ogre has been started.
RenderWorkUnit * RenderWork
The work unit that does all the rendering.
Enables Fullscreen Anti-Aliasing level 8 for the window.
Definition: gamewindow.h:85
virtual void SwapAllBuffers(Boole WaitForVsync)
Swaps all the buffers of all GameWindows.
Node AppendChild(NodeType Type=NodeElement)
Creates a Node and makes it a child of this one.
A class that store's a collection of SettingSets that can be applied together.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
Real ConvertToReal(const String &ToConvert)
Converts a string into a Real.
Definition: stringtool.cpp:392
This class is for creating and managing game windows.
Definition: gamewindow.h:63
void CreateD3D9RenderSystem()
Creates the rendersystem and populates internal structures appropriately for use. ...
virtual void Deinitialize()=0
Removes this manager from any necessary configuration so it can be safely disposed of...
virtual void Initialize()
Configures this manager for use prior to entering the main loop.
virtual void AppendCurrentSettings(XML::Node &SettingsRootNode)
Takes all the current settings of this handler and serializes them to an XML::Node.
Maximizes the window immediately after construction.
Definition: gamewindow.h:88
void DestroyD3D11RenderSystem()
Shutsdown the rendersystem and removes it from internal structures.
Boole Initialized
Simple Boole indicating whether or not this manager has been initialized.
Definition: managerbase.h:111
void SetDimensions(const Vector2 &Position, const Vector2 &Size)
Sets the position and size of this viewport within the game window.
Definition: viewport.cpp:111