0022627: Change OCCT memory management defaults
[occt.git] / src / OpenGl / OpenGl_PrimitiveArray.cxx
CommitLineData
2166f0fa
SK
1// File: OpenGl_PrimitiveArray.cxx
2// Created: 13 July 2011
3// Author: Sergey ZERCHANINOV
4// Copyright: OPEN CASCADE 2011
7fd59977 5
5f8b738e 6#include <OpenGl_ArbVBO.hxx>
7#include <OpenGl_Context.hxx>
8
2166f0fa 9#include <OpenGl_PrimitiveArray.hxx>
7fd59977 10
2166f0fa
SK
11#include <OpenGl_AspectFace.hxx>
12#include <OpenGl_GraphicDriver.hxx>
13#include <OpenGl_Memory.hxx>
d4c2114a 14#include <OpenGl_ResourceCleaner.hxx>
15#include <OpenGl_ResourceVBO.hxx>
2166f0fa
SK
16#include <OpenGl_Structure.hxx>
17#include <OpenGl_TextureBox.hxx>
18
7fd59977 19#include <InterfaceGraphic_PrimitiveArray.hxx>
2166f0fa
SK
20
21enum
7fd59977 22{
2166f0fa
SK
23 VBO_NOT_INITIALIZED = -1,
24 VBO_ERROR = 0,
25 VBO_OK = 1
26};
27
28namespace
29{
30 static unsigned long vRand = 1L;
31 #define OGL_Rand() (vRand = vRand * 214013L + 2531011L)
32};
7fd59977 33
2166f0fa
SK
34// =======================================================================
35// function : clearMemoryOwn
36// purpose :
37// =======================================================================
38void OpenGl_PrimitiveArray::clearMemoryOwn() const
7fd59977 39{
2166f0fa
SK
40 if (myPArray->bufferVBO[VBOEdges] != 0)
41 {
42 Standard::Free ((Standard_Address& )myPArray->edges);
43 myPArray->edges = NULL;
7fd59977 44 }
2166f0fa
SK
45 if (myPArray->bufferVBO[VBOVertices] != 0)
46 {
47 Standard::Free ((Standard_Address& )myPArray->vertices);
48 myPArray->vertices = NULL;
7fd59977 49 }
2166f0fa
SK
50 if (myPArray->bufferVBO[VBOVcolours] != 0)
51 {
52 Standard::Free ((Standard_Address& )myPArray->vcolours);
53 myPArray->vcolours = NULL;
7fd59977 54 }
2166f0fa
SK
55 if (myPArray->bufferVBO[VBOVnormals] != 0)
56 {
57 Standard::Free ((Standard_Address& )myPArray->vnormals);
58 myPArray->vnormals = NULL;
59 }
60 if (myPArray->bufferVBO[VBOVtexels] != 0)
61 {
62 Standard::Free ((Standard_Address& )myPArray->vtexels);
63 myPArray->vtexels = NULL;
64 }
65 if (myPArray->edge_vis != NULL) /// ????
66 {
67 Standard::Free ((Standard_Address& )myPArray->edge_vis);
68 myPArray->edge_vis = NULL;
7fd59977 69 }
7fd59977 70}
71
2166f0fa
SK
72// =======================================================================
73// function : clearMemoryGL
74// purpose :
75// =======================================================================
76void OpenGl_PrimitiveArray::clearMemoryGL (const Handle(OpenGl_Context)& theGlContext) const
7fd59977 77{
2166f0fa
SK
78 if (myPArray->bufferVBO[VBOEdges] != 0)
79 {
80 theGlContext->arbVBO->glDeleteBuffersARB (1, &myPArray->bufferVBO[VBOEdges]);
81 }
82 if (myPArray->bufferVBO[VBOVertices] != 0)
83 {
84 theGlContext->arbVBO->glDeleteBuffersARB (1, &myPArray->bufferVBO[VBOVertices]);
85 }
86 if (myPArray->bufferVBO[VBOVcolours] != 0)
87 {
88 theGlContext->arbVBO->glDeleteBuffersARB (1, &myPArray->bufferVBO[VBOVcolours]);
7fd59977 89 }
2166f0fa
SK
90 if (myPArray->bufferVBO[VBOVnormals] != 0)
91 {
92 theGlContext->arbVBO->glDeleteBuffersARB (1, &myPArray->bufferVBO[VBOVnormals]);
93 }
94 if (myPArray->bufferVBO[VBOVtexels] != 0)
95 {
96 theGlContext->arbVBO->glDeleteBuffersARB (1, &myPArray->bufferVBO[VBOVtexels]);
97 }
5f8b738e 98 theGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0);
99 theGlContext->arbVBO->glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
7fd59977 100}
101
2166f0fa
SK
102// =======================================================================
103// function : checkSizeForGraphicMemory
104// purpose :
105// =======================================================================
106Standard_Boolean OpenGl_PrimitiveArray::checkSizeForGraphicMemory (const Handle(OpenGl_Context)& theGlContext) const
7fd59977 107{
2166f0fa
SK
108 if (glGetError() == GL_OUT_OF_MEMORY)
109 {
110 myPArray->flagBufferVBO = VBO_ERROR;
111 clearMemoryGL (theGlContext);
112 }
113 else
114 {
115 myPArray->flagBufferVBO = VBO_OK;
116 }
117 return myPArray->flagBufferVBO == VBO_OK;
7fd59977 118}
119
2166f0fa
SK
120// =======================================================================
121// function : BuildVBO
122// purpose :
123// =======================================================================
124Standard_Boolean OpenGl_PrimitiveArray::BuildVBO (const Handle(OpenGl_Workspace)& theWorkspace) const
7fd59977 125{
126 int size_reqd = 0;
2166f0fa
SK
127 const Handle(OpenGl_Context)& aGlContext = theWorkspace->GetGlContext();
128 if (myPArray->edges != NULL)
129 {
130 size_reqd = myPArray->num_edges * sizeof(Tint);
131 aGlContext->arbVBO->glGenBuffersARB (1, &myPArray->bufferVBO[VBOEdges]);
5f8b738e 132 aGlContext->arbVBO->glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOEdges]);
133 aGlContext->arbVBO->glBufferDataARB (GL_ELEMENT_ARRAY_BUFFER_ARB, size_reqd, myPArray->edges, GL_STATIC_DRAW_ARB);
2166f0fa
SK
134 if (!checkSizeForGraphicMemory (aGlContext))
135 return Standard_False;
7fd59977 136 }
137
2166f0fa
SK
138 if (myPArray->vertices != NULL)
139 {
140 size_reqd = myPArray->num_vertexs * sizeof(TEL_POINT);
141 aGlContext->arbVBO->glGenBuffersARB (1, &myPArray->bufferVBO[VBOVertices]);
142 aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVertices]);
143 aGlContext->arbVBO->glBufferDataARB (GL_ARRAY_BUFFER_ARB, size_reqd, myPArray->vertices, GL_STATIC_DRAW_ARB);
144 if (!checkSizeForGraphicMemory (aGlContext))
145 return Standard_False;
7fd59977 146 }
147
2166f0fa
SK
148 if (myPArray->vcolours != NULL)
149 {
150 size_reqd = myPArray->num_vertexs * sizeof(Tint);
151 aGlContext->arbVBO->glGenBuffersARB (1, &myPArray->bufferVBO[VBOVcolours]);
152 aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVcolours]);
153 aGlContext->arbVBO->glBufferDataARB (GL_ARRAY_BUFFER_ARB, size_reqd, myPArray->vcolours, GL_STATIC_DRAW_ARB);
154 if (!checkSizeForGraphicMemory (aGlContext))
155 return Standard_False;
7fd59977 156 }
157
2166f0fa
SK
158 if (myPArray->vnormals != NULL)
159 {
160 size_reqd = myPArray->num_vertexs * sizeof(TEL_POINT);
161 aGlContext->arbVBO->glGenBuffersARB (1, &myPArray->bufferVBO[VBOVnormals]);
162 aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVnormals]);
163 aGlContext->arbVBO->glBufferDataARB (GL_ARRAY_BUFFER_ARB, size_reqd, myPArray->vnormals, GL_STATIC_DRAW_ARB);
164 if (!checkSizeForGraphicMemory (aGlContext))
165 return Standard_False;
7fd59977 166 }
167
2166f0fa
SK
168 if (myPArray->vtexels)
169 {
170 size_reqd = myPArray->num_vertexs * sizeof(TEL_TEXTURE_COORD);
171 aGlContext->arbVBO->glGenBuffersARB (1, &myPArray->bufferVBO[VBOVtexels]);
172 aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVtexels]);
173 aGlContext->arbVBO->glBufferDataARB (GL_ARRAY_BUFFER_ARB, size_reqd, myPArray->vtexels, GL_STATIC_DRAW_ARB);
174 if (!checkSizeForGraphicMemory (aGlContext))
175 return Standard_False;
176 }
7fd59977 177
2166f0fa
SK
178 if (myPArray->flagBufferVBO == VBO_OK)
179 clearMemoryOwn();
7fd59977 180
2166f0fa
SK
181 // specify context for VBO resource
182 myPArray->contextId = (Standard_Address )theWorkspace->GetGContext();
183 return Standard_True;
7fd59977 184}
185
2166f0fa
SK
186// =======================================================================
187// function : DrawArrays
188// purpose : Auxiliary method to split Feedback/Normal rendering modes
189// =======================================================================
190inline void DrawArrays (const Handle(OpenGl_Workspace)& theWorkspace,
191 const CALL_DEF_PARRAY* thePArray,
192 const Standard_Boolean theIsFeedback,
193 GLenum theMode,
194 GLint theFirst,
195 GLsizei theCount)
7fd59977 196{
2166f0fa
SK
197 if (!theIsFeedback)
198 {
199 glDrawArrays (theMode, theFirst, theCount);
200 return;
201 }
7fd59977 202
2166f0fa
SK
203 glBegin (theMode);
204 for (int anIter = theFirst; anIter < (theFirst + theCount); ++anIter)
205 {
206 if (thePArray->vnormals != NULL)
207 glNormal3fv (thePArray->vnormals[anIter].xyz);
208 if (thePArray->vtexels != NULL && (theWorkspace->NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0)
209 glTexCoord3fv (thePArray->vtexels[anIter].xy);
210 if (thePArray->vertices != NULL)
211 glVertex3fv (thePArray->vertices[anIter].xyz);
212 if (thePArray->vcolours != NULL)
213 glColor4ubv((GLubyte* )thePArray->vcolours[anIter]);
214 }
215 glEnd();
7fd59977 216}
217
2166f0fa
SK
218// =======================================================================
219// function : DrawElements
220// purpose : Auxiliary method to split Feedback/Normal rendering modes
221// =======================================================================
222inline void DrawElements (const Handle(OpenGl_Workspace)& theWorkspace,
223 const CALL_DEF_PARRAY* thePArray,
224 const Standard_Boolean theIsFeedback,
225 GLenum theMode,
226 GLsizei theCount,
227 GLenum* theIndices)
7fd59977 228{
2166f0fa
SK
229 if (!theIsFeedback)
230 {
231 glDrawElements (theMode, theCount, GL_UNSIGNED_INT, theIndices);
232 return;
7fd59977 233 }
234
2166f0fa
SK
235 GLenum anIndex;
236 glBegin (theMode);
237 for (GLsizei anIter = 0; anIter < theCount; ++anIter)
238 {
239 anIndex = theIndices[anIter];
240 if (thePArray->vnormals != NULL)
241 glNormal3fv (thePArray->vnormals[anIndex].xyz);
242 if (thePArray->vtexels != NULL && (theWorkspace->NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0)
243 glTexCoord3fv (thePArray->vtexels[anIndex].xy);
244 if (thePArray->vertices != NULL)
245 glVertex3fv (thePArray->vertices[anIndex].xyz);
246 if (thePArray->vcolours != NULL)
247 glColor4ubv ((GLubyte* )thePArray->vcolours[anIndex]);
7fd59977 248 }
249 glEnd();
250}
251
2166f0fa
SK
252// =======================================================================
253// function : DrawArray
254// purpose :
255// =======================================================================
256void OpenGl_PrimitiveArray::DrawArray (Tint theLightingModel,
257 const Aspect_InteriorStyle theInteriorStyle,
258 Tint theEdgeFlag,
259 const TEL_COLOUR* theInteriorColour,
260 const TEL_COLOUR* theLineColour,
261 const TEL_COLOUR* theEdgeColour,
262 const OPENGL_SURF_PROP* theFaceProp,
263 const Handle(OpenGl_Workspace)& theWorkspace) const
7fd59977 264{
2166f0fa
SK
265 const Handle(OpenGl_Context)& aGlContext = theWorkspace->GetGlContext();
266
7fd59977 267 Tint i,n;
268 Tint transp = 0;
269 GLint renderMode;
2166f0fa
SK
270 // Following pointers have been provided for performance improvement
271 tel_colour pfc = myPArray->fcolours;
272 Tint* pvc = myPArray->vcolours;
273 if (pvc != NULL)
274 {
275 for (i = 0; i < myPArray->num_vertexs; ++i)
276 {
277 transp = int(theFaceProp->trans * 255.0f);
278 #if defined (sparc) || defined (__sparc__) || defined (__sparc)
279 pvc[i] = (pvc[i] & 0xffffff00);
280 pvc[i] += transp;
281 #else
282 pvc[i] = (pvc[i] & 0x00ffffff);
7fd59977 283 pvc[i] += transp << 24;
2166f0fa 284 #endif
7fd59977 285 }
286 }
7fd59977 287
2166f0fa
SK
288 switch (myPArray->type)
289 {
7fd59977 290 case TelPointsArrayType:
7fd59977 291 case TelPolylinesArrayType:
7fd59977 292 case TelSegmentsArrayType:
2166f0fa 293 glColor3fv (theLineColour->rgb);
7fd59977 294 break;
295 case TelPolygonsArrayType:
7fd59977 296 case TelTrianglesArrayType:
7fd59977 297 case TelQuadranglesArrayType:
7fd59977 298 case TelTriangleStripsArrayType:
7fd59977 299 case TelQuadrangleStripsArrayType:
7fd59977 300 case TelTriangleFansArrayType:
2166f0fa 301 glColor3fv (theInteriorColour->rgb);
7fd59977 302 break;
7fd59977 303 }
304
2166f0fa
SK
305 // Temporarily disable environment mapping
306 if (myDrawMode <= GL_LINE_STRIP)
307 {
308 glPushAttrib (GL_ENABLE_BIT);
309 glDisable (GL_TEXTURE_1D);
310 glDisable (GL_TEXTURE_2D);
7fd59977 311 }
312
2166f0fa
SK
313 if (theWorkspace->DegenerateModel < 2 &&
314 ((myDrawMode > GL_LINE_STRIP && theInteriorStyle != Aspect_IS_EMPTY) ||
315 (myDrawMode <= GL_LINE_STRIP)))
316 {
317 if (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT)
318 {
7fd59977 319 pfc = NULL;
320 pvc = NULL;
321 }
322
2166f0fa
SK
323 if (theInteriorStyle == Aspect_IS_HIDDENLINE)
324 {
325 theEdgeFlag = 1;
7fd59977 326 pfc = NULL;
327 pvc = NULL;
328 }
329
2166f0fa
SK
330 // Sometimes the GL_LIGHTING mode is activated here
331 // without glEnable(GL_LIGHTING) call for an unknown reason, so it is necessary
332 // to call glEnable(GL_LIGHTING) to synchronize Light On/Off mechanism*
333 if (theLightingModel == 0 || myDrawMode <= GL_LINE_STRIP)
334 glDisable (GL_LIGHTING);
335 else
336 glEnable (GL_LIGHTING);
337
338 glGetIntegerv (GL_RENDER_MODE, &renderMode);
339
340 if (myPArray->num_vertexs > 0
341 && myPArray->flagBufferVBO != VBO_OK
342 && renderMode != GL_FEEDBACK)
343 {
344 if (myPArray->vertices != NULL)
345 {
346 glVertexPointer (3, GL_FLOAT, 0, myPArray->vertices); // array of vertices
347 glEnableClientState (GL_VERTEX_ARRAY);
348 }
349 if (myPArray->vnormals != NULL)
350 {
351 glNormalPointer (GL_FLOAT, 0, myPArray->vnormals); // array of normals
352 glEnableClientState (GL_NORMAL_ARRAY);
353 }
354 if (myPArray->vtexels != NULL)
355 {
356 glTexCoordPointer (2, GL_FLOAT, 0, myPArray->vtexels); // array of texture coordinates
357 glEnableClientState (GL_TEXTURE_COORD_ARRAY);
358 }
7fd59977 359
2166f0fa
SK
360 if (pvc != NULL)
361 {
362 glColorPointer (4, GL_UNSIGNED_BYTE, 0, pvc); // array of colors
363 glEnableClientState (GL_COLOR_ARRAY);
364 glColorMaterial (GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
365 glEnable (GL_COLOR_MATERIAL);
7fd59977 366 }
367 }
2166f0fa
SK
368 else if (myPArray->num_vertexs > 0
369 && myPArray->flagBufferVBO == VBO_OK)
370 {
371 // Bindings concrete pointer in accordance with VBO buffer
372 if (myPArray->bufferVBO[VBOVertices] != 0)
373 {
374 aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVertices]);
375 glVertexPointer (3, GL_FLOAT, 0, NULL); // array of vertices
376 glEnableClientState (GL_VERTEX_ARRAY);
7fd59977 377 }
2166f0fa
SK
378 if (myPArray->bufferVBO[VBOVnormals] != 0)
379 {
380 aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVnormals]);
381 glNormalPointer (GL_FLOAT, 0, NULL); // array of normals
382 glEnableClientState (GL_NORMAL_ARRAY);
7fd59977 383 }
2166f0fa
SK
384 if (myPArray->bufferVBO[VBOVtexels] != 0 && (theWorkspace->NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0)
385 {
386 aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVtexels]);
387 glTexCoordPointer (2, GL_FLOAT, 0, NULL); // array of texture coordinates
388 glEnableClientState (GL_TEXTURE_COORD_ARRAY);
7fd59977 389 }
2166f0fa
SK
390 if (myPArray->bufferVBO[VBOVcolours] != 0)
391 {
392 aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVcolours]);
393 glColorPointer (4, GL_UNSIGNED_BYTE, 0, NULL); // array of colors
394 glEnableClientState (GL_COLOR_ARRAY);
395 glColorMaterial (GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
396 glEnable (GL_COLOR_MATERIAL);
7fd59977 397 }
398 }
2166f0fa 399
7fd59977 400 // OCC22236 NOTE: draw for all situations:
2166f0fa 401 // 1) draw elements from myPArray->bufferVBO[VBOEdges] indicies array
7fd59977 402 // 2) draw elements from vertice array, when bounds defines count of primitive's verts.
762aacae 403 // 3) draw primitive by vertexes if no edges and bounds array is specified
2166f0fa
SK
404 if (myPArray->flagBufferVBO == VBO_OK)
405 {
406 if (myPArray->num_edges > 0 && myPArray->bufferVBO[VBOEdges] != 0)
407 {
5f8b738e 408 aGlContext->arbVBO->glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOEdges]); // for edge indices
2166f0fa
SK
409 if (myPArray->num_bounds > 0)
410 {
411 // draw primitives by vertex count with the indicies
412 Tint* anOffset = NULL;
413 for (i = 0; i < myPArray->num_bounds; ++i)
414 {
415 glDrawElements (myDrawMode, myPArray->bounds[i], GL_UNSIGNED_INT, anOffset);
416 anOffset += myPArray->bounds[i];
762aacae
A
417 }
418 }
2166f0fa
SK
419 else
420 {
421 // draw one (or sequential) primitive by the indicies
422 glDrawElements (myDrawMode, myPArray->num_edges, GL_UNSIGNED_INT, NULL);
762aacae 423 }
7fd59977 424 }
2166f0fa
SK
425 else if (myPArray->num_bounds > 0)
426 {
427 for (i = n = 0; i < myPArray->num_bounds; ++i)
428 {
429 glDrawArrays (myDrawMode, n, myPArray->bounds[i]);
430 n += myPArray->bounds[i];
7fd59977 431 }
432 }
2166f0fa
SK
433 else
434 {
435 glDrawArrays (myDrawMode, 0, myPArray->num_vertexs);
762aacae
A
436 }
437
2166f0fa
SK
438 // bind with 0
439 aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0);
5f8b738e 440 aGlContext->arbVBO->glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
7fd59977 441 }
2166f0fa
SK
442 else
443 {
444 if (myPArray->num_bounds > 0)
445 {
446 if (myPArray->num_edges > 0)
447 {
448 for (i = n = 0; i < myPArray->num_bounds; ++i)
449 {
450 if (pfc != NULL) glColor3fv (pfc[i].rgb);
451 DrawElements (theWorkspace, myPArray, (renderMode == GL_FEEDBACK), myDrawMode,
452 myPArray->bounds[i], (GLenum* )&myPArray->edges[n]);
453 n += myPArray->bounds[i];
454 }
455 }
456 else
457 {
458 for (i = n = 0; i < myPArray->num_bounds; ++i)
459 {
460 if (pfc != NULL)
461 {
462 glColor3fv (pfc[i].rgb);
7fd59977 463 }
2166f0fa
SK
464 DrawArrays (theWorkspace, myPArray, (renderMode == GL_FEEDBACK), myDrawMode,
465 n, myPArray->bounds[i]);
466 n += myPArray->bounds[i];
467 }
7fd59977 468 }
2166f0fa
SK
469 }
470 else if (myPArray->num_edges > 0)
471 {
472 DrawElements (theWorkspace, myPArray, (renderMode == GL_FEEDBACK), myDrawMode,
473 myPArray->num_edges, (GLenum* )myPArray->edges);
474 }
475 else
476 {
477 DrawArrays (theWorkspace, myPArray, (renderMode == GL_FEEDBACK), myDrawMode,
478 0, myPArray->num_vertexs);
479 }
7fd59977 480 }
481
2166f0fa
SK
482 if (myPArray->bufferVBO[VBOVcolours] != 0 || pvc != NULL)
483 {
484 glDisable (GL_COLOR_MATERIAL);
485 theWorkspace->NamedStatus |= OPENGL_NS_RESMAT; // Reset material
7fd59977 486 }
2166f0fa
SK
487
488 if (myPArray->bufferVBO[VBOVertices] != 0 || myPArray->vertices != NULL)
489 glDisableClientState (GL_VERTEX_ARRAY);
490 if (myPArray->bufferVBO[VBOVcolours] != 0 || myPArray->vcolours != NULL)
491 glDisableClientState (GL_COLOR_ARRAY);
492 if (myPArray->bufferVBO[VBOVnormals] != 0 || myPArray->vnormals != NULL)
493 glDisableClientState (GL_NORMAL_ARRAY);
494 if ((myPArray->bufferVBO[VBOVtexels] != 0 && (theWorkspace->NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0) || myPArray->vtexels != NULL)
495 glDisableClientState (GL_TEXTURE_COORD_ARRAY);
496
497 if (theWorkspace->DegenerateModel)
498 {
499 if (myDrawMode <= GL_LINE_STRIP)
500 {
7fd59977 501 glPopAttrib();
2166f0fa 502 }
7fd59977 503 return;
504 }
505 }
506
2166f0fa
SK
507 if (theEdgeFlag || theWorkspace->DegenerateModel)
508 {
509 switch (theWorkspace->DegenerateModel)
510 {
511 default: // XXX_TDM_NODE or TINY
512 // On some NVIDIA graphic cards, using glEdgeFlagPointer() in
513 // combination with VBO ( edge flag data put into a VBO buffer)
514 // leads to a crash in a driver. Therefore, edge flags are simply
515 // igonored when VBOs are enabled, so all the edges are drawn if
516 // edge visibility is turned on. In order to draw edges selectively,
517 // either disable VBO or turn off edge visibilty in the current
518 // primitive array and create a separate primitive array (segments)
519 // and put edges to be drawn into it.
520 DrawEdges (theEdgeFlag ? theEdgeColour : theInteriorColour, theWorkspace);
521 break;
522 // DegenerateModel(as Lines, Points, BBoxs) are used only without VBO
523 case 2: // XXX_TDM_WIREFRAME
524 if (myPArray->VBOEnabled == 0)
525 DrawDegeneratesAsLines ((theEdgeFlag ? theEdgeColour : theInteriorColour), theWorkspace);
526 break;
527 case 3: // XXX_TDM_MARKER
528 if (myPArray->VBOEnabled == 0)
529 DrawDegeneratesAsPoints ((theEdgeFlag ? theEdgeColour : theInteriorColour), theWorkspace->SkipRatio);
7fd59977 530 break;
2166f0fa
SK
531 case 4: // XXX_TDM_BBOX
532 if (myPArray->VBOEnabled == 0)
533 DrawDegeneratesAsBBoxs (theEdgeFlag ? theEdgeColour : theInteriorColour);
534 break;
535 }
536 }
537
538 if (myDrawMode <= GL_LINE_STRIP)
7fd59977 539 glPopAttrib();
540}
541
2166f0fa
SK
542// =======================================================================
543// function : DrawEdges
544// purpose :
545// =======================================================================
546void OpenGl_PrimitiveArray::DrawEdges (const TEL_COLOUR* theEdgeColour,
547 const Handle(OpenGl_Workspace)& theWorkspace) const
7fd59977 548{
2166f0fa 549 glDisable (GL_LIGHTING);
7fd59977 550
2166f0fa
SK
551 const Handle(OpenGl_Context)& aGlContext = theWorkspace->GetGlContext();
552 const OpenGl_AspectLine* anAspectLineOld = NULL;
553 if (myDrawMode > GL_LINE_STRIP)
554 {
555 anAspectLineOld = theWorkspace->SetAspectLine (theWorkspace->AspectFace (Standard_True)->AspectEdge());
556 theWorkspace->AspectLine (Standard_True);
7fd59977 557
2166f0fa
SK
558 glPushAttrib (GL_POLYGON_BIT);
559 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
560 }
7fd59977 561
2166f0fa 562 Tint i, j, n;
7fd59977 563 GLint renderMode;
7fd59977 564
565 // OCC22236 NOTE: draw edges for all situations:
2166f0fa 566 // 1) draw elements with GL_LINE style as edges from myPArray->bufferVBO[VBOEdges] indicies array
762aacae
A
567 // 2) draw elements from vertice array, when bounds defines count of primitive's verts.
568 // 3) draw primitive's edges by vertexes if no edges and bounds array is specified
2166f0fa 569 if (myPArray->flagBufferVBO == VBO_OK)
7fd59977 570 {
2166f0fa
SK
571 aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOVertices]);
572 glEnableClientState (GL_VERTEX_ARRAY);
573 glColor3fv (theEdgeColour->rgb);
574 if (myPArray->num_edges > 0 && myPArray->bufferVBO[VBOEdges])
575 {
5f8b738e 576 aGlContext->arbVBO->glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, myPArray->bufferVBO[VBOEdges]);
2166f0fa 577
762aacae 578 // draw primitives by vertex count with the indicies
2166f0fa
SK
579 if (myPArray->num_bounds > 0)
580 {
762aacae 581 Tint* offset = 0;
2166f0fa
SK
582 for (i = 0, offset = 0; i < myPArray->num_bounds; ++i)
583 {
584 glDrawElements (myDrawMode, myPArray->bounds[i], GL_UNSIGNED_INT, offset);
585 offset += myPArray->bounds[i];
762aacae
A
586 }
587 }
588 // draw one (or sequential) primitive by the indicies
2166f0fa
SK
589 else
590 {
591 glDrawElements (myDrawMode, myPArray->num_edges, GL_UNSIGNED_INT, NULL);
762aacae 592 }
7fd59977 593 }
2166f0fa
SK
594 else if (myPArray->num_bounds > 0)
595 {
596 for (i = n = 0; i < myPArray->num_bounds; ++i)
597 {
598 glDrawArrays (myDrawMode, n, myPArray->bounds[i]);
599 n += myPArray->bounds[i];
7fd59977 600 }
601 }
2166f0fa
SK
602 else
603 {
604 glDrawArrays (myDrawMode, 0, myPArray->num_vertexs);
762aacae
A
605 }
606
607 // unbind buffers
2166f0fa
SK
608 glDisableClientState (GL_VERTEX_ARRAY);
609 aGlContext->arbVBO->glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0);
5f8b738e 610 aGlContext->arbVBO->glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
2166f0fa
SK
611 }
612 else
613 {
614 glEnableClientState (GL_VERTEX_ARRAY);
615 glVertexPointer (3, GL_FLOAT, 0, myPArray->vertices); // array of vertices
616 glGetIntegerv (GL_RENDER_MODE, &renderMode);
617
618 glColor3fv (theEdgeColour->rgb);
619 if (myPArray->num_bounds > 0)
620 {
621 if (myPArray->num_edges > 0)
622 {
623 for (i = n = 0; i < myPArray->num_bounds; ++i)
624 {
625 if (myPArray->edge_vis)
626 {
627 glBegin (myDrawMode);
628 for (j = 0; j < myPArray->bounds[i]; ++j)
629 {
630 glEdgeFlag (myPArray->edge_vis[n+j]);
631 glVertex3fv (&myPArray->vertices[myPArray->edges[n+j]].xyz[0]);
632 }
633 glEnd();
7fd59977 634 }
2166f0fa
SK
635 else
636 {
637 DrawElements (theWorkspace, myPArray, (renderMode == GL_FEEDBACK), myDrawMode,
638 myPArray->bounds[i], (GLenum* )&myPArray->edges[n]);
7fd59977 639 }
2166f0fa 640 n += myPArray->bounds[i];
7fd59977 641 }
2166f0fa 642 }
7fd59977 643 else
2166f0fa
SK
644 {
645 for (i = n = 0 ; i < myPArray->num_bounds; ++i)
646 {
647 DrawArrays (theWorkspace, myPArray, (renderMode == GL_FEEDBACK), myDrawMode,
648 n, myPArray->bounds[i]);
649 n += myPArray->bounds[i];
650 }
651 }
652 }
653 else if (myPArray->num_edges > 0)
654 {
655 if (myPArray->edge_vis)
656 {
657 glBegin (myDrawMode);
658 for (i = 0; i < myPArray->num_edges; ++i)
659 {
660 glEdgeFlag (myPArray->edge_vis[i]);
661 glVertex3fv (&myPArray->vertices[myPArray->edges[i]].xyz[0]);
662 }
663 glEnd();
664 }
7fd59977 665 else
2166f0fa
SK
666 {
667 DrawElements (theWorkspace, myPArray, (renderMode == GL_FEEDBACK), myDrawMode,
668 myPArray->num_edges, (GLenum* )myPArray->edges);
7fd59977 669 }
670 }
2166f0fa
SK
671 else
672 {
673 DrawArrays (theWorkspace, myPArray, (renderMode == GL_FEEDBACK), myDrawMode,
674 0, myPArray->num_vertexs);
7fd59977 675 }
2166f0fa
SK
676 }
677
678 if (myDrawMode > GL_LINE_STRIP)
679 {
680 // Restore line context
681 theWorkspace->SetAspectLine (anAspectLineOld);
7fd59977 682 glPopAttrib();
683 }
684}
685
2166f0fa
SK
686// =======================================================================
687// function : DrawDegeneratesPointsAsPoints
688// purpose :
689// =======================================================================
690void OpenGl_PrimitiveArray::DrawDegeneratesPointsAsPoints() const
691{
692 tel_point pv = myPArray->vertices;
693 for (Tint aVertId = 0; aVertId < myPArray->num_vertexs; ++aVertId)
694 {
695 glVertex3fv (&pv[aVertId].xyz[0]);
7fd59977 696 }
2166f0fa 697}
7fd59977 698
2166f0fa
SK
699// =======================================================================
700// function : DrawDegeneratesLinesAsPoints
701// purpose :
702// =======================================================================
703void OpenGl_PrimitiveArray::DrawDegeneratesLinesAsPoints() const
704{
705 GLfloat pt[3];
706 tel_point pv = myPArray->vertices;
707
708 Tint j = 0;
709 while (j < myPArray->num_vertexs)
710 {
711 pt[0] = pv[j].xyz[0];
712 pt[1] = pv[j].xyz[1];
713 pt[2] = pv[j].xyz[2]; ++j;
714 pt[0] += pv[j].xyz[0];
715 pt[1] += pv[j].xyz[1];
716 pt[2] += pv[j].xyz[2]; ++j;
717 pt[0] *= 0.5f;
718 pt[1] *= 0.5f;
719 pt[2] *= 0.5f;
720 glVertex3fv (pt);
7fd59977 721 }
722}
723
2166f0fa
SK
724// =======================================================================
725// function : DrawDegeneratesTrianglesAsPoints
726// purpose :
727// =======================================================================
728void OpenGl_PrimitiveArray::DrawDegeneratesTrianglesAsPoints() const
729{
730 Tint i, j, iv;
731 GLfloat pt[ 3 ];
732 tel_point pv = myPArray->vertices;
733
734 if (myPArray->num_edges > 0)
735 {
736 for (j = 0; j < myPArray->num_edges; j += 3)
737 {
738 iv = myPArray->edges[j];
739 pt[0] = pv[iv].xyz[0];
740 pt[1] = pv[iv].xyz[1];
741 pt[2] = pv[iv].xyz[2];
742 for (i = 1; i < 3; ++i)
743 {
744 iv = myPArray->edges[j+i];
745 pt[0] += pv[iv].xyz[0];
746 pt[1] += pv[iv].xyz[1];
747 pt[2] += pv[iv].xyz[2];
7fd59977 748 }
2166f0fa
SK
749 pt[0] /= 3.f;
750 pt[1] /= 3.f;
751 pt[2] /= 3.f;
752 glVertex3fv (pt);
7fd59977 753 }
2166f0fa
SK
754 }
755 else
756 {
757 for (j = 0; j < myPArray->num_vertexs; j += 3)
758 {
759 pt[0] = pv[j].xyz[0];
760 pt[1] = pv[j].xyz[1];
761 pt[2] = pv[j].xyz[2];
762 for (i = 1; i < 3; ++i)
763 {
764 pt[0] += pv[j+i].xyz[0];
765 pt[1] += pv[j+i].xyz[1];
766 pt[2] += pv[j+i].xyz[2];
7fd59977 767 }
2166f0fa
SK
768 pt[0] /= 3.f;
769 pt[1] /= 3.f;
770 pt[2] /= 3.f;
771 glVertex3fv (pt);
7fd59977 772 }
773 }
2166f0fa 774}
7fd59977 775
2166f0fa
SK
776// =======================================================================
777// function : DrawDegeneratesTrianglesAsPoints
778// purpose :
779// =======================================================================
780void OpenGl_PrimitiveArray::DrawDegeneratesTrianglestripsAsPoints() const
781{
782 Tint i, j, k, n;
783 GLfloat pt[ 3 ];
784 tel_point pv = myPArray->vertices;
785
786 if (myPArray->num_bounds > 0)
787 {
788 for (k = n = 0; k < myPArray->num_bounds; ++k)
789 {
790 for (j = 0; j < myPArray->bounds[k] - 2; ++j)
791 {
792 pt[0] = pv[n+j].xyz[0];
793 pt[1] = pv[n+j].xyz[1];
794 pt[2] = pv[n+j].xyz[2];
795 for (i = 1; i < 3; ++i)
796 {
797 pt[0] += pv[n+j+i].xyz[0];
798 pt[1] += pv[n+j+i].xyz[1];
799 pt[2] += pv[n+j+i].xyz[2];
7fd59977 800 }
2166f0fa
SK
801 pt[0] /= 3.f;
802 pt[1] /= 3.f;
803 pt[2] /= 3.f;
804 glVertex3fv (pt);
7fd59977 805 }
2166f0fa 806 n += myPArray->bounds[k];
7fd59977 807 }
2166f0fa
SK
808 }
809 else
810 {
811 for (j = 0; j < myPArray->num_vertexs - 2; ++j)
812 {
813 pt[0] = pv[j].xyz[0];
814 pt[1] = pv[j].xyz[1];
815 pt[2] = pv[j].xyz[2];
816 for (i = 1; i < 3; ++i)
817 {
818 pt[0] += pv[j+i].xyz[0];
819 pt[1] += pv[j+i].xyz[1];
820 pt[2] += pv[j+i].xyz[2];
7fd59977 821 }
2166f0fa
SK
822 pt[0] /= 3.f;
823 pt[1] /= 3.f;
824 pt[2] /= 3.f;
825 glVertex3fv (pt);
7fd59977 826 }
827 }
2166f0fa 828}
7fd59977 829
2166f0fa
SK
830// =======================================================================
831// function : DrawDegeneratesPolygonsAsPoints
832// purpose :
833// =======================================================================
834void OpenGl_PrimitiveArray::DrawDegeneratesPolygonsAsPoints() const
835{
836 Tint j, k, n, iv;
837 GLfloat pt[3];
838 tel_point pv = myPArray->vertices;
839
840 if (myPArray->num_bounds > 0)
841 {
842 if (myPArray->num_edges > 0)
843 {
844 for (k = n = 0; k < myPArray->num_bounds; ++k)
845 {
846 pt[0] = pt[1] = pt[2] = 0.0;
847 for (j = 0; j < myPArray->bounds[k]; ++j)
848 {
849 iv = myPArray->edges[n+j];
850 pt[0] += pv[iv].xyz[0];
851 pt[1] += pv[iv].xyz[1];
852 pt[2] += pv[iv].xyz[2];
7fd59977 853 }
2166f0fa
SK
854 pt[0] /= myPArray->bounds[k];
855 pt[1] /= myPArray->bounds[k];
856 pt[2] /= myPArray->bounds[k];
857 glVertex3fv (pt);
858 n += myPArray->bounds[k];
7fd59977 859 }
2166f0fa
SK
860 }
861 else
862 {
863 for (k = n = 0; k < myPArray->num_bounds; ++k)
864 {
865 pt[0] = pt[1] = pt[2] = 0.0;
866 for (j = 0; j < myPArray->bounds[k]; ++j)
867 {
868 pt[0] += pv[n+j].xyz[0];
869 pt[1] += pv[n+j].xyz[1];
870 pt[2] += pv[n+j].xyz[2];
7fd59977 871 }
2166f0fa
SK
872 pt[0] /= myPArray->bounds[k];
873 pt[1] /= myPArray->bounds[k];
874 pt[2] /= myPArray->bounds[k];
875 glVertex3fv (pt);
876 n += myPArray->bounds[k];
7fd59977 877 }
878 }
2166f0fa
SK
879 }
880 else if (myPArray->num_edges > 0)
881 {
882 pt[0] = pt[1] = pt[2] = 0.0;
883 for (j = 0; j < myPArray->num_edges; ++j)
884 {
885 iv = myPArray->edges[j];
886 pt[0] += pv[iv].xyz[0];
887 pt[1] += pv[iv].xyz[1];
888 pt[2] += pv[iv].xyz[2];
7fd59977 889 }
2166f0fa
SK
890 pt[0] /= myPArray->num_edges;
891 pt[1] /= myPArray->num_edges;
892 pt[2] /= myPArray->num_edges;
893 glVertex3fv (pt);
894 }
895 else
896 {
897 pt[0] = pt[1] = pt[2] = 0.0;
898 for (j = 0; j < myPArray->num_vertexs; ++j)
899 {
900 pt[0] += pv[j].xyz[0];
901 pt[1] += pv[j].xyz[1];
902 pt[2] += pv[j].xyz[2];
7fd59977 903 }
2166f0fa
SK
904 pt[0] /= myPArray->num_vertexs;
905 pt[1] /= myPArray->num_vertexs;
906 pt[2] /= myPArray->num_vertexs;
907 glVertex3fv (pt);
7fd59977 908 }
2166f0fa 909}
7fd59977 910
2166f0fa
SK
911// =======================================================================
912// function : DrawDegeneratesQuadranglesAsPoints
913// purpose :
914// =======================================================================
915void OpenGl_PrimitiveArray::DrawDegeneratesQuadranglesAsPoints() const
916{
917 Tint i, j, iv;
918 GLfloat pt[ 3 ];
919 tel_point pv = myPArray->vertices;
920
921 if (myPArray->num_edges > 0)
922 {
923 for (j = 0; j < myPArray->num_edges; j += 4)
924 {
925 pt[0] = pt[1] = pt[2] = 0.0;
926 for (i = 0; i < 4; ++i)
927 {
928 iv = myPArray->edges[j+i];
929 pt[0] += pv[iv].xyz[0];
930 pt[1] += pv[iv].xyz[1];
931 pt[2] += pv[iv].xyz[2];
7fd59977 932 }
2166f0fa
SK
933 pt[0] /= 4;
934 pt[1] /= 4;
935 pt[2] /= 4;
7fd59977 936 glVertex3fv ( pt );
937 }
2166f0fa
SK
938 }
939 else
940 {
941 for (j = 0; j < myPArray->num_vertexs; j += 4)
942 {
943 pt[0] = pt[1] = pt[2] = 0.0;
944 for (i = 0; i < 4; ++i)
945 {
946 pt[0] += pv[j+i].xyz[0];
947 pt[1] += pv[j+i].xyz[1];
948 pt[2] += pv[j+i].xyz[2];
7fd59977 949 }
2166f0fa
SK
950 pt[0] /= 4;
951 pt[1] /= 4;
952 pt[2] /= 4;
953 glVertex3fv (pt);
7fd59977 954 }
955 }
956}
957
2166f0fa
SK
958// =======================================================================
959// function : DrawDegeneratesAsPoints
960// purpose :
961// =======================================================================
962void OpenGl_PrimitiveArray::DrawDegeneratesQuadranglestripsAsPoints() const
963{
964 Tint i, j, k, n;
965 GLfloat pt[3];
966 tel_point pv = myPArray->vertices;
967
968 if (myPArray->num_bounds > 0)
969 {
970 for (k = n = 0; k < myPArray->num_bounds; ++k)
971 {
972 for (j = 0; j < myPArray->bounds[k] - 2; j += 2)
973 {
7fd59977 974 pt[0] = pt[1] = pt[2] = 0.;
2166f0fa
SK
975 for (i = 0; i < 4; ++i)
976 {
977 pt[0] += pv[n+j+i].xyz[0];
978 pt[1] += pv[n+j+i].xyz[1];
979 pt[2] += pv[n+j+i].xyz[2];
7fd59977 980 }
2166f0fa
SK
981 pt[0] /= 4;
982 pt[1] /= 4;
983 pt[2] /= 4;
984 glVertex3fv (pt);
7fd59977 985 }
2166f0fa 986 n += myPArray->bounds[k];
7fd59977 987 }
2166f0fa
SK
988 }
989 else
990 {
991 for (j = 0; j < myPArray->num_vertexs - 2; j += 2)
992 {
7fd59977 993 pt[0] = pt[1] = pt[2] = 0.;
2166f0fa
SK
994 for (i = 0; i < 4; ++i)
995 {
996 pt[0] += pv[j+i].xyz[0];
997 pt[1] += pv[j+i].xyz[1];
998 pt[2] += pv[j+i].xyz[2];
7fd59977 999 }
2166f0fa
SK
1000 pt[0] /= 4;
1001 pt[1] /= 4;
1002 pt[2] /= 4;
1003 glVertex3fv (pt);
7fd59977 1004 }
1005 }
2166f0fa 1006}
7fd59977 1007
2166f0fa
SK
1008// =======================================================================
1009// function : DrawDegeneratesAsPoints
1010// purpose :
1011// =======================================================================
1012void OpenGl_PrimitiveArray::DrawDegeneratesAsPoints (const TEL_COLOUR* theEdgeColour,
1013 const float theSkipRatio) const
7fd59977 1014{
2166f0fa
SK
1015 if (theSkipRatio >= 1.0f)
1016 return;
7fd59977 1017
2166f0fa
SK
1018 GLboolean zbuff_state = glIsEnabled (GL_DEPTH_TEST);
1019 glDisable (GL_LIGHTING);
1020 if (zbuff_state)
1021 glDisable (GL_DEPTH_TEST);
1022 glColor3fv (theEdgeColour->rgb);
1023
1024 glBegin (GL_POINTS);
1025 switch (myDrawMode)
1026 {
1027 case GL_POINTS:
1028 DrawDegeneratesPointsAsPoints();
1029 break;
1030 case GL_LINES:
1031 DrawDegeneratesLinesAsPoints();
1032 break;
1033 case GL_LINE_STRIP:
1034 case GL_POLYGON:
1035 DrawDegeneratesPolygonsAsPoints();
1036 break;
1037 case GL_TRIANGLES:
1038 DrawDegeneratesTrianglesAsPoints();
1039 break;
1040 case GL_QUADS:
1041 DrawDegeneratesQuadranglesAsPoints();
1042 break;
1043 case GL_TRIANGLE_FAN:
1044 case GL_TRIANGLE_STRIP:
1045 DrawDegeneratesTrianglestripsAsPoints();
1046 break;
1047 case GL_QUAD_STRIP:
1048 DrawDegeneratesQuadranglestripsAsPoints();
1049 break;
1050 default:
1051 break;
7fd59977 1052 }
2166f0fa
SK
1053 glEnd();
1054 if (zbuff_state)
1055 glEnable (GL_DEPTH_TEST);
7fd59977 1056}
1057
2166f0fa
SK
1058// =======================================================================
1059// function : DrawDegeneratesLinesAsLines
1060// purpose :
1061// =======================================================================
1062void OpenGl_PrimitiveArray::DrawDegeneratesLinesAsLines (const float theSkipRatio) const
1063{
1064 Tint i, iv;
1065 tel_point pv = myPArray->vertices;
7fd59977 1066
2166f0fa
SK
1067 Tint n = myPArray->num_vertexs;
1068 Tint j = int((1.0f - theSkipRatio) * n);
1069 for (; j > 0; --j)
1070 {
7fd59977 1071 i = OGL_Rand() % n;
2166f0fa
SK
1072 myPArray->keys[i] = -myPArray->keys[i];
1073 }
1074
1075 if (myPArray->num_bounds > 0)
1076 {
1077 if (myPArray->num_edges > 0)
1078 {
1079 for (i = n = 0; i < myPArray->num_bounds; ++i)
1080 {
1081 glBegin (GL_LINES);
1082 for (j = 0; j < myPArray->bounds[i]; ++j)
1083 {
1084 iv = myPArray->edges[n + j];
1085 if (myPArray->keys[iv] < 0)
1086 {
1087 myPArray->keys[iv] = -myPArray->keys[iv];
1088 glVertex3fv (pv[iv].xyz);
7fd59977 1089 }
1090 }
1091 glEnd();
2166f0fa 1092 n += myPArray->bounds[i];
7fd59977 1093 }
2166f0fa
SK
1094 }
1095 else
1096 {
1097 for (i = n = 0; i < myPArray->num_bounds; ++i)
1098 {
1099 glBegin (GL_LINES);
1100 for (j = 0; j < myPArray->bounds[i]; ++j)
1101 {
1102 if (myPArray->keys[n+j] < 0)
1103 {
1104 myPArray->keys[n+j] = -myPArray->keys[n+j];
1105 glVertex3fv (pv[n+j].xyz);
7fd59977 1106 }
1107 }
1108 glEnd();
2166f0fa 1109 n += myPArray->bounds[i];
7fd59977 1110 }
1111 }
2166f0fa
SK
1112 }
1113 else if (myPArray->num_edges > 0)
1114 {
1115 glBegin (GL_LINES);
1116 for (j = 0; j < myPArray->num_edges; ++j)
1117 {
1118 iv = myPArray->edges[j];
1119 if (myPArray->keys[iv] < 0)
1120 {
1121 myPArray->keys[iv] = -myPArray->keys[iv];
1122 glVertex3fv (pv[iv].xyz);
7fd59977 1123 }
1124 }
1125 glEnd();
2166f0fa
SK
1126 }
1127 else
1128 {
1129 glBegin (GL_LINES);
1130 for (j = 0; j < myPArray->num_vertexs; ++j)
1131 {
1132 if (myPArray->keys[j] < 0)
1133 {
1134 myPArray->keys[j] = -myPArray->keys[j];
1135 glVertex3fv (pv[j].xyz);
7fd59977 1136 }
1137 }
1138 glEnd();
1139 }
2166f0fa 1140}
7fd59977 1141
2166f0fa
SK
1142// =======================================================================
1143// function : DrawDegeneratesTrianglesAsLines
1144// purpose :
1145// =======================================================================
1146void OpenGl_PrimitiveArray::DrawDegeneratesTrianglesAsLines (const float theSkipRatio) const
7fd59977 1147{
2166f0fa
SK
1148 Tint i, iv;
1149 tel_point pv = myPArray->vertices;
7fd59977 1150
2166f0fa
SK
1151 Tint n = myPArray->num_vertexs / 3;
1152 Tint j = int((1.0f - theSkipRatio) * n);
1153 for (; j > 0; --j)
1154 {
7fd59977 1155 i = OGL_Rand() % n; i *= 3;
2166f0fa
SK
1156 myPArray->keys[i] = -myPArray->keys[i];
1157 }
1158
1159 if (myPArray->num_edges > 0)
1160 {
1161 for (j = 0; j < myPArray->num_edges; j += 3)
1162 {
1163 iv = myPArray->edges[j];
1164 if (myPArray->keys[iv] < 0)
1165 {
1166 myPArray->keys[iv] = -myPArray->keys[iv];
1167 glBegin (GL_LINE_LOOP);
1168 for (i = 0; i < 3; ++i)
1169 {
1170 iv = myPArray->edges[j+i];
1171 glVertex3fv (pv[iv].xyz);
7fd59977 1172 }
1173 glEnd();
1174 }
1175 }
2166f0fa
SK
1176 }
1177 else
1178 {
1179 for (j = 0; j < myPArray->num_vertexs; j += 3)
1180 {
1181 if (myPArray->keys[j] < 0)
1182 {
1183 myPArray->keys[j] = -myPArray->keys[j];
1184 glBegin (GL_LINE_LOOP);
1185 for (i = 0; i < 3; ++i)
1186 {
1187 glVertex3fv (pv[j+i].xyz);
7fd59977 1188 }
1189 glEnd();
1190 }
1191 }
1192 }
2166f0fa 1193}
7fd59977 1194
2166f0fa
SK
1195// =======================================================================
1196// function : DrawDegeneratesTrianglesAsLines
1197// purpose :
1198// =======================================================================
1199void OpenGl_PrimitiveArray::DrawDegeneratesTrianglestripsAsLines (const float theSkipRatio) const
7fd59977 1200{
2166f0fa
SK
1201 Tint i, j, k, n, ni;
1202 tel_point pv = myPArray->vertices;
1203
1204 if (myPArray->num_bounds > 0)
1205 {
1206 for (i = n = 0; i < myPArray->num_bounds; ++i)
1207 {
1208 ni = myPArray->bounds[i] - 2;
1209 k = int((1.0f - theSkipRatio) * ni);
1210 for (; k > 0; --k)
1211 {
7fd59977 1212 j = OGL_Rand() % ni; j += 2;
2166f0fa
SK
1213 myPArray->keys[n+j] = -myPArray->keys[n+j];
1214 }
1215 for (j = 2; j < myPArray->bounds[i]; ++j)
1216 {
1217 if (myPArray->keys[n+j] < 0)
1218 {
1219 myPArray->keys[n+j] = -myPArray->keys[n+j];
1220 glBegin (GL_LINE_LOOP);
1221 glVertex3fv (pv[n+j-2].xyz);
1222 glVertex3fv (pv[n+j-1].xyz);
1223 glVertex3fv (pv[n+j].xyz);
7fd59977 1224 glEnd();
1225 }
1226 }
2166f0fa 1227 n += myPArray->bounds[i];
7fd59977 1228 }
2166f0fa
SK
1229 }
1230 else
1231 {
1232 ni = myPArray->num_vertexs - 2;
1233 k = int((1.0f - theSkipRatio) * ni);
1234 for (; k > 0; --k)
1235 {
7fd59977 1236 j = OGL_Rand() % ni; j += 2;
2166f0fa
SK
1237 myPArray->keys[j] = -myPArray->keys[j];
1238 }
1239 for (j = 2; j < myPArray->num_vertexs; ++j)
1240 {
1241 if (myPArray->keys[j] < 0)
1242 {
1243 myPArray->keys[j] = -myPArray->keys[j];
1244 glBegin (GL_LINE_LOOP);
1245 glVertex3fv (pv[j-2].xyz);
1246 glVertex3fv (pv[j-1].xyz);
1247 glVertex3fv (pv[j].xyz);
7fd59977 1248 glEnd();
1249 }
1250 }
1251 }
2166f0fa 1252}
7fd59977 1253
2166f0fa
SK
1254// =======================================================================
1255// function : DrawDegeneratesPolygonsAsLines
1256// purpose :
1257// =======================================================================
1258void OpenGl_PrimitiveArray::DrawDegeneratesPolygonsAsLines (const float theSkipRatio) const
7fd59977 1259{
2166f0fa
SK
1260 Tint i, iv;
1261 tel_point pv = myPArray->vertices;
7fd59977 1262
2166f0fa
SK
1263 Tint n = myPArray->num_vertexs;
1264 Tint j = int((1.0f - theSkipRatio) * n);
1265 for (; j > 0; --j)
1266 {
7fd59977 1267 i = OGL_Rand() % n;
2166f0fa
SK
1268 myPArray->keys[i] = -myPArray->keys[i];
1269 }
1270
1271 if (myPArray->num_bounds > 0)
1272 {
1273 if (myPArray->num_edges > 0)
1274 {
1275 for (i = n = 0; i < myPArray->num_bounds; ++i)
1276 {
1277 glBegin (GL_LINE_LOOP);
1278 for (j = 0; j < myPArray->bounds[i]; ++j)
1279 {
1280 iv = myPArray->edges[n+j];
1281 if (myPArray->keys[iv] < 0)
1282 {
1283 myPArray->keys[iv] = -myPArray->keys[iv];
1284 glVertex3fv (pv[iv].xyz);
7fd59977 1285 }
1286 }
1287 glEnd();
2166f0fa 1288 n += myPArray->bounds[i];
7fd59977 1289 }
2166f0fa
SK
1290 }
1291 else
1292 {
1293 for (i = n = 0; i < myPArray->num_bounds; ++i)
1294 {
1295 glBegin (GL_LINE_LOOP);
1296 for (j = 0; j < myPArray->bounds[i]; ++j)
1297 {
1298 if (myPArray->keys[n+j] < 0)
1299 {
1300 myPArray->keys[n+j] = -myPArray->keys[n+j];
1301 glVertex3fv (pv[n+j].xyz);
7fd59977 1302 }
1303 }
1304 glEnd();
2166f0fa 1305 n += myPArray->bounds[i];
7fd59977 1306 }
1307 }
2166f0fa
SK
1308 }
1309 else if (myPArray->num_edges > 0)
1310 {
1311 glBegin (GL_LINE_LOOP);
1312 for (j = 0; j < myPArray->num_edges; ++j)
1313 {
1314 iv = myPArray->edges[j];
1315 if (myPArray->keys[iv] < 0)
1316 {
1317 myPArray->keys[iv] = -myPArray->keys[iv];
1318 glVertex3fv (pv[iv].xyz);
7fd59977 1319 }
1320 }
1321 glEnd();
2166f0fa
SK
1322 }
1323 else
1324 {
1325 glBegin (GL_LINE_LOOP);
1326 for (j = 0; j < myPArray->num_vertexs; ++j)
1327 {
1328 if (myPArray->keys[j] < 0)
1329 {
1330 myPArray->keys[j] = -myPArray->keys[j];
1331 glVertex3fv (pv[j].xyz);
7fd59977 1332 }
1333 }
1334 glEnd();
1335 }
7fd59977 1336}
1337
2166f0fa
SK
1338// =======================================================================
1339// function : DrawDegeneratesQuadranglesAsLines
1340// purpose :
1341// =======================================================================
1342void OpenGl_PrimitiveArray::DrawDegeneratesQuadranglesAsLines (const float theSkipRatio) const
1343{
1344 Tint i, iv;
1345 tel_point pv = myPArray->vertices;
7fd59977 1346
2166f0fa
SK
1347 Tint n = myPArray->num_vertexs / 4;
1348 Tint j = int((1.0f - theSkipRatio) * n);
1349 for (; j > 0; --j)
1350 {
7fd59977 1351 i = OGL_Rand() % n; i *= 4;
2166f0fa
SK
1352 myPArray->keys[i] = -myPArray->keys[i];
1353 }
1354
1355 if (myPArray->num_edges > 0)
1356 {
1357 for (j = 0; j < myPArray->num_edges; j += 4)
1358 {
1359 iv = myPArray->edges[j];
1360 if (myPArray->keys[iv] < 0)
1361 {
1362 myPArray->keys[iv] = -myPArray->keys[iv];
1363 glBegin (GL_LINE_LOOP);
1364 for (i = 0; i < 4; ++i)
1365 {
1366 iv = myPArray->edges[j+i];
1367 glVertex3fv (pv[iv].xyz);
7fd59977 1368 }
1369 glEnd();
1370 }
1371 }
2166f0fa
SK
1372 }
1373 else
1374 {
1375 for (j = 0; j < myPArray->num_vertexs; j += 4)
1376 {
1377 if (myPArray->keys[j] < 0)
1378 {
1379 myPArray->keys[j] = -myPArray->keys[j];
1380 glBegin (GL_LINE_LOOP);
1381 for (i = 0; i < 4; ++i)
1382 {
1383 glVertex3fv (pv[j+i].xyz);
7fd59977 1384 }
1385 glEnd();
1386 }
1387 }
1388 }
2166f0fa 1389}
7fd59977 1390
2166f0fa
SK
1391// =======================================================================
1392// function : DrawDegeneratesQuadranglesAsLines
1393// purpose :
1394// =======================================================================
1395void OpenGl_PrimitiveArray::DrawDegeneratesQuadranglestripsAsLines (const float theSkipRatio) const
7fd59977 1396{
2166f0fa
SK
1397 Tint i, j, k, n, ni;
1398 tel_point pv = myPArray->vertices;
1399
1400 if (myPArray->num_bounds > 0)
1401 {
1402 for (i = n = 0; i < myPArray->num_bounds; ++i)
1403 {
1404 ni = myPArray->bounds[i] / 2 - 2;
1405 k = int((1.0f - theSkipRatio) * ni);
1406 for (; k > 0; --k)
1407 {
1408 j = OGL_Rand() % ni; j = j * 2 + 2;
1409 myPArray->keys[n+j] = -myPArray->keys[n+j];
1410 }
1411 for (j = 3; j < myPArray->bounds[i]; j += 2)
1412 {
1413 if (myPArray->keys[n+j] < 0)
1414 {
1415 myPArray->keys[n+j] = -myPArray->keys[n+j];
1416 glBegin (GL_LINE_LOOP);
1417 glVertex3fv (pv[n+j-3].xyz);
1418 glVertex3fv (pv[n+j-2].xyz);
1419 glVertex3fv (pv[n+j-1].xyz);
1420 glVertex3fv (pv[n+j].xyz);
7fd59977 1421 glEnd();
1422 }
1423 }
2166f0fa
SK
1424 n += myPArray->bounds[i];
1425 }
1426 }
1427 else
1428 {
1429 ni = myPArray->num_vertexs / 2 - 2;
1430 k = int((1.0f - theSkipRatio) * ni);
1431 for (; k > 0; --k)
1432 {
1433 j = OGL_Rand() % ni; j = j * 2 + 2;
1434 myPArray->keys[j] = -myPArray->keys[j];
7fd59977 1435 }
2166f0fa
SK
1436 for (j = 3; j < myPArray->num_vertexs; j += 2)
1437 {
1438 if (myPArray->keys[j] < 0)
1439 {
1440 myPArray->keys[j] = -myPArray->keys[j];
1441 glBegin (GL_LINE_LOOP);
1442 glVertex3fv (pv[j-3].xyz);
1443 glVertex3fv (pv[j-2].xyz);
1444 glVertex3fv (pv[j-1].xyz);
1445 glVertex3fv (pv[j].xyz);
7fd59977 1446 glEnd();
1447 }
1448 }
1449 }
2166f0fa 1450}
7fd59977 1451
2166f0fa
SK
1452// =======================================================================
1453// function : DrawDegeneratesAsLines
1454// purpose :
1455// =======================================================================
1456void OpenGl_PrimitiveArray::DrawDegeneratesAsLines (const TEL_COLOUR* theEdgeColour,
1457 const Handle(OpenGl_Workspace)& theWorkspace) const
7fd59977 1458{
2166f0fa 1459 const float aSkipRatio = theWorkspace->SkipRatio;
7fd59977 1460
2166f0fa 1461 GLboolean zbuff_state = glIsEnabled (GL_DEPTH_TEST);
7fd59977 1462
2166f0fa 1463 glDisable (GL_LIGHTING);
7fd59977 1464
2166f0fa
SK
1465 if (zbuff_state)
1466 glDisable (GL_DEPTH_TEST);
7fd59977 1467
2166f0fa 1468 glColor3fv (theEdgeColour->rgb);
7fd59977 1469
2166f0fa
SK
1470 if (aSkipRatio != 0.0f)
1471 {
1472 switch (myDrawMode)
1473 {
7fd59977 1474 case GL_POINTS:
2166f0fa
SK
1475 if (aSkipRatio < 1.0f)
1476 DrawDegeneratesPointsAsPoints();
7fd59977 1477 break;
1478 case GL_LINES:
2166f0fa 1479 DrawDegeneratesLinesAsLines (aSkipRatio);
7fd59977 1480 break;
1481 case GL_LINE_STRIP:
1482 case GL_POLYGON:
2166f0fa 1483 DrawDegeneratesPolygonsAsLines (aSkipRatio);
7fd59977 1484 break;
1485 case GL_TRIANGLES:
2166f0fa 1486 DrawDegeneratesTrianglesAsLines (aSkipRatio);
7fd59977 1487 break;
1488 case GL_QUADS:
2166f0fa 1489 DrawDegeneratesQuadranglesAsLines (aSkipRatio);
7fd59977 1490 break;
1491 case GL_TRIANGLE_FAN:
1492 case GL_TRIANGLE_STRIP:
2166f0fa 1493 DrawDegeneratesTrianglestripsAsLines (aSkipRatio);
7fd59977 1494 break;
1495 case GL_QUAD_STRIP:
2166f0fa 1496 DrawDegeneratesQuadranglestripsAsLines (aSkipRatio);
7fd59977 1497 break;
1498 default:
1499 break;
2166f0fa 1500 }
7fd59977 1501 }
2166f0fa
SK
1502 else
1503 {
7fd59977 1504 int i,n;
2166f0fa
SK
1505 glPushAttrib (GL_POLYGON_BIT);
1506 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
1507
1508 GLboolean color_array_mode = glIsEnabled (GL_COLOR_ARRAY);
1509 GLboolean edge_flag_array_mode = glIsEnabled (GL_EDGE_FLAG_ARRAY);
1510 GLboolean index_array_mode = glIsEnabled (GL_INDEX_ARRAY);
1511 GLboolean normal_array_mode = glIsEnabled (GL_NORMAL_ARRAY);
1512 GLboolean texture_coord_array_mode = glIsEnabled (GL_TEXTURE_COORD_ARRAY);
1513 GLboolean vertex_array_mode = glIsEnabled (GL_VERTEX_ARRAY);
1514
1515 glDisableClientState (GL_COLOR_ARRAY);
1516 glDisableClientState (GL_EDGE_FLAG_ARRAY);
1517 glDisableClientState (GL_INDEX_ARRAY);
1518 glDisableClientState (GL_NORMAL_ARRAY);
1519 glDisableClientState (GL_TEXTURE_COORD_ARRAY);
1520
1521 if (!vertex_array_mode)
1522 glEnableClientState (GL_VERTEX_ARRAY);
1523
1524 glVertexPointer (3, GL_FLOAT, 0, myPArray->vertices); // array of vertices
1525
1526 GLint renderMode;
1527 glGetIntegerv (GL_RENDER_MODE, &renderMode);
1528
1529 if (myPArray->num_bounds > 0)
1530 {
1531 if (myPArray->num_edges > 0)
1532 {
1533 for (i = n = 0; i < myPArray->num_bounds; ++i)
1534 {
1535 DrawElements (theWorkspace, myPArray, (renderMode == GL_FEEDBACK), myDrawMode,
1536 myPArray->bounds[i], (GLenum* )&myPArray->edges[n]);
1537 n += myPArray->bounds[i];
7fd59977 1538 }
1539 }
7fd59977 1540 else
2166f0fa
SK
1541 {
1542 for (i = n = 0; i < myPArray->num_bounds; ++i)
1543 {
1544 DrawArrays (theWorkspace, myPArray, (renderMode == GL_FEEDBACK), myDrawMode,
1545 n, myPArray->bounds[i]);
1546 n += myPArray->bounds[i];
1547 }
1548 }
1549 }
1550 else if (myPArray->num_edges > 0)
1551 {
1552 DrawElements (theWorkspace, myPArray, (renderMode == GL_FEEDBACK), myDrawMode,
1553 myPArray->num_edges, (GLenum* )myPArray->edges);
1554 }
1555 else
1556 {
1557 DrawArrays (theWorkspace, myPArray, (renderMode == GL_FEEDBACK), myDrawMode,
1558 0, myPArray->num_vertexs);
7fd59977 1559 }
1560
2166f0fa
SK
1561 if (!vertex_array_mode) glDisableClientState (GL_VERTEX_ARRAY);
1562
1563 if (color_array_mode) glEnableClientState (GL_COLOR_ARRAY);
1564 if (edge_flag_array_mode) glEnableClientState (GL_EDGE_FLAG_ARRAY);
1565 if (index_array_mode) glEnableClientState (GL_INDEX_ARRAY);
1566 if (normal_array_mode) glEnableClientState (GL_NORMAL_ARRAY);
1567 if (texture_coord_array_mode) glEnableClientState (GL_TEXTURE_COORD_ARRAY);
7fd59977 1568
7fd59977 1569 glPopAttrib();
1570 }
1571
2166f0fa
SK
1572 if (zbuff_state)
1573 glEnable(GL_DEPTH_TEST);
7fd59977 1574}
1575
2166f0fa
SK
1576// =======================================================================
1577// function : DrawDegeneratesAsBBoxs
1578// purpose :
1579// =======================================================================
1580void OpenGl_PrimitiveArray::DrawDegeneratesAsBBoxs (const TEL_COLOUR* theEdgeColour) const
7fd59977 1581{
2166f0fa
SK
1582 GLfloat minp[3] = { FLT_MAX, FLT_MAX, FLT_MAX };
1583 GLfloat maxp[3] = { FLT_MIN, FLT_MIN, FLT_MIN };
1584 tel_point pv = myPArray->vertices;
1585
1586 glDisable (GL_LIGHTING);
1587
1588 glColor3fv (theEdgeColour->rgb);
1589
1590 for (Tint i = 0; i < myPArray->num_vertexs; ++i)
1591 {
1592 if (pv[i].xyz[0] < minp[0])
1593 minp[0] = pv[i].xyz[0];
1594 if (pv[i].xyz[1] < minp[1])
1595 minp[1] = pv[i].xyz[1];
1596 if (pv[i].xyz[2] < minp[2])
1597 minp[2] = pv[i].xyz[2];
1598
1599 if (pv[i].xyz[0] > maxp[0])
1600 maxp[0] = pv[i].xyz[0];
1601 if (pv[i].xyz[1] > maxp[1])
1602 maxp[1] = pv[i].xyz[1];
1603 if (pv[i].xyz[2] > maxp[2])
1604 maxp[2] = pv[i].xyz[2];
1605 }
1606
1607 glBegin (GL_LINE_STRIP);
1608
1609 glVertex3fv (minp);
1610 glVertex3f (minp[0], maxp[1], minp[2]);
1611 glVertex3f (minp[0], maxp[1], maxp[2]);
1612 glVertex3f (minp[0], minp[1], maxp[2]);
1613 glVertex3f (minp[0], minp[1], minp[2]);
1614
1615 glVertex3f (maxp[0], minp[1], minp[2]);
1616 glVertex3f (maxp[0], maxp[1], minp[2]);
1617 glVertex3f (maxp[0], maxp[1], maxp[2]);
1618 glVertex3f (maxp[0], minp[1], maxp[2]);
1619 glVertex3f (maxp[0], minp[1], minp[2]);
7fd59977 1620
2166f0fa
SK
1621 glVertex3f (maxp[0], minp[1], maxp[2]);
1622 glVertex3f (minp[0], minp[1], maxp[2]);
1623 glVertex3f (minp[0], maxp[1], maxp[2]);
1624 glVertex3fv (maxp);
1625 glVertex3f (maxp[0], maxp[1], minp[2]);
1626 glVertex3f (minp[0], maxp[1], minp[2]);
7fd59977 1627
1628 glEnd();
2166f0fa 1629}
7fd59977 1630
2166f0fa
SK
1631// =======================================================================
1632// function : OpenGl_PrimitiveArray
1633// purpose :
1634// =======================================================================
1635OpenGl_PrimitiveArray::OpenGl_PrimitiveArray (CALL_DEF_PARRAY* thePArray)
1636: myPArray (thePArray),
1637 myDrawMode (GL_NONE)
1638{
1639 switch (myPArray->type)
1640 {
1641 case TelPointsArrayType:
1642 myDrawMode = GL_POINTS;
1643 break;
1644 case TelPolylinesArrayType:
1645 myDrawMode = GL_LINE_STRIP;
1646 break;
1647 case TelSegmentsArrayType:
1648 myDrawMode = GL_LINES;
1649 break;
1650 case TelPolygonsArrayType:
1651 myDrawMode = GL_POLYGON;
1652 break;
1653 case TelTrianglesArrayType:
1654 myDrawMode = GL_TRIANGLES;
1655 break;
1656 case TelQuadranglesArrayType:
1657 myDrawMode = GL_QUADS;
1658 break;
1659 case TelTriangleStripsArrayType:
1660 myDrawMode = GL_TRIANGLE_STRIP;
1661 break;
1662 case TelQuadrangleStripsArrayType:
1663 myDrawMode = GL_QUAD_STRIP;
1664 break;
1665 case TelTriangleFansArrayType:
1666 myDrawMode = GL_TRIANGLE_FAN;
1667 break;
1668 }
1669}
1670
1671// =======================================================================
1672// function : ~OpenGl_PrimitiveArray
1673// purpose :
1674// =======================================================================
1675OpenGl_PrimitiveArray::~OpenGl_PrimitiveArray ()
1676{
1677 if (myPArray == NULL)
1678 return;
1679
1680 if (myPArray->VBOEnabled == VBO_OK)
1681 {
1682 OpenGl_ResourceCleaner* aResCleaner = OpenGl_ResourceCleaner::GetInstance();
1683 if (myPArray->bufferVBO[VBOEdges] != 0)
1684 aResCleaner->AddResource ((GLCONTEXT )myPArray->contextId,
1685 new OpenGl_ResourceVBO (myPArray->bufferVBO[VBOEdges]));
1686 if (myPArray->bufferVBO[VBOVertices] != 0)
1687 aResCleaner->AddResource ((GLCONTEXT )myPArray->contextId,
1688 new OpenGl_ResourceVBO (myPArray->bufferVBO[VBOVertices]));
1689 if (myPArray->bufferVBO[VBOVcolours] != 0)
1690 aResCleaner->AddResource ((GLCONTEXT )myPArray->contextId,
1691 new OpenGl_ResourceVBO (myPArray->bufferVBO[VBOVcolours]));
1692 if (myPArray->bufferVBO[VBOVnormals] != 0)
1693 aResCleaner->AddResource ((GLCONTEXT )myPArray->contextId,
1694 new OpenGl_ResourceVBO (myPArray->bufferVBO[VBOVnormals]));
1695 if (myPArray->bufferVBO[VBOVtexels] != 0)
1696 aResCleaner->AddResource ((GLCONTEXT )myPArray->contextId,
1697 new OpenGl_ResourceVBO (myPArray->bufferVBO[VBOVtexels]));
1698 }
1699}
1700
1701// =======================================================================
1702// function : Render
1703// purpose :
1704// =======================================================================
1705void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
1706{
1707 if (myPArray == NULL || myDrawMode == GL_NONE)
1708 return;
1709
1710 // create VBOs on first render call
1711 if (myPArray->VBOEnabled == -1) // special value for uninitialized state
1712 {
1713 myPArray->VBOEnabled = OpenGl_GraphicDriver::ToUseVBO() && (theWorkspace->GetGlContext()->arbVBO != NULL);
1714 if (myPArray->VBOEnabled != 0)
1715 BuildVBO (theWorkspace);
1716 }
1717
1718 switch (myPArray->type)
1719 {
1720 case TelPointsArrayType:
1721 case TelPolylinesArrayType:
1722 case TelSegmentsArrayType:
1723 {
1724 glDisable (GL_LIGHTING);
1725
1726 if ((theWorkspace->NamedStatus & OPENGL_NS_ANIMATION) != 0 &&
1727 (theWorkspace->NamedStatus & OPENGL_NS_WIREFRAME) == 0 &&
1728 theWorkspace->DegenerateModel)
1729 {
1730 glDisable (GL_DEPTH_TEST);
1731 if (theWorkspace->NamedStatus & OPENGL_NS_TEXTURE)
1732 DisableTexture();
1733 theWorkspace->NamedStatus |= OPENGL_NS_WIREFRAME;
1734 }
1735 break;
1736 }
1737 case TelPolygonsArrayType:
1738 case TelTrianglesArrayType:
1739 case TelQuadranglesArrayType:
1740 case TelTriangleStripsArrayType:
1741 case TelTriangleFansArrayType:
1742 case TelQuadrangleStripsArrayType:
1743 {
1744 if ((theWorkspace->NamedStatus & OPENGL_NS_ANIMATION) != 0 &&
1745 (theWorkspace->NamedStatus & OPENGL_NS_WIREFRAME) != 0 &&
1746 theWorkspace->DegenerateModel < 2)
1747 {
1748 if (theWorkspace->NamedStatus & OPENGL_NS_TEXTURE)
1749 EnableTexture();
1750 glEnable (GL_DEPTH_TEST);
1751 theWorkspace->NamedStatus &= ~OPENGL_NS_WIREFRAME;
1752 }
1753 break;
1754 }
1755 default:
1756 break;
1757 }
1758
1759 const OpenGl_AspectFace* anAspectFace = theWorkspace->AspectFace (Standard_True);
1760 const OpenGl_AspectLine* anAspectLine = theWorkspace->AspectLine (Standard_True);
1761
1762 Tint aFrontLightingModel = anAspectFace->Context().IntFront.color_mask;
1763 const TEL_COLOUR* anInteriorColor = &anAspectFace->Context().IntFront.matcol;
1764 const TEL_COLOUR* anEdgeColor = &anAspectFace->AspectEdge()->Color();
1765 const TEL_COLOUR* aLineColor = &anAspectLine->Color();
1766
1767 // Use highlight colors
1768 if (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT)
1769 {
1770 anEdgeColor = anInteriorColor = aLineColor = theWorkspace->HighlightColor;
1771 aFrontLightingModel = 0;
1772 }
1773
1774 DrawArray (aFrontLightingModel,
1775 anAspectFace->Context().InteriorStyle,
1776 anAspectFace->Context().Edge,
1777 anInteriorColor,
1778 aLineColor,
1779 anEdgeColor,
1780 &anAspectFace->Context().IntFront,
1781 theWorkspace);
1782
1783 switch (myPArray->type)
1784 {
1785 case TelPointsArrayType:
1786 case TelPolylinesArrayType:
1787 case TelSegmentsArrayType:
1788 {
1789 if (theWorkspace->NamedStatus & OPENGL_NS_TEXTURE)
1790 EnableTexture();
1791 }
1792 }
1793}