Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5397 in orxonox.OLD for trunk/src/lib/graphics


Ignore:
Timestamp:
Oct 18, 2005, 5:33:11 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: Elemet2D-drawing better
prevent segfault in setParent with NULL as new Parent in Element2D and PNode

Location:
trunk/src/lib/graphics
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/graphics_engine.cc

    r5347 r5397  
    546546  GraphicsEngine::storeMatrices();
    547547  Shader::suspendShader();
    548   Render2D::getInstance()->draw(E2D_ALL_LAYERS);
     548  Render2D::getInstance()->draw(E2D_LAYER_ALL);
    549549  Shader::restoreShader();
    550550  LightManager::getInstance()->draw();
  • trunk/src/lib/graphics/render2D/element_2d.cc

    r5396 r5397  
    3535{
    3636  this->init();
     37  Render2D::getInstance()->registerElement2D(this);
    3738  this->setParent2D(NullElement2D::getInstance());
    3839}
     
    4849{
    4950  this->init();
     51  Render2D::getInstance()->registerElement2D(this);
    5052
    5153  // check Parenting, and if ok parent the stuff
     
    124126  this->toDirection = NULL;
    125127  this->setSize2D(1,1);
    126 
    127   Render2D::getInstance()->registerElement2D(this);
    128128}
    129129
     
    471471    child->parentMode = parentingMode;
    472472  child->parent = this;
    473   this->children->add(child);
     473  if (likely(this != NULL))
     474    this->children->add(child);
    474475  child->parentCoorChanged();
    475476}
     
    667668
    668669
    669     if (this->alignment == E2D_ALIGN_SCREEN_CENTER && this->bRelCoorChanged)
     670    if (unlikely(this->alignment & E2D_ALIGN_SCREEN_CENTER && this->bRelCoorChanged))
    670671    {
    671672      this->prevRelCoordinate = this->relCoordinate;
     
    674675      this->absCoordinate.z = 0.0;
    675676    }
    676     else if (this->bindNode)
     677    else if (unlikely(this->bindNode != NULL))
    677678    {
    678679      GLdouble projectPos[3];
  • trunk/src/lib/graphics/render2D/element_2d.h

    r5387 r5397  
    2121typedef enum
    2222{
    23   E2D_BELOW_ALL                 =     1,        //!< Will be rendered below the 3D-scene. @todo make this work.
    24   E2D_BOTTOM                    =     2,        //!< Will be rendered on the bottom Layer
    25   E2D_MEDIUM                    =     4,        //!< Will be rendered on the medium Layer.
    26   E2D_TOP                       =     8,        //!< Will be rendered on top of everything else
    27 
    28   E2D_LAYER_COUNT               =     4         //!< The count of Layers.
     23  E2D_BELOW_ALL,       //!< Will be rendered below the 3D-scene. @todo make this work.
     24  E2D_BOTTOM,          //!< Will be rendered on the bottom Layer
     25  E2D_MEDIUM,          //!< Will be rendered on the medium Layer.
     26  E2D_TOP,             //!< Will be rendered on top of everything else
     27
     28  E2D_LAYER_COUNT,     //!< The count of Layers.
     29
     30  E2D_LAYER_ALL,
    2931} E2D_LAYER;
    3032#define E2D_DEFAULT_LAYER       E2D_TOP
    31 #define E2D_ALL_LAYERS          E2D_TOP | E2D_MEDIUM | E2D_BOTTOM | E2D_BELOW_ALL
    3233
    3334typedef enum
     
    153154    void setParent2D (const char* parentName);
    154155    /** @returns the parent of this Element2D */
    155     inline Element2D* getParent () const { return this->parent; };
     156    inline Element2D* getParent2D () const { return this->parent; };
    156157    /** @returns the List of Children of this Element2D */
    157158    inline const tList<Element2D>* getChildren2D() const { return this->children; };
  • trunk/src/lib/graphics/render2D/render_2d.cc

    r5382 r5397  
    6767{
    6868  if (likely(element2D != NULL))
    69     this->element2DList[(int)log2(E2D_DEFAULT_LAYER)]->add(element2D);
     69    this->element2DList[E2D_DEFAULT_LAYER]->add(element2D);
    7070}
    7171
     
    7979void Render2D::unregisterElement2D(Element2D* element2D)
    8080{
    81   this->element2DList[(int)log2(element2D->getLayer())]->remove(element2D);
     81  this->element2DList[element2D->getLayer()]->remove(element2D);
    8282}
    8383
     
    9393    return;
    9494
    95   if (unlikely(pow(2, E2D_LAYER_COUNT ) > to))
     95  if (E2D_LAYER_COUNT  > to)
    9696    to = E2D_DEFAULT_LAYER;
    9797  if (element2D->getLayer() != to)
    9898  {
    99     this->element2DList[(int)log2(element2D->getLayer())]->remove(element2D);
    100     this->element2DList[(int)log2(to)]->add(element2D);
     99    this->element2DList[element2D->getLayer()]->remove(element2D);
     100    this->element2DList[to]->add(element2D);
    101101  }
    102102}
     
    124124
    125125/**
    126  * renders all the Elements of the Render2D-engine
    127  * @param layer the Layer to draw
     126 * renders all the Elements of the Render2D-engine's layer
     127 * @param layer the Layer to draw (if E2D_LAYER_ALL then all layers will be drawn)
    128128 */
    129129void Render2D::draw(unsigned int layer) const
     
    131131  GraphicsEngine::enter2DMode();
    132132
    133   int drawLayer = 1;
    134 
    135   for (int i = 0; i < E2D_LAYER_COUNT; i++)
     133  if (layer != E2D_LAYER_ALL)
    136134  {
    137     if (layer & drawLayer && this->element2DList[i]->getSize() > 0)
     135    if ( this->element2DList[layer]->getSize() > 0)
    138136    {
    139       tIterator<Element2D>* iterator = this->element2DList[i]->getIterator();
     137      tIterator<Element2D>* iterator = this->element2DList[layer]->getIterator();
    140138      Element2D* elem = iterator->firstElement();
    141139      while (elem != NULL)
     
    147145      delete iterator;
    148146    }
    149     drawLayer << 1;
     147  }
     148  else  // if (layer != E2D_LAYER_ALL)
     149  {
     150    for (int i = 0; i < E2D_LAYER_COUNT; i++)
     151    {
     152      if (this->element2DList[i]->getSize() > 0)
     153      {
     154        tIterator<Element2D>* iterator = this->element2DList[i]->getIterator();
     155        Element2D* elem = iterator->firstElement();
     156        while (elem != NULL)
     157        {
     158          if (elem->isVisible())
     159            elem->draw();
     160          elem = iterator->nextElement();
     161        }
     162        delete iterator;
     163      }
     164    }
    150165  }
    151166  GraphicsEngine::leave2DMode();
  • trunk/src/lib/graphics/render2D/render_2d.h

    r4862 r5397  
    1515//! A default singleton class.
    1616class Render2D : public BaseObject {
     17  friend class Element2D;
    1718
    18  public:
    19   virtual ~Render2D();
    20   /** @returns a Pointer to the only object of this Class */
    21   inline static Render2D* getInstance() { if (!singletonRef) singletonRef = new Render2D();  return singletonRef; };
     19  public:
     20    virtual ~Render2D();
     21    /** @returns a Pointer to the only object of this Class */
     22    inline static Render2D* getInstance() { if (!singletonRef) singletonRef = new Render2D();  return singletonRef; };
    2223
    23   void tick(float dt);
    24   void draw(unsigned int layer) const;
     24    void tick(float dt);
     25    void draw(unsigned int layer) const;
    2526
    26   void registerElement2D(Element2D* element2D);
    27   void unregisterElement2D(Element2D* element2D);
    28   void moveToLayer(Element2D* element2D, E2D_LAYER to);
    2927
    30  private:
    31   Render2D();
    32   static Render2D*              singletonRef;                    //!< Reference to this class.
     28  private:
     29    void registerElement2D(Element2D* element2D);
     30    void unregisterElement2D(Element2D* element2D);
     31    void moveToLayer(Element2D* element2D, E2D_LAYER to);
     32
     33
     34    Render2D();
     35    static Render2D*              singletonRef;                    //!< Reference to this class.
    3336
    3437//  tList<Element2D>*             element2DList;                   //!< List of all valid 2D-elements.
    35   tList<Element2D>*             element2DList[E2D_LAYER_COUNT];  //!< List of all valid 2D-elements in the different Layers.
     38    tList<Element2D>*             element2DList[E2D_LAYER_COUNT];  //!< List of all valid 2D-elements in the different Layers.
    3639};
    3740
Note: See TracChangeset for help on using the changeset viewer.