40 #ifndef _graphicsmanager_cpp
41 #define _graphicsmanager_cpp
43 #include "Graphics/graphicsmanager.h"
44 #include "Graphics/texturemanager.h"
46 #include "Graphics/viewport.h"
50 #include "UI/uimanager.h"
52 #include "eventmanager.h"
53 #include "crossplatform.h"
54 #include "stringtool.h"
60 #ifdef MEZZ_BUILD_DIRECTX9_SUPPORT
61 #include "d3d9rendersyshelper.h.cpp"
63 #ifdef MEZZ_BUILD_DIRECTX11_SUPPORT
64 #include "d3d11rendersyshelper.h.cpp"
66 #ifdef MEZZ_BUILD_OPENGL_SUPPORT
67 #include "oglrendersyshelper.h.cpp"
69 #ifdef MEZZ_BUILD_OPENGL3PLUS_SUPPORT
70 #include "ogl3plusrendersyshelper.h.cpp"
72 #ifdef MEZZ_BUILD_OPENGLES_SUPPORT
73 #include "oglesrendersyshelper.h.cpp"
75 #ifdef MEZZ_BUILD_OPENGLES2_SUPPORT
76 #include "ogles2rendersyshelper.h.cpp"
84 template<> Graphics::GraphicsManager* Singleton<Graphics::GraphicsManager>::SingletonPtr = NULL;
112 Ogre::WindowEventUtilities::messagePump();
125 PrimaryGameWindow(NULL),
127 ThreadResources(NULL),
128 CurrRenderSys(Graphics::RS_OpenGL2),
129 OgreBeenInitialized(false)
136 PrimaryGameWindow(NULL),
138 ThreadResources(NULL),
139 CurrRenderSys(Graphics::RS_OpenGL2),
140 OgreBeenInitialized(false)
158 #ifdef MEZZ_BUILD_DIRECTX9_SUPPORT
161 #ifdef MEZZ_BUILD_DIRECTX11_SUPPORT
164 #ifdef MEZZ_BUILD_OPENGL_SUPPORT
167 #ifdef MEZZ_BUILD_OPENGL3PLUS_SUPPORT
170 #ifdef MEZZ_BUILD_OPENGLES_SUPPORT
173 #ifdef MEZZ_BUILD_OPENGLES2_SUPPORT
190 UInt32 InitSDLSystems = SDL_WasInit(0);
191 if( (SDL_INIT_VIDEO & InitSDLSystems) == 0 ) {
192 if( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0 ) {
197 SDL_DisplayMode DeskMode;
198 SDL_GetDesktopDisplayMode(0,&DeskMode);
203 #ifdef MEZZ_BUILD_DIRECTX9_SUPPORT
206 #ifdef MEZZ_BUILD_DIRECTX11_SUPPORT
209 #ifdef MEZZ_BUILD_OPENGL_SUPPORT
212 #ifdef MEZZ_BUILD_OPENGL3PLUS_SUPPORT
215 #ifdef MEZZ_BUILD_OPENGLES_SUPPORT
218 #ifdef MEZZ_BUILD_OPENGLES2_SUPPORT
226 Ogre::Root* OgreCore = Ogre::Root::getSingletonPtr();
227 const Ogre::RenderSystemList& RSList = OgreCore->getAvailableRenderers();
228 if( RSList.size() == 1 ) {
230 OgreCore->setRenderSystem( RSList[0] );
233 OgreCore->setRenderSystem( OgreCore->getRenderSystemByName( this->GetRenderSystemName( this->CurrRenderSys ) ) );
236 OgreCore->initialise(
false,
"");
246 return "DefaultGraphicsManagerSettings";
258 { (*WinIt)->ProtoSerialize(CurrentSettings); }
266 if(
"RenderSystem" == (*SubSetIt)->GetName() ) {
268 CurrSettingValue = (*SubSetIt)->GetSettingValue(
"Name");
270 RenderSys = Graphics::RS_DirectX9;
272 RenderSys = Graphics::RS_DirectX11;
274 RenderSys = Graphics::RS_OpenGL2;
276 RenderSys = Graphics::RS_OpenGLES1;
278 RenderSys = Graphics::RS_OpenGLES2;
287 "These Settings will be applied the next time settings are loaded during manager construction if current settings are saved.");
290 else if(
"GameWindow" == (*SubSetIt)->GetName() )
293 String WinCaption(
"Mezzanine Window");
294 Whole WinWidth = 800;
295 Whole WinHeight = 600;
299 if( PropertiesSet != NULL ) {
302 if(!CurrSettingValue.empty())
303 WinCaption = CurrSettingValue;
306 if(!CurrSettingValue.empty())
310 if(!CurrSettingValue.empty())
314 if(!CurrSettingValue.empty()) {
320 if(!CurrSettingValue.empty()) {
326 if(!CurrSettingValue.empty()) {
332 if(!CurrSettingValue.empty()) {
338 if(!CurrSettingValue.empty()) {
344 if(!CurrSettingValue.empty()) {
350 if(!CurrSettingValue.empty()) {
368 CurrWindow = this->
CreateGameWindow(WinCaption,WinWidth,WinHeight,WinFlags);
372 if( ViewportsSet != NULL && CurrWindow != NULL ) {
375 if(
"Viewport" == (*VPIt)->GetName() ) {
380 CurrSettingValue = (*VPIt)->GetSettingValue(
"ZOrder");
381 if( !CurrSettingValue.empty() ) {
386 if( PositionSet != NULL ) {
390 if( !CurrSettingValue.empty() ) {
394 if( !CurrSettingValue.empty() ) {
400 if( SizeSet != NULL ) {
404 if( !CurrSettingValue.empty() ) {
408 if( !CurrSettingValue.empty() ) {
444 if( (*WinIt)->GetWindowCaption() == Caption ) {
460 if( ToBeDestroyed == (*it) ) {
461 delete ToBeDestroyed;
474 if(!ExcludePrimary) {
513 if( InitializeRenderSystem )
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;
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;
576 Ogre::Root::getSingleton().renderOneFrame();
579 Ogre::Root::getSingleton().clearEventTimes();
608 Ogre::ConfigOptionMap& CurrentRendererOptions = Ogre::Root::getSingleton().getRenderSystem()->getConfigOptions();
609 for( Ogre::ConfigOptionMap::iterator configItr = CurrentRendererOptions.begin() ; configItr != CurrentRendererOptions.end() ; configItr++ )
611 if( (configItr)->first ==
"Video Mode" ) {
612 for(
Whole X = 0 ; X < (configItr)->second.possibleValues.size() ; X++ )
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);
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] ); }
666 return SDL_WasInit(SDL_INIT_VIDEO);
719 {
delete ToBeDestroyed; }
Creates a window with resizable borders, otherwise it is fixed size.
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.
Thrown when an unknown internal error occurred.
Enables Fullscreen Anti-Aliasing level 4 for the window.
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.
RenderSystem
Used primarily by the graphics manager class during initialization.
Enables Fullscreen Anti-Aliasing level 16 for the window.
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.
Whole Height
The pixel height of the window.
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.).
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.
This stores all the basic configuration options a game window supports.
int Integer
A datatype used to represent any integer close to.
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.
This stores all the basic configuration options a game window supports.
void _Log(const T &Message)
Runtime event and message logging.
Ogre::RenderWindow * _GetOgreWindowPointer()
This will get a pointer to the Ogre RenderWindow.
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.
DefaultGraphicsManagerFactory()
Class constructor.
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.
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.
This enables vsync for the window.
Viewport * CreateViewport(CameraProxy *ViewportCamera, const Integer ZOrder)
Creates an additional Viewport within a created render window.
static Entresol * GetSingletonPtr()
Fetches a pointer to the singleton.
This class is for creating and managing viewports within a game window.
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.
Real Y
Coordinate on the Y vector.
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.
GraphicsManager()
Basic constructor.
GameWindowContainer::const_iterator ConstGameWindowIterator
Const Iterator type for GameWindow instances stored by this class.
A light-weight handle for manipulating nodes in DOM tree.
Real X
Coordinate on the X vector.
uint32_t UInt32
An 32-bit unsigned integer.
GameWindow * GetPrimaryGameWindow()
Gets the primary(first) game window.
This is used to represent a point on a 2 dimentional area, such as a screen.
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.
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.
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...
Thrown when the available information should have worked but failed for unknown reasons.
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.
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.
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.
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.
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.
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.
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.
This class is for creating and managing game windows.
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.
void DestroyD3D11RenderSystem()
Shutsdown the rendersystem and removes it from internal structures.
Boole Initialized
Simple Boole indicating whether or not this manager has been initialized.
void SetDimensions(const Vector2 &Position, const Vector2 &Size)
Sets the position and size of this viewport within the game window.