File: vtkOpenGLPainterDeviceAdapter.cxx

package info (click to toggle)
vtk6 6.3.0%2Bdfsg2-8.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 118,972 kB
  • sloc: cpp: 1,442,790; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,119; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 154; makefile: 68; objc: 17
file content (932 lines) | stat: -rw-r--r-- 29,356 bytes parent folder | download | duplicates (5)
1
2
3
4
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
37
38
39
40
41
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
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
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
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkOpenGLPainterDeviceAdapter.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
/*
 * Copyright 2004 Sandia Corporation.
 * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
 * license for use of this work by or on behalf of the
 * U.S. Government. Redistribution and use in source and binary forms, with
 * or without modification, are permitted provided that this Notice and any
 * statement of authorship are reproduced on all copies.
 */

#include "vtkOpenGLPainterDeviceAdapter.h"

#include "vtkDataArray.h"
#include "vtkDataSetAttributes.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLGL2PSHelper.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkgl.h"

#include <algorithm>

#include "vtkOpenGL.h"
#include "vtkOpenGLError.h"

vtkStandardNewMacro(vtkOpenGLPainterDeviceAdapter);

//-----------------------------------------------------------------------------
vtkOpenGLPainterDeviceAdapter::vtkOpenGLPainterDeviceAdapter()
{
  this->PointSize = 1.0;
  this->RangeNear = 0.0;
  this->RangeFar = 1.0;
  this->MaxStencil = 0;
  this->Initialized = false;
}

//-----------------------------------------------------------------------------
vtkOpenGLPainterDeviceAdapter::~vtkOpenGLPainterDeviceAdapter()
{
}

//-----------------------------------------------------------------------------
void vtkOpenGLPainterDeviceAdapter::PrintSelf(ostream &os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}

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

// This array is a map from VTK primitive identifiers (VTK_VERTEX, VTK_LINE,
// etc.) to OpenGL polygon primitive identifiers (GL_POINTS, GL_LINES, etc.)
// Note that some VTK polygon types (e.g. VTK_EMPTY_CELL and VTK_PIXEL) have no
// analogue in OpenGL.  Using them will undoubtedly result in an OpenGL error.
static const GLenum VTK2OpenGLPrimitive[] = {
  static_cast<GLenum>(0xFFFF),       // 0 - VTK_EMPTY_CELL
  GL_POINTS,            // 1 - VTK_VERTEX
  GL_POINTS,            // 2 - VTK_POLY_VERTEX
  GL_LINES,             // 3 - VTK_LINE
  GL_LINE_STRIP,        // 4 - VTK_POLY_LINE
  GL_TRIANGLES,         // 5 - VTK_TRIANGLE
  GL_TRIANGLE_STRIP,    // 6 - VTK_TRIANGLE_STRIP
  GL_POLYGON,           // 7 - VTK_POLYGON
  static_cast<GLenum>(0xFFFF),       // 8 - VTK_PIXEL
  GL_QUADS,             // 9 - VTK_QUAD
  GL_LINE_LOOP          // 10 - VTK_TETRA
};

