DrawModes.cc 26.4 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
}


Jan Möbius's avatar
Jan Möbius committed
186
DrawMode::DrawMode(size_t _index)
187
{
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
}
    
Jan Möbius's avatar
Jan Möbius committed
203
204
205
DrawMode::DrawMode(ModeFlagSet _flags) :
        modeFlags_(_flags)
{
206
  layers_.resize(1);
207
  layers_[0] = DrawModeProperties();
Jan Möbius's avatar
Jan Möbius committed
208
}
Jan Möbius's avatar
 
Jan Möbius committed
209

210
DrawMode::operator bool() const {
Jan Möbius's avatar
Jan Möbius committed
211
212
  return( modeFlags_ != NONE.modeFlags_ );
}
213
/*
214
215
216
217
218
219
220
221
222
223
224
225
226
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;
  }
}
227
*/
228

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

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

Jan Möbius's avatar
Jan Möbius committed
246
bool DrawMode::operator==(const DrawMode& _mode) const {
247
248
    return modeFlags_ == _mode.modeFlags_;
  //return ((modeFlags_ & _mode.modeFlags_).any());
Jan Möbius's avatar
Jan Möbius committed
249
250
}

Jan Möbius's avatar
Jan Möbius committed
251
DrawMode & DrawMode::operator =(const DrawMode& _mode) {
252
  modeFlags_ = _mode.modeFlags_;
Jan Möbius's avatar
Jan Möbius committed
253
  layers_    = _mode.layers_;
254

Jan Möbius's avatar
Jan Möbius committed
255
256
  //  checkConsistency();
  return (*this);
257
258
}

Jan Möbius's avatar
Jan Möbius committed
259
260
261
262
263
264
265
266
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;
  }
267
268

  modeFlags_ <<= 1;
Jan Möbius's avatar
Jan Möbius committed
269
270
271
272
  
  return (*this);
}

273
DrawMode DrawMode::operator&(const DrawMode& _mode) const {
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
  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
291
292
293
294
295
}

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

299
//  assert(checkConsistency());
300

Jan Möbius's avatar
Jan Möbius committed
301
302
  return (*this);
}
Jan Möbius's avatar
 
Jan Möbius committed
303

Jan Möbius's avatar
Jan Möbius committed
304
305
DrawMode& DrawMode::operator&=( const DrawMode& _mode2  ) {
  modeFlags_ &= _mode2.modeFlags_;
306
307
308
309
310
311
312
313
314

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

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

316
//  assert(checkConsistency());
317

Jan Möbius's avatar
Jan Möbius committed
318
319
320
321
  return (*this);
}

DrawMode DrawMode::operator|( const DrawMode& _mode2  ) const {
322
323
324
325
326
327
328
329
330
331
332
  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
333
334
335
}

DrawMode DrawMode::operator^( const DrawMode& _mode2  ) const {
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
378
379
380
381
382
383
384
385
386
387

  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())
388
389
  {
    xorMode.removeLayer(0u);
390
    return xorMode; // return default property set to not cause exceptions
391
  }
392
393
394
395
396

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

  xorMode.setDrawModeProperties(tmpLayers[0]);
397
  for (unsigned int i = 1; i < tmpLayers.size(); ++i)
398
399
    xorMode.addLayer(tmpLayers[i]);

400
401
402

//  assert(xorMode.checkConsistency());

403
  return xorMode;
Jan Möbius's avatar
Jan Möbius committed
404
405
406
407
408
409
410
411
}

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



Jan Möbius's avatar
Jan Möbius committed
412
size_t DrawMode::getIndex() const {
Jan Möbius's avatar
Jan Möbius committed
413
414
415
416
417
418
419
420
421
  if ( modeFlags_.count() == 1 ) {
    for ( size_t i = 0 ; i < modeFlags_.size() ; ++i ) 
     if ( modeFlags_[i] ) 
      return i; 
  } 
    
  return 0;
}

422
std::string DrawMode::description() const
Jan Möbius's avatar
Jan Möbius committed
423
{
Jan Möbius's avatar
 
Jan Möbius committed
424
425
  std::string text("");
  
426
427
  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
  for( modeIter = registeredDrawModes_.begin();  modeIter != modeEnd;  ++modeIter )
Jan Möbius's avatar
 
Jan Möbius committed
428
  {
429
    if( (*this) & modeIter->id() )
Jan Möbius's avatar
 
Jan Möbius committed
430
431
    {
      if (!text.empty()) text += "+";
432
      text += modeIter->name();
Jan Möbius's avatar
 
Jan Möbius committed
433
434
    }
  }
Jan Möbius's avatar
Jan Möbius committed
435
  
Jan Möbius's avatar
 
Jan Möbius committed
436
437
438
439
440
  return text;
}

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

