MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
graphicsmanager.h
1 // © Copyright 2010 - 2014 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_h
41 #define _graphicsmanager_h
42 
44 #include "managerbase.h"
45 #include "managerfactory.h"
46 #include "singleton.h"
47 #include "Graphics/windowsettings.h"
48 #include "Graphics/graphicsenumerations.h"
49 #include "Graphics/gamewindow.h"
50 #include "objectsettings.h"
51 
52 namespace Ogre
53 {
54  class Timer;
55  class RenderWindow;
56  class Viewport;
57  class Plugin;
58 }
59 
60 struct SDL_Surface;
61 struct SDL_Window;
62 
63 namespace Mezzanine
64 {
65  namespace Graphics
66  {
67  // Used by the scripting language binder to help create bindgings for this class. SWIG does know to creation template instances
68  #ifdef SWIG
69  %template(SingletonGraphicsManager) Singleton<GraphicsManager>;
70  #endif
71 
72  class GraphicsManager;
73 
74  /// @brief This does the main loop processing for required to make the Graphics Manager function
76  {
77  private:
78  /// @internal
79  /// @brief The GraphicsManager this will work with
80  GraphicsManager* TargetManager;
81 
82  /// @internal
83  /// @brief Private copy constructor to prevent useless copying of this,
85 
86  /// @internal
87  /// @brief Private assignment operator to prevent useless assignment of this,
88  void operator=(RenderWorkUnit) {}
89 
90  public:
91  /// @brief Create a GraphicsWorkUnit
92  /// @param WhichGraphicsManager This is the Manager that this Work unit must work with.
94 
95  /// @brief virtual deconstructor
96  virtual ~RenderWorkUnit();
97 
98  /// @brief Once The graphics is properly multithread, this will set the amount of threads it should use
99  /// @param AmountToUse Currently Ignored.
100  virtual void UseThreads(const Whole& AmountToUse);
101 
102  /// @brief Get the amount of threads this will attempt to sue
103  /// @return 1, this will return 1 until this Ogre threading is implemented.
104  virtual Whole UsingThreadCount();
105 
106  /// @brief This does any required update of the Graphical Scene graph and REnders one frame
107  virtual void DoWork(Threading::DefaultThreadSpecificStorage::Type& CurrentThreadStorage);
108  };//RenderWorkUnit
109 
110  ///////////////////////////////////////////////////////////////////////////////
111  /// @class GraphicsManager
112  /// @headerfile graphicsmanager.h
113  /// @brief This is intended to store basic graphics setting for the user.
114  /// @details This stores x/y resolution, fullscreen and in the future other
115  /// settings. This is intended to make it easy for developers to pass/move around
116  /// complex graphics settings. We hope to eventually include other items like
117  /// shader settings, rendering API, and maybe other settings too.
118  ///////////////////////////////////////
120  {
121  public:
122  /// @brief Basic container type for @ref GameWindow storage by this class.
123  typedef std::vector<GameWindow*> GameWindowContainer;
124  /// @brief Iterator type for @ref GameWindow instances stored by this class.
125  typedef GameWindowContainer::iterator GameWindowIterator;
126  /// @brief Const Iterator type for @ref GameWindow instances stored by this class.
127  typedef GameWindowContainer::const_iterator ConstGameWindowIterator;
128  /// @brief Basic container type for internal plugin storage by this class.
129  typedef std::vector<Ogre::Plugin*> InternalPluginContainer;
130  /// @brief Basic container type for registered rendersystem type storage by this class.
131  typedef std::vector<RenderSystem> RenderSystemTypeContainer;
132  protected:
133  /// @internal
134  /// @brief The RenderWorkUnit really is an extension of the GraphicsManager, it just exists as a Functor for the sake of simplicity.
135  friend class RenderWorkUnit;
136  /// @internal
137  /// @brief Track all statically linked Ogre render systems, usually only one, but could be many.
138  InternalPluginContainer RenderSystems;
139  /// @internal
140  /// @brief A listing of the types of rendersystems Types that correspond to the entry in @ref RenderSystems.
141  RenderSystemTypeContainer RenderSystemTypes;
142  /// @internal
143  /// @brief A container storing all the game windows created by this manager.
144  GameWindowContainer GameWindows;
145  /// @internal
146  /// @brief A container of strings storing all the detected supported resolutions on the current hardware.
148  /// @internal
149  /// @brief A container of strings storing all the detected names of video devices on the current hardware.
151  /// @internal
152  /// @brief A struct storing the dimensions of the desktop on the current hardware.
154  /// @internal
155  /// @brief A pointer to the hidden window storing the context and render resources.
157 
158  /// @internal
159  /// @brief The work unit that does all the rendering.
161  /// @internal
162  /// @brief Can be used for thread safe logging and other thread Specific resources.
164 
165  /// @internal
166  /// @brief A RenderSystem enum value storing the RenderSystem type currently in use.
168  /// @internal
169  /// @brief Stores whether the internal graphics subsystem has been initialized.
171 
172  /// @internal
173  /// @brief Construct the manager and set sane defaults.
174  void Construct();
175  /// @internal
176  /// @brief Initializes the internal graphics subsystem with the currently set configuration.
177  void InitOgreRenderSystem();
178  /// @copydoc ObjectSettingsHandler::GetObjectRootNodeName() const
179  virtual String GetObjectRootNodeName() const;
180  /// @copydoc ObjectSettingsHandler::AppendCurrentSettings(XML::Node&)
181  virtual void AppendCurrentSettings(XML::Node& SettingsRootNode);
182  /// @copydoc ObjectSettingsHandler::ApplySettingGroupImpl(ObjectSettingGroup*)
183  virtual void ApplySettingGroupImpl(ObjectSettingGroup* Group);
184  public:
185  /// @brief Basic constructor
186  /// @details This creates a basic Graphics Settings with resolution 640x480 with fullscreen set to false
187  GraphicsManager();
188  /// @brief XML constructor.
189  /// @param XMLNode The node of the xml document to construct from.
190  GraphicsManager(XML::Node& XMLNode);
191  /// @brief Class Destructor.
192  virtual ~GraphicsManager();
193 
194  ///////////////////////////////////////////////////////////////////////////////
195  // Window Management
196 
197  /// @brief Creates a new game window to be rendered to.
198  /// @param WindowCaption The caption to be set in the window titlebar.
199  /// @param Width The desired width in pixels.
200  /// @param Height The desired height in pixels.
201  /// @param Flags Additional misc parameters, see GameWindow class for more info.
202  /// @return Returns a pointer to the created window.
203  GameWindow* CreateGameWindow(const String& WindowCaption, const Whole& Width, const Whole& Height, const Whole& Flags);
204  /// @brief Gets a game window by index.
205  /// @param Index The index of the window to retrieve.
206  /// @return Returns a pointer to the game window at the specified index.
207  GameWindow* GetGameWindow(const Whole& Index) const;
208  /// @brief Gets a game window by it's caption text.
209  /// @note If multiple windows have the same caption, the first one found will be returned.
210  /// @param Caption The caption of the window to retrieve.
211  /// @return Returns a pointer to the game window with the specified caption, or NULL if no game windows with that caption exist.
212  GameWindow* GetGameWindow(const String& Caption) const;
213  /// @brief Gets the number of game windows within this manager.
214  /// @return Returns a Whole representing the number of game windows within this manager.
215  Whole GetNumGameWindows() const;
216  /// @brief Destroys a created game window by index.
217  /// @param WindowIndex The index of the window to be destroyed.
218  void DestroyGameWindow(GameWindow* ToBeDestroyed);
219  /// @brief Destroys every game window created.
220  /// @param ExcludePrimary Whether or not you want to spare the primary window created.
221  void DestroyAllGameWindows(bool ExcludePrimary = true);
222  /// @brief Gets the primary(first) game window.
223  /// @return Returns a pointer to the primary game window.
224  GameWindow* GetPrimaryGameWindow();
225 
226  /// @brief Gets an iterator to the first GameWindow stored in this manager.
227  GameWindowIterator BeginGameWindow();
228  /// @brief Gets an iterator to one passed the last GameWindow stored in this manager.
229  GameWindowIterator EndGameWindow();
230  /// @brief Gets a const iterator to the first GameWindow stored in this manager.
231  ConstGameWindowIterator BeginGameWindow() const;
232  /// @brief Gets a const iterator to one passed the last GameWindow stored in this manager.
233  ConstGameWindowIterator EndGameWindow() const;
234 
235  ///////////////////////////////////////////////////////////////////////////////
236  // RenderSystem Management
237 
238  /// @brief Sets the render system to be used.
239  /// @remarks This will only work prior to a window being created/graphics manager being initialized. The internal structures to be built need
240  /// to know what rendersystem to build for. Additionally this cannot be swapped/changed at runtime. If called after a window has been made this will throw an exception.
241  /// @param RenderSys The Render system to be used.
242  /// @param InitializeRenderSystem Whether to immediately initialize the rendersystem afterwords.
243  void SetRenderSystem(const Graphics::RenderSystem& RenderSys, bool InitializeRenderSystem = false);
244  /// @brief Gets the current rendersystem being used.
245  /// @remarks This does not return a pointer or any other kind of accessor to the actual rendersystem structure. If you need that, then we're doing something wrong.
246  /// @return Returns an enum value coresponding to the render system being used.
247  Graphics::RenderSystem GetCurrRenderSystem();
248  /// @brief Gets the name of the provided render system.
249  /// @param RenderSys The rendersystem to get the name of.
250  /// @return Returns a string containing the name of the provided render system.
251  String GetRenderSystemName(const Graphics::RenderSystem& RenderSys);
252  /// @brief Gets a short hand name of the provided render system.
253  /// @param RenderSys The rendersystem to get the name of.
254  /// @return Returns a string containing the shortened name of the provided render system.
255  String GetShortenedRenderSystemName(const Graphics::RenderSystem& RenderSys);
256 
257  ///////////////////////////////////////////////////////////////////////////////
258  // Query Methods
259 
260  /// @brief Gets a vector containing all the resolutions supported by this render system on the current hardware.
261  /// @details This vector is populated when the manager gets initialized. Calling on it before then will give you an empty vector.
262  /// @return Returns a Const Pointer to the vector storing all the supported resolutions.
263  const StringVector* GetSupportedResolutions();
264  /// @brief Gets a vector containing all the devices supported by this render system on the current hardware.
265  /// @details This vector is populated when the manager gets initialized. Calling on it before then will give you an empty vector.
266  /// @return Returns a Const Pointer to the vector storing all the supported devices.
267  const StringVector* GetSupportedDevices();
268  /// @brief Gets the desktop display settings.
269  /// @param Returns a WindowSettings struct with the desktop display settings.
270  const WindowSettings& GetDesktopSettings();
271 
272  ///////////////////////////////////////////////////////////////////////////////
273  // Utility Methods
274 
275  /// @brief Renders one frame of the scene.
276  virtual void RenderOneFrame();
277  /// @brief Swaps all the buffers of all GameWindows.
278  /// @param WaitForVsync Whether or not the buffer should swap after the vsync interval is completed.
279  virtual void SwapAllBuffers(bool WaitForVsync);
280 
281  /// @copydoc ManagerBase::Initialize()
282  /// @details Added a GraphicWorkUnit to the WorkScheduler on the Entresol as a
283  /// Monopoly, Initializes the Render device and rendering system if that has
284  /// not already been done, if configured to will save all graphics configuration
285  /// files.
286  virtual void Initialize();
287  /// @copydoc ManagerBase::Deinitialize()
288  virtual void Deinitialize();
289 
290  /// @brief Gets the work unit responsible for performing the graphics render of all scenes.
291  /// @return Returns a pointer to the RenderWorkUnit being used by this manager.
292  RenderWorkUnit* GetRenderWork();
293 
294  ///////////////////////////////////////////////////////////////////////////////
295  // SubSystem Initialization
296 
297  /// @brief Gets whether or not SDL has been started.
298  /// @return Returns a bool indicating whether or not SDL has been initialized yet.
299  bool HasSDLBeenInitialized();
300  /// @brief Gets whether or not Ogre has been started.
301  /// @return Returns a bool indicating whether or not Ogre has been initialized yet.
302  bool HasOgreBeenInitialized();
303 
304  ///////////////////////////////////////////////////////////////////////////////
305  // Type Identifier Methods
306 
307  /// @copydoc ManagerBase::GetInterfaceType()
308  virtual ManagerType GetInterfaceType() const;
309  /// @copydoc ManagerBase::GetImplementationTypeName()
310  virtual String GetImplementationTypeName() const;
311  };//GraphicsManager
312 
313  ///////////////////////////////////////////////////////////////////////////////
314  /// @class DefaultGraphicsManagerFactory
315  /// @headerfile graphicsmanager.h
316  /// @brief A factory responsible for the creation and destruction of the default graphicsmanager.
317  ///////////////////////////////////////
319  {
320  public:
321  /// @brief Class constructor.
323  /// @brief Class destructor.
325 
326  /// @copydoc ManagerFactory::GetManagerTypeName()
327  String GetManagerTypeName() const;
328 
329  /// @copydoc ManagerFactory::CreateManager(NameValuePairList&)
330  ManagerBase* CreateManager(NameValuePairList& Params);
331  /// @copydoc ManagerFactory::CreateManager(XML::Node&)
332  ManagerBase* CreateManager(XML::Node& XMLNode);
333  /// @copydoc ManagerFactory::DestroyManager(ManagerBase*)
334  void DestroyManager(ManagerBase* ToBeDestroyed);
335  }; // DefaultGraphicsManagerFactory
336  } // Graphics namespace
337 } // Mezzanine
338 #endif