static inline GLenum VTK2OpenGLType(int type)
{
  switch (type)
    {
#if VTK_SIZEOF_CHAR == 1
    case VTK_CHAR:              return GL_BYTE;
    case VTK_UNSIGNED_CHAR:     return GL_UNSIGNED_BYTE;
#elif VTK_SIZE_OF_CHAR == 2
    case VTK_CHAR:              return GL_SHORT;
    case VTK_UNSIGNED CHAR:     return GL_UNSIGNED_SHORT;
#endif

#if VTK_SIZEOF_SHORT == 1
    case VTK_SHORT:             return GL_BYTE;
    case VTK_UNSIGNED_SHORT:    return GL_UNSIGNED_BYTE;
#elif VTK_SIZEOF_SHORT == 2
    case VTK_SHORT:             return GL_SHORT;
    case VTK_UNSIGNED_SHORT:    return GL_UNSIGNED_SHORT;
#elif VTK_SIZEOF_SHORT == 4
    case VTK_SHORT:             return GL_INT;
    case VTK_UNSIGNED_SHORT:    return GL_UNSIGNED_INT;
#endif

#if VTK_SIZEOF_INT == 2
    case VTK_INT:               return GL_SHORT;
    case VTK_UNSIGNED_INT:      return GL_UNSIGNED_SHORT;
#elif VTK_SIZEOF_INT == 4
    case VTK_INT:               return GL_INT;
    case VTK_UNSIGNED_INT:      return GL_UNSIGNED_INT;
#endif

#if VTK_SIZEOF_LONG == 4
    case VTK_LONG:              return GL_INT;
    case VTK_UNSIGNED_LONG:     return GL_UNSIGNED_INT;
#endif

#if VTK_SIZEOF_ID_TYPE == 4
    case VTK_ID_TYPE:           return GL_INT;
#endif

#if VTK_SIZEOF_FLOAT == 4
    case VTK_FLOAT:             return GL_FLOAT;
#elif VTK_SIZEOF_FLOAT == 8
    case VTK_FLOAT:             return GL_DOUBLE;
#endif

#if VTK_SIZEOF_DOUBLE == 4
    case VTK_DOUBLE:            return GL_FLOAT;
#elif VTK_SIZEOF_DOUBLE == 8
    case VTK_DOUBLE:            return GL_DOUBLE;
#endif

    default:                    return GL_FALSE;
    }
}

static inline GLenum VTK2SignedOpenGLType(int type)
{
  switch (type)
    {
#if VTK_SIZEOF_CHAR == 1
    case VTK_CHAR:              return GL_BYTE;
    case VTK_UNSIGNED_CHAR:     return GL_BYTE;
#elif VTK_SIZE_OF_CHAR == 2
    case VTK_CHAR:              return GL_SHORT;
    case VTK_UNSIGNED CHAR:     return GL_SHORT;
#endif

#if VTK_SIZEOF_SHORT == 1
    case VTK_SHORT:             return GL_BYTE;
    case VTK_UNSIGNED_SHORT:    return GL_BYTE;
#elif VTK_SIZEOF_SHORT == 2
    case VTK_SHORT:             return GL_SHORT;
    case VTK_UNSIGNED_SHORT:    return GL_SHORT;
#elif VTK_SIZEOF_SHORT == 4
    case VTK_SHORT:             return GL_INT;
    case VTK_UNSIGNED_SHORT:    return GL_INT;
#endif

#if VTK_SIZEOF_INT == 2
    case VTK_INT:               return GL_SHORT;
    case VTK_UNSIGNED_INT:      return GL_SHORT;
#elif VTK_SIZEOF_INT == 4
    case VTK_INT:               return GL_INT;
    case VTK_UNSIGNED_INT:      return GL_INT;
#endif

#if VTK_SIZEOF_ID_TYPE == 4
    case VTK_ID_TYPE:           return GL_INT;
#endif

#if VTK_SIZEOF_LONG == 4
    case VTK_LONG:              return GL_INT;
    case VTK_UNSIGNED_LONG:     return GL_INT;
#endif

#if VTK_SIZEOF_FLOAT == 4
    case VTK_FLOAT:             return GL_FLOAT;
#elif VTK_SIZEOF_FLOAT == 8
    case VTK_FLOAT:             return GL_DOUBLE;
#endif

#if VTK_SIZEOF_DOUBLE == 4
    case VTK_DOUBLE:            return GL_FLOAT;
#elif VTK_SIZEOF_DOUBLE == 8
    case VTK_DOUBLE:            return GL_DOUBLE;
#endif

    default:                    return GL_FALSE;
    }
}

