DrawModes.cc 25.7 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
2
3
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
Jan Möbius's avatar
Jan Möbius committed
4
 *      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen      *
Jan Möbius's avatar
Jan Möbius committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
37
 *   $Revision$                                                       *
Jan Möbius's avatar
Jan Möbius committed
38
39
40
41
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67




//=============================================================================
//
//  CLASS DrawModes - IMPLEMENTATION
//
//=============================================================================


//== INCLUDES =================================================================

#include "DrawModes.hh"
#include "BaseNode.hh"

#include <algorithm>


//== NAMESPACES ============================================================== 

namespace ACG {
namespace SceneGraph {
namespace DrawModes {


68
// == Default Draw Mode initialization ======================================
Jan Möbius's avatar
Jan Möbius committed
69

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
DrawMode NONE                              = ModeFlagSet(0);
DrawMode DEFAULT                           = ModeFlagSet(1);
DrawMode POINTS                            = ModeFlagSet(1) << 1;
DrawMode POINTS_COLORED                    = ModeFlagSet(1) << 2;
DrawMode POINTS_SHADED                     = ModeFlagSet(1) << 3;
DrawMode EDGES                             = ModeFlagSet(1) << 4;
DrawMode EDGES_COLORED                     = ModeFlagSet(1) << 5;
DrawMode WIREFRAME                         = ModeFlagSet(1) << 6;
DrawMode FACES                             = ModeFlagSet(1) << 7;
DrawMode HIDDENLINE                        = ModeFlagSet(1) << 8;
DrawMode SOLID_FLAT_SHADED                 = ModeFlagSet(1) << 9;
DrawMode SOLID_SMOOTH_SHADED               = ModeFlagSet(1) << 10;
DrawMode SOLID_PHONG_SHADED                = ModeFlagSet(1) << 11;
DrawMode SOLID_FACES_COLORED               = ModeFlagSet(1) << 12;
DrawMode SOLID_POINTS_COLORED              = ModeFlagSet(1) << 13;
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
DrawMode SOLID_POINTS_COLORED_SHADED       = ModeFlagSet(1) << 14;
DrawMode SOLID_ENV_MAPPED                  = ModeFlagSet(1) << 15;
DrawMode SOLID_TEXTURED                    = ModeFlagSet(1) << 16;
DrawMode SOLID_TEXTURED_SHADED             = ModeFlagSet(1) << 17;
DrawMode SOLID_1DTEXTURED                  = ModeFlagSet(1) << 18;
DrawMode SOLID_1DTEXTURED_SHADED           = ModeFlagSet(1) << 19;
DrawMode SOLID_3DTEXTURED                  = ModeFlagSet(1) << 20;
DrawMode SOLID_3DTEXTURED_SHADED           = ModeFlagSet(1) << 21;
DrawMode SOLID_FACES_COLORED_FLAT_SHADED   = ModeFlagSet(1) << 22;
DrawMode SOLID_FACES_COLORED_SMOOTH_SHADED = ModeFlagSet(1) << 23;
DrawMode SOLID_2DTEXTURED_FACE             = ModeFlagSet(1) << 24;
DrawMode SOLID_2DTEXTURED_FACE_SHADED      = ModeFlagSet(1) << 25;
DrawMode SOLID_SHADER                      = ModeFlagSet(1) << 26;
DrawMode SOLID_SMOOTH_SHADED_FEATURES      = ModeFlagSet(1) << 27;
DrawMode CELLS                             = ModeFlagSet(1) << 28;
DrawMode CELLS_COLORED                     = ModeFlagSet(1) << 29;
DrawMode HALFEDGES                         = ModeFlagSet(1) << 30;
DrawMode HALFEDGES_COLORED                 = ModeFlagSet(1) << 31;
DrawMode UNUSED                            = ModeFlagSet(1) << 32;
Jan Möbius's avatar
Jan Möbius committed
104
  
Jan Möbius's avatar
Jan Möbius committed
105

Jan Möbius's avatar
 
Jan Möbius committed
106
107
108
//== IMPLEMENTATION ========================================================== 


109
110
111
112
113
114
115
116
/** \brief Definition of a draw mode
 *
 * This class is used to collect Information about a DrawMode in one central class.
 * It stores the name and the id of a DrawMode.
 *
 * If the DrawMode gets switched to a property based one, this class will also
 * store the properties.
 */
Jan Möbius's avatar
Jan Möbius committed
117
118
119
class DrawModeInternal {
  
