0023022: This is desirable to access OpenGl extensions and core API (1.2+) in one...
[occt.git] / src / OpenGl / OpenGl_TriangleStrip.cxx
CommitLineData
2166f0fa
SK
1// File: OpenGl_TriangleStrip.cxx
2// Created: 13 July 2011
3// Author: Sergey ZERCHANINOV
4// Copyright: OPEN CASCADE 2011
5
5f8b738e 6#include <OpenGl_GlCore11.hxx>
2166f0fa
SK
7
8#include <OpenGl_TriangleStrip.hxx>
9
10#include <OpenGl_telem_util.hxx>
11#include <OpenGl_TextureBox.hxx>
12
13#include <OpenGl_AspectFace.hxx>
14#include <OpenGl_Structure.hxx>
15
16/*----------------------------------------------------------------------*/
17
18void draw_degenerates_as_points ( PDS_INTERNAL, tel_point, Tint, const Handle(OpenGl_Workspace) & );
19void draw_degenerates_as_bboxs ( PDS_INTERNAL, tel_point, Tint, const Handle(OpenGl_Workspace) & );
20extern void set_drawable_items ( GLboolean*, int, const float );
21
22/*----------------------------------------------------------------------*/
23
24void OpenGl_TriangleStrip::draw_tmesh (const Tint front_lighting_model,
25 const Aspect_InteriorStyle interior_style,
26 const TEL_COLOUR *edge_colour,
27 const Handle(OpenGl_Workspace) &AWorkspace) const
28{
29 Tint i, newList = 0;
30
2166f0fa
SK
31 tel_colour pfc = myData.fcolours;
32 tel_point pv = myData.vertices;
33 tel_colour pvc = myData.vcolours;
34 tel_point pvn = myData.vnormals;
35 tel_texture_coord pvt = myData.vtexturecoord;
36
37 if ( AWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT ) pvc = pfc = 0;
38
39 if ( AWorkspace->DegenerateModel < 2 && interior_style != Aspect_IS_EMPTY )
40 {
41 if ( front_lighting_model )
42 glEnable(GL_LIGHTING);
43 else
44 glDisable(GL_LIGHTING);
45
46 if ( (AWorkspace->NamedStatus & OPENGL_NS_ANIMATION) == 0 )
47 goto doDraw; /* Disable object display list out of animation */
48 if ( myDS->model != front_lighting_model || !myDS->list || myDS->model == -1 ||
49 ( AWorkspace->DegenerateModel && myDS->skipRatio != AWorkspace->SkipRatio ) )
50 {
51 myDS->skipRatio = AWorkspace->SkipRatio;
52 myDS->model = front_lighting_model;
53 myDS->degMode = AWorkspace->DegenerateModel;
54
55 if ( AWorkspace->SkipRatio <= 0.f ) {
56
57 if ( !myDS->list ) myDS->list = glGenLists ( 1 );
58
59 glNewList ( myDS->list, GL_COMPILE_AND_EXECUTE );
60 newList = 1;
61doDraw:
62 glBegin ( GL_TRIANGLE_STRIP );
63
64 if ( front_lighting_model )
65 {
66 if ( pvt && (AWorkspace->NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0 )
67 {
68 for ( i = 0; i < myData.num_facets + 2; ++i )
69 {
70 glNormal3fv ( pvn[ i ].xyz );
71 glTexCoord2fv ( pvt[ i ].xy );
72 glVertex3fv ( pv [ i ].xyz );
73 }
74 }
75 else
76 for ( i = 0; i < myData.num_facets + 2; ++i )
77 {
78 glNormal3fv( pvn[ i ].xyz );
79 glVertex3fv( pv[ i ].xyz );
80 }
81 }
82 else
83 {
84 if ( pvc )
85 {
86 for ( i = 0; i < myData.num_facets + 2; ++i )
87 {
88 glColor3fv ( pvc[ i ].rgb );
89 glVertex3fv ( pv [ i ].xyz );
90 }
91 }
92 else if ( pfc )
93 {
94 glColor3fv ( pfc[ 0 ].rgb );
95 glVertex3fv ( pv [ 0 ].xyz );
96 glVertex3fv ( pv [ 1 ].xyz );
97 for ( i = 2; i < myData.num_facets + 2; ++i )
98 {
99 glColor3fv ( pfc[ i - 2 ].rgb );
100 glVertex3fv( pv [ i ].xyz );
101 }
102 }
103 else
104 for ( i = 0; i < myData.num_facets + 2; ++i ) glVertex3fv ( pv[ i ].xyz );
105 }
106 glEnd ();
107 }
108 else if ( AWorkspace->SkipRatio < 1.f )
109 {
110 set_drawable_items ( myDS->bDraw, myData.num_facets + 2, AWorkspace->SkipRatio );
111
112 if ( !myDS->dlist ) myDS->dlist = glGenLists ( 1 );
113
114 glNewList ( myDS->dlist, GL_COMPILE_AND_EXECUTE );
115 newList = 1;
116
117 glBegin ( GL_TRIANGLES );
118
119 if ( front_lighting_model )
120 {
121 if ( pvt && (AWorkspace->NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0 )
122 {
123 for ( i = 0; i < myData.num_facets; ++i )
124 {
125 if ( myDS->bDraw[ i ] )
126 {
127 if ( i % 2 )
128 {
129 glNormal3fv ( pvn[ i ].xyz );
130 glTexCoord2fv ( pvt[ i ].xy );
131 glVertex3fv ( pv [ i ].xyz );
132 glNormal3fv ( pvn[ i + 2 ].xyz );
133 glTexCoord2fv ( pvt[ i + 2 ].xy );
134 glVertex3fv ( pv [ i + 2 ].xyz );
135 glNormal3fv ( pvn[ i + 1 ].xyz );
136 glTexCoord2fv ( pvt[ i + 1 ].xy );
137 glVertex3fv ( pv [ i + 1 ].xyz );
138 }
139 else
140 {
141 glNormal3fv ( pvn[ i + 2 ].xyz );
142 glTexCoord2fv ( pvt[ i + 2 ].xy );
143 glVertex3fv ( pv [ i + 2 ].xyz );
144 glNormal3fv ( pvn[ i ].xyz );
145 glTexCoord2fv ( pvt[ i ].xy );
146 glVertex3fv ( pv [ i ].xyz );
147 glNormal3fv ( pvn[ i + 1 ].xyz );
148 glTexCoord2fv ( pvt[ i + 1 ].xy );
149 glVertex3fv ( pv [ i + 1 ].xyz );
150 }
151 }
152 }
153 }
154 else
155 {
156 for ( i = 0; i < myData.num_facets; ++i )
157 {
158 if ( myDS->bDraw[ i ] )
159 {
160 if ( i % 2 )
161 {
162 glNormal3fv( pvn[ i ].xyz );
163 glVertex3fv( pv[ i ].xyz );
164 glNormal3fv( pvn[ i + 2 ].xyz );
165 glVertex3fv( pv[ i + 2 ].xyz );
166 glNormal3fv( pvn[ i + 1 ].xyz );
167 glVertex3fv( pv[ i + 1 ].xyz );
168 }
169 else
170 {
171 glNormal3fv( pvn[ i + 2 ].xyz );
172 glVertex3fv( pv[ i + 2 ].xyz );
173 glNormal3fv( pvn[ i ].xyz );
174 glVertex3fv( pv[ i ].xyz );
175 glNormal3fv( pvn[ i + 1 ].xyz );
176 glVertex3fv( pv[ i + 1 ].xyz );
177 }
178 }
179 }
180 }
181 }
182 else
183 {
184 if ( pvc )
185 {
186 for ( i = 0; i < myData.num_facets; ++i )
187 {
188 if ( myDS->bDraw[ i ] )
189 {
190 if ( i % 2 )
191 {
192 glColor3fv ( pvc[ i ].rgb );
193 glVertex3fv ( pv [ i ].xyz );
194 glColor3fv ( pvc[ i + 2 ].rgb );
195 glVertex3fv ( pv [ i + 2 ].xyz );
196 glColor3fv ( pvc[ i + 1 ].rgb );
197 glVertex3fv ( pv [ i + 1 ].xyz );
198 }
199 else
200 {
201 glColor3fv ( pvc[ i + 2 ].rgb );
202 glVertex3fv ( pv [ i + 2 ].xyz );
203 glColor3fv ( pvc[ i ].rgb );
204 glVertex3fv ( pv [ i ].xyz );
205 glColor3fv ( pvc[ i + 1 ].rgb );
206 glVertex3fv ( pv [ i + 1 ].xyz );
207 }
208 }
209 }
210 }
211 else if ( pfc )
212 {
213 for ( i = 0; i < myData.num_facets; ++i )
214 {
215 if ( myDS->bDraw[ i ] )
216 {
217 if ( i % 2 )
218 {
219 glColor3fv ( pfc[ i ].rgb );
220 glVertex3fv( pv [ i ].xyz );
221 glColor3fv ( pfc[ i + 2 ].rgb );
222 glVertex3fv( pv [ i + 2 ].xyz );
223 glColor3fv ( pfc[ i + 1 ].rgb );
224 glVertex3fv( pv [ i + 1 ].xyz );
225 }
226 else
227 {
228 glColor3fv ( pfc[ i + 2 ].rgb );
229 glVertex3fv( pv [ i + 2 ].xyz );
230 glColor3fv ( pfc[ i ].rgb );
231 glVertex3fv( pv [ i ].xyz );
232 glColor3fv ( pfc[ i + 1 ].rgb );
233 glVertex3fv( pv [ i + 1 ].xyz );
234 }
235 }
236 }
237 }
238 else
239 {
240 for ( i = 0; i < myData.num_facets; ++i )
241 {
242 if ( myDS->bDraw[ i ] )
243 {
244 if ( i % 2 )
245 {
246 glVertex3fv ( pv[ i ].xyz );
247 glVertex3fv ( pv[ i + 2 ].xyz );
248 glVertex3fv ( pv[ i + 1 ].xyz );
249 }
250 else
251 {
252 glVertex3fv ( pv[ i + 2 ].xyz );
253 glVertex3fv ( pv[ i ].xyz );
254 glVertex3fv ( pv[ i + 1 ].xyz );
255 }
256 }
257 }
258 }
259 }
260 glEnd ();
261 }
262 else
263 {
264 if ( !myDS->dlist ) myDS->dlist = glGenLists ( 1 );
265
266 glNewList ( myDS->dlist, GL_COMPILE_AND_EXECUTE );
267 newList = 1;
268 }
269 if ( newList ) glEndList ();
270
271 if ( AWorkspace->DegenerateModel ) return;
272 }
273 else
274 {
275 glCallList ( AWorkspace->SkipRatio <= 0.f ? myDS->list : myDS->dlist );
276 if ( AWorkspace->DegenerateModel ) return;
277 }
278 }
279
280 i = 0;
281
282 /* OCC11904 -- Temporarily disable environment mapping */
283 glPushAttrib(GL_ENABLE_BIT);
284 glDisable(GL_TEXTURE_1D);
285 glDisable(GL_TEXTURE_2D);
286
287 switch ( AWorkspace->DegenerateModel )
288 {
289 default:
290 break;
291
292 case 2: /* XXX_TDM_WIREFRAME */
293 i = 1;
294 break;
295
296 case 3: /* XXX_TDM_MARKER */
297 draw_degenerates_as_points ( myDS, myData.vertices, myData.num_facets + 2, AWorkspace );
298 glPopAttrib();
299 return;
300
301 case 4: /* XXX_TDM_BBOX */
302 draw_degenerates_as_bboxs ( myDS, myData.vertices, myData.num_facets + 2, AWorkspace );
303 glPopAttrib();
304 return;
305 }
306
307 draw_edges ( edge_colour, interior_style, i, AWorkspace );
308
309 glPopAttrib();
310}
311
312/*----------------------------------------------------------------------*/
313
314void OpenGl_TriangleStrip::draw_edges (const TEL_COLOUR *edge_colour, const Aspect_InteriorStyle interior_style,
315 Tint forceDraw, const Handle(OpenGl_Workspace) &AWorkspace) const
316{
317 const OpenGl_AspectFace *aspect_face = AWorkspace->AspectFace( Standard_True );
318
319 if ( interior_style != Aspect_IS_HIDDENLINE && !forceDraw && aspect_face->Context().Edge == TOff )
320 return;
321
322 glDisable(GL_LIGHTING);
323 const GLboolean texture_on = IsTextureEnabled();
324 if ( texture_on ) DisableTexture();
325
326 // Setup line aspect
327 const OpenGl_AspectLine *aspect_line_old = AWorkspace->SetAspectLine( aspect_face->AspectEdge() );
328 AWorkspace->AspectLine( Standard_True );
329
330 tel_point pv = myData.vertices;
331 Tint i, newList = 0;
332
333 glColor3fv ( edge_colour->rgb );
334 if ( !forceDraw )
335 draw_line_loop ();
336 else
337 {
338 if ( (AWorkspace->NamedStatus & OPENGL_NS_ANIMATION) == 0 )
339 goto doDraw; /* Disable object display list out of animation */
340 if ( myDS->degMode != 2 || myDS->skipRatio != AWorkspace->SkipRatio || !myDS->dlist ) {
341
342 if ( !myDS->dlist ) myDS->dlist = glGenLists ( 1 );
343
344 myDS->degMode = 2;
345 myDS->skipRatio = AWorkspace->SkipRatio;
346 glNewList ( myDS->dlist, GL_COMPILE_AND_EXECUTE );
347 newList = 1;
348doDraw:
349 glPushAttrib ( GL_DEPTH_BUFFER_BIT );
350 glDisable ( GL_DEPTH_TEST );
351
352 if ( AWorkspace->SkipRatio <= 0.f )
353
354 draw_line_loop ();
355
356 else if ( AWorkspace->SkipRatio < 1.f ) {
357
358 set_drawable_items ( myDS->bDraw, myData.num_facets + 2, AWorkspace->SkipRatio );
359
360 for ( i = 0; i < myData.num_facets; ++i )
361
362 if ( myDS->bDraw[ i ] ) {
363
364 glBegin ( GL_LINE_LOOP );
365 glVertex3fv ( pv[ i ].xyz );
366 glVertex3fv ( pv[ i + 1 ].xyz );
367 glVertex3fv ( pv[ i + 2 ].xyz );
368 glEnd();
369
370 } /* end if */
371
372 } /* end if */
373
374 glPopAttrib ();
375 if ( newList ) glEndList ();
376
377 } else glCallList ( myDS->dlist );
378
379 } /* end else */
380
381 // Restore line context
382 AWorkspace->SetAspectLine( aspect_line_old );
383
384 if ( texture_on ) EnableTexture ();
385}
386
387void draw_degenerates_as_points ( PDS_INTERNAL pd, tel_point p, Tint n, const Handle(OpenGl_Workspace) &AWorkspace )
388{
389 int i, newList = 0;
390
391 glDisable(GL_LIGHTING);
392 if ( (AWorkspace->NamedStatus & OPENGL_NS_ANIMATION) == 0 )
393 goto doDraw; /* Disable object display list out of animation */
394 if ( pd -> degMode != 3 || pd -> skipRatio != AWorkspace->SkipRatio || !pd -> dlist ) {
395
396 if ( !pd -> dlist ) pd -> dlist = glGenLists ( 1 );
397
398 pd -> degMode = 3;
399 pd -> skipRatio = AWorkspace->SkipRatio;
400 glNewList ( pd -> dlist, GL_COMPILE_AND_EXECUTE );
401 newList = 1;
402
403 if ( AWorkspace->SkipRatio <= 0.f ) {
404doDraw:
405 glBegin ( GL_POINTS );
406
407 for ( i = 0; i < n; ++i ) glVertex3fv ( p[ i ].xyz );
408
409 glEnd ();
410
411 } else if ( AWorkspace->SkipRatio < 1.f ) {
412
413 set_drawable_items ( pd -> bDraw, n, AWorkspace->SkipRatio );
414
415 glBegin ( GL_POINTS );
416
417 for ( i = 0; i < n; ++i )
418
419 if ( pd -> bDraw[ i ] ) glVertex3fv ( p[ i ].xyz );
420
421 glEnd ();
422
423 } /* end if */
424 if ( newList ) glEndList ();
425
426 } else glCallList ( pd -> dlist );
427
428} /* end draw_degenerates_as_points */
429
430void draw_degenerates_as_bboxs ( PDS_INTERNAL pd, tel_point p, Tint n, const Handle(OpenGl_Workspace) &AWorkspace )
431{
432 int i, newList = 0;
433 GLfloat minp[ 3 ] = { FLT_MAX, FLT_MAX, FLT_MAX };
434 GLfloat maxp[ 3 ] = { FLT_MIN, FLT_MIN, FLT_MIN };
435
436 glDisable(GL_LIGHTING);
437 if ( (AWorkspace->NamedStatus & OPENGL_NS_ANIMATION) == 0 )
438 goto doDraw; /* Disable object display list out of animation */
439 if ( pd -> degMode != 4 || !pd -> dlist ) {
440
441 if ( !pd -> dlist ) pd -> dlist = glGenLists ( 1 );
442
443 pd -> degMode = 4;
444
445 glNewList ( pd -> dlist, GL_COMPILE_AND_EXECUTE );
446 newList = 1;
447doDraw:
448 for ( i = 0; i < n; ++i ) {
449
450 TEL_POINT pt = p[ i ];
451
452 if ( pt.xyz[ 0 ] < minp[ 0 ] )
453 minp[ 0 ] = pt.xyz[ 0 ] ;
454 if ( pt.xyz[ 1 ] < minp[ 1 ] )
455 minp[ 1 ] = pt.xyz[ 1 ] ;
456 if ( pt.xyz[ 2 ] < minp[ 2 ] )
457 minp[ 2 ] = pt.xyz[ 2 ] ;
458
459 if ( pt.xyz[ 0 ] > maxp[ 0 ] )
460 maxp[ 0 ] = pt.xyz[ 0 ] ;
461 if ( pt.xyz[ 1 ] > maxp[ 1 ] )
462 maxp[ 1 ] = pt.xyz[ 1 ] ;
463 if ( pt.xyz[ 2 ] > maxp[ 2 ] )
464 maxp[ 2 ] = pt.xyz[ 2 ] ;
465
466 } /* end for */
467
468 glBegin ( GL_LINE_STRIP );
469
470 glVertex3fv ( minp );
471 glVertex3f ( minp[ 0 ], maxp[ 1 ], minp[ 2 ] );
472 glVertex3f ( minp[ 0 ], maxp[ 1 ], maxp[ 2 ] );
473 glVertex3f ( minp[ 0 ], minp[ 1 ], maxp[ 2 ] );
474 glVertex3f ( minp[ 0 ], minp[ 1 ], minp[ 2 ] );
475
476 glVertex3f ( maxp[ 0 ], minp[ 1 ], minp[ 2 ] );
477 glVertex3f ( maxp[ 0 ], maxp[ 1 ], minp[ 2 ] );
478 glVertex3f ( maxp[ 0 ], maxp[ 1 ], maxp[ 2 ] );
479 glVertex3f ( maxp[ 0 ], minp[ 1 ], maxp[ 2 ] );
480 glVertex3f ( maxp[ 0 ], minp[ 1 ], minp[ 2 ] );
481
482 glVertex3f ( maxp[ 0 ], minp[ 1 ], maxp[ 2 ] );
483 glVertex3f ( minp[ 0 ], minp[ 1 ], maxp[ 2 ] );
484 glVertex3f ( minp[ 0 ], maxp[ 1 ], maxp[ 2 ] );
485 glVertex3fv ( maxp );
486 glVertex3f ( maxp[ 0 ], maxp[ 1 ], minp[ 2 ] );
487 glVertex3f ( minp[ 0 ], maxp[ 1 ], minp[ 2 ] );
488
489 glEnd();
490 if ( newList ) glEndList ();
491
492 } else glCallList ( pd -> dlist );
493
494} /* end draw_degenerates_as_bboxs */
495
496void OpenGl_TriangleStrip::draw_line_loop () const
497{
498 int i;
499
500 for ( i = 0; i < myData.num_facets; ++i )
501 {
502 glBegin ( GL_LINE_LOOP );
503 glVertex3fv ( myData.vertices[ i ].xyz );
504 glVertex3fv ( myData.vertices[ i + 1 ].xyz );
505 glVertex3fv ( myData.vertices[ i + 2 ].xyz );
506 glEnd();
507 }
508}
509
510/*----------------------------------------------------------------------*/
511
512OpenGl_TriangleStrip::OpenGl_TriangleStrip (const Graphic3d_Array1OfVertex& AListVertex)
513{
514 const Standard_Integer nv = AListVertex.Length();
515 TEL_POINT *points = new TEL_POINT[nv];
516 memcpy( points, &AListVertex(AListVertex.Lower()), nv*sizeof(TEL_POINT) );
517
518 Init(nv - 2,points,NULL,NULL,NULL,NULL,NULL);
519}
520
521/*----------------------------------------------------------------------*/
522
523OpenGl_TriangleStrip::OpenGl_TriangleStrip (const Graphic3d_Array1OfVertexN& AListVertex)
524{
525 const Standard_Integer nv = AListVertex.Length ();
526
527 // Dynamic allocation
528 TEL_POINT *points = new TEL_POINT[nv];
529 TEL_POINT *normals = new TEL_POINT[nv];
530
531 Standard_Integer i = 0, j = AListVertex.Lower();
532 Standard_Real X, Y, Z;
533 for ( ; i < nv; i++, j++)
534 {
535 AListVertex(j).Coord (X, Y, Z);
536 points[i].xyz[0] = float (X);
537 points[i].xyz[1] = float (Y);
538 points[i].xyz[2] = float (Z);
539 AListVertex(j).Normal (X, Y, Z);
540 normals[i].xyz[0] = float (X);
541 normals[i].xyz[1] = float (Y);
542 normals[i].xyz[2] = float (Z);
543 }
544
545 Init(nv - 2,points,normals,NULL,NULL,NULL,NULL);
546}
547
548/*----------------------------------------------------------------------*/
549
550OpenGl_TriangleStrip::OpenGl_TriangleStrip (const Graphic3d_Array1OfVertexNT& AListVertex)
551{
552 const Standard_Integer nv = AListVertex.Length();
553
554 // Dynamic allocation
555 TEL_POINT *points = new TEL_POINT[nv];
556 TEL_POINT *normals = new TEL_POINT[nv];
557 TEL_TEXTURE_COORD *tcoords = new TEL_TEXTURE_COORD[nv];
558
559 Standard_Integer i = 0, j = AListVertex.Upper();
560 Standard_Real X, Y, Z;
561 for ( ; i < nv; i++, j++)
562 {
563 AListVertex(j).Coord (X, Y, Z);
564 points[i].xyz[0] = float (X);
565 points[i].xyz[1] = float (Y);
566 points[i].xyz[2] = float (Z);
567 AListVertex(j).Normal (X, Y, Z);
568 normals[i].xyz[0] = float (X);
569 normals[i].xyz[1] = float (Y);
570 normals[i].xyz[2] = float (Z);
571 AListVertex(j).TextureCoordinate(X, Y);
572 tcoords[i].xy[0] = float(X);
573 tcoords[i].xy[1] = float(Y);
574 }
575
576 Init(nv - 2,points,normals,NULL,tcoords,NULL,NULL);
577}
578
579/*----------------------------------------------------------------------*/
580
581void OpenGl_TriangleStrip::Init (const Tint ANbFacets, tel_point AVertices,
582 tel_point AVNormals, tel_colour AVColors, tel_texture_coord ATCoords,
583 tel_point AFNormals, tel_colour AFColors)
584{
585 myData.num_facets = ANbFacets;
586
587 const Tint nv = ANbFacets + 2;
588
589 Tint i;
590
591 // Store vertices
592 myData.vertices = AVertices;
593
594 // Store or compute (based on vertices) facet normals
595 if (AFNormals)
596 {
597 myData.facet_flag = TEL_FA_NORMAL;
598 myData.fnormals = AFNormals;
599 for( i = 0; i < ANbFacets; i++ )
600 vecnrm( myData.fnormals[i].xyz );
601 }
602 else
603 {
604 myData.facet_flag = TEL_FA_NONE;
605 myData.fnormals = new TEL_POINT[ANbFacets];
606 for( i = 0; i < ANbFacets; i++ )
607 {
608 if( i & 1 ) {
609 TelGetNormal( myData.vertices[i].xyz, myData.vertices[i+2].xyz, myData.vertices[i+1].xyz, myData.fnormals[i].xyz );
610 } else {
611 TelGetNormal( myData.vertices[i].xyz, myData.vertices[i+1].xyz, myData.vertices[i+2].xyz, myData.fnormals[i].xyz );
612 }
613 }
614 }
615
616 // Store or compute (based on facet normals) vertex normals
617 if (AVNormals)
618 {
619 myData.vertex_flag = TEL_VT_NORMAL;
620 myData.vnormals = AVNormals;
621 for( i = 0; i < nv; i++ )
622 vecnrm( myData.vnormals[i].xyz );
623 }
624 else
625 {
626 myData.vertex_flag = TEL_VT_NONE;
627 myData.vnormals = new TEL_POINT[nv];
628 for( i = 2; i < ANbFacets; i++ )
629 {
630 myData.vnormals[i].xyz[0] = ( myData.fnormals[i-2].xyz[0] + myData.fnormals[i-1].xyz[0] + myData.fnormals[i].xyz[0] ) / 3.0F;
631 myData.vnormals[i].xyz[1] = ( myData.fnormals[i-2].xyz[1] + myData.fnormals[i-1].xyz[1] + myData.fnormals[i].xyz[1] ) / 3.0F;
632 myData.vnormals[i].xyz[2] = ( myData.fnormals[i-2].xyz[2] + myData.fnormals[i-1].xyz[2] + myData.fnormals[i].xyz[2] ) / 3.0F;
633 }
634 myData.vnormals[0] = myData.fnormals[0];
635 if( ANbFacets > 1 )
636 {
637 myData.vnormals[1].xyz[0] = ( myData.fnormals[0].xyz[0] + myData.fnormals[1].xyz[0] ) / 2.0F;
638 myData.vnormals[1].xyz[1] = ( myData.fnormals[0].xyz[1] + myData.fnormals[1].xyz[1] ) / 2.0F;
639 myData.vnormals[1].xyz[2] = ( myData.fnormals[0].xyz[2] + myData.fnormals[1].xyz[2] ) / 2.0F;
640 }
641 else
642 myData.vnormals[1] = myData.fnormals[0];
643 // last vertex
644 myData.vnormals[ANbFacets+1] = myData.fnormals[ANbFacets-1];
645 // second last vertex
646 if( ANbFacets > 1 )
647 {
648 myData.vnormals[ANbFacets].xyz[0] = ( myData.fnormals[ANbFacets-1].xyz[0] + myData.fnormals[ANbFacets-2].xyz[0] ) / 2.0F;
649 myData.vnormals[ANbFacets].xyz[1] = ( myData.fnormals[ANbFacets-1].xyz[1] + myData.fnormals[ANbFacets-2].xyz[1] ) / 2.0F;
650 myData.vnormals[ANbFacets].xyz[2] = ( myData.fnormals[ANbFacets-1].xyz[2] + myData.fnormals[ANbFacets-2].xyz[2] ) / 2.0F;
651 }
652 }
653
654 myData.vcolours = AVColors;
655 myData.vtexturecoord = ATCoords;
656 myData.fcolours = AFColors;
657
658 myDS = new DS_INTERNAL();
659 myDS->list = 0;
660 myDS->dlist = 0;
661 myDS->degMode = 0;
662 myDS->model = -1;
663 myDS->skipRatio = 0.0F;
664 myDS->bDraw = new unsigned char[nv];
665}
666
667/*----------------------------------------------------------------------*/
668
669OpenGl_TriangleStrip::~OpenGl_TriangleStrip ()
670{
671 if( myData.fnormals )
672 delete[] myData.fnormals;
673 if( myData.fcolours )
674 delete[] myData.fcolours;
675 if( myData.vertices )
676 delete[] myData.vertices;
677 if( myData.vcolours )
678 delete[] myData.vcolours;
679 if( myData.vnormals )
680 delete[] myData.vnormals;
681 if ( myData.vtexturecoord )
682 delete[] myData.vtexturecoord;
683
684 if ( myDS )
685 {
686 if ( GET_GL_CONTEXT() != NULL )
687 {
688 if ( myDS->list ) glDeleteLists ( myDS->list, 1 );
689 if ( myDS->dlist ) glDeleteLists ( myDS->dlist, 1 );
690 }
691 if ( myDS->bDraw )
692 delete[] myDS->bDraw;
693
694 delete myDS;
695 }
696}
697
698/*----------------------------------------------------------------------*/
699
700void OpenGl_TriangleStrip::Render (const Handle(OpenGl_Workspace) &AWorkspace) const
701{
702 const OpenGl_AspectFace *aspect_face = AWorkspace->AspectFace( Standard_True );
703
704 Tint front_lighting_model = aspect_face->Context().IntFront.color_mask;
705 const TEL_COLOUR *interior_colour = &aspect_face->Context().IntFront.matcol;
706 const TEL_COLOUR *edge_colour = &aspect_face->AspectEdge()->Color();
707
708 // Use highlight colors
709 if ( AWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT )
710 {
711 edge_colour = interior_colour = AWorkspace->HighlightColor;
712 front_lighting_model = 0;
713 }
714
715 glColor3fv( interior_colour->rgb );
716
717 draw_tmesh( front_lighting_model,
718 aspect_face->Context().InteriorStyle,
719 edge_colour,
720 AWorkspace );
721}
722
723/*----------------------------------------------------------------------*/