static inline GLenum VTK2UnsignedOpenGLType(int type)
{
  switch (type)
    {
#if VTK_SIZEOF_CHAR == 1
    case VTK_CHAR:              return GL_UNSIGNED_BYTE;
    case VTK_UNSIGNED_CHAR:     return GL_UNSIGNED_BYTE;
#elif VTK_SIZE_OF_CHAR == 2
    case VTK_CHAR:              return GL_UNSIGNED_SHORT;
    case VTK_UNSIGNED CHAR:     return GL_UNSIGNED_SHORT;
#endif

#if VTK_SIZEOF_SHORT == 1
    case VTK_SHORT:             return GL_UNSIGNED_BYTE;
    case VTK_UNSIGNED_SHORT:    return GL_UNSIGNED_BYTE;
#elif VTK_SIZEOF_SHORT == 2
    case VTK_SHORT:             return GL_UNSIGNED_SHORT;
    case VTK_UNSIGNED_SHORT:    return GL_UNSIGNED_SHORT;
#elif VTK_SIZEOF_SHORT == 4
    case VTK_SHORT:             return GL_UNSIGNED_INT;
    case VTK_UNSIGNED_SHORT:    return GL_UNSIGNED_INT;
#endif

#if VTK_SIZEOF_INT == 2
    case VTK_INT:               return GL_UNSIGNED_SHORT;
    case VTK_UNSIGNED_INT:      return GL_UNSIGNED_SHORT;
#elif VTK_SIZEOF_INT == 4
    case VTK_INT:               return GL_UNSIGNED_INT;
    case VTK_UNSIGNED_INT:      return GL_UNSIGNED_INT;
#endif

#if VTK_SIZEOF_ID_TYPE == 4
    case VTK_ID_TYPE:           return GL_UNSIGNED_INT;
#endif

#if VTK_SIZEOF_LONG == 4
    case VTK_LONG:              return GL_UNSIGNED_INT;
    case VTK_UNSIGNED_LONG:     return GL_UNSIGNED_INT;
#endif

    default:                    return GL_FALSE;
    }
}


//-----------------------------------------------------------------------------
void vtkOpenGLPainterDeviceAdapter::BeginPrimitive(int mode)
{
  glBegin(VTK2OpenGLPrimitive[mode]);
}

//-----------------------------------------------------------------------------
void vtkOpenGLPainterDeviceAdapter::EndPrimitive()
{
  glEnd();
}

//-----------------------------------------------------------------------------
int vtkOpenGLPainterDeviceAdapter::IsAttributesSupported(int attribute)
{
  switch(attribute)
    {
  case vtkDataSetAttributes::NUM_ATTRIBUTES:
  case vtkDataSetAttributes::NORMALS:
  case vtkDataSetAttributes::SCALARS:
  case vtkDataSetAttributes::TCOORDS:
  case vtkDataSetAttributes::EDGEFLAG:
    return 1;
    }
  return 0;
}

