Spinning Topp Logo BlackTopp Studios
inc
graphicsmanager.h
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_h
41 #define _graphicsmanager_h
42 
44 #include "entresolmanager.h"
45 #include "entresolmanagerfactory.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 storing the detected supported fullscreen resolutions on the current system.
129  typedef std::vector<Resolution> ResolutionContainer;
130  /// @brief Iterator type for stored supported resolutions.
131  typedef ResolutionContainer::iterator ResolutionIterator;
132  /// @brief Const Iterator type for stored supported resolutions.
133  typedef ResolutionContainer::const_iterator ConstResolutionIterator;
134  /// @brief Basic container type for registered rendersystem type storage by this class.
135  typedef std::vector<RenderSystem> RenderSystemTypeContainer;
136 
137  /// @brief A String containing the name of this manager implementation.
139  /// @brief A ManagerType enum value used to describe the type of interface/functionality this manager provides.
141  protected:
142  /// @internal
143  /// @brief The RenderWorkUnit really is an extension of the GraphicsManager, it just exists as a Functor for the sake of simplicity.
144  friend class RenderWorkUnit;
145  /// @internal
146  /// @brief A container storing all the game windows created by this manager.
147  GameWindowContainer GameWindows;
148  /// @internal
149  /// @brief A container of strings storing all the detected supported resolutions on the current hardware.
150  ResolutionContainer SupportedResolutions;
151  /// @internal
152  /// @brief A container of strings storing all the detected names of video devices on the current hardware.
154  /// @internal
155  /// @brief A struct storing the dimensions of the desktop on the current hardware.
157  /// @internal
158  /// @brief A pointer to the hidden window storing the context and render resources.
160 
161  /// @internal
162  /// @brief The work unit that does all the rendering.
164  /// @internal
165  /// @brief Can be used for thread safe logging and other thread Specific resources.
167 
168  /// @internal
169  /// @brief A RenderSystem enum value storing the RenderSystem type currently in use.
171  /// @internal
172  /// @brief Stores whether the internal graphics subsystem has been initialized.
174 
175  /// @internal
176  /// @brief Construct the manager and set sane defaults.
177  void Construct();
178  /// @internal
179  /// @brief Initializes the internal graphics subsystem with the currently set configuration.
180  void InitOgreRenderSystem();
181  /// @copydoc ObjectSettingsHandler::GetObjectRootNodeName() const
182  virtual String GetObjectRootNodeName() const;
183  /// @copydoc ObjectSettingsHandler::AppendCurrentSettings(XML::Node&)
184  virtual void AppendCurrentSettings(XML::Node& SettingsRootNode);
185  /// @copydoc ObjectSettingsHandler::ApplySettingGroupImpl(ObjectSettingGroup*)
186  virtual void ApplySettingGroupImpl(ObjectSettingGroup* Group);
187  public:
188  /// @brief Basic constructor.
189  /// @details This creates a basic Graphics Settings with resolution 640x480 with fullscreen set to false.
190  GraphicsManager();
191  /// @brief XML constructor.
192  /// @param XMLNode The node of the xml document to construct from.
193  GraphicsManager(const XML::Node& XMLNode);
194  /// @brief Class Destructor.
195  virtual ~GraphicsManager();
196 
197  ///////////////////////////////////////////////////////////////////////////////
198  // Window Management
199 
200  /// @brief Creates a new game window to be rendered to.
201  /// @param WindowCaption The caption to be set in the window titlebar.
202  /// @param Width The desired width in pixels.
203  /// @param Height The desired height in pixels.
204  /// @param Flags Additional misc parameters, see GameWindow class for more info.
205  /// @return Returns a pointer to the created window.
206  GameWindow* CreateGameWindow(const String& WindowCaption, const Whole& Width, const Whole& Height, const Whole& Flags);
207  /// @brief Gets a game window by index.
208  /// @param Index The index of the window to retrieve.
209  /// @return Returns a pointer to the game window at the specified index.
210  GameWindow* GetGameWindow(const Whole& Index) const;
211  /// @brief Gets a game window by it's caption text.
212  /// @note If multiple windows have the same caption, the first one found will be returned.
213  /// @param Caption The caption of the window to retrieve.
214  /// @return Returns a pointer to the game window with the specified caption, or NULL if no game windows with that caption exist.
215  GameWindow* GetGameWindow(const String& Caption) const;
216  /// @brief Gets the number of game windows within this manager.
217  /// @return Returns a Whole representing the number of game windows within this manager.
218  Whole GetNumGameWindows() const;
219  /// @brief Destroys a created game window by index.
220  /// @param WindowIndex The index of the window to be destroyed.
221  void DestroyGameWindow(GameWindow* ToBeDestroyed);
222  /// @brief Destroys every game window created.
223  /// @param ExcludePrimary Whether or not you want to spare the primary window created.
224  void DestroyAllGameWindows(Boole ExcludePrimary = true);
225  /// @brief Gets the primary(first) game window.
226  /// @return Returns a pointer to the primary game window.
227  GameWindow* GetPrimaryGameWindow();
228 
229  /// @brief Gets an iterator to the first GameWindow stored in this manager.
230  GameWindowIterator BeginGameWindow();
231  /// @brief Gets an iterator to one passed the last GameWindow stored in this manager.
232  GameWindowIterator EndGameWindow();
233  /// @brief Gets a const iterator to the first GameWindow stored in this manager.
234  ConstGameWindowIterator BeginGameWindow() const;
235  /// @brief Gets a const iterator to one passed the last GameWindow stored in this manager.
236  ConstGameWindowIterator EndGameWindow() const;
237 
238  ///////////////////////////////////////////////////////////////////////////////
239  // RenderSystem Management
240 
241  /// @brief Sets the render system to be used.
242  /// @remarks This will only work prior to a window being created/graphics manager being initialized. The internal structures to be built need
243  /// 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.
244  /// @param RenderSys The Render system to be used.
245  /// @param InitializeRenderSystem Whether to immediately initialize the rendersystem afterwords.
246  void SetRenderSystem(const Graphics::RenderSystem& RenderSys, Boole InitializeRenderSystem = false);
247  /// @brief Gets the current rendersystem being used.
248  /// @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.
249  /// @return Returns an enum value coresponding to the render system being used.
250  Graphics::RenderSystem GetCurrRenderSystem();
251  /// @brief Gets the name of the provided render system.
252  /// @param RenderSys The rendersystem to get the name of.
253  /// @return Returns a string containing the name of the provided render system.
254  String GetRenderSystemName(const Graphics::RenderSystem& RenderSys);
255  /// @brief Gets a short hand name of the provided render system.
256  /// @param RenderSys The rendersystem to get the name of.
257  /// @return Returns a string containing the shortened name of the provided render system.
258  String GetShortenedRenderSystemName(const Graphics::RenderSystem& RenderSys);
259 
260  ///////////////////////////////////////////////////////////////////////////////
261  // Query Methods
262 
263  /// @brief Gets a vector containing all the resolutions supported by this render system on the current hardware.
264  /// @details This vector is populated when the manager gets initialized. Calling on it before then will give you an empty vector.
265  /// @return Returns a Const Pointer to the vector storing all the supported resolutions.
266  const ResolutionContainer& GetSupportedResolutions() const;
267  /// @brief Gets a vector containing all the devices supported by this render system on the current hardware.
268  /// @details This vector is populated when the manager gets initialized. Calling on it before then will give you an empty vector.
269  /// @return Returns a Const Pointer to the vector storing all the supported devices.
270  const StringVector& GetSupportedDevices() const;
271  /// @brief Gets the desktop display settings.
272  /// @param Returns a WindowSettings struct with the desktop display settings.
273  const WindowSettings& GetDesktopSettings() const;
274 
275  ///////////////////////////////////////////////////////////////////////////////
276  // Utility Methods
277 
278  /// @brief Renders one frame of the scene.
279  virtual void RenderOneFrame();
280  /// @brief Swaps all the buffers of all GameWindows.
281  /// @param WaitForVsync Whether or not the buffer should swap after the vsync interval is completed.
282  virtual void SwapAllBuffers(Boole WaitForVsync);
283 
284  /// @copydoc ManagerBase::Initialize()
285  /// @details Added a GraphicWorkUnit to the WorkScheduler on the Entresol as a
286  /// Monopoly, Initializes the Render device and rendering system if that has
287  /// not already been done, if configured to will save all graphics configuration
288  /// files.
289  virtual void Initialize();
290  /// @copydoc ManagerBase::Deinitialize()
291  virtual void Deinitialize();
292 
293  /// @brief Gets the work unit responsible for performing the graphics render of all scenes.
294  /// @return Returns a pointer to the RenderWorkUnit being used by this manager.
295  RenderWorkUnit* GetRenderWork();
296 
297  ///////////////////////////////////////////////////////////////////////////////
298  // SubSystem Initialization
299 
300  /// @brief Gets whether or not SDL has been started.
301  /// @return Returns a Boole indicating whether or not SDL has been initialized yet.
302  Boole HasSDLBeenInitialized();
303  /// @brief Gets whether or not Ogre has been started.
304  /// @return Returns a Boole indicating whether or not Ogre has been initialized yet.
305  Boole HasOgreBeenInitialized();
306 
307  ///////////////////////////////////////////////////////////////////////////////
308  // Type Identifier Methods
309 
310  /// @copydoc ManagerBase::GetInterfaceType()
311  virtual ManagerType GetInterfaceType() const;
312  /// @copydoc ManagerBase::GetImplementationTypeName()
313  virtual String GetImplementationTypeName() const;
314  };//GraphicsManager
315 
316  ///////////////////////////////////////////////////////////////////////////////
317  /// @class DefaultGraphicsManagerFactory
318  /// @headerfile graphicsmanager.h
319  /// @brief A factory responsible for the creation and destruction of the default graphicsmanager.
320  ///////////////////////////////////////
322  {
323  public:
324  /// @brief Class constructor.
326  /// @brief Class destructor.
328 
329  /// @copydoc ManagerFactory::GetManagerImplName()
330  String GetManagerImplName() const;
331  /// @copydoc ManagerFactory::GetManagerType() const
332  ManagerBase::ManagerType GetManagerType() const;
333 
334  /// @copydoc EntresolManagerFactory::CreateManager(const NameValuePairList&)
335  EntresolManager* CreateManager(const NameValuePairList& Params);
336  /// @copydoc EntresolManagerFactory::CreateManager(const XML::Node&)
337  EntresolManager* CreateManager(const XML::Node& XMLNode);
338  /// @copydoc EntresolManagerFactory::DestroyManager(EntresolManager*)
339  void DestroyManager(EntresolManager* ToBeDestroyed);
340  }; // DefaultGraphicsManagerFactory
341  } // Graphics namespace
342 } // Mezzanine
343 #endif
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
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
RenderSystem
Used primarily by the graphics manager class during initialization.
ResolutionContainer::const_iterator ConstResolutionIterator
Const Iterator type for stored supported resolutions.
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
static const String ImplementationName
A String containing the name of this manager implementation.
This is a base class for factories that construct managers used by the Entresol class.
Threading::DefaultThreadSpecificStorage::Type * ThreadResources
Can be used for thread safe logging and other thread Specific resources.
A factory responsible for the creation and destruction of the default graphicsmanager.
ResolutionContainer::iterator ResolutionIterator
Iterator type for stored supported resolutions.
This stores all the basic configuration options a game window supports.
std::vector< GameWindow * > GameWindowContainer
Basic container type for GameWindow storage by this class.
static const ManagerBase::ManagerType InterfaceType
A ManagerType enum value used to describe the type of interface/functionality this manager provides...
An abstract class for other classes that manage groups of settings.
GameWindowContainer::iterator GameWindowIterator
Iterator type for GameWindow instances stored by this class.
std::vector< RenderSystem > RenderSystemTypeContainer
Basic container type for registered rendersystem type storage by this class.
A kind of workunit given exclusive runtime so it can consume time on multiple threads.
Definition: monopoly.h:62
A thread specific collection of double-buffered and algorithm specific resources. ...
This is the base class for all managers that do no describe properties of a single world...
WindowSettings DesktopSettings
A struct storing the dimensions of the desktop on the current hardware.
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
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
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.
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.
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
This is intended to store basic graphics setting for the user.
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
std::vector< Resolution > ResolutionContainer
Basic container type for storing the detected supported fullscreen resolutions on the current system...
This is the file that code using this library should include. It includes all the required components...
RenderWorkUnit * RenderWork
The work unit that does all the rendering.
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
This class is for creating and managing game windows.
Definition: gamewindow.h:63