Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: the flare now look good, but occlusion culling missing :D Lenseflare will be displayed also if the sun is not visible

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