//-----------------------------------------------------------------------------
void vtkOpenGLPainterDeviceAdapter::SendAttribute(int index, int numcomp,
  int type, const void *attribute, vtkIdType offset/*=0*/)
{
  switch (index)
    {
  case vtkDataSetAttributes::NUM_ATTRIBUTES:     // Vertex
      if ((numcomp < 2) || (numcomp > 4))
        {
        vtkErrorMacro("Bad number of components.");
        return;
        }
      switch (VTK2SignedOpenGLType(type))
        {
        case GL_SHORT:
          switch (numcomp)
            {
            case 2:
              glVertex2sv(static_cast<const GLshort *>(attribute) + offset);
              break;
            case 3:
              glVertex3sv(static_cast<const GLshort *>(attribute) + offset);
              break;
            case 4:
              glVertex4sv(static_cast<const GLshort *>(attribute) + offset);
              break;
            }
          break;
        case GL_INT:
          switch (numcomp)
            {
            case 2:
              glVertex2iv(static_cast<const GLint *>(attribute) + offset);
              break;
            case 3:
              glVertex3iv(static_cast<const GLint *>(attribute) + offset);
              break;
            case 4:
              glVertex4iv(static_cast<const GLint *>(attribute) + offset);
              break;
            }
          break;
        case GL_FLOAT:
          switch (numcomp)
            {
            case 2:
              glVertex2fv(static_cast<const GLfloat *>(attribute) + offset);
              break;
            case 3:
              glVertex3fv(static_cast<const GLfloat *>(attribute) + offset);
              break;
            case 4:
              glVertex4fv(static_cast<const GLfloat *>(attribute) + offset);
              break;
            }
          break;
        case GL_DOUBLE:
          switch (numcomp)
            {
            case 2:
              glVertex2dv(static_cast<const GLdouble *>(attribute) + offset);
              break;
            case 3:
              glVertex3dv(static_cast<const GLdouble *>(attribute) + offset);
              break;
            case 4:
              glVertex4dv(static_cast<const GLdouble *>(attribute) + offset);
              break;
            }
          break;
        default:
          vtkErrorMacro("Unsupported type for vertices: " << type);
          return;
        }
      break;
  case vtkDataSetAttributes::NORMALS:     // Normal
      if (numcomp != 3)
        {
        vtkErrorMacro("Bad number of components.");
        return;
        }
      switch (VTK2SignedOpenGLType(type))
        {
        case GL_BYTE:
          glNormal3bv(static_cast<const GLbyte *>(attribute) + offset);
          break;
        case GL_SHORT:
          glNormal3sv(static_cast<const GLshort *>(attribute) + offset);
          break;
        case GL_INT:
          glNormal3iv(static_cast<const GLint *>(attribute) + offset);
          break;
        case GL_FLOAT:
          glNormal3fv(static_cast<const GLfloat *>(attribute) + offset);
          break;
        case GL_DOUBLE:
          glNormal3dv(static_cast<const GLdouble *>(attribute) + offset);
          break;
        default:
          vtkErrorMacro("Unsupported type for normals: " << type);
          return;
        }
      break;
  case vtkDataSetAttributes::SCALARS:     // Color
      if ((numcomp != 3) && (numcomp != 4))
        {
        vtkErrorMacro("Bad number of components.");
        return;
        }
      switch (VTK2OpenGLType(type))
        {
        case GL_BYTE:
          switch (numcomp)
            {
            case 3: glColor3bv(static_cast<const GLbyte *>(attribute) + offset);
              break;
            case 4: glColor4bv(static_cast<const GLbyte *>(attribute) + offset);
              break;
            }
          break;
        case GL_UNSIGNED_BYTE:
          switch (numcomp)
            {
            case 3: glColor3ubv(static_cast<const GLubyte *>(attribute) + offset);
              break;
            case 4: glColor4ubv(static_cast<const GLubyte *>(attribute) + offset);
              break;
            }
          break;
        case GL_SHORT:
          switch (numcomp)
            {
            case 3: glColor3sv(static_cast<const GLshort *>(attribute) + offset);
              break;
            case 4: glColor4sv(static_cast<const GLshort *>(attribute) + offset);
              break;
            }
          break;
        case GL_UNSIGNED_SHORT:
          switch (numcomp)
            {
            case 3: glColor3usv(static_cast<const GLushort *>(attribute) + offset);
              break;
            case 4: glColor4usv(static_cast<const GLushort *>(attribute) + offset);
              break;
            }
          break;
        case GL_INT:
          switch (numcomp)
            {
            case 3: glColor3iv(static_cast<const GLint *>(attribute) + offset);
              break;
            case 4: glColor4iv(static_cast<const GLint *>(attribute) + offset);
              break;
            }
          break;
        case GL_UNSIGNED_INT:
          switch (numcomp)
            {
            case 3: glColor3uiv(static_cast<const GLuint *>(attribute) + offset);
              break;
            case 4: glColor4uiv(static_cast<const GLuint *>(attribute) + offset);
              break;
            }
          break;
        case GL_FLOAT:
          switch (numcomp)
            {
            case 3: glColor3fv(static_cast<const GLfloat *>(attribute) + offset);
              break;
            case 4: glColor4fv(static_cast<const GLfloat *>(attribute) + offset);
              break;
            }
          break;
        case GL_DOUBLE:
          switch (numcomp)
            {
            case 3: glColor3dv(static_cast<const GLdouble *>(attribute) + offset);
              break;
            case 4: glColor4dv(static_cast<const GLdouble *>(attribute) + offset);
              break;
            }
          break;
        default:
          vtkErrorMacro("Unsupported type for colors: " << type);
          return;
        }
      break;

  case vtkDataSetAttributes::TCOORDS:     // Texture Coordinate
      if ((numcomp < 1) || (numcomp > 4))
        {
        vtkErrorMacro("Bad number of components.");
        return;
        }
      switch (VTK2SignedOpenGLType(type))
        {
        case GL_SHORT:
          switch (numcomp)
            {
            case 1:
              glTexCoord1sv(static_cast<const GLshort *>(attribute) + offset);
              break;
            case 2:
              glTexCoord2sv(static_cast<const GLshort *>(attribute) + offset);
              break;
            case 3:
              glTexCoord3sv(static_cast<const GLshort *>(attribute) + offset);
              break;
            case 4:
              glTexCoord4sv(static_cast<const GLshort *>(attribute) + offset);
              break;
            }
          break;
        case GL_INT:
          switch (numcomp)
            {
            case 1:
              glTexCoord1iv(static_cast<const GLint *>(attribute) + offset);
              break;
            case 2:
              glTexCoord2iv(static_cast<const GLint *>(attribute) + offset);
              break;
            case 3:
              glTexCoord3iv(static_cast<const GLint *>(attribute) + offset);
              break;
            case 4:
              glTexCoord4iv(static_cast<const GLint *>(attribute) + offset);
              break;
            }
          break;
        case GL_FLOAT:
          switch (numcomp)
            {
            case 1:
              glTexCoord1fv(static_cast<const GLfloat *>(attribute) + offset);
              break;
            case 2:
              glTexCoord2fv(static_cast<const GLfloat *>(attribute) + offset);
              break;
            case 3:
              glTexCoord3fv(static_cast<const GLfloat *>(attribute) + offset);
              break;
            case 4:
              glTexCoord4fv(static_cast<const GLfloat *>(attribute) + offset);
              break;
            }
          break;
        case GL_DOUBLE:
          switch (numcomp)
            {
            case 1:
              glTexCoord1dv(static_cast<const GLdouble *>(attribute) + offset);
              break;
            case 2:
              glTexCoord2dv(static_cast<const GLdouble *>(attribute) + offset);
              break;
            case 3:
              glTexCoord3dv(static_cast<const GLdouble *>(attribute) + offset);
              break;
            case 4:
              glTexCoord4dv(static_cast<const GLdouble *>(attribute) + offset);
              break;
            }
          break;
        default:
          vtkErrorMacro("Unsupported type for texture coordinates: " << type);
          return;
        }
      break;
    case vtkDataSetAttributes::EDGEFLAG:        // Edge Flag
      if (numcomp != 1)
        {
        vtkErrorMacro("Bad number of components.");
        return;
        }
       switch (type)
        {
        vtkTemplateMacro(glEdgeFlag(static_cast<GLboolean>(
                          reinterpret_cast<const VTK_TT*>(attribute)[offset])));
        }
      break;
    default:
      vtkErrorMacro("Unsupported attribute index: " << index);
      return;
    };
}

