Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/graphics_engine.cc @ 6976

Last change on this file since 6976 was 6976, checked in by patrick, 18 years ago

trunk: the graphicsengine is now loadable

File size: 19.1 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
17
18#include "graphics_engine.h"
19#include "resource_manager.h"
20#include "event_handler.h"
21#include "state.h"
22
23#include "world_entity.h"
24
25#include "render_2d.h"
26#include "text_engine.h"
27#include "light.h"
28#include "shader.h"
29#include "debug.h"
30
31#include "parser/ini_parser/ini_parser.h"
32#include "substring.h"
33#include "text.h"
34
35#include "globals.h"
36#include "texture.h"
37
38#include "effects/graphics_effect.h"
39#include "effects/fog_effect.h"
40#include "effects/lense_flare.h"
41
42#include "shell_command.h"
43
44
45#include "parser/tinyxml/tinyxml.h"
46#include "load_param.h"
47#include "factory.h"
48
49#ifdef __WIN32__
50 #include "class_list.h"
51 #include "static_model.h"
52#endif
53using namespace std;
54
55SHELL_COMMAND(wireframe, GraphicsEngine, wireframe);
56
57
58/**
59 *  standard constructor
60 */
61GraphicsEngine::GraphicsEngine ()
62{
63  this->setClassID(CL_GRAPHICS_ENGINE, "GraphicsEngine");
64  this->setName("GraphicsEngine");
65
66  this->isInit = false;
67
68  this->bDisplayFPS = false;
69  this->minFPS = 9999;
70  this->maxFPS = 0;
71
72  this->geTextCFPS = NULL;
73  this->geTextMaxFPS = NULL;
74  this->geTextMinFPS = NULL;
75
76  this->fullscreenFlag = 0;
77  this->videoFlags = 0;
78  this->screen = NULL;
79
80
81  // Hardware
82  this->hwRenderer = NULL;
83  this->hwVendor = NULL;
84  this->hwVersion = NULL;
85  this->hwExtensions = NULL;
86
87  // initialize the TextEngine
88  TextEngine::getInstance();
89}
90
91/**
92 *  The Pointer to this GraphicsEngine
93*/
94GraphicsEngine* GraphicsEngine::singletonRef = NULL;
95
96/**
97 *  destructs the graphicsEngine.
98*/
99GraphicsEngine::~GraphicsEngine ()
100{
101  // delete what has to be deleted here
102  delete this->geTextCFPS;
103  delete this->geTextMaxFPS;
104  delete this->geTextMinFPS;
105
106  delete[] this->hwRenderer;
107  delete[] this->hwVendor;
108  delete[] this->hwVersion;
109  delete this->hwExtensions;
110
111  //TextEngine
112  delete TextEngine::getInstance();
113  // render 2D
114  delete Render2D::getInstance();
115
116  SDL_QuitSubSystem(SDL_INIT_VIDEO);
117//   if (this->screen != NULL)
118//     SDL_FreeSurface(this->screen);
119
120  GraphicsEngine::singletonRef = NULL;
121}
122
123
124/**
125 * loads the GraphicsEngine Specific Parameters.
126 * @param root: the XML-Element to load the Data From
127 */
128void GraphicsEngine::loadParams(const TiXmlElement* root)
129{
130  LoadParamXML(root, "GraphicsEffect", this, GraphicsEngine, loadGraphicsEffectXML)
131      .describe("loads a graphics effect");
132}
133
134
135/**
136 * initializes the GraphicsEngine with default settings.
137 */
138int GraphicsEngine::init()
139{
140  if (this->isInit)
141    return -1;
142  this->initVideo(640, 480, 16);
143}
144
145/**
146 * loads the GraphicsEngine's settings from a given ini-file and section
147 * @param iniParser the iniParser to load from
148 * @param section the Section in the ini-file to load from
149 * @returns nothing usefull
150 */
151int GraphicsEngine::initFromIniFile(IniParser* iniParser)
152{
153  // looking if we are in fullscreen-mode
154  const char* fullscreen = iniParser->getVar(CONFIG_NAME_FULLSCREEN, CONFIG_SECTION_VIDEO, "0");
155  if (strchr(fullscreen, '1') || !strcasecmp(fullscreen, "true"))
156    this->fullscreenFlag = SDL_FULLSCREEN;
157
158  // looking if we are in fullscreen-mode
159  const char* textures = iniParser->getVar(CONFIG_NAME_TEXTURES, CONFIG_SECTION_VIDEO_ADVANCED, "0");
160  if (strchr(textures, '1') || !strcasecmp(textures, "true"))
161    Texture::setTextureEnableState( true);
162  else
163    Texture::setTextureEnableState(false);
164
165  // searching for a usefull resolution
166  SubString resolution(iniParser->getVar(CONFIG_NAME_RESOLUTION, CONFIG_SECTION_VIDEO, "640x480"), 'x');
167  //resolution.debug();
168
169  this->initVideo(atoi(resolution.getString(0)), atoi(resolution.getString(1)), 16);
170
171//   GraphicsEffect* fe = new FogEffect(NULL);
172//   this->loadGraphicsEffect(fe);
173//   fe->activate();
174//   PRINTF(0)("--------------------------------------------------------------\n");
175
176  //LenseFlare* ge = new LenseFlare();
177  //this->loadGraphicsEffect(ge);
178
179  //ge->addFlare("pictures/lense_flare/sun.png"); //sun
180  //ge->addFlare("pictures/lense_flare/lens2.png"); //first halo
181  //ge->addFlare("pictures/lense_flare/lens1.png"); //small birst
182  //ge->addFlare("pictures/lense_flare/lens3.png"); //second halo
183  //ge->addFlare("pictures/lense_flare/lens4.png");
184  //ge->addFlare("pictures/lense_flare/lens1.png");
185  //ge->addFlare("pictures/lense_flare/lens3.png");
186
187  //ge->activate();
188}
189
190
191
192/**
193 *  initializes the Video for openGL.
194 *
195 * This has to be done only once when starting orxonox.
196 */
197int GraphicsEngine::initVideo(unsigned int resX, unsigned int resY, unsigned int bbp)
198{
199  if (this->isInit)
200    return -1;
201  //   initialize SDL_VIDEO
202  if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1)
203  {
204    PRINTF(1)("could not initialize SDL Video\n");
205      //      return -1;
206  }
207  // initialize SDL_GL-settings
208  this->setGLattribs();
209
210  // setting the Video Flags.
211  this->videoFlags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE | SDL_DOUBLEBUF | SDL_GL_DOUBLEBUFFER;
212
213  /* query SDL for information about our video hardware */
214  const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo ();
215  if( videoInfo == NULL)
216    {
217      PRINTF(1)("Failed getting Video Info :%s\n", SDL_GetError());
218      SDL_Quit ();
219    }
220  if( videoInfo->hw_available)
221    this->videoFlags |= SDL_HWSURFACE;
222  else
223    this->videoFlags |= SDL_SWSURFACE;
224  /*
225  if(VideoInfo -> blit_hw)
226    VideoFlags |= SDL_HWACCEL;
227  */
228    // setting up the Resolution
229  this->setResolution(resX, resY, bbp);
230
231  // GRABBING ALL GL-extensions
232  this->grabHardwareSettings();
233
234  // Enable default GL stuff
235  glEnable(GL_DEPTH_TEST);
236
237  Render2D::getInstance();
238
239  this->isInit = true;
240}
241
242/**
243 * sets the Window Captions and the Name of the icon.
244 * @param windowName The name of the Window
245 * @param icon The name of the Icon on the Disc
246 */
247void GraphicsEngine::setWindowName(const char* windowName, const char* icon)
248{
249  SDL_Surface* iconSurf = SDL_LoadBMP(icon);
250  if (iconSurf != NULL)
251  {
252    Uint32 colorkey = SDL_MapRGB(iconSurf->format, 0, 0, 0);
253    SDL_SetColorKey(iconSurf, SDL_SRCCOLORKEY, colorkey);
254    SDL_WM_SetIcon(iconSurf,NULL);
255    SDL_FreeSurface(iconSurf);
256  }
257
258  SDL_WM_SetCaption (windowName, icon);
259}
260
261
262/**
263 *  Sets the GL-attributes
264 */
265int GraphicsEngine::setGLattribs()
266{
267  // Set video mode
268  // TO DO: parse arguments for settings
269  //SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
270  //SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
271  //SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
272  //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
273
274
275  SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
276  SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16);
277  SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0);
278  SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 0);
279  SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 0);
280  SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 0);
281  SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0);
282}
283
284/**
285 * grabs the Hardware Specifics
286 * checks for all the different HW-types
287 */
288void GraphicsEngine::grabHardwareSettings()
289{
290  const char* renderer = (const char*) glGetString(GL_RENDERER);
291  const char* vendor   = (const char*) glGetString(GL_VENDOR);
292  const char* version  = (const char*) glGetString(GL_VERSION);
293  const char* extensions = (const char*) glGetString(GL_EXTENSIONS);
294
295//  printf("%s %s %s\n %s", renderer, vendor, version, extensions);
296
297  if (this->hwRenderer == NULL && renderer != NULL)
298  {
299    this->hwRenderer = new char[strlen(renderer)+1];
300    strcpy(this->hwRenderer, renderer);
301  }
302  if (this->hwVendor == NULL && vendor != NULL)
303  {
304    this->hwVendor = new char[strlen(vendor)+1];
305    strcpy(this->hwVendor, vendor);
306  }
307  if (this->hwVersion == NULL && version != NULL)
308  {
309    this->hwVersion = new char[strlen(version)+11];
310    strcpy(this->hwVersion, version);
311  }
312
313  if (this->hwExtensions == NULL && extensions != NULL)
314    this->hwExtensions = new SubString((char*)glGetString(GL_EXTENSIONS), " \n\t,");
315
316  PRINT(4)("Running on : vendor: %s,  renderer: %s,  version:%s\n", vendor, renderer, version);
317  PRINT(4)("Extensions:\n");
318  if (this->hwExtensions != NULL)
319    for (unsigned int i = 0; i < this->hwExtensions->getCount(); i++)
320      PRINT(4)("%d: %s\n", i, this->hwExtensions->getString(i));
321
322
323  // inizializing GLEW
324  GLenum err = glewInit();
325  if (GLEW_OK != err)
326  {
327    /* Problem: glewInit failed, something is seriously wrong. */
328    PRINTF(1)("%s\n", glewGetErrorString(err));
329  }
330  PRINTF(4)("Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
331}
332
333
334/**
335 *  sets the Resolution of the Screen to display the Graphics to.
336 * @param width The width of the window
337 * @param height The height of the window
338 * @param bpp bits per pixel
339 */
340int GraphicsEngine::setResolution(int width, int height, int bpp)
341{
342  this->resolutionX = width;
343  this->resolutionY = height;
344  this->bitsPerPixel = bpp;
345  State::setResolution( width, height);
346
347  if (this->screen != NULL)
348    SDL_FreeSurface(screen);
349  if((this->screen = SDL_SetVideoMode(this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags | this->fullscreenFlag)) == NULL)
350    {
351      PRINTF(1)("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags, SDL_GetError());
352      //    SDL_Quit();
353      //    return -1;
354    }
355    glViewport(0, 0, width, height);                     // Reset The Current Viewport
356
357#ifdef __WIN32__
358    // REBUILDING TEXTURES (ON WINDOWS CONTEXT SWITCH)
359    const std::list<BaseObject*>* texList = ClassList::getList(CL_TEXTURE);
360    if (texList != NULL)
361    {
362      std::list<BaseObject*>::const_iterator reTex;
363      for (reTex = texList->begin(); reTex != texList->end(); reTex++)
364        dynamic_cast<Texture*>(*reTex)->rebuild();
365    }
366    // REBUILDING MODELS
367    const std::list<BaseObject*>* modelList = ClassList::getList(CL_STATIC_MODEL);
368    if (texList != NULL)
369    {
370      std::list<BaseObject*>::const_iterator reModel;
371      for (reModel = modelList->begin(); reModel != modelList->end(); reModel++)
372        dynamic_cast<StaticModel*>(*reModel)->rebuild();
373    }
374#endif /* __WIN32__ */
375}
376
377/**
378 *  sets Fullscreen mode
379 * @param fullscreen true if fullscreen, false if windowed
380*/
381void GraphicsEngine::setFullscreen(bool fullscreen)
382{
383  if (fullscreen)
384    this->fullscreenFlag = SDL_FULLSCREEN;
385  else
386    this->fullscreenFlag = 0;
387  this->setResolution(this->resolutionX, this->resolutionY, this->bitsPerPixel);
388}
389
390/**
391 *  sets the background color
392 * @param red the red part of the background
393 * @param blue the blue part of the background
394 * @param green the green part of the background
395 * @param alpha the alpha part of the background
396 */
397void GraphicsEngine::setBackgroundColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
398{
399  glClearColor(red, green, blue, alpha);
400}
401
402/**
403 *  Signalhandler, for when the resolution has changed
404 * @param resizeInfo SDL information about the size of the new screen size
405 */
406int GraphicsEngine::resolutionChanged(const SDL_ResizeEvent& resizeInfo)
407{
408  this->setResolution(resizeInfo.w, resizeInfo.h, this->bitsPerPixel);
409}
410
411/**
412 *
413 * @param show if The mouse-cursor should be visible
414 */
415void GraphicsEngine::showMouse(bool show)
416{
417  if (show)
418    SDL_ShowCursor(SDL_ENABLE);
419  else
420    SDL_ShowCursor(SDL_DISABLE);
421}
422
423/**
424 *
425 * @returns The Visinility of the mouse-cursor (true if visible, false if it is invisible)
426 */
427bool GraphicsEngine::isMouseVisible()
428{
429  if (SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE)
430    return true;
431  else
432    return false;
433}
434
435/**
436 *
437 * @param steal If the Winodow-Managers Events should be stolen to this app
438 * (steals the mouse, and all WM-clicks)
439 *
440 * This only happens, if the HARD-Debug-level is set to 0,1,2, because otherwise a Segfault could
441 * result in the loss of System-controll
442 */
443void GraphicsEngine::stealWMEvents(bool steal)
444{
445#if DEBUG < 3
446   if (steal)
447     SDL_WM_GrabInput(SDL_GRAB_ON);
448   else
449     SDL_WM_GrabInput(SDL_GRAB_OFF);
450#endif
451}
452
453/**
454 *
455 * @returns true if Events are stolen from the WM, false if not.
456 */
457bool GraphicsEngine::isStealingEvents()
458{
459   if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON)
460     return true;
461   else
462     return false;
463};
464
465/**
466 *  entering 2D Mode
467
468   this is a GL-Projection-mode, that is orthogonal, for placing the font in fron of everything else
469*/
470void GraphicsEngine::enter2DMode()
471{
472  //GraphicsEngine::storeMatrices();
473  SDL_Surface *screen = SDL_GetVideoSurface();
474
475  /* Note, there may be other things you need to change,
476     depending on how you have your OpenGL state set up.
477  */
478  glPushAttrib(GL_ENABLE_BIT);
479  glDisable(GL_DEPTH_TEST);
480  glDisable(GL_CULL_FACE);
481  glDisable(GL_LIGHTING);  // will be set back when leaving 2D-mode
482
483  glMatrixMode(GL_PROJECTION);
484  glPushMatrix();
485  glLoadIdentity();
486  glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
487
488  glMatrixMode(GL_MODELVIEW);
489  glPushMatrix();
490  glLoadIdentity();
491}
492
493/**
494 *  leaves the 2DMode again also @see Font::enter2DMode()
495 */
496void GraphicsEngine::leave2DMode()
497{
498
499  glMatrixMode(GL_MODELVIEW);
500  glPopMatrix();
501
502  glMatrixMode(GL_PROJECTION);
503  glPopMatrix();
504
505  glPopAttrib();
506}
507
508void GraphicsEngine::wireframe()
509{
510  glPolygonMode(GL_FRONT, GL_LINE);
511}
512
513/**
514 *  stores the GL_matrices
515 */
516void GraphicsEngine::storeMatrices()
517{
518  glGetDoublev(GL_PROJECTION_MATRIX, GraphicsEngine::projMat);
519  glGetDoublev(GL_MODELVIEW_MATRIX, GraphicsEngine::modMat);
520  glGetIntegerv(GL_VIEWPORT, GraphicsEngine::viewPort);
521}
522
523//! the stored ModelView Matrix.
524GLdouble GraphicsEngine::modMat[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
525//! the stored Projection Matrix
526GLdouble GraphicsEngine::projMat[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
527//! The ViewPort
528GLint GraphicsEngine::viewPort[4] = {0,0,0,0};
529
530
531
532/**
533 *  outputs all the Fullscreen modes.
534 */
535void GraphicsEngine::listModes()
536{
537  /* Get available fullscreen/hardware modes */
538  this->videoModes=SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);
539
540  /* Check is there are any modes available */
541  if(this->videoModes == (SDL_Rect **)0){
542    PRINTF(1)("No modes available!\n");
543    exit(-1);
544  }
545
546  /* Check if our resolution is restricted */
547  if(this->videoModes == (SDL_Rect **)-1){
548    PRINTF(2)("All resolutions available.\n");
549  }
550  else{
551    /* Print valid modes */
552    PRINT(0)("Available Resoulution Modes are\n");
553    for(int i = 0; this->videoModes[i]; ++i)
554      PRINT(4)(" |  %d x %d\n", this->videoModes[i]->w, this->videoModes[i]->h);
555  }
556}
557
558/**
559 * checks wether a certain extension is availiable
560 * @param extension the Extension to check for (ex. GL_ARB_texture_env_dot3)
561 * @return true if it is, false otherwise
562 */
563bool GraphicsEngine::hwSupportsEXT(const char* extension)
564{
565  if (this->hwExtensions != NULL)
566    for (unsigned int i = 0; i < this->hwExtensions->getCount(); i++)
567      if (!strcmp(extension, this->hwExtensions->getString(i)))
568        return true;
569  return false;
570}
571
572/**
573 * updates everything that is to be updated in the GraphicsEngine
574 */
575void GraphicsEngine::update(float dt)
576{
577  Render2D::getInstance()->update(dt);
578}
579
580
581/**
582 *  ticks the Text
583 * @param dt the time passed
584 */
585void GraphicsEngine::tick(float dt)
586{
587  if( unlikely(this->bDisplayFPS))
588  {
589    this->currentFPS = 1.0/dt;
590    if( unlikely(this->currentFPS > this->maxFPS)) this->maxFPS = this->currentFPS;
591    if( unlikely(this->currentFPS < this->minFPS)) this->minFPS = this->currentFPS;
592
593#ifndef NO_TEXT
594      char tmpChar1[20];
595      sprintf(tmpChar1, "Current:  %4.0f", this->currentFPS);
596      this->geTextCFPS->setText(tmpChar1);
597      char tmpChar2[20];
598      sprintf(tmpChar2, "Max:    %4.0f", this->maxFPS);
599      this->geTextMaxFPS->setText(tmpChar2);
600      char tmpChar3[20];
601      sprintf(tmpChar3, "Min:    %4.0f", this->minFPS);
602      this->geTextMinFPS->setText(tmpChar3);
603#endif /* NO_TEXT */
604
605  }
606
607  Render2D::getInstance()->tick(dt);
608
609  // tick the graphics effects
610  list<GraphicsEffect*>::iterator it;
611  for (it = this->graphicsEffects.begin(); it != this->graphicsEffects.end(); it++)
612    (*it)->tick(dt);
613}
614
615
616void GraphicsEngine::draw() const
617{
618
619  LightManager::getInstance()->draw();
620
621  GraphicsEngine::storeMatrices();
622  Shader::suspendShader();
623
624  Render2D::getInstance()->draw(E2D_LAYER_ALL);
625  Shader::restoreShader();
626
627  //draw the graphics effects
628  list<GraphicsEffect*>::const_iterator it;
629  for (it = this->graphicsEffects.begin(); it != this->graphicsEffects.end(); it++)
630    (*it)->draw();
631}
632
633void GraphicsEngine::draw(const std::list<WorldEntity*>& drawList ) const
634{
635  std::list<WorldEntity*>::const_iterator entity;
636  for (entity = drawList.begin(); entity != drawList.end(); entity++)
637    if ((*entity)->isVisible())
638      (*entity)->draw();
639}
640
641
642/**
643 * displays the Frames per second
644 * @param display if the text should be displayed
645*/
646void GraphicsEngine::displayFPS(bool display)
647{
648#ifndef NO_TEXT
649  if( display )
650{
651  if (this->geTextCFPS == NULL)
652  {
653    this->geTextCFPS = new Text("fonts/arial_black.ttf", 15);
654    this->geTextCFPS->setName("curFPS");
655    this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT);
656    this->geTextCFPS->setAbsCoor2D(5, 0);
657  }
658  if (this->geTextMaxFPS == NULL)
659  {
660    this->geTextMaxFPS = new Text("fonts/arial_black.ttf", 15);
661    this->geTextMaxFPS->setName("MaxFPS");
662    this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT);
663    this->geTextMaxFPS->setAbsCoor2D(5, 20);
664  }
665  if (this->geTextMinFPS == NULL)
666  {
667    this->geTextMinFPS = new Text("fonts/arial_black.ttf", 15);
668    this->geTextMinFPS->setName("MinFPS");
669    this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT);
670    this->geTextMinFPS->setAbsCoor2D(5, 40);
671  }
672}
673else
674{
675  delete this->geTextCFPS;
676  this->geTextCFPS = NULL;
677  delete this->geTextMaxFPS;
678  this->geTextMaxFPS = NULL;
679  delete this->geTextMinFPS;
680  this->geTextMinFPS = NULL;
681}
682  this->bDisplayFPS = display;
683#else
684  this->bDisplayFPS = false;
685#endif /* NO_TEXT */
686}
687
688
689/**
690  processes the events for the GraphicsEngine class
691* @param the event to handle
692 */
693void GraphicsEngine::process(const Event &event)
694{
695  switch (event.type)
696  {
697    case EV_VIDEO_RESIZE:
698      this->resolutionChanged(event.resize);
699      break;
700  }
701}
702
703
704/**
705 * @param root The XML-element to load GraphicsEffects from
706 */
707void GraphicsEngine::loadGraphicsEffectXML(const TiXmlElement* root)
708{
709  const TiXmlElement* element = root->FirstChildElement();
710
711  while (element != NULL)
712  {
713    Factory::fabricate(element);
714
715    element = element->NextSiblingElement();
716  }
717}
718
719
720/**
721 * loads a GraphicsEffect into the engine
722 * @param effect the GraphicsEffect to add
723 */
724bool GraphicsEngine::loadGraphicsEffect(GraphicsEffect* effect)
725{
726  list<GraphicsEffect*>::iterator it;
727  for (it = this->graphicsEffects.begin(); it != this->graphicsEffects.end(); it++)
728    if( (*it) == effect)
729      return false;
730
731  this->graphicsEffects.push_back(effect);
732
733  return true;
734}
735
736
737/**
738 * unloads a GraphicsEffect from the engine
739 * @param effect the GraphicsEffect to remove
740 */
741bool GraphicsEngine::unloadGraphicsEffect(GraphicsEffect* effect)
742{
743  list<GraphicsEffect*>::iterator it;
744  for (it = this->graphicsEffects.begin(); it != this->graphicsEffects.end(); it++)
745  {
746    if( (*it) == effect)
747    {
748      this->graphicsEffects.erase(it);
749      return true;
750    }
751  }
752
753  return false;
754}
755
Note: See TracBrowser for help on using the repository browser.