  public:
120

Jan Möbius's avatar
 
Jan Möbius committed
121
    /** Initializing constructor. */
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
    DrawModeInternal(const std::string & _name, const DrawMode & _id, const bool _propertyBased = false) :
      name_(_name),
      id_(_id),
      propertyBased_(_propertyBased)
    {
    }

    /// Set the name of the DrawMode
    void name(const std::string& _name) {
      name_ = _name;
    }

    /// Get the name of the DrawMode
    const std::string& name() const {
      return name_;
    }
Jan Möbius's avatar
 
Jan Möbius committed
138
    
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
    const DrawMode& id() const {
      return id_;
    }

    bool propertyBased() const {
      return propertyBased_;
    }


    DrawModeProperties& properties() {
      return properties_;
    }

  private:
    std::string        name_;          ///< Human Readable Name
    DrawMode           id_;            ///< The id of the DrawMode
    bool               propertyBased_; ///< Flag if the DrawMode is property based
    DrawModeProperties properties_;    ///< The properties associated with this DrawMode
Jan Möbius's avatar
 
Jan Möbius committed
157
158
};

Jan Möbius's avatar
Jan Möbius committed
159
160

typedef std::vector< DrawModeInternal > VecDrawModes;
Jan Möbius's avatar
 
Jan Möbius committed
161
162
163

/** Vector of all currently defined DrawModes.
*/
164
static VecDrawModes registeredDrawModes_;
Jan Möbius's avatar
 
Jan Möbius committed
165
166

/** First free DrawMode ID for custom modes. */
Jan Möbius's avatar
Jan Möbius committed
167
static DrawMode firstFreeID_;
Jan Möbius's avatar
 
Jan Möbius committed
168
169


170
171
172
173
174
175
176
177
178
179
180
181
DrawModeProperties::DrawModeProperties(DrawModePrimitive _primitive, 
                                       DrawModeLightStage _lightStage, 
                                       DrawModeNormalSource _normalSource,
                                       DrawModeColorSource _colorSource,
                                       DrawModeTexCoordSource _texcoordSource,
                                       bool _envMapping):
envMapped_(_envMapping),
primitive_(_primitive),
lightStage_(_lightStage),
colorSource_(_colorSource),
texcoordSource_(_texcoordSource),
normalSource_(_normalSource)
182
{
183
184
185
186
187
}


DrawMode::DrawMode(unsigned int _index)
{
Jan Möbius's avatar
Jan Möbius committed
188
189
190
191
192
193
  modeFlags_.reset();
  if ( _index >= modeFlags_.size() ) {
    std::cerr << "Illegal drawMode specification from unsigned int. This should not be a bitset!!!" << std::endl;
  } else {
    modeFlags_.set(_index);
  }
194
  layers_.resize(1);
195
  layers_[0] = DrawModeProperties();
Jan Möbius's avatar
Jan Möbius committed
196
}
Jan Möbius's avatar
 
Jan Möbius committed
197

Jan Möbius's avatar
Jan Möbius committed
198
DrawMode::DrawMode() {
199
  layers_.resize(1);
200
  layers_[0] = DrawModeProperties();
Jan Möbius's avatar
Jan Möbius committed
201
202
203
204
}
    
DrawMode::DrawMode( ModeFlagSet _flags ) {
  modeFlags_ = _flags;
205
  layers_.resize(1);
206
  layers_[0] = DrawModeProperties();
Jan Möbius's avatar
Jan Möbius committed
207
}
Jan Möbius's avatar
 
Jan Möbius committed
208

209
DrawMode::operator bool() const {
Jan Möbius's avatar
Jan Möbius committed
210
211
  return( modeFlags_ != NONE.modeFlags_ );
}
212
/*
213
214
215
216
217
218
219
220
221
222
223
224
225
bool DrawMode::propertyBased() const {
  if ( isAtomic() ) {
    return registeredDrawModes_[getIndex()].propertyBased();
  } else {
    // Combined drawmode, iterate over all contained modes and return
    VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
    for( modeIter = registeredDrawModes_.begin();  modeIter != modeEnd;  ++modeIter )
      if( ((*this) & modeIter->id()) && modeIter->propertyBased() )
        return true;

    return false;
  }
}
226
*/
227

228
void DrawMode::setDrawModeProperties(const DrawModeProperties* _props) {
229
230
231
232
233
234
235
236
237
  if (_props)
  {
    if (layers_.empty())
      layers_.push_back(*_props);
    else
      layers_[0] = *_props;
  }
  else
    layers_.erase(layers_.begin());
238
239
240
241
242
}

void DrawMode::setDrawModeProperties( const DrawModeProperties& _props )
{
  setDrawModeProperties(&_props);
243
244
}

Jan Möbius's avatar
Jan Möbius committed
245
246
247
248
249
250
251
252
253
254
255
256
bool DrawMode::operator==(const DrawMode& _mode) const {
  return ((modeFlags_ & _mode.modeFlags_).any());
}

bool DrawMode::operator!=( const DrawMode& _mode2  ) const {
  return (modeFlags_ != _mode2.modeFlags_);
}

DrawMode& DrawMode::operator++() {
  if ( modeFlags_.count() != 1 ) {
    std::cerr << "Operator ++ for drawMode which is not atomic!!" << std::endl;
  }
257
258

  modeFlags_ <<= 1;
Jan Möbius's avatar
Jan Möbius committed
259
260
261
262
  
  return (*this);
}

263
DrawMode DrawMode::operator&(const DrawMode& _mode) const {
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
  DrawMode andMode = (modeFlags_ & _mode.modeFlags_);

  andMode.setDrawModeProperties(getDrawModeProperties());

  for (unsigned int i = 1; i < getNumLayers(); ++i)
    andMode.addLayer(getLayer(i));

  // remove all distinct layers
  for (int i = (int)andMode.getNumLayers() - 1; i >= 0; --i)
  {
    int layerIndex = _mode.getLayerIndex(andMode.getLayer(i));

    if (layerIndex < 0)
      andMode.removeLayer(i);
  }

  return andMode;
Jan Möbius's avatar
Jan Möbius committed
281
282
283
284
285
}

DrawMode& DrawMode::operator|=( const DrawMode& _mode2  ) {
  modeFlags_ |= _mode2.modeFlags_;
  
286
287
288
  for (unsigned int i = 0; i < _mode2.getNumLayers(); ++i)
    addLayer(_mode2.getLayer(i));

289
//  assert(checkConsistency());
290

Jan Möbius's avatar
Jan Möbius committed
291
292
  return (*this);
}
Jan Möbius's avatar
 
Jan Möbius committed
293

Jan Möbius's avatar
Jan Möbius committed
294
295
DrawMode& DrawMode::operator&=( const DrawMode& _mode2  ) {
  modeFlags_ &= _mode2.modeFlags_;
296
297
298
299
300
301
302
303
304

  // remove all distinct layers
  for (int i = (int)getNumLayers() - 1; i >= 0; --i)
  {
    int layerIndex2 = _mode2.getLayerIndex(getLayer(i));

    if (layerIndex2 < 0)
      removeLayer(i);
  }
305

306
//  assert(checkConsistency());
Jan Möbius's avatar
Jan Möbius committed
307
308
309
310
311
  
  return (*this);
}

DrawMode DrawMode::operator|( const DrawMode& _mode2  ) const {
312
313
314
315
316
317
318
319
320
321
322
  DrawMode combined = ( modeFlags_ | _mode2.modeFlags_ );

  combined.setDrawModeProperties(getDrawModeProperties());

  for (unsigned int i = 1; i < getNumLayers(); ++i)
    combined.addLayer(getLayer(i));

  for (unsigned int i = 0; i < _mode2.getNumLayers(); ++i)
    combined.addLayer(_mode2.getLayer(i));

  return combined;
Jan Möbius's avatar
Jan Möbius committed
323
324
325
}

DrawMode DrawMode::operator^( const DrawMode& _mode2  ) const {
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377

  DrawMode xorMode = ( modeFlags_ ^ _mode2.modeFlags_ );


  // xor on properties
  const DrawModeProperties* curProps = 0;

  // do xor on new temporary DrawMode
  //  internal layers of this and _mode2 must stay the same
  std::vector<const DrawModeProperties*> tmpLayers;


  // initialize tmpLayers with my own layers
  for (unsigned int i = 0; i < getNumLayers(); ++i)
  {
    curProps = getLayer(i);

    if (curProps)
      tmpLayers.push_back(curProps);
  }


  // xor on tmpLayers
  for (unsigned int i = 0; i < _mode2.getNumLayers(); ++i)
  {
    curProps = _mode2.getLayer(i);

    if (!curProps) continue;
   


    int addToVec = 1;

    // is the other layer already contained in my own list?
    for (unsigned int k = 0; addToVec && k < tmpLayers.size(); ++k)
    {
      if (!memcmp(tmpLayers[k], curProps, sizeof(DrawModeProperties)))
      {
        // yes, remove it  (layer exists in both drawmodes)
        tmpLayers.erase(tmpLayers.begin() + k);
        addToVec = 0;
      }
    }

    if (addToVec) // no, add it
      tmpLayers.push_back(curProps);
  }



  // DrawModes equal?
  if (tmpLayers.empty())
378
379
  {
    xorMode.removeLayer(0u);
380
    return xorMode; // return default property set to not cause exceptions
381
  }
382
383
384
385
386

  // layers not empty,
  //  copy to temporary drawmode and return

  xorMode.setDrawModeProperties(tmpLayers[0]);
387
  for (unsigned int i = 1; i < tmpLayers.size(); ++i)
388
389
    xorMode.addLayer(tmpLayers[i]);

390
391
392

//  assert(xorMode.checkConsistency());

393
  return xorMode;
Jan Möbius's avatar
Jan Möbius committed
394
395
396
397
398
399
400
401
}

DrawMode DrawMode::operator~( ) const {
  return( ~modeFlags_ );
}    



402
unsigned int DrawMode::getIndex() const {
Jan Möbius's avatar
Jan Möbius committed
403
404
405
406
407
408
409
410
411
  if ( modeFlags_.count() == 1 ) {
    for ( size_t i = 0 ; i < modeFlags_.size() ; ++i ) 
     if ( modeFlags_[i] ) 
      return i; 
  } 
    
  return 0;
}

412
std::string DrawMode::description() const
Jan Möbius's avatar
Jan Möbius committed
413
{
Jan Möbius's avatar
 
Jan Möbius committed
414
415
  std::string text("");
  
416
417
  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
  for( modeIter = registeredDrawModes_.begin();  modeIter != modeEnd;  ++modeIter )
Jan Möbius's avatar
 
Jan Möbius committed
418
  {
419
    if( (*this) & modeIter->id() )
Jan Möbius's avatar
 
Jan Möbius committed
420
421
    {
      if (!text.empty()) text += "+";
422
      text += modeIter->name();
Jan Möbius's avatar
 
Jan Möbius committed
423
424
    }
  }
Jan Möbius's avatar
Jan Möbius committed
425
  
Jan Möbius's avatar
 
Jan Möbius committed
426
427
428
429
430
  return text;
}

//----------------------------------------------------------------------------

431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
void DrawMode::filter( DrawMode _filter )
{
  modeFlags_ = (modeFlags_ | _filter.modeFlags_) ^ _filter.modeFlags_;

  for (unsigned int i = 0; i < _filter.getNumLayers(); ++i)
  {
    int idx = getLayerIndex(_filter.getLayer(i));

    removeLayer((unsigned int)idx);
  }
}



//----------------------------------------------------------------------------

void DrawMode::combine( DrawMode _mode )
{
  // XOR on bitflag
  modeFlags_ = (modeFlags_ ^ _mode.modeFlags_);

  // addLayer does redundancy check here
  for (unsigned int i = 0; i < _mode.getNumLayers(); ++i)
    addLayer(_mode.getLayer(i));

//  assert(checkConsistency());
}

//----------------------------------------------------------------------------

Jan Möbius's avatar
Jan Möbius committed
461
std::vector< DrawMode >
462
DrawMode::getAtomicDrawModes() const
Jan Möbius's avatar
 
Jan Möbius committed
463
{
Jan Möbius's avatar
Jan Möbius committed
464
465
  std::vector< DrawMode > draw_mode_ids;
  
466
467
  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
  for( modeIter = registeredDrawModes_.begin();
Jan Möbius's avatar
Jan Möbius committed
468
469
  modeIter != modeEnd;
  ++modeIter )
470
471
  if( (*this) & modeIter->id() )
    draw_mode_ids.push_back( modeIter->id() );
Jan Möbius's avatar
Jan Möbius committed
472
  
Jan Möbius's avatar
 
Jan Möbius committed
473
474
475
476
477
478
  return draw_mode_ids;
}


//----------------------------------------------------------------------------

Jan Möbius's avatar
Jan Möbius committed
479
bool DrawMode::isAtomic() const {
Jan Möbius's avatar
Jan Möbius committed
480
481
482
483
484
  return(modeFlags_.count() == 1 );
}
 

//----------------------------------------------------------------------------
Jan Möbius's avatar
 
Jan Möbius committed
485
486
 
bool
487
DrawMode::containsAtomicDrawMode( DrawMode _atomicDrawMode) const
Jan Möbius's avatar
 
Jan Möbius committed
488
{
Jan Möbius's avatar
Jan Möbius committed
489
490
491
492
493
  return (*this) & _atomicDrawMode;
}
 
//---------------------------------------------------------------------------- 
 
494
unsigned int DrawMode::maxModes() const {
Jan Möbius's avatar
Jan Möbius committed
495
  return (modeFlags_.size() );
Jan Möbius's avatar
 
Jan Möbius committed
496
}
497
498
499
500
501
502
503
504
505
506
507
508

unsigned int DrawMode::getNumLayers() const {
  return layers_.size();
}

const DrawModeProperties* DrawMode::getLayer( unsigned int i ) const {
  return (i >= layers_.size() ? 0 : &layers_[i]);
}


void DrawMode::addLayer( const DrawModeProperties* _props )
{
509
  if (getLayerIndex(_props) < 0 && _props)
510
    layers_.push_back(*_props);
511
512
513
514
}

bool DrawMode::removeLayer( unsigned int _i )
{
Jan Möbius's avatar
Jan Möbius committed
515
  if (_i < layers_.size() )
516
517
518
519
520
521
  {
    layers_.erase(layers_.begin() + _i);
    return true;
  }

  return false;
522
523
524
525
526
527
528
}

const DrawModeProperties* DrawMode::getDrawModeProperties() const
{
  return getLayer(0);
}

Jan Möbius's avatar
 
Jan Möbius committed
529

530
531
bool DrawMode::checkConsistency() const
{
532
533
534
535
536
537
538
539
  for (unsigned int i = 0; i < layers_.size(); ++i)
  {
    for (unsigned int k = i+1; k < layers_.size(); ++k)
    {
      if (layers_[i].primitive() == layers_[k].primitive())
        return false;
    }
  }
540
541
542
543
544
545

  return true;
}

int DrawMode::getLayerIndex( const DrawModeProperties* _prop ) const
{
546
547
  if (!_prop) return -1;

548
549
550
551
552
553
554
555
556
  for (unsigned int i = 0; i < layers_.size(); ++i)
  {
    if (!memcmp(&layers_[i], _prop, sizeof(DrawModeProperties)))
      return (int)i;
  }
  return -1;
}


Jan Möbius's avatar
 
Jan Möbius committed
557
558
559
560
561
562
563
564
565
566
//----------------------------------------------------------------------------


void initializeDefaultDrawModes( void )
{
    static bool initialized_ = false;

    if( initialized_ )
	return;

567
    registeredDrawModes_.clear();
Jan Möbius's avatar
 
Jan Möbius committed
568

569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
    NONE.removeLayer(0u);
    DEFAULT.removeLayer(0u);

    POINTS.                     setDrawModeProperties(DrawModeProperties(PRIMITIVE_POINT));
    POINTS_COLORED.             setDrawModeProperties(DrawModeProperties(PRIMITIVE_POINT, LIGHTSTAGE_UNLIT, NORMAL_NONE, COLOR_PER_VERTEX));
    POINTS_SHADED.              setDrawModeProperties(DrawModeProperties(PRIMITIVE_POINT, LIGHTSTAGE_SMOOTH, NORMAL_PER_VERTEX));

    EDGES.                      setDrawModeProperties(DrawModeProperties(PRIMITIVE_EDGE));
    EDGES_COLORED.              setDrawModeProperties(DrawModeProperties(PRIMITIVE_EDGE, LIGHTSTAGE_UNLIT, NORMAL_NONE, COLOR_PER_VERTEX));

    WIREFRAME.                  setDrawModeProperties(DrawModeProperties(PRIMITIVE_EDGE));
    EDGES_COLORED.              setDrawModeProperties(DrawModeProperties(PRIMITIVE_EDGE, LIGHTSTAGE_UNLIT, NORMAL_NONE, COLOR_PER_VERTEX));

    WIREFRAME.                  setDrawModeProperties(DrawModeProperties(PRIMITIVE_WIREFRAME));

    FACES.                      setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON));

    HIDDENLINE.                 setDrawModeProperties(DrawModeProperties(PRIMITIVE_HIDDENLINE));

    SOLID_FLAT_SHADED.          setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_FACE));
    SOLID_SMOOTH_SHADED.        setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_VERTEX));

    SOLID_PHONG_SHADED.         setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_PHONG, NORMAL_PER_VERTEX));

    SOLID_FACES_COLORED.        setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_FACE, COLOR_PER_FACE));
    
    SOLID_POINTS_COLORED.       setDrawModeProperties(DrawModeProperties(PRIMITIVE_POINT, LIGHTSTAGE_UNLIT,   NORMAL_NONE,      COLOR_PER_VERTEX));
    SOLID_POINTS_COLORED_SHADED.setDrawModeProperties(DrawModeProperties(PRIMITIVE_POINT, LIGHTSTAGE_SMOOTH,  NORMAL_PER_FACE,  COLOR_PER_VERTEX));

    SOLID_ENV_MAPPED.           setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_UNLIT, NORMAL_NONE,      COLOR_NONE, TEXCOORD_PER_VERTEX, true));

    SOLID_TEXTURED.             setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_UNLIT,   NORMAL_NONE,      COLOR_NONE, TEXCOORD_PER_VERTEX));
    SOLID_TEXTURED_SHADED.      setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH,  NORMAL_PER_VERTEX,COLOR_NONE, TEXCOORD_PER_VERTEX));

    SOLID_1DTEXTURED.           setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_UNLIT,   NORMAL_NONE,  COLOR_NONE, TEXCOORD_PER_VERTEX));
    SOLID_1DTEXTURED_SHADED.    setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH,  NORMAL_PER_VERTEX,COLOR_NONE, TEXCOORD_PER_VERTEX));

    SOLID_3DTEXTURED.           setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_UNLIT,   NORMAL_NONE,  COLOR_NONE, TEXCOORD_PER_VERTEX));
    SOLID_3DTEXTURED_SHADED.    setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH,  NORMAL_PER_VERTEX,COLOR_NONE, TEXCOORD_PER_VERTEX));

    SOLID_FACES_COLORED_FLAT_SHADED.  setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_FACE,   COLOR_PER_FACE));
    SOLID_FACES_COLORED_SMOOTH_SHADED.setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_VERTEX, COLOR_PER_FACE));

    SOLID_2DTEXTURED_FACE.       setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_UNLIT, NORMAL_NONE, COLOR_NONE, TEXCOORD_PER_VERTEX));
    SOLID_2DTEXTURED_FACE_SHADED.setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_FACE, COLOR_NONE, TEXCOORD_PER_VERTEX));

    SOLID_SMOOTH_SHADED_FEATURES.setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_HALFEDGE));

    CELLS.setDrawModeProperties(DrawModeProperties(PRIMITIVE_CELL));
    CELLS_COLORED.setDrawModeProperties(DrawModeProperties(PRIMITIVE_CELL, LIGHTSTAGE_UNLIT, NORMAL_NONE, COLOR_PER_VERTEX));

    HALFEDGES.setDrawModeProperties(DrawModeProperties(PRIMITIVE_HALFEDGE));
    HALFEDGES_COLORED.setDrawModeProperties(DrawModeProperties(PRIMITIVE_HALFEDGE, LIGHTSTAGE_UNLIT, NORMAL_NONE, COLOR_PER_HALFEDGE));


624
625
    registeredDrawModes_.push_back( DrawModeInternal( "<invalid>", NONE ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Default", DEFAULT ) );
Jan Möbius's avatar
 
Jan Möbius committed
626

627
628
629
    registeredDrawModes_.push_back( DrawModeInternal( "Points", POINTS ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Points (colored)", POINTS_COLORED ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Points (shaded)", POINTS_SHADED  ) );
Jan Möbius's avatar
Jan Möbius committed
630
    
631
632
    registeredDrawModes_.push_back( DrawModeInternal( "Edges", EDGES ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Edges Colored", EDGES_COLORED ) );
Jan Möbius's avatar
Jan Möbius committed
633
    
634
    registeredDrawModes_.push_back( DrawModeInternal( "Wireframe", WIREFRAME ) );
Jan Möbius's avatar
Jan Möbius committed
635
    
636
    registeredDrawModes_.push_back( DrawModeInternal( "Faces", FACES ) );
Jan Möbius's avatar
 
Jan Möbius committed
637
    
638
    registeredDrawModes_.push_back( DrawModeInternal( "Hiddenline", HIDDENLINE ) );
Jan Möbius's avatar
 
Jan Möbius committed
639
    
640
641
642
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (flat shaded)", SOLID_FLAT_SHADED ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (smooth shaded)", SOLID_SMOOTH_SHADED ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (Phong shaded)", SOLID_PHONG_SHADED ) );
Jan Möbius's avatar
 
Jan Möbius committed
643
    
644
645
646
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (colored per-face)", SOLID_FACES_COLORED ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (colored per-vertex)", SOLID_POINTS_COLORED ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (colored per-vertex, shaded)", SOLID_POINTS_COLORED_SHADED ) );
Jan Möbius's avatar
 
Jan Möbius committed
647
    
648
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (environment mapped)", SOLID_ENV_MAPPED ) );
Jan Möbius's avatar
 
Jan Möbius committed
649
    
650
651
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (textured)", SOLID_TEXTURED ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (textured, shaded)", SOLID_TEXTURED_SHADED ) );
Jan Möbius's avatar
 
Jan Möbius committed
652
    
653
654
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (scalar field)", SOLID_1DTEXTURED ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (scalar field, shaded)", SOLID_1DTEXTURED_SHADED ) );
Jan Möbius's avatar
 
Jan Möbius committed
655
    
656
657
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (3D textured)", SOLID_3DTEXTURED ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (3D textured, shaded)", SOLID_3DTEXTURED_SHADED ) );
Jan Möbius's avatar
 
Jan Möbius committed
658

659
660
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (colored per-face, flat shaded)", SOLID_FACES_COLORED_FLAT_SHADED ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (colored per-face, smooth shaded)", SOLID_FACES_COLORED_SMOOTH_SHADED ) );
Jan Möbius's avatar
 
Jan Möbius committed
661

662
663
664
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (face textured)", SOLID_2DTEXTURED_FACE ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (face textured, shaded)", SOLID_2DTEXTURED_FACE_SHADED ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Shader controlled", SOLID_SHADER ) );
665

666
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (smooth shaded, features)", SOLID_SMOOTH_SHADED_FEATURES ) );
667

668
669
    registeredDrawModes_.push_back( DrawModeInternal( "Cells", CELLS ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Cells Colored", CELLS_COLORED ) );
Jan Möbius's avatar
 
Jan Möbius committed
670
    
671
672
    registeredDrawModes_.push_back( DrawModeInternal( "Halfedges", HALFEDGES ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Halfedges Colored", HALFEDGES_COLORED ) );
673

Jan Möbius's avatar
 
Jan Möbius committed
674
675
676
677
678
679
680
681
    firstFreeID_ = UNUSED;
    initialized_ = true;
}


//----------------------------------------------------------------------------


682
const DrawMode& addDrawMode( const std::string & _name , bool _propertyBased)
Jan Möbius's avatar
 
Jan Möbius committed
683
{
684
  // check if mode exists already
685
  VecDrawModes::iterator modeIter, modeEnd( registeredDrawModes_.end() );
Jan Möbius's avatar
 
Jan Möbius committed
686

687
688
689
  for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter ) {
    if( _name == modeIter->name() ) {
      return modeIter->id();
690
    }
691
  }
Jan Möbius's avatar
 
Jan Möbius committed
692
693


694
  // add new mode
695
  registeredDrawModes_.push_back( DrawModeInternal( _name, firstFreeID_ , _propertyBased) );
696
  ++firstFreeID_;
697

698
  return registeredDrawModes_[ registeredDrawModes_.size() - 1 ].id();
Jan Möbius's avatar
 
Jan Möbius committed
699
700
701
}


702
703
704
//----------------------------------------------------------------------------


705
const DrawMode& getDrawMode( const std::string & _name )
706
{
707
  // check if mode exists
708
  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
709

710
  for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd;  ++modeIter )
711
  {
712
    if( _name == modeIter->name() )
713
    {
714
      return modeIter->id();
715
    }
716
  }
717

718
719
  // the DrawMode does not exists
  return DrawModes::NONE;
720
721
}

Jan Möbius's avatar
Jan Möbius committed
722
723
724
bool drawModeExists(const std::string & _name) {
  
  // check if mode exists
725
  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
Jan Möbius's avatar
Jan Möbius committed
726
  
727
  for( modeIter = registeredDrawModes_.begin();  modeIter != modeEnd;  ++modeIter )
Jan Möbius's avatar
Jan Möbius committed
728
  {
729
    if( _name == modeIter->name() )
Jan Möbius's avatar
Jan Möbius committed
730
731
732
733
734
735
736
      return true;
  }
  
  // the DrawMode does not exists
  return false;  
}

737

Jan Möbius's avatar
Jan Möbius committed
738
739
740
DrawMode getDrawModeFromIndex( unsigned int _index ) {
  return DrawMode(_index);
}
Jan Möbius's avatar
 
Jan Möbius committed
741
742
743
744
745
746

//=============================================================================
} // namespace DrawModes
} // namespace SceneGraph
} // namespace ACG
//=============================================================================