//-----------------------------------------------------------------------------
void vtkOpenGLPainterDeviceAdapter::SendMultiTextureCoords(int numcomp,
  int type, const void *attribute, int idx, vtkIdType offset)
{
  if(! vtkgl::MultiTexCoord2d)
    {
    vtkErrorMacro("MultiTexturing not supported.");
    return;
    }

  if ((numcomp < 1) || (numcomp > 4))
    {
    vtkErrorMacro("Bad number of components.");
    return;
    }

  int textureIndex = vtkgl::TEXTURE0 + idx;
  switch (VTK2SignedOpenGLType(type))
    {
    case GL_SHORT:
      switch (numcomp)
        {
        case 1:
          vtkgl::MultiTexCoord1sv(textureIndex, static_cast<const GLshort *>(attribute) + offset);
          break;
        case 2:
          vtkgl::MultiTexCoord2sv(textureIndex, static_cast<const GLshort *>(attribute) + offset);
          break;
        case 3:
          vtkgl::MultiTexCoord3sv(textureIndex, static_cast<const GLshort *>(attribute) + offset);
          break;
        case 4:
          vtkgl::MultiTexCoord4sv(textureIndex, static_cast<const GLshort *>(attribute) + offset);
          break;
        }
      break;
    case GL_INT:
      switch (numcomp)
        {
        case 1:
          vtkgl::MultiTexCoord1iv(textureIndex, static_cast<const GLint *>(attribute) + offset);
          break;
        case 2:
          vtkgl::MultiTexCoord2iv(textureIndex, static_cast<const GLint *>(attribute) + offset);
          break;
        case 3:
          vtkgl::MultiTexCoord3iv(textureIndex, static_cast<const GLint *>(attribute) + offset);
          break;
        case 4:
          vtkgl::MultiTexCoord4iv(textureIndex, static_cast<const GLint *>(attribute) + offset);
          break;
        }
      break;
    case GL_FLOAT:
      switch (numcomp)
        {
        case 1:
          vtkgl::MultiTexCoord1fv(textureIndex, static_cast<const GLfloat *>(attribute) + offset);
          break;
        case 2:
          vtkgl::MultiTexCoord2fv(textureIndex, static_cast<const GLfloat *>(attribute) + offset);
          break;
        case 3:
          vtkgl::MultiTexCoord3fv(textureIndex, static_cast<const GLfloat *>(attribute) + offset);
          break;
        case 4:
          vtkgl::MultiTexCoord4fv(textureIndex, static_cast<const GLfloat *>(attribute) + offset);
          break;
        }
      break;
    case GL_DOUBLE:
      switch (numcomp)
        {
        case 1:
          vtkgl::MultiTexCoord1dv(textureIndex, static_cast<const GLdouble *>(attribute) + offset);
          break;
        case 2:
          vtkgl::MultiTexCoord2dv(textureIndex, static_cast<const GLdouble *>(attribute) + offset);
          break;
        case 3:
          vtkgl::MultiTexCoord3dv(textureIndex, static_cast<const GLdouble *>(attribute) + offset);
          break;
        case 4:
          vtkgl::MultiTexCoord4dv(textureIndex, static_cast<const GLdouble *>(attribute) + offset);
          break;
        }
      break;
    default:
      vtkErrorMacro("Unsupported type for texture coordinates: " << type);
      return;
    }

}

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

void vtkOpenGLPainterDeviceAdapter::SetAttributePointer(int index,
              int numcomponents,
              int type, int stride,
              const void *pointer)
{
  GLenum gltype;

  switch (index)
    {
  case vtkDataSetAttributes::NUM_ATTRIBUTES:     // Vertex
      gltype = VTK2SignedOpenGLType(type);
      switch (gltype)
        {
        case GL_SHORT:
        case GL_INT:
        case GL_FLOAT:
        case GL_DOUBLE:
          break;
        default:
          vtkErrorMacro("Unsupported type for vertices: " << type);
          return;
        }
      glVertexPointer(numcomponents, gltype, stride, pointer);
      break;
  case vtkDataSetAttributes::NORMALS:     // Normal
      gltype = VTK2SignedOpenGLType(type);
      switch (gltype)
        {
        case GL_BYTE:
        case GL_SHORT:
        case GL_INT:
        case GL_FLOAT:
        case GL_DOUBLE:
          break;
        default:
          vtkErrorMacro("Unsupported type for normals: " << type);
          return;
        }
      if (numcomponents != 3)
        {
        vtkErrorMacro("Unsupported number of components for normals.");
        return;
        }
      glNormalPointer(gltype, stride, pointer);
      break;
  case vtkDataSetAttributes::SCALARS:     // Color
      gltype = VTK2OpenGLType(type);
      switch (gltype)
        {
        case GL_BYTE:
        case GL_UNSIGNED_BYTE:
        case GL_SHORT:
        case GL_UNSIGNED_SHORT:
        case GL_INT:
        case GL_UNSIGNED_INT:
        case GL_FLOAT:
        case GL_DOUBLE:
          break;
        default:
          vtkErrorMacro("Unsupported type for colors: " << type);
          return;
        }
      glColorPointer(numcomponents, gltype, stride, pointer);
      break;
  case vtkDataSetAttributes::TCOORDS:     // Texture Coordinate
      gltype = VTK2SignedOpenGLType(type);
      switch (gltype)
        {
        case GL_SHORT:
        case GL_INT:
        case GL_FLOAT:
        case GL_DOUBLE:
          break;
        default:
          vtkErrorMacro("Unsupported type for texture coordinates: " << type);
          return;
        }
      glTexCoordPointer(numcomponents, gltype, stride, pointer);
      break;
    case vtkDataSetAttributes::EDGEFLAG:        // Edge flag
      if (numcomponents != 1)
        {
        vtkErrorMacro("Edge flag must have one component.");
        return;
        }
      // Flag must be conformant to GLboolean
      if ((type == VTK_FLOAT) || (type == GL_DOUBLE))
        {
        vtkErrorMacro("Unsupported type for edge flag: " << type);
        return;
        }
      // Thus is an unfriendly way to force the array to be conformant to
      // a GLboolean array.  At the very least there should be some indication
      // in VTK outside of OpenGL to determine which VTK type to use.
      switch (type)
        {
        vtkTemplateMacro(if (sizeof(VTK_TT) != sizeof(GLboolean))
                           {
                           vtkErrorMacro(<< "Unsupported tyep for edge flag: "
                                         << type);
                           return;
                           }
                         );
        }
      glEdgeFlagPointer(stride, pointer);
      break;
    default:
      vtkErrorMacro("Unsupported attribute index: " << index);
      return;
    };
}

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

