Skip to content
Snippets Groups Projects
Commit 341cbce9 authored by Oliver Bock's avatar Oliver Bock
Browse files

Added new factory for graphics engines.

* Support for flexible requests of engine and specific science app support
* Could easily be passed as command line parameter for instance
parent 7eb950de
No related branches found
No related tags found
No related merge requests found
#include "GraphicsEngineFactory.h"
GraphicsEngineFactory::~GraphicsEngineFactory()
{
}
GraphicsEngineFactory::GraphicsEngineFactory()
{
}
AbstractGraphicsEngine * GraphicsEngineFactory::createInstance(
GraphicsEngineFactory::Engines engine,
GraphicsEngineFactory::Applications application)
{
switch(engine) {
case Starsphere:
switch(application) {
case EinsteinS5R3:
return new StarsphereS5R3();
break;
default:
return NULL;
}
break;
default:
return NULL;
}
}
#ifndef GRAPHICSENGINEFACTORY_H_
#define GRAPHICSENGINEFACTORY_H_
#include "AbstractGraphicsEngine.h"
#include "StarsphereS5R3.h"
/**
* \brief Factory to create graphics engines
*
* \author Oliver Bock\n
* Max-Planck-Institute for Gravitational Physics\n
* Hannover, Germany
*/
class GraphicsEngineFactory
{
public:
virtual ~GraphicsEngineFactory();
/// Identifiers of supported graphics engines
enum Engines {
Starsphere = 1
};
/// Identifiers of supported science applications
enum Applications {
EinsteinS5R3 = 53
};
/**
* \brief Instaniates a new graphics engine
*
* Use this method to create a new grahics engine instance. However, please make
* that you use only sensible combinations of \c engine and \c application (you
* should know them).
*
* \param engine The identifier of the requested graphics engine
* \param application The identifier of the requested science application support
*
* \return The pointer to the new engine instance
*
* \see Engines
* \see Applications
*/
static AbstractGraphicsEngine * createInstance(Engines engine, Applications application);
private:
// Contructor (private since this a purely static factory)
GraphicsEngineFactory();
};
#endif /*GRAPHICSENGINEFACTORY_H_*/
......@@ -31,7 +31,8 @@
#include "WindowManager.h"
#include "ResourceFactory.h"
#include "Starsphere.h"
#include "AbstractGraphicsEngine.h"
#include "GraphicsEngineFactory.h"
using namespace std;
......@@ -41,10 +42,19 @@ int main(int argc, char **argv)
// prepare main objects
WindowManager window;
ResourceFactory factory;
Starsphere graphics;
AbstractGraphicsEngine *graphics = GraphicsEngineFactory::createInstance(
GraphicsEngineFactory::Starsphere,
GraphicsEngineFactory::EinsteinS5R3);
if(!graphics) {
cerr << "Requested graphics engine could not be found/instantiated!" << endl;
exit(1);
}
// initialize window manager
if(!window.initialize()) {
cerr << "Window manager could not be initialized!" << endl;
delete graphics;
exit(1);
}
......@@ -53,11 +63,13 @@ int main(int argc, char **argv)
if(fontResource == NULL) {
cerr << "Font resource could not be loaded!" << endl;
delete graphics;
exit(1);
}
if(fontResource->data()->size() <= 0) {
cerr << "Font resource could not be loaded!" << endl;
delete graphics;
delete fontResource;
exit(1);
}
......@@ -65,7 +77,7 @@ int main(int argc, char **argv)
window.setWindowCaption("Einstein@Home");
// register starsphere as event observer
window.registerEventObserver(&graphics);
window.registerEventObserver(graphics);
#ifdef NDEBUG
// switch to fullscreen when in release mode
......@@ -73,14 +85,15 @@ int main(int argc, char **argv)
#endif
// pepare rendering
graphics.initialize(window.windowWidth(), window.windowHeight(), fontResource);
graphics.refreshBOINCInformation();
graphics->initialize(window.windowWidth(), window.windowHeight(), fontResource);
graphics->refreshBOINCInformation();
// enter main event loop
window.eventLoop();
// clean up end exit
window.unregisterEventObserver(&graphics);
window.unregisterEventObserver(graphics);
delete graphics;
delete fontResource;
exit(0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment