2 File OpenGl_PrimitiveArray.c
4 Created 16/06/2000 : ATS : G005 : Modified version of OpenGl_indexpolygons.c, which use glDrawArrays or glDrawElements for rendering of primitive
5 21.06.03 : SAN : suppress display at all in animation mode if degenartion ratio == 1 (FULL_DEGENER)
6 03.07.03 : SAN : draw_degenerates_as_lines() function - all client states disabled except GL_VERTEX_ARRAY
7 in order to avoid exceptions in animation mode (OCC3192)
10 #define xOGLBUG /* UNFORTUNATLY the edge flags are attached to vertexes
11 and not to the edges. So the edge visibillity flags array
24 #define OGL_Max(a,b) ((a) > (b) ? (a) : (b))
28 static unsigned long vRand = 1L;
29 #define OGL_Rand() (vRand = vRand * 214013L + 2531011L)
33 #define OCC7833 /* ASL 26/01/05 transparency of polygon with colors assigned to vertices */
35 /*----------------------------------------------------------------------*/
40 #include <OpenGl_tgl_all.hxx>
47 #include <OpenGl_cmn_varargs.hxx>
48 #include <OpenGl_telem_attri.hxx>
49 #include <OpenGl_tsm.hxx>
50 #include <OpenGl_telem.hxx>
51 #include <OpenGl_telem_util.hxx>
52 #include <OpenGl_telem_highlight.hxx>
53 #include <OpenGl_telem_inquire.hxx>
54 #include <OpenGl_telem_view.hxx>
55 #include <OpenGl_tgl_funcs.hxx>
56 #include <OpenGl_LightBox.hxx>
57 #include <OpenGl_TextureBox.hxx>
58 #include <InterfaceGraphic_PrimitiveArray.hxx>
59 #include <OpenGl_Memory.hxx>
60 #include <Standard.hxx>
63 # define DEF_DS_INTERNAL
64 # include <OpenGl_degeneration.hxx>
66 #include <OpenGl_Extension.hxx>
68 extern GLboolean g_fBitmap;
70 typedef CALL_DEF_PARRAY *call_def_parray;
72 #define GL_ARRAY_BUFFER_ARB 0x8892
73 #define GL_STATIC_DRAW_ARB 0x88E4
74 #define GL_ELEMENTS_ARRAY_BUFFER_ARB 0x8893
75 #define GL_EDGE_FLAG_ARRAY_EXT 0x8079
78 typedef void (APIENTRY* PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
79 typedef void (APIENTRY* PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
80 typedef void (APIENTRY* PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
81 typedef void (APIENTRY* PFNGLBUFFERDATAARBPROC) (GLenum target, int size, const GLvoid *data, GLenum usage);
83 typedef void (*PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
84 typedef void (*PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
85 typedef void (*PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
87 typedef void (*PFNGLBUFFERDATAARBPROC) (GLenum target, int size, const GLvoid *data, GLenum usage);
89 typedef void (*PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage);
94 PFNGLGENBUFFERSARBPROC glVBOGenBuffersARB = NULL; // VBO Name Generation Procedure
95 PFNGLBINDBUFFERARBPROC glVBOBindBufferARB = NULL; // VBO Bind Procedure
96 PFNGLBUFFERDATAARBPROC glVBOBufferDataARB = NULL; // VBO Data Loading Procedure
97 PFNGLDELETEBUFFERSARBPROC glVBODeleteBuffersARB = NULL; // VBO Data Deleting Procedure
102 #define VBO_NOT_INITIALIZED -1
107 #define glGetProcAddress( x ) glXGetProcAddress( (const GLubyte*) x )
109 #define glGetProcAddress( x ) wglGetProcAddress( x )
112 void clearRAMMemory( CALL_DEF_PARRAY* p )
114 if( p->bufferVBO[VBOEdges] ){
115 Standard::Free((Standard_Address&)p->edges);
118 if( p->bufferVBO[VBOVertices] ){
119 Standard::Free((Standard_Address&)p->vertices);
122 if( p->bufferVBO[VBOVcolours] ){
123 Standard::Free((Standard_Address&)p->vcolours);
126 if( p->bufferVBO[VBOVnormals] ){
127 Standard::Free((Standard_Address&)p->vnormals);
130 if( p->bufferVBO[VBOVtexels] ){
131 Standard::Free((Standard_Address&)p->vtexels);
135 Standard::Free((Standard_Address&)p->edge_vis);
140 void clearGraphicRAMMemory( CALL_DEF_PARRAY* p )
142 if( p->bufferVBO[VBOEdges] ){
143 glVBODeleteBuffersARB( 1 , &p->bufferVBO[VBOEdges]);
145 if( p->bufferVBO[VBOVertices] ){
146 glVBODeleteBuffersARB( 1 , &p->bufferVBO[VBOVertices]);
148 if( p->bufferVBO[VBOVcolours] ){
149 glVBODeleteBuffersARB( 1 , &p->bufferVBO[VBOVcolours]);
151 if( p->bufferVBO[VBOVnormals] ){
152 glVBODeleteBuffersARB( 1 , &p->bufferVBO[VBOVnormals]);
154 if( p->bufferVBO[VBOVtexels] ){
155 glVBODeleteBuffersARB( 1 , &p->bufferVBO[VBOVtexels]);
157 glVBOBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
158 glVBOBindBufferARB(GL_ELEMENTS_ARRAY_BUFFER_ARB, 0);
161 int checkSizeForGraphicMemory( CALL_DEF_PARRAY* p )
163 if( GL_OUT_OF_MEMORY == glGetError() ){
164 p->flagBufferVBO = VBO_ERROR;
165 clearGraphicRAMMemory(p);
168 p->flagBufferVBO = VBO_OK;
169 return p->flagBufferVBO ;
174 if(CheckExtension((char *)"GL_ARB_vertex_buffer_object",(const char *)glGetString( GL_EXTENSIONS ))){
175 glVBOGenBuffersARB = (PFNGLGENBUFFERSARBPROC) glGetProcAddress("glGenBuffersARB");
176 glVBOBindBufferARB = (PFNGLBINDBUFFERARBPROC) glGetProcAddress("glBindBufferARB");
177 glVBOBufferDataARB = (PFNGLBUFFERDATAARBPROC) glGetProcAddress("glBufferDataARB");
178 glVBODeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC) glGetProcAddress("glDeleteBuffersARB");
185 static void BuildVBO( CALL_DEF_PARRAY* p )
189 size_reqd = ( p->num_edges * sizeof( Tint ) );
190 glVBOGenBuffersARB( 1, &p->bufferVBO[VBOEdges] );
191 glVBOBindBufferARB( GL_ELEMENTS_ARRAY_BUFFER_ARB, p->bufferVBO[VBOEdges] );
192 glVBOBufferDataARB( GL_ELEMENTS_ARRAY_BUFFER_ARB, size_reqd , p->edges, GL_STATIC_DRAW_ARB );
193 if( checkSizeForGraphicMemory( p ) == VBO_ERROR )
198 size_reqd = ( p->num_vertexs * sizeof( TEL_POINT ) );
199 glVBOGenBuffersARB( 1, &p->bufferVBO[VBOVertices]);
200 glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVertices] );
201 glVBOBufferDataARB( GL_ARRAY_BUFFER_ARB, size_reqd , p->vertices, GL_STATIC_DRAW_ARB );
202 if( checkSizeForGraphicMemory( p ) == VBO_ERROR )
207 size_reqd = ( p->num_vertexs * sizeof( Tint ) );
208 glVBOGenBuffersARB( 1, &p->bufferVBO[VBOVcolours] );
209 glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVcolours]);
210 glVBOBufferDataARB( GL_ARRAY_BUFFER_ARB, size_reqd , p->vcolours, GL_STATIC_DRAW_ARB );
211 if( checkSizeForGraphicMemory( p ) == VBO_ERROR )
216 size_reqd = ( p->num_vertexs * sizeof( TEL_POINT ) );
217 glVBOGenBuffersARB( 1, &p->bufferVBO[VBOVnormals] );
218 glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVnormals] );
219 glVBOBufferDataARB( GL_ARRAY_BUFFER_ARB, size_reqd , p->vnormals, GL_STATIC_DRAW_ARB );
220 if( checkSizeForGraphicMemory( p ) == VBO_ERROR)
225 size_reqd = ( p->num_vertexs * sizeof( TEL_TEXTURE_COORD ) );
226 glVBOGenBuffersARB( 1, &p->bufferVBO[VBOVtexels] );
227 glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVtexels] );
228 glVBOBufferDataARB( GL_ARRAY_BUFFER_ARB, size_reqd , p->vtexels , GL_STATIC_DRAW_ARB );
229 if( checkSizeForGraphicMemory( p ) == VBO_ERROR )
233 if( p->flagBufferVBO == VBO_OK )
237 /*----------------------------------------------------------------------*/
242 /*----------------------------------------------------------------------*/
247 static TStatus ParrayDisplay( TSM_ELEM_DATA, Tint, cmn_key* );
248 static TStatus ParrayAdd( TSM_ELEM_DATA, Tint, cmn_key* );
249 static TStatus ParrayDelete( TSM_ELEM_DATA, Tint, cmn_key* );
250 static TStatus ParrayPrint( TSM_ELEM_DATA, Tint, cmn_key* );
251 static TStatus ParrayInquire( TSM_ELEM_DATA, Tint, cmn_key* );
253 /*static GLboolean lighting_mode;*/
255 static void draw_array(
257 Tint, /* highlight_flag */
258 Tint, /* front_lighting_model, */
259 Tint, /* interior_style, */
260 Tint, /* edge_flag, */
261 tel_colour, /* interior_colour, */
262 tel_colour, /* line_colour, */
263 tel_colour /* edge_colour, */
269 static void draw_edges ( call_def_parray, tel_colour );
270 static void draw_degenerates_as_points ( call_def_parray, tel_colour );
271 static void draw_degenerates_as_lines ( call_def_parray, tel_colour );
272 static void draw_degenerates_as_bboxs ( call_def_parray, tel_colour );
274 static TStatus (*MtdTbl[])( TSM_ELEM_DATA, Tint, cmn_key* ) =
276 NULL, /* PickTraverse */
283 static GLenum draw_mode;
285 /*----------------------------------------------------------------------*/
290 extern Tint ForbidSetTextureMapping; /* currently defined in tsm/tsm.c */
292 extern int g_nDegenerateModel;
293 extern float g_fSkipRatio;
295 /*----------------------------------------------------------------------*/
298 TelParrayInitClass( TelType* el )
304 /*----------------------------------------------------------------------*/
307 ParrayAdd( TSM_ELEM_DATA d, Tint n, cmn_key *k )
310 if( k[0]->id != PARRAY_ID ) return TFailure;
312 ((tsm_elem_data)(d.pdata))->pdata = k[0]->data.pdata;
317 /*----------------------------------------------------------------------*/
320 ParrayDisplay( TSM_ELEM_DATA data, Tint n, cmn_key *k )
322 CMN_KEY k11, k12, k17, k18, k111, k114, k115;
324 Tint front_lighting_model;
326 TEL_COLOUR interior_colour;
327 TEL_COLOUR edge_colour;
328 TEL_COLOUR line_colour;
336 call_def_parray d = (call_def_parray)data.pdata;
338 k12.id = TelInteriorReflectanceEquation;
339 k17.id = TelInteriorStyle;
340 k18.id = TelEdgeFlag;
341 k111.id = TelInteriorColour;
342 k111.data.pdata = &interior_colour;
343 k114.id = TelEdgeColour;
344 k114.data.pdata = &edge_colour;
345 k115.id = TelPolylineColour;
346 k115.data.pdata = &line_colour;
349 k117.id = TelSurfaceAreaProperties;
350 k117.data.pdata = ∝
354 TsmGetAttri( 7, &k12, &k17, &k18, &k111, &k114, &k115, &k117 );
356 TsmGetAttri( 6, &k12, &k17, &k18, &k111, &k114, &k115 );
359 front_lighting_model = k12.data.ldata;
360 interior_style = k17.data.ldata;
361 edge_flag = k18.data.ldata;
364 printf("ParrayDisplay type %d\n",d->type);
368 * Use highlight colours
371 if( k[0]->id == TOn ) {
374 k11.id = TelHighlightIndex;
375 TsmGetAttri( 1, &k11 );
376 if( TelGetHighlightRep( TglActiveWs, k11.data.ldata, &hrep ) == TSuccess ) {
377 if( hrep.type == TelHLForcedColour ) {
378 edge_colour = interior_colour = line_colour = hrep.col;
379 front_lighting_model = CALL_PHIGS_REFL_NONE;
380 } else if( hrep.type == TelHLColour ) {
381 edge_colour = hrep.col;
385 TelGetHighlightRep( TglActiveWs, 0, &hrep );
386 if( hrep.type == TelHLForcedColour ) {
387 edge_colour = interior_colour = line_colour = hrep.col;
388 front_lighting_model = CALL_PHIGS_REFL_NONE;
389 } else if( hrep.type == TelHLColour ) {
390 edge_colour = hrep.col;
396 draw_array( d, k[0]->id,
397 front_lighting_model,
412 /*----------------------------------------------------------------------*/
415 draw_primitive_array( call_def_parray p, GLenum mode, GLint first, GLsizei count )
419 for( i=first; i<(first + count); i++ ){
421 glNormal3fv( p->vnormals[i].xyz );
422 if( p->vtexels && !ForbidSetTextureMapping )
423 glTexCoord3fv( p->vtexels[i].xy );
425 glVertex3fv( p->vertices[i].xyz );
427 glColor4ubv( (GLubyte*) p->vcolours[i] );
432 /*----------------------------------------------------------------------*/
434 draw_primitive_elements( call_def_parray p, GLenum mode, GLsizei count, GLenum type, GLenum *indices )
439 for( i=0; i<count; i++ ){
442 glNormal3fv( p->vnormals[index].xyz );
443 if( p->vtexels && !ForbidSetTextureMapping )
444 glTexCoord3fv( p->vtexels[index].xy );
446 glVertex3fv( p->vertices[index].xyz );
448 glColor4ubv( (GLubyte*) p->vcolours[index] );
452 /*----------------------------------------------------------------------*/
454 draw_array( call_def_parray p, Tint hflag,
458 tel_colour interior_colour,
459 tel_colour line_colour,
460 tel_colour edge_colour
468 /* Following pointers have been provided for performance improvement */
477 for( i=0; i<p->num_vertexs; i++ ){
478 transp = (int)(prop->trans * 255.);
479 #if defined (sparc) || defined (__sparc__) || defined (__sparc)
480 pvc[i] = ( pvc[i] & 0xffffff00 );
484 pvc[i] = ( pvc[i] & 0x00ffffff );
485 pvc[i] += transp << 24;
492 case TelPointsArrayType:
493 draw_mode = GL_POINTS;
494 glColor3fv( line_colour->rgb );
496 case TelPolylinesArrayType:
497 draw_mode = GL_LINE_STRIP;
498 glColor3fv( line_colour->rgb );
500 case TelSegmentsArrayType:
501 draw_mode = GL_LINES;
502 glColor3fv( line_colour->rgb );
504 case TelPolygonsArrayType:
505 draw_mode = GL_POLYGON;
506 glColor3fv( interior_colour->rgb );
508 case TelTrianglesArrayType:
509 draw_mode = GL_TRIANGLES;
510 glColor3fv( interior_colour->rgb );
512 case TelQuadranglesArrayType:
513 draw_mode = GL_QUADS;
514 glColor3fv( interior_colour->rgb );
516 case TelTriangleStripsArrayType:
517 draw_mode = GL_TRIANGLE_STRIP;
518 glColor3fv( interior_colour->rgb );
520 case TelQuadrangleStripsArrayType:
521 draw_mode = GL_QUAD_STRIP;
522 glColor3fv( interior_colour->rgb );
524 case TelTriangleFansArrayType:
525 draw_mode = GL_TRIANGLE_FAN;
526 glColor3fv( interior_colour->rgb );
532 /* OCC11904 -- Temporarily disable environment mapping */
533 if( draw_mode <= GL_LINE_STRIP ){
534 glPushAttrib(GL_ENABLE_BIT);
535 glDisable(GL_TEXTURE_1D);
536 glDisable(GL_TEXTURE_2D);
539 if( p->VBOEnabled == -1 ){
540 p->VBOEnabled = VBOenabled;
541 if( VBOExtension == 0)
543 if( (VBOExtension == 1) && (p->VBOEnabled != 0))
549 printf(" $$$ g_nDegenerateModel %d\n",g_nDegenerateModel);
551 if ( g_nDegenerateModel < 2 &&
552 ( (draw_mode > GL_LINE_STRIP && interior_style != TSM_EMPTY) ||
553 (draw_mode <= GL_LINE_STRIP /*&& !hflag*/)) ) {
560 if ( interior_style == TSM_HIDDENLINE) {
566 /*OCC12297 - Sometimes the GL_LIGHTING mode is activated here
567 without LightOn() call for an unknown reason, so it is necessary
568 to call LightOn() to synchronize LightOn/Off mechanism*/
571 if( lighting_model == CALL_PHIGS_REFL_NONE || draw_mode <= GL_LINE_STRIP )
574 glGetIntegerv( GL_RENDER_MODE, &renderMode );
576 if ( p->num_vertexs > 0 && p->flagBufferVBO != VBO_OK) {
577 if( renderMode != GL_FEEDBACK ){
579 glVertexPointer(3, GL_FLOAT, 0, p->vertices);/* array of vertices */
580 glEnableClientState(GL_VERTEX_ARRAY);
584 glNormalPointer(GL_FLOAT, 0, p->vnormals);/* array of normals */
585 glEnableClientState(GL_NORMAL_ARRAY);
589 glTexCoordPointer(2, GL_FLOAT, 0, p->vtexels);/* array of texture coordinates */
590 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
595 glColorPointer(4, GL_UNSIGNED_BYTE, 0, pvc); /* array of colors */
597 glColorPointer(3, GL_UNSIGNED_BYTE, 0, pvc); /* array of colors */
599 glEnableClientState(GL_COLOR_ARRAY);
600 glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
601 glEnable(GL_COLOR_MATERIAL);
606 //Bindings concrete pointer in accordance with VBO buffer
608 if ( p->num_vertexs > 0 && p->flagBufferVBO == VBO_OK ) {
609 if( p->bufferVBO[VBOVertices] ){
610 glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVertices]);
611 glVertexPointer(3, GL_FLOAT, 0, (char *) NULL);// array of vertices
612 glEnableClientState(GL_VERTEX_ARRAY);
615 if( p->bufferVBO[VBOVnormals] ){
616 glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVnormals]);
617 glNormalPointer(GL_FLOAT, 0, (char *) NULL);// array of normals
618 glEnableClientState(GL_NORMAL_ARRAY);
621 if ( p->bufferVBO[VBOVtexels] && !ForbidSetTextureMapping ) {
622 glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVtexels]);
623 glTexCoordPointer(2, GL_FLOAT, 0, (char *) NULL);/* array of texture coordinates */
624 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
627 if ( p->bufferVBO[VBOVcolours] ) {
628 glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVcolours]);
629 glColorPointer( 4, GL_UNSIGNED_BYTE, 0, (char *) NULL);// array of colors
630 glEnableClientState(GL_COLOR_ARRAY);
631 glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
632 glEnable(GL_COLOR_MATERIAL);
635 // OCC22236 NOTE: draw for all situations:
636 // 1) draw elements from p->bufferVBO[VBOEdges] indicies array
637 // 2) draw elements from vertice array, when bounds defines count of primitive's verts.
639 if( p->flagBufferVBO == VBO_OK ){
640 if ( p->num_edges > 0 && p->bufferVBO[VBOEdges] ) {
641 glVBOBindBufferARB(GL_ELEMENTS_ARRAY_BUFFER_ARB, p->bufferVBO[VBOEdges]); // for edge indices
642 glDrawElements( draw_mode, p->num_edges , GL_UNSIGNED_INT, 0);
645 for( i = n = 0 ; i < p->num_bounds ; i ++ ){
646 glDrawArrays( draw_mode, n, p->bounds[i]);
651 glVBOBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
652 glVBOBindBufferARB(GL_ELEMENTS_ARRAY_BUFFER_ARB, 0);
655 if( p->num_bounds > 0 ) {
656 if( p->num_edges > 0 ) {
657 for( i=n=0 ; i<p->num_bounds ; i++ ) {
658 if( pfc ) glColor3fv ( pfc[i].rgb );
659 if( renderMode == GL_FEEDBACK )
660 draw_primitive_elements( p, draw_mode, p->bounds[i],
661 GL_UNSIGNED_INT,(GLenum*) &p->edges[n]);
663 glDrawElements( draw_mode, p->bounds[i],
664 GL_UNSIGNED_INT, &p->edges[n]);
668 for( i=n=0 ; i<p->num_bounds ; i++ ) {
670 glColor3fv ( pfc[i].rgb );
671 if( renderMode == GL_FEEDBACK )
672 draw_primitive_array( p, draw_mode, n, p->bounds[i]);
675 glDrawArrays( draw_mode, n, p->bounds[i]);
680 } else if( p->num_edges > 0 ) {
681 if( renderMode == GL_FEEDBACK )
682 draw_primitive_elements( p, draw_mode, p->num_edges,
683 GL_UNSIGNED_INT,(GLenum*) &p->edges[0]);
685 glDrawElements( draw_mode, p->num_edges, GL_UNSIGNED_INT, p->edges);
687 if( renderMode == GL_FEEDBACK )
688 draw_primitive_array( p, draw_mode, 0, p->num_vertexs);
690 glDrawArrays( draw_mode, 0, p->num_vertexs);
695 if( p->bufferVBO[VBOVcolours] || pvc ) {
696 glDisable(GL_COLOR_MATERIAL);
701 if( p->bufferVBO[VBOVertices] || p->vertices )
702 glDisableClientState(GL_VERTEX_ARRAY);
703 if( p->bufferVBO[VBOVcolours] || p->vcolours )
704 glDisableClientState(GL_COLOR_ARRAY);
705 if( p->bufferVBO[VBOVnormals] || p->vnormals )
706 glDisableClientState(GL_NORMAL_ARRAY);
707 if ( (p->bufferVBO[VBOVtexels] && !ForbidSetTextureMapping ) || p->vtexels )
708 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
710 if ( g_nDegenerateModel ){
711 if(draw_mode <= GL_LINE_STRIP)
717 if( edge_flag || g_nDegenerateModel )
718 switch ( g_nDegenerateModel ) {
719 default: /* XXX_TDM_NODE or TINY */
721 On some NVIDIA graphic cards, using glEdgeFlagPointer() in
722 combination with VBO ( edge flag data put into a VBO buffer)
723 leads to a crash in a driver. Therefore, edge flags are simply
724 igonored when VBOs are enabled, so all the edges are drawn if
725 edge visibility is turned on. In order to draw edges selectively,
726 either disable VBO or turn off edge visibilty in the current
727 primitive array and create a separate primitive array (segments)
728 and put edges to be drawn into it.
730 draw_edges ( p, edge_flag ? edge_colour : interior_colour );
732 // DegenerateModel(as Lines, Points, BBoxs) are used only without VBO
733 case 2: /* XXX_TDM_WIREFRAME */
734 if( p->VBOEnabled == 0 )
735 draw_degenerates_as_lines ( p, edge_flag ? edge_colour : interior_colour );
737 case 3: /* XXX_TDM_MARKER */
738 if( p->VBOEnabled == 0 )
739 draw_degenerates_as_points ( p, edge_flag ? edge_colour : interior_colour );
741 case 4: /* XXX_TDM_BBOX */
742 if( p->VBOEnabled == 0 )
743 draw_degenerates_as_bboxs ( p, edge_flag ? edge_colour : interior_colour );
747 if(draw_mode <= GL_LINE_STRIP)
751 /*----------------------------------------------------------------------*/
754 ParrayDelete( TSM_ELEM_DATA data, Tint n, cmn_key *k )
759 /*----------------------------------------------------------------------*/
762 draw_edges ( call_def_parray p, tel_colour edge_colour )
765 Tint edge_type=0, line_type_preserve=0;
766 Tfloat edge_width=0, line_width_preserve=0;
767 /* GLboolean texture_on;*/
773 if( draw_mode > GL_LINE_STRIP ) {
774 CMN_KEY k, k1, k2, k3, k4;
776 k1.id = TelPolylineWidth;
777 k2.id = TelPolylineType;
779 k4.id = TelEdgeWidth;
781 TsmGetAttri( 4, &k1, &k2, &k3, &k4 );
783 line_width_preserve = k1.data.fdata;
784 line_type_preserve = k2.data.ldata;
785 edge_type = k3.data.ldata;
786 edge_width = k4.data.fdata;
788 if( line_width_preserve != edge_width ) {
789 k.id = TelPolylineWidth;
790 k.data.fdata = edge_width;
791 TsmSetAttri( 1, &k );
793 if( line_type_preserve != edge_type ) {
794 k.id = TelPolylineType;
795 k.data.ldata = edge_type;
796 TsmSetAttri( 1, &k );
799 glPushAttrib( GL_POLYGON_BIT );
800 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
803 // OCC22236 NOTE: draw edges for all situations:
804 // 1) draw elements with GL_LINE style as edges from p->bufferVBO[VBOEdges] indicies array
805 // 2) draw elements with GL_LINE style as edges from vertice array,
806 // when bounds defines count of primitive's verts.
807 if(p->flagBufferVBO == VBO_OK)
809 glVBOBindBufferARB( GL_ARRAY_BUFFER_ARB, p->bufferVBO[VBOVertices] );
810 glEnableClientState( GL_VERTEX_ARRAY );
811 glColor3fv( edge_colour->rgb );
812 if ( p->num_edges > 0 && p->bufferVBO[VBOEdges] ) {
813 glVBOBindBufferARB(GL_ELEMENTS_ARRAY_BUFFER_ARB, p->bufferVBO[VBOEdges]);
814 glDrawElements( draw_mode, p->num_edges, GL_UNSIGNED_INT, 0);
817 for( i = n = 0 ; i < p->num_bounds ; i ++ ) {
818 glDrawArrays( draw_mode , n , p->bounds[i]);
822 glDisableClientState(GL_VERTEX_ARRAY);
823 glVBOBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
824 glVBOBindBufferARB(GL_ELEMENTS_ARRAY_BUFFER_ARB, 0);
828 glEnableClientState(GL_VERTEX_ARRAY);
829 glVertexPointer(3, GL_FLOAT, 0, p->vertices); /* array of vertices */
832 glEnableClientState(GL_EDGE_FLAG_ARRAY);
833 glEdgeFlagPointer( sizeof(Tchar), p->edge_vis);
835 glDisableClientState(GL_EDGE_FLAG_ARRAY);
838 glGetIntegerv( GL_RENDER_MODE, &renderMode );
840 glColor3fv( edge_colour->rgb );
841 if( p->num_bounds > 0 ) {
842 if( p->num_edges > 0 ) {
843 for( i=n=0 ; i<p->num_bounds ; i++ ) {
846 glBegin( draw_mode );
847 for( j=0 ; j<p->bounds[i] ; j++ ) {
848 glEdgeFlag( p->edge_vis[n+j] );
849 glVertex3fv( &p->vertices[p->edges[n+j]].xyz[0] );
854 if( renderMode == GL_FEEDBACK )
855 draw_primitive_elements( p, draw_mode, p->bounds[i],
856 GL_UNSIGNED_INT, (GLenum*)&p->edges[n]);
858 glDrawElements( draw_mode, p->bounds[i],
859 GL_UNSIGNED_INT, &p->edges[n]);
863 for( i=n=0 ; i<p->num_bounds ; i++ ) {
864 if( renderMode == GL_FEEDBACK )
865 draw_primitive_array( p, draw_mode, n, p->bounds[i]);
867 glDrawArrays( draw_mode, n, p->bounds[i]);
872 else if( p->num_edges > 0 ) {
875 glBegin( draw_mode );
876 for( i=0 ; i<p->num_edges ; i++ ) {
877 glEdgeFlag( p->edge_vis[i] );
878 glVertex3fv( &p->vertices[p->edges[i]].xyz[0] );
883 if( renderMode == GL_FEEDBACK )
884 draw_primitive_elements( p, draw_mode, p->num_edges,
885 GL_UNSIGNED_INT,(GLenum*) p->edges);
887 glDrawElements( draw_mode, p->num_edges,
888 GL_UNSIGNED_INT, p->edges);
890 if( renderMode == GL_FEEDBACK )
891 draw_primitive_array( p, draw_mode, 0, p->num_vertexs);
893 glDrawArrays( draw_mode, 0, p->num_vertexs);
897 if( draw_mode > GL_LINE_STRIP ) {
899 if( line_width_preserve != edge_width ) {
900 k.id = TelPolylineWidth;
901 k.data.fdata = line_width_preserve;
902 TsmSetAttri( 1, &k );
904 if( line_type_preserve != edge_type ) {
905 k.id = TelPolylineType;
906 k.data.ldata = line_type_preserve;
907 TsmSetAttri( 1, &k );
913 /*----------------------------------------------------------------------*/
914 static void draw_degenerates_points_as_points ( call_def_parray p ) {
917 tel_point pv = p -> vertices;
920 if ( g_fSkipRatio == 1. )
924 for ( j=0 ; j<p->num_vertexs ; j++ ) {
925 glVertex3fv ( &pv[j].xyz[0] );
929 /*----------------------------------------------------------------------*/
930 static void draw_degenerates_lines_as_points ( call_def_parray p ) {
934 tel_point pv = p -> vertices;
937 if ( g_fSkipRatio == 1. )
941 for ( j=0 ; j<p->num_vertexs ; j+=2 ) {
942 pt[0] = pt[1] = pt[2] = 0.;
943 pt[ 0 ] += pv[j].xyz[ 0 ];
944 pt[ 1 ] += pv[j].xyz[ 1 ];
945 pt[ 2 ] += pv[j].xyz[ 2 ];
946 pt[ 0 ] += pv[j+1].xyz[ 0 ];
947 pt[ 1 ] += pv[j+1].xyz[ 1 ];
948 pt[ 2 ] += pv[j+1].xyz[ 2 ];
956 /*----------------------------------------------------------------------*/
957 static void draw_degenerates_triangles_as_points ( call_def_parray p ) {
961 tel_point pv = p -> vertices;
964 if ( g_fSkipRatio == 1. )
968 if( p->num_edges > 0 ) {
969 for ( j=0 ; j<p->num_edges ; j+=3 ) {
970 pt[0] = pt[1] = pt[2] = 0.;
971 for ( i=0 ; i<3 ; i++ ) {
973 pt[ 0 ] += pv[iv].xyz[ 0 ];
974 pt[ 1 ] += pv[iv].xyz[ 1 ];
975 pt[ 2 ] += pv[iv].xyz[ 2 ];
983 for ( j=0 ; j<p->num_vertexs ; j+=3 ) {
984 pt[0] = pt[1] = pt[2] = 0.;
985 for ( i=0 ; i<3 ; i++ ) {
986 pt[ 0 ] += pv[j+i].xyz[ 0 ];
987 pt[ 1 ] += pv[j+i].xyz[ 1 ];
988 pt[ 2 ] += pv[j+i].xyz[ 2 ];
998 /*----------------------------------------------------------------------*/
999 static void draw_degenerates_trianglestrips_as_points ( call_def_parray p ) {
1003 tel_point pv = p -> vertices;
1006 if ( g_fSkipRatio == 1. )
1010 if( p->num_bounds > 0 ) {
1011 for ( k=n=0 ; k<p->num_bounds ; k++ ) {
1012 for ( j=0 ; j<p->bounds[k]-2 ; j++ ) {
1013 pt[0] = pt[1] = pt[2] = 0.;
1014 for ( i=0 ; i<3 ; i++ ) {
1015 pt[ 0 ] += pv[n+j+i].xyz[ 0 ];
1016 pt[ 1 ] += pv[n+j+i].xyz[ 1 ];
1017 pt[ 2 ] += pv[n+j+i].xyz[ 2 ];
1027 for ( j=0 ; j<p->num_vertexs-2 ; j++ ) {
1028 pt[0] = pt[1] = pt[2] = 0.;
1029 for ( i=0 ; i<3 ; i++ ) {
1030 pt[ 0 ] += pv[j+i].xyz[ 0 ];
1031 pt[ 1 ] += pv[j+i].xyz[ 1 ];
1032 pt[ 2 ] += pv[j+i].xyz[ 2 ];
1042 /*----------------------------------------------------------------------*/
1043 static void draw_degenerates_polygons_as_points ( call_def_parray p ) {
1047 tel_point pv = p -> vertices;
1050 if ( g_fSkipRatio == 1. )
1054 if( p->num_bounds > 0 ) {
1055 if( p->num_edges > 0 ) {
1056 for ( k=n=0 ; k<p->num_bounds ; k++ ) {
1057 pt[0] = pt[1] = pt[2] = 0.;
1058 for ( j=0 ; j<p->bounds[k] ; j++ ) {
1060 pt[ 0 ] += pv[iv].xyz[ 0 ];
1061 pt[ 1 ] += pv[iv].xyz[ 1 ];
1062 pt[ 2 ] += pv[iv].xyz[ 2 ];
1064 pt[ 0 ] /= p->bounds[k];
1065 pt[ 1 ] /= p->bounds[k];
1066 pt[ 2 ] /= p->bounds[k];
1071 for ( k=n=0 ; k<p->num_bounds ; k++ ) {
1072 pt[0] = pt[1] = pt[2] = 0.;
1073 for ( j=0 ; j<p->bounds[k] ; j++ ) {
1074 pt[ 0 ] += pv[n+j].xyz[ 0 ];
1075 pt[ 1 ] += pv[n+j].xyz[ 1 ];
1076 pt[ 2 ] += pv[n+j].xyz[ 2 ];
1078 pt[ 0 ] /= p->bounds[k];
1079 pt[ 1 ] /= p->bounds[k];
1080 pt[ 2 ] /= p->bounds[k];
1085 } else if( p->num_edges > 0 ) {
1086 pt[0] = pt[1] = pt[2] = 0.;
1087 for ( j=0 ; j<p->num_edges ; j++ ) {
1089 pt[ 0 ] += pv[iv].xyz[ 0 ];
1090 pt[ 1 ] += pv[iv].xyz[ 1 ];
1091 pt[ 2 ] += pv[iv].xyz[ 2 ];
1093 pt[ 0 ] /= p->num_edges;
1094 pt[ 1 ] /= p->num_edges;
1095 pt[ 2 ] /= p->num_edges;
1098 pt[0] = pt[1] = pt[2] = 0.;
1099 for ( j=0 ; j<p->num_vertexs ; j++ ) {
1100 pt[ 0 ] += pv[j].xyz[ 0 ];
1101 pt[ 1 ] += pv[j].xyz[ 1 ];
1102 pt[ 2 ] += pv[j].xyz[ 2 ];
1104 pt[ 0 ] /= p->num_vertexs;
1105 pt[ 1 ] /= p->num_vertexs;
1106 pt[ 2 ] /= p->num_vertexs;
1111 /*----------------------------------------------------------------------*/
1112 static void draw_degenerates_quadrangles_as_points ( call_def_parray p ) {
1116 tel_point pv = p -> vertices;
1119 if ( g_fSkipRatio == 1. )
1123 if( p->num_edges > 0 ) {
1124 for ( j=0 ; j<p->num_edges ; j+=4 ) {
1125 pt[0] = pt[1] = pt[2] = 0.;
1126 for ( i=0 ; i<4 ; i++ ) {
1128 pt[ 0 ] += pv[iv].xyz[ 0 ];
1129 pt[ 1 ] += pv[iv].xyz[ 1 ];
1130 pt[ 2 ] += pv[iv].xyz[ 2 ];
1138 for ( j=0 ; j<p->num_vertexs ; j+=4 ) {
1139 pt[0] = pt[1] = pt[2] = 0.;
1140 for ( i=0 ; i<4 ; i++ ) {
1141 pt[ 0 ] += pv[j+i].xyz[ 0 ];
1142 pt[ 1 ] += pv[j+i].xyz[ 1 ];
1143 pt[ 2 ] += pv[j+i].xyz[ 2 ];
1153 /*----------------------------------------------------------------------*/
1154 static void draw_degenerates_quadranglestrips_as_points ( call_def_parray p ) {
1158 tel_point pv = p -> vertices;
1161 if ( g_fSkipRatio == 1. )
1165 if( p->num_bounds > 0 ) {
1166 for ( k=n=0 ; k<p->num_bounds ; k++ ) {
1167 for ( j=0 ; j<p->bounds[k]-2 ; j+=2 ) {
1168 pt[0] = pt[1] = pt[2] = 0.;
1169 for ( i=0 ; i<4 ; i++ ) {
1170 pt[ 0 ] += pv[n+j+i].xyz[ 0 ];
1171 pt[ 1 ] += pv[n+j+i].xyz[ 1 ];
1172 pt[ 2 ] += pv[n+j+i].xyz[ 2 ];
1182 for ( j=0 ; j<p->num_vertexs-2 ; j+=2 ) {
1183 pt[0] = pt[1] = pt[2] = 0.;
1184 for ( i=0 ; i<4 ; i++ ) {
1185 pt[ 0 ] += pv[j+i].xyz[ 0 ];
1186 pt[ 1 ] += pv[j+i].xyz[ 1 ];
1187 pt[ 2 ] += pv[j+i].xyz[ 2 ];
1197 /*----------------------------------------------------------------------*/
1198 static void draw_degenerates_as_points ( call_def_parray p,
1199 tel_colour edge_colour )
1202 GLboolean zbuff_state = glIsEnabled(GL_DEPTH_TEST);
1204 if( zbuff_state ) glDisable(GL_DEPTH_TEST);
1205 glColor3fv( edge_colour->rgb );
1206 glBegin ( GL_POINTS );
1207 switch( draw_mode ) {
1209 draw_degenerates_points_as_points( p );
1212 draw_degenerates_lines_as_points( p );
1216 draw_degenerates_polygons_as_points( p );
1219 draw_degenerates_triangles_as_points( p );
1222 draw_degenerates_quadrangles_as_points( p );
1224 case GL_TRIANGLE_FAN:
1225 case GL_TRIANGLE_STRIP:
1226 draw_degenerates_trianglestrips_as_points( p );
1229 draw_degenerates_quadranglestrips_as_points( p );
1237 if( zbuff_state ) glEnable(GL_DEPTH_TEST);
1240 /*----------------------------------------------------------------------*/
1241 static void draw_degenerates_lines_as_lines ( call_def_parray p ) {
1244 tel_point pv = p -> vertices;
1247 j = (int)((1.-g_fSkipRatio)*n);
1250 p->keys[i] = -p->keys[i];
1253 if( p->num_bounds > 0 ) {
1254 if( p->num_edges > 0 ) {
1255 for ( i=n=0 ; i<p->num_bounds ; i++ ) {
1256 glBegin ( GL_LINES );
1257 for ( j=0 ; j<p->bounds[i] ; j++ ) {
1259 if( p->keys[iv] < 0 ) {
1260 p->keys[iv] = -p->keys[iv];
1261 glVertex3fv ( pv[iv].xyz );
1268 for ( i=n=0 ; i<p->num_bounds ; i++ ) {
1269 glBegin ( GL_LINES );
1270 for ( j=0 ; j<p->bounds[i] ; j++ ) {
1271 if( p->keys[n+j] < 0 ) {
1272 p->keys[n+j] = -p->keys[n+j];
1273 glVertex3fv ( pv[n+j].xyz );
1280 } else if( p->num_edges > 0 ) {
1281 glBegin ( GL_LINES );
1282 for ( j=0 ; j<p->num_edges ; j++ ) {
1284 if( p->keys[iv] < 0 ) {
1285 p->keys[iv] = -p->keys[iv];
1286 glVertex3fv ( pv[iv].xyz );
1291 glBegin ( GL_LINES );
1292 for ( j=0 ; j<p->num_vertexs ; j++ ) {
1293 if( p->keys[j] < 0 ) {
1294 p->keys[j] = -p->keys[j];
1295 glVertex3fv ( pv[j].xyz );
1302 /*----------------------------------------------------------------------*/
1303 static void draw_degenerates_triangles_as_lines ( call_def_parray p )
1307 tel_point pv = p -> vertices;
1309 n = p->num_vertexs/3;
1310 j = (int)((1.-g_fSkipRatio)*n);
1312 i = OGL_Rand() % n; i *= 3;
1313 p->keys[i] = -p->keys[i];
1316 if( p->num_edges > 0 ) {
1317 for ( j=0 ; j<p->num_edges ; j+=3 ) {
1319 if( p->keys[iv] < 0 ) {
1320 p->keys[iv] = -p->keys[iv];
1321 glBegin ( GL_LINE_LOOP );
1322 for ( i=0 ; i<3 ; i++ ) {
1324 glVertex3fv ( pv[iv].xyz );
1330 for ( j=0 ; j<p->num_vertexs ; j+=3 ) {
1331 if( p->keys[j] < 0 ) {
1332 p->keys[j] = -p->keys[j];
1333 glBegin ( GL_LINE_LOOP );
1334 for ( i=0 ; i<3 ; i++ ) {
1335 glVertex3fv ( pv[j+i].xyz );
1343 /*----------------------------------------------------------------------*/
1344 static void draw_degenerates_trianglestrips_as_lines ( call_def_parray p )
1348 tel_point pv = p -> vertices;
1350 if( p->num_bounds > 0 ) {
1351 for ( i=n=0 ; i<p->num_bounds ; i++ ) {
1352 ni = p->bounds[i]-2;
1353 k = (int)((1.-g_fSkipRatio)*ni);
1355 j = OGL_Rand() % ni; j += 2;
1356 p->keys[n+j] = -p->keys[n+j];
1358 for ( j=2 ; j<p->bounds[i] ; j++ ) {
1359 if( p->keys[n+j] < 0 ) {
1360 p->keys[n+j] = -p->keys[n+j];
1361 glBegin ( GL_LINE_LOOP );
1362 glVertex3fv ( pv[n+j-2].xyz );
1363 glVertex3fv ( pv[n+j-1].xyz );
1364 glVertex3fv ( pv[n+j].xyz );
1371 ni = p->num_vertexs-2;
1372 k = (int)((1.-g_fSkipRatio)*ni);
1374 j = OGL_Rand() % ni; j += 2;
1375 p->keys[j] = -p->keys[j];
1377 for ( j=2 ; j<p->num_vertexs ; j++ ) {
1378 if( p->keys[j] < 0 ) {
1379 p->keys[j] = -p->keys[j];
1380 glBegin ( GL_LINE_LOOP );
1381 glVertex3fv ( pv[j-2].xyz );
1382 glVertex3fv ( pv[j-1].xyz );
1383 glVertex3fv ( pv[j].xyz );
1390 /*----------------------------------------------------------------------*/
1391 static void draw_degenerates_polygons_as_lines ( call_def_parray p )
1394 tel_point pv = p -> vertices;
1397 j = (int)((1.-g_fSkipRatio)*n);
1400 p->keys[i] = -p->keys[i];
1403 if( p->num_bounds > 0 ) {
1404 if( p->num_edges > 0 ) {
1405 for ( i=n=0 ; i<p->num_bounds ; i++ ) {
1406 glBegin ( GL_LINE_LOOP );
1407 for ( j=0 ; j<p->bounds[i] ; j++ ) {
1409 if( p->keys[iv] < 0 ) {
1410 p->keys[iv] = -p->keys[iv];
1411 glVertex3fv ( pv[iv].xyz );
1418 for ( i=n=0 ; i<p->num_bounds ; i++ ) {
1419 glBegin ( GL_LINE_LOOP );
1420 for ( j=0 ; j<p->bounds[i] ; j++ ) {
1421 if( p->keys[n+j] < 0 ) {
1422 p->keys[n+j] = -p->keys[n+j];
1423 glVertex3fv ( pv[n+j].xyz );
1430 } else if( p->num_edges > 0 ) {
1431 glBegin ( GL_LINE_LOOP );
1432 for ( j=0 ; j<p->num_edges ; j++ ) {
1434 if( p->keys[iv] < 0 ) {
1435 p->keys[iv] = -p->keys[iv];
1436 glVertex3fv ( pv[iv].xyz );
1441 glBegin ( GL_LINE_LOOP );
1442 for ( j=0 ; j<p->num_vertexs ; j++ ) {
1443 if( p->keys[j] < 0 ) {
1444 p->keys[j] = -p->keys[j];
1445 glVertex3fv ( pv[j].xyz );
1453 /*----------------------------------------------------------------------*/
1454 static void draw_degenerates_quadrangles_as_lines ( call_def_parray p )
1458 tel_point pv = p -> vertices;
1460 n = p->num_vertexs/4;
1461 j = (int)((1.-g_fSkipRatio)*n);
1463 i = OGL_Rand() % n; i *= 4;
1464 p->keys[i] = -p->keys[i];
1467 if( p->num_edges > 0 ) {
1468 for ( j=0 ; j<p->num_edges ; j+=4 ) {
1470 if( p->keys[iv] < 0 ) {
1471 p->keys[iv] = -p->keys[iv];
1472 glBegin ( GL_LINE_LOOP );
1473 for ( i=0 ; i<4 ; i++ ) {
1475 glVertex3fv ( pv[iv].xyz );
1481 for ( j=0 ; j<p->num_vertexs ; j+=4 ) {
1482 if( p->keys[j] < 0 ) {
1483 p->keys[j] = -p->keys[j];
1484 glBegin ( GL_LINE_LOOP );
1485 for ( i=0 ; i<4 ; i++ ) {
1486 glVertex3fv ( pv[j+i].xyz );
1494 /*----------------------------------------------------------------------*/
1495 static void draw_degenerates_quadranglestrips_as_lines ( call_def_parray p )
1499 tel_point pv = p -> vertices;
1501 if( p->num_bounds > 0 ) {
1502 for ( i=n=0 ; i<p->num_bounds ; i++ ) {
1503 ni = p->bounds[i]/2-2;
1504 k = (int)((1.-g_fSkipRatio)*ni);
1506 j = OGL_Rand() % ni; j = j*2+2;
1507 p->keys[n+j] = -p->keys[n+j];
1509 for ( j=3 ; j<p->bounds[i] ; j+=2 ) {
1510 if( p->keys[n+j] < 0 ) {
1511 p->keys[n+j] = -p->keys[n+j];
1512 glBegin ( GL_LINE_LOOP );
1513 glVertex3fv ( pv[n+j-3].xyz );
1514 glVertex3fv ( pv[n+j-2].xyz );
1515 glVertex3fv ( pv[n+j-1].xyz );
1516 glVertex3fv ( pv[n+j].xyz );
1523 ni = p->num_vertexs/2-2;
1524 k = (int)((1.-g_fSkipRatio)*ni);
1526 j = OGL_Rand() % ni; j = j*2+2;
1527 p->keys[j] = -p->keys[j];
1529 for ( j=3 ; j<p->num_vertexs ; j+=2 ) {
1530 if( p->keys[j] < 0 ) {
1531 p->keys[j] = -p->keys[j];
1532 glBegin ( GL_LINE_LOOP );
1533 glVertex3fv ( pv[j-3].xyz );
1534 glVertex3fv ( pv[j-2].xyz );
1535 glVertex3fv ( pv[j-1].xyz );
1536 glVertex3fv ( pv[j].xyz );
1543 /*----------------------------------------------------------------------*/
1544 static void draw_degenerates_as_lines ( call_def_parray p,
1545 tel_colour edge_colour )
1550 GLboolean zbuff_state = glIsEnabled(GL_DEPTH_TEST);
1554 if( zbuff_state ) glDisable(GL_DEPTH_TEST);
1556 glColor3fv( edge_colour->rgb );
1558 if( g_fSkipRatio != 0 ) switch( draw_mode ) {
1560 draw_degenerates_points_as_points( p );
1563 draw_degenerates_lines_as_lines( p );
1567 draw_degenerates_polygons_as_lines( p );
1570 draw_degenerates_triangles_as_lines( p );
1573 draw_degenerates_quadrangles_as_lines( p );
1575 case GL_TRIANGLE_FAN:
1576 case GL_TRIANGLE_STRIP:
1577 draw_degenerates_trianglestrips_as_lines( p );
1580 draw_degenerates_quadranglestrips_as_lines( p );
1589 GLboolean color_array_mode,
1590 edge_flag_array_mode,
1593 texture_coord_array_mode,
1596 glPushAttrib( GL_POLYGON_BIT );
1597 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
1600 color_array_mode = glIsEnabled( GL_COLOR_ARRAY );
1601 edge_flag_array_mode = glIsEnabled( GL_EDGE_FLAG_ARRAY );
1602 index_array_mode = glIsEnabled( GL_INDEX_ARRAY );
1603 normal_array_mode = glIsEnabled( GL_NORMAL_ARRAY );
1604 texture_coord_array_mode = glIsEnabled( GL_TEXTURE_COORD_ARRAY );
1605 vertex_array_mode = glIsEnabled( GL_VERTEX_ARRAY );
1607 glDisableClientState( GL_COLOR_ARRAY );
1608 glDisableClientState( GL_EDGE_FLAG_ARRAY );
1609 glDisableClientState( GL_INDEX_ARRAY );
1610 glDisableClientState( GL_NORMAL_ARRAY );
1611 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1613 if( !vertex_array_mode ) glEnableClientState( GL_VERTEX_ARRAY );
1615 glEnableClientState( GL_VERTEX_ARRAY );
1617 glVertexPointer(3, GL_FLOAT, 0, p->vertices); /* array of vertices */
1619 glGetIntegerv( GL_RENDER_MODE, &renderMode );
1621 if( p->num_bounds > 0 ) {
1622 if( p->num_edges > 0 ) {
1623 for( i=n=0 ; i<p->num_bounds ; i++ ) {
1624 if( renderMode == GL_FEEDBACK )
1625 draw_primitive_elements( p, draw_mode, p->bounds[i],
1626 GL_UNSIGNED_INT, (GLenum*) &p->edges[n]);
1628 glDrawElements( draw_mode, p->bounds[i],
1629 GL_UNSIGNED_INT, &p->edges[n]);
1633 for( i=n=0 ; i<p->num_bounds ; i++ ) {
1634 if( renderMode == GL_FEEDBACK )
1635 draw_primitive_array( p, draw_mode, n, p->bounds[i]);
1637 glDrawArrays( draw_mode, n, p->bounds[i]);
1641 } else if( p->num_edges > 0 ) {
1642 if( renderMode == GL_FEEDBACK )
1643 draw_primitive_elements( p, draw_mode, p->num_edges,
1644 GL_UNSIGNED_INT, (GLenum*) p->edges);
1646 glDrawElements( draw_mode, p->num_edges,
1647 GL_UNSIGNED_INT, p->edges);
1649 if( renderMode == GL_FEEDBACK )
1650 draw_primitive_array( p, draw_mode, 0, p->num_vertexs);
1652 glDrawArrays( draw_mode, 0, p->num_vertexs);
1656 if( !vertex_array_mode ) glDisableClientState( GL_VERTEX_ARRAY );
1658 if( color_array_mode ) glEnableClientState( GL_COLOR_ARRAY );
1659 if( edge_flag_array_mode ) glEnableClientState( GL_EDGE_FLAG_ARRAY );
1660 if( index_array_mode ) glEnableClientState( GL_INDEX_ARRAY );
1661 if( normal_array_mode ) glEnableClientState( GL_NORMAL_ARRAY );
1662 if( texture_coord_array_mode ) glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1667 if( zbuff_state ) glEnable(GL_DEPTH_TEST);
1671 static void draw_degenerates_as_bboxs ( call_def_parray p,
1672 tel_colour edge_colour )
1676 GLfloat minp[ 3 ] = { FLT_MAX, FLT_MAX, FLT_MAX };
1677 GLfloat maxp[ 3 ] = { FLT_MIN, FLT_MIN, FLT_MIN };
1678 tel_point pv = p -> vertices;
1682 glColor3fv( edge_colour->rgb );
1684 for ( i=0 ; i<p->num_vertexs ; ++i ) {
1685 if ( pv[ i ].xyz[ 0 ] < minp[ 0 ] )
1686 minp[ 0 ] = pv[ i ].xyz[ 0 ] ;
1687 if ( pv[ i ].xyz[ 1 ] < minp[ 1 ] )
1688 minp[ 1 ] = pv[ i ].xyz[ 1 ] ;
1689 if ( pv[ i ].xyz[ 2 ] < minp[ 2 ] )
1690 minp[ 2 ] = pv[ i ].xyz[ 2 ] ;
1692 if ( pv[ i ].xyz[ 0 ] > maxp[ 0 ] )
1693 maxp[ 0 ] = pv[ i ].xyz[ 0 ] ;
1694 if ( pv[ i ].xyz[ 1 ] > maxp[ 1 ] )
1695 maxp[ 1 ] = pv[ i ].xyz[ 1 ] ;
1696 if ( pv[ i ].xyz[ 2 ] > maxp[ 2 ] )
1697 maxp[ 2 ] = pv[ i ].xyz[ 2 ] ;
1698 } /* end for ( i ) */
1700 glBegin ( GL_LINE_STRIP );
1702 glVertex3fv ( minp );
1703 glVertex3f ( minp[ 0 ], maxp[ 1 ], minp[ 2 ] );
1704 glVertex3f ( minp[ 0 ], maxp[ 1 ], maxp[ 2 ] );
1705 glVertex3f ( minp[ 0 ], minp[ 1 ], maxp[ 2 ] );
1706 glVertex3f ( minp[ 0 ], minp[ 1 ], minp[ 2 ] );
1708 glVertex3f ( maxp[ 0 ], minp[ 1 ], minp[ 2 ] );
1709 glVertex3f ( maxp[ 0 ], maxp[ 1 ], minp[ 2 ] );
1710 glVertex3f ( maxp[ 0 ], maxp[ 1 ], maxp[ 2 ] );
1711 glVertex3f ( maxp[ 0 ], minp[ 1 ], maxp[ 2 ] );
1712 glVertex3f ( maxp[ 0 ], minp[ 1 ], minp[ 2 ] );
1714 glVertex3f ( maxp[ 0 ], minp[ 1 ], maxp[ 2 ] );
1715 glVertex3f ( minp[ 0 ], minp[ 1 ], maxp[ 2 ] );
1716 glVertex3f ( minp[ 0 ], maxp[ 1 ], maxp[ 2 ] );
1717 glVertex3fv ( maxp );
1718 glVertex3f ( maxp[ 0 ], maxp[ 1 ], minp[ 2 ] );
1719 glVertex3f ( minp[ 0 ], maxp[ 1 ], minp[ 2 ] );
1723 } /* end draw_degenerates_as_bboxs */