void vtkOpenGLPainterDeviceAdapter::EnableAttributeArray(int index)
{
  switch (index)
    {
  case vtkDataSetAttributes::NUM_ATTRIBUTES:
      glEnableClientState(GL_VERTEX_ARRAY);  break;
  case vtkDataSetAttributes::NORMALS:
      glEnableClientState(GL_NORMAL_ARRAY);  break;
  case vtkDataSetAttributes::SCALARS:
      glEnableClientState(GL_COLOR_ARRAY);  break;
  case vtkDataSetAttributes::TCOORDS:
      glEnableClientState(GL_TEXTURE_COORD_ARRAY);  break;
  case vtkDataSetAttributes::EDGEFLAG:
      glEnableClientState(GL_EDGE_FLAG_ARRAY);  break;
    default:
      vtkErrorMacro("Unsupported attribute index: " << index);
      return;
    };
}

void vtkOpenGLPainterDeviceAdapter::DisableAttributeArray(int index)
{
  switch (index)
    {
  case vtkDataSetAttributes::NUM_ATTRIBUTES:
      glDisableClientState(GL_VERTEX_ARRAY);  break;
  case vtkDataSetAttributes::NORMALS:
      glDisableClientState(GL_NORMAL_ARRAY);  break;
  case vtkDataSetAttributes::SCALARS:
      glDisableClientState(GL_COLOR_ARRAY);  break;
  case vtkDataSetAttributes::TCOORDS:
      glDisableClientState(GL_TEXTURE_COORD_ARRAY);  break;
  case vtkDataSetAttributes::EDGEFLAG:
      glDisableClientState(GL_EDGE_FLAG_ARRAY);  break;
    default:
      vtkErrorMacro("Unsupported attribute index: " << index);
      return;
    };
}

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

void vtkOpenGLPainterDeviceAdapter::DrawArrays(int mode, vtkIdType first,
                                               vtkIdType count)
{
  glDrawArrays(VTK2OpenGLPrimitive[mode],static_cast<GLint>(first),
               static_cast<GLsizei>(count));
}

void vtkOpenGLPainterDeviceAdapter::DrawElements(int mode, vtkIdType count,
                                                 int type, void *indices)
{
  GLenum gltype = VTK2UnsignedOpenGLType(type);
  switch (gltype)
    {
    case GL_UNSIGNED_BYTE:
    case GL_UNSIGNED_SHORT:
    case GL_UNSIGNED_INT:
      break;
    default:
      if (type == VTK_ID_TYPE)
        {
        // This seems really inefficient for handling vtkIdType when they
        // are 64 bit, but OpenGL does not handle 64 bit indices.  What
        // else can I do?
        vtkIdType *oldarray = static_cast<vtkIdType *>(indices);
        GLuint *newarray = new GLuint[count];
        std::copy(oldarray, oldarray + count, newarray);
        glDrawElements(VTK2OpenGLPrimitive[mode], static_cast<GLsizei>(count),
                       GL_UNSIGNED_INT, newarray);
        delete[] newarray;
        return;
        }
      else
        {
        vtkErrorMacro("Invalid type for indices.");
        return;
        }
    }
  glDrawElements(VTK2OpenGLPrimitive[mode],static_cast<GLsizei>(count), gltype,
                 indices);
}

//-----------------------------------------------------------------------------
int vtkOpenGLPainterDeviceAdapter::Compatible(vtkRenderer *renderer)
{
  vtkOpenGLRenderWindow *context
    = vtkOpenGLRenderWindow::SafeDownCast(renderer->GetRenderWindow());
  if (!context)
    {
    return false;
    }
  return true;
}

//-----------------------------------------------------------------------------
void vtkOpenGLPainterDeviceAdapter::MakeVertexEmphasis(bool mode)
{
  if (mode)
    {
    float s;
    glGetFloatv(GL_POINT_SIZE, &s);
    this->PointSize = s;
    glPointSize(4.0); //make verts large enough to be sure to overlap cell
    vtkOpenGLGL2PSHelper::SetPointSize(4.0);

    float nf[2];   //put verts just in front of associated cells
    glGetFloatv(GL_DEPTH_RANGE, nf);
    this->RangeNear = nf[0];
    this->RangeFar = nf[1];
    glDepthRange(0.0, nf[1]*0.999999);
    glDepthMask(GL_FALSE); //prevent verts from interfering with each other
    }
  else
    {
    glPointSize(static_cast<GLfloat>(this->PointSize));
    vtkOpenGLGL2PSHelper::SetPointSize(static_cast<GLfloat>(this->PointSize));
    glDepthRange(this->RangeNear, this->RangeFar);
    glDepthMask(GL_TRUE);
    }
  vtkOpenGLCheckErrorMacro("failed after MakeVertexEmphasis");
}

//-----------------------------------------------------------------------------
void vtkOpenGLPainterDeviceAdapter::WriteStencil(vtkIdType value)
{
  if (this->MaxStencil)
    {
    value = value % this->MaxStencil + 1;
    if (value == 1)
      {
      glClearStencil(0); //start over so don't write into some previous area
      }
    glStencilFunc(GL_ALWAYS, static_cast<GLint>(value), this->MaxStencil);
    glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
    vtkOpenGLCheckErrorMacro("failed after WriteStencil");
    }
}

//-----------------------------------------------------------------------------
void vtkOpenGLPainterDeviceAdapter::TestStencil(vtkIdType value)
{
  if (this->MaxStencil)
    {
    value = value % this->MaxStencil + 1;
    glStencilFunc(GL_EQUAL, static_cast<GLint>(value), this->MaxStencil);
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
    vtkOpenGLCheckErrorMacro("failed after TestStencil");
    }
}

//-----------------------------------------------------------------------------
void vtkOpenGLPainterDeviceAdapter::Stencil(int on)
{
  if (on)
    {
    glEnable(GL_STENCIL_TEST);
    GLint stencilbits;
    glGetIntegerv(GL_STENCIL_BITS, &stencilbits);
    this->MaxStencil = (1<<stencilbits)-1;
    }
  else
    {
    glDisable(GL_STENCIL_TEST);
    }
  vtkOpenGLCheckErrorMacro("failed after Stencil");
}