441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
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));

466
//  checkConsistency();
467
468
469
470
471
//  assert(checkConsistency());
}

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

Jan Möbius's avatar
Jan Möbius committed
472
std::vector< DrawMode >
473
DrawMode::getAtomicDrawModes() const
Jan Möbius's avatar
 
Jan Möbius committed
474
{
Jan Möbius's avatar
Jan Möbius committed
475
476
  std::vector< DrawMode > draw_mode_ids;
  
477
478
  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
  for( modeIter = registeredDrawModes_.begin();
Jan Möbius's avatar
Jan Möbius committed
479
480
  modeIter != modeEnd;
  ++modeIter )
481
482
  if( (*this) & modeIter->id() )
    draw_mode_ids.push_back( modeIter->id() );
Jan Möbius's avatar
Jan Möbius committed
483
  
Jan Möbius's avatar
 
Jan Möbius committed
484
485
486
487
488
489
  return draw_mode_ids;
}


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

Jan Möbius's avatar
Jan Möbius committed
490
bool DrawMode::isAtomic() const {
Jan Möbius's avatar
Jan Möbius committed
491
492
493
494
495
  return(modeFlags_.count() == 1 );
}
 

//----------------------------------------------------------------------------
Jan Möbius's avatar
 
Jan Möbius committed
496
497
 
bool
498
DrawMode::containsAtomicDrawMode( DrawMode _atomicDrawMode) const
Jan Möbius's avatar
 
Jan Möbius committed
499
{
Jan Möbius's avatar
Jan Möbius committed
500
501
502
503
504
  return (*this) & _atomicDrawMode;
}
 
//---------------------------------------------------------------------------- 
 
Jan Möbius's avatar
Jan Möbius committed
505
size_t DrawMode::maxModes() const {
Jan Möbius's avatar
Jan Möbius committed
506
  return (modeFlags_.size() );
Jan Möbius's avatar
 
Jan Möbius committed
507
}
508

Jan Möbius's avatar
Jan Möbius committed
509
size_t DrawMode::getNumLayers() const {
510
511
512
513
514
515
516
517
518
519
  return layers_.size();
}

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


void DrawMode::addLayer( const DrawModeProperties* _props )
{
520
  if (getLayerIndex(_props) < 0 && _props)
521
    layers_.push_back(*_props);
522
523
524
525
}

bool DrawMode::removeLayer( unsigned int _i )
{
Jan Möbius's avatar
Jan Möbius committed
526
  if (_i < layers_.size() )
527
528
529
530
531
532
  {
    layers_.erase(layers_.begin() + _i);
    return true;
  }

  return false;
533
534
535
536
537
538
539
}

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

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

541
542
bool DrawMode::checkConsistency() const
{
543
544

  // allow at most one layer per primitive
545
546
547
548
549
550
551
552
  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;
    }
  }
553

554
555
556
557
558
559


  // bitflag -> layer parallelism

  // points-mode in bitflag => point layer expected

Hans-Christian Ebke's avatar
Hans-Christian Ebke committed
560
561
562
  if ((*this & DrawModes::POINTS) ||
      (*this & DrawModes::POINTS_COLORED) ||
      (*this & DrawModes::POINTS_SHADED))
563
564
565
566
567
568
569
570
571
572
573
574
575
  {
    int pointsLayer = 0;
    for (unsigned int k = 0; k < layers_.size(); ++k)
    {
      if (layers_[k].primitive() == PRIMITIVE_POINT)
        pointsLayer++;
    }

    if (!pointsLayer)
      return false;
  } 


576
577
578
579
580
  return true;
}

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

583
584
  for (unsigned int i = 0; i < layers_.size(); ++i)
  {
585
    if ( layers_[i] == *_prop )
586
      return (int)i;
587
588
589

    //    if (!memcmp(&layers_[i], &bla, sizeof(DrawModeProperties)))
    //      return (int)i;
590
591
592
593
594
  }
  return -1;
}


Jan Möbius's avatar
 
Jan Möbius committed
595
596
597
598
599
600
601
602
603
604
//----------------------------------------------------------------------------


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

    if( initialized_ )
	return;

605
    registeredDrawModes_.clear();
Jan Möbius's avatar
 
Jan Möbius committed
606

607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
    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));

650
651
    SOLID_2DTEXTURED_FACE.       setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_UNLIT, NORMAL_NONE, COLOR_NONE, TEXCOORD_PER_HALFEDGE));
    SOLID_2DTEXTURED_FACE_SHADED.setDrawModeProperties(DrawModeProperties(PRIMITIVE_POLYGON, LIGHTSTAGE_SMOOTH, NORMAL_PER_FACE, COLOR_NONE, TEXCOORD_PER_HALFEDGE));
652
653
654
655
656
657
658
659
660
661

    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));


662
663
    registeredDrawModes_.push_back( DrawModeInternal( "<invalid>", NONE ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Default", DEFAULT ) );
Jan Möbius's avatar
 
Jan Möbius committed
664

665
666
667
    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
668
    
669
670
    registeredDrawModes_.push_back( DrawModeInternal( "Edges", EDGES ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Edges Colored", EDGES_COLORED ) );
Jan Möbius's avatar
Jan Möbius committed
671
    
672
    registeredDrawModes_.push_back( DrawModeInternal( "Wireframe", WIREFRAME ) );
Jan Möbius's avatar
Jan Möbius committed
673
    
674
    registeredDrawModes_.push_back( DrawModeInternal( "Faces", FACES ) );
Jan Möbius's avatar
 
Jan Möbius committed
675
    
676
    registeredDrawModes_.push_back( DrawModeInternal( "Hiddenline", HIDDENLINE ) );
Jan Möbius's avatar
 
Jan Möbius committed
677
    
678
679
680
    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
681
    
682
683
684
    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
685
    
686
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (environment mapped)", SOLID_ENV_MAPPED ) );
Jan Möbius's avatar
 
Jan Möbius committed
687
    
688
689
    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
690
    
691
692
    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
693
    
694
695
    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
696

697
698
    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
699

700
701
702
    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 ) );
703

704
    registeredDrawModes_.push_back( DrawModeInternal( "Solid (smooth shaded, features)", SOLID_SMOOTH_SHADED_FEATURES ) );
705

706
707
    registeredDrawModes_.push_back( DrawModeInternal( "Cells", CELLS ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Cells Colored", CELLS_COLORED ) );
Jan Möbius's avatar
 
Jan Möbius committed
708
    
709
710
    registeredDrawModes_.push_back( DrawModeInternal( "Halfedges", HALFEDGES ) );
    registeredDrawModes_.push_back( DrawModeInternal( "Halfedges Colored", HALFEDGES_COLORED ) );
711

Jan Möbius's avatar
 
Jan Möbius committed
712
713
714
715
716
717
718
719
    firstFreeID_ = UNUSED;
    initialized_ = true;
}


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


720
const DrawMode& addDrawMode( const std::string & _name , bool _propertyBased)
Jan Möbius's avatar
 
Jan Möbius committed
721
{
722
  // check if mode exists already
723
  VecDrawModes::iterator modeIter, modeEnd( registeredDrawModes_.end() );
Jan Möbius's avatar
 
Jan Möbius committed
724

725
726
727
  for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd; ++modeIter ) {
    if( _name == modeIter->name() ) {
      return modeIter->id();
728
    }
729
  }
Jan Möbius's avatar
 
Jan Möbius committed
730
731


732
  // add new mode
733
  registeredDrawModes_.push_back( DrawModeInternal( _name, firstFreeID_ , _propertyBased) );
734
  ++firstFreeID_;
735

736
  return registeredDrawModes_[ registeredDrawModes_.size() - 1 ].id();
Jan Möbius's avatar
 
Jan Möbius committed
737
738
739
}


740
741
742
//----------------------------------------------------------------------------


743
const DrawMode& getDrawMode( const std::string & _name )
744
{
745
  // check if mode exists
746
  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
747

748
  for( modeIter = registeredDrawModes_.begin(); modeIter != modeEnd;  ++modeIter )
749
  {
750
    if( _name == modeIter->name() )
751
    {
752
      return modeIter->id();
753
    }
754
  }
755

756
757
  // the DrawMode does not exists
  return DrawModes::NONE;
758
759
}

Jan Möbius's avatar
Jan Möbius committed
760
761
762
bool drawModeExists(const std::string & _name) {
  
  // check if mode exists
763
  VecDrawModes::const_iterator modeIter, modeEnd( registeredDrawModes_.end() );
Jan Möbius's avatar
Jan Möbius committed
764
  
765
  for( modeIter = registeredDrawModes_.begin();  modeIter != modeEnd;  ++modeIter )
Jan Möbius's avatar
Jan Möbius committed
766
  {
767
    if( _name == modeIter->name() )
Jan Möbius's avatar
Jan Möbius committed
768
769
770
771
772
773
774
      return true;
  }
  
  // the DrawMode does not exists
  return false;  
}

775

Jan Möbius's avatar
Jan Möbius committed
776
777
778
DrawMode getDrawModeFromIndex( unsigned int _index ) {
  return DrawMode(_index);
}
Jan Möbius's avatar
 
Jan Möbius committed
779
780
781
782
783
784

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