0026122: Visualization, TKOpenGl - clipping and capping is broken when ffp is disable...
[occt.git] / src / OpenGl / OpenGl_LineAttributes.cxx
CommitLineData
b311480e 1// Created on: 2011-10-25
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
2166f0fa 15
5f8b738e 16#include <OpenGl_GlCore11.hxx>
17
73192b37 18#include <OpenGl_LineAttributes.hxx>
19#include <OpenGl_Context.hxx>
2166f0fa 20
2166f0fa
SK
21static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
22{
23 //TEL_HS_SOLID
24 {
25 0xFFFFFFFF,
26 0xFFFFFFFF,
27 0xFFFFFFFF,
28 0xFFFFFFFF,
29 0xFFFFFFFF,
30 0xFFFFFFFF,
31 0xFFFFFFFF,
32 0xFFFFFFFF,
33 0xFFFFFFFF,
34 0xFFFFFFFF,
35 0xFFFFFFFF,
36 0xFFFFFFFF,
37 0xFFFFFFFF,
38 0xFFFFFFFF,
39 0xFFFFFFFF,
40 0xFFFFFFFF,
41 0xFFFFFFFF,
42 0xFFFFFFFF,
43 0xFFFFFFFF,
44 0xFFFFFFFF,
45 0xFFFFFFFF,
46 0xFFFFFFFF,
47 0xFFFFFFFF,
48 0xFFFFFFFF,
49 0xFFFFFFFF,
50 0xFFFFFFFF,
51 0xFFFFFFFF,
52 0xFFFFFFFF,
53 0xFFFFFFFF,
54 0xFFFFFFFF,
55 0xFFFFFFFF,
56 0xFFFFFFFF
57 },
58 //TEL_HS_CROSS
59 {
60 0xFFFFFFFF,
61 0xBBBBBBBB,
62 0xEEEEEEEE,
63 0xBBBBBBBB,
64 0xEEEEEEEE,
65 0xBBBBBBBB,
66 0xEEEEEEEE,
67 0xBBBBBBBB,
68 0xEEEEEEEE,
69 0xBBBBBBBB,
70 0xEEEEEEEE,
71 0xBBBBBBBB,
72 0xEEEEEEEE,
73 0xBBBBBBBB,
74 0xEEEEEEEE,
75 0xBBBBBBBB,
76 0xEEEEEEEE,
77 0xBBBBBBBB,
78 0xEEEEEEEE,
79 0xBBBBBBBB,
80 0xEEEEEEEE,
81 0xBBBBBBBB,
82 0xEEEEEEEE,
83 0xBBBBBBBB,
84 0xEEEEEEEE,
85 0xBBBBBBBB,
86 0xEEEEEEEE,
87 0xBBBBBBBB,
88 0xEEEEEEEE,
89 0xBBBBBBBB,
90 0xEEEEEEEE,
91 0xBBBBBBBB
92 },
93 //TEL_HS_CROSS_SPARSE
94 {
95 0x81818181,
96 0x24242424,
97 0x18181818,
98 0x42424242,
99 0x81818181,
100 0x24242424,
101 0x18181818,
102 0x42424242,
103 0x81818181,
104 0x24242424,
105 0x18181818,
106 0x42424242,
107 0x81818181,
108 0x24242424,
109 0x18181818,
110 0x42424242,
111 0x81818181,
112 0x24242424,
113 0x18181818,
114 0x42424242,
115 0x81818181,
116 0x24242424,
117 0x18181818,
118 0x42424242,
119 0x81818181,
120 0x24242424,
121 0x18181818,
122 0x42424242,
123 0x81818181,
124 0x24242424,
125 0x18181818,
126 0x42424242
127 },
128 //TEL_HS_GRID
129 {
130 0xFFFFFFFF,
131 0x88888888,
132 0xFFFFFFFF,
133 0x88888888,
134 0xFFFFFFFF,
135 0x88888888,
136 0xFFFFFFFF,
137 0x88888888,
138 0xFFFFFFFF,
139 0x88888888,
140 0xFFFFFFFF,
141 0x88888888,
142 0xFFFFFFFF,
143 0x88888888,
144 0xFFFFFFFF,
145 0x88888888,
146 0xFFFFFFFF,
147 0x88888888,
148 0xFFFFFFFF,
149 0x88888888,
150 0xFFFFFFFF,
151 0x88888888,
152 0xFFFFFFFF,
153 0x88888888,
154 0xFFFFFFFF,
155 0x88888888,
156 0xFFFFFFFF,
157 0x88888888,
158 0xFFFFFFFF,
159 0x88888888,
160 0xFFFFFFFF,
161 0x88888888
162 },
163 //TEL_HS_GRID_SPARSE
164 {
165 0xFFFFFFFF,
166 0x80808080,
167 0x80808080,
168 0x80808080,
169 0xFFFFFFFF,
170 0x80808080,
171 0x80808080,
172 0x80808080,
173 0xFFFFFFFF,
174 0x80808080,
175 0x80808080,
176 0x80808080,
177 0xFFFFFFFF,
178 0x80808080,
179 0x80808080,
180 0x80808080,
181 0xFFFFFFFF,
182 0x80808080,
183 0x80808080,
184 0x80808080,
185 0xFFFFFFFF,
186 0x80808080,
187 0x80808080,
188 0x80808080,
189 0xFFFFFFFF,
190 0x80808080,
191 0x80808080,
192 0x80808080,
193 0xFFFFFFFF,
194 0x80808080,
195 0x80808080,
196 0x80808080
197 },
198 //TEL_HS_DIAG_45
199 {
200 0x88888888,
201 0x22222222,
202 0x88888888,
203 0x22222222,
204 0x88888888,
205 0x22222222,
206 0x88888888,
207 0x22222222,
208 0x88888888,
209 0x22222222,
210 0x88888888,
211 0x22222222,
212 0x88888888,
213 0x22222222,
214 0x88888888,
215 0x22222222,
216 0x88888888,
217 0x22222222,
218 0x88888888,
219 0x22222222,
220 0x88888888,
221 0x22222222,
222 0x88888888,
223 0x22222222,
224 0x88888888,
225 0x22222222,
226 0x88888888,
227 0x22222222,
228 0x88888888,
229 0x22222222,
230 0x88888888,
231 0x22222222
232 },
233 //TEL_HS_DIAG_135
234 {
235 0x11111111,
236 0x44444444,
237 0x11111111,
238 0x44444444,
239 0x11111111,
240 0x44444444,
241 0x11111111,
242 0x44444444,
243 0x11111111,
244 0x44444444,
245 0x11111111,
246 0x44444444,
247 0x11111111,
248 0x44444444,
249 0x11111111,
250 0x44444444,
251 0x11111111,
252 0x44444444,
253 0x11111111,
254 0x44444444,
255 0x11111111,
256 0x44444444,
257 0x11111111,
258 0x44444444,
259 0x11111111,
260 0x44444444,
261 0x11111111,
262 0x44444444,
263 0x11111111,
264 0x44444444,
265 0x11111111,
266 0x44444444
267 },
268 //TEL_HS_HORIZONTAL
269 {
270 0xFFFFFFFF,
271 0x00000000,
272 0xFFFFFFFF,
273 0x00000000,
274 0xFFFFFFFF,
275 0x00000000,
276 0xFFFFFFFF,
277 0x00000000,
278 0xFFFFFFFF,
279 0x00000000,
280 0xFFFFFFFF,
281 0x00000000,
282 0xFFFFFFFF,
283 0x00000000,
284 0xFFFFFFFF,
285 0x00000000,
286 0xFFFFFFFF,
287 0x00000000,
288 0xFFFFFFFF,
289 0x00000000,
290 0xFFFFFFFF,
291 0x00000000,
292 0xFFFFFFFF,
293 0x00000000,
294 0xFFFFFFFF,
295 0x00000000,
296 0xFFFFFFFF,
297 0x00000000,
298 0xFFFFFFFF,
299 0x00000000,
300 0xFFFFFFFF,
301 0x00000000
302 },
303 //TEL_HS_VERTICAL
304 {
305 0x11111111,
306 0x11111111,
307 0x11111111,
308 0x11111111,
309 0x11111111,
310 0x11111111,
311 0x11111111,
312 0x11111111,
313 0x11111111,
314 0x11111111,
315 0x11111111,
316 0x11111111,
317 0x11111111,
318 0x11111111,
319 0x11111111,
320 0x11111111,
321 0x11111111,
322 0x11111111,
323 0x11111111,
324 0x11111111,
325 0x11111111,
326 0x11111111,
327 0x11111111,
328 0x11111111,
329 0x11111111,
330 0x11111111,
331 0x11111111,
332 0x11111111,
333 0x11111111,
334 0x11111111,
335 0x11111111,
336 0x11111111
337 },
338 //TEL_HS_DIAG_45_SPARSE
339 {
340 0x80808080,
341 0x20202020,
342 0x08080808,
343 0x02020202,
344 0x80808080,
345 0x20202020,
346 0x08080808,
347 0x02020202,
348 0x80808080,
349 0x20202020,
350 0x08080808,
351 0x02020202,
352 0x80808080,
353 0x20202020,
354 0x08080808,
355 0x02020202,
356 0x80808080,
357 0x20202020,
358 0x08080808,
359 0x02020202,
360 0x80808080,
361 0x20202020,
362 0x08080808,
363 0x02020202,
364 0x80808080,
365 0x20202020,
366 0x08080808,
367 0x02020202,
368 0x80808080,
369 0x20202020,
370 0x08080808,
371 0x02020202
372 },
373 //TEL_HS_DIAG_135_SPARSE
374 {
375 0x01010101,
376 0x04040404,
377 0x10101010,
378 0x40404040,
379 0x01010101,
380 0x04040404,
381 0x10101010,
382 0x40404040,
383 0x01010101,
384 0x04040404,
385 0x10101010,
386 0x40404040,
387 0x01010101,
388 0x04040404,
389 0x10101010,
390 0x40404040,
391 0x01010101,
392 0x04040404,
393 0x10101010,
394 0x40404040,
395 0x01010101,
396 0x04040404,
397 0x10101010,
398 0x40404040,
399 0x01010101,
400 0x04040404,
401 0x10101010,
402 0x40404040,
403 0x01010101,
404 0x04040404,
405 0x10101010,
406 0x40404040
407 },
408 //TEL_HS_HORIZONTAL_SPARSE
409 {
410 0xFFFFFFFF,
411 0x00000000,
412 0x00000000,
413 0x00000000,
414 0xFFFFFFFF,
415 0x00000000,
416 0x00000000,
417 0x00000000,
418 0xFFFFFFFF,
419 0x00000000,
420 0x00000000,
421 0x00000000,
422 0xFFFFFFFF,
423 0x00000000,
424 0x00000000,
425 0x00000000,
426 0xFFFFFFFF,
427 0x00000000,
428 0x00000000,
429 0x00000000,
430 0xFFFFFFFF,
431 0x00000000,
432 0x00000000,
433 0x00000000,
434 0xFFFFFFFF,
435 0x00000000,
436 0x00000000,
437 0x00000000,
438 0xFFFFFFFF,
439 0x00000000,
440 0x00000000,
441 0x00000000
442 },
443 //TEL_HS_VERTICAL_SPARSE
444 {
445 0x10101010,
446 0x10101010,
447 0x10101010,
448 0x10101010,
449 0x10101010,
450 0x10101010,
451 0x10101010,
452 0x10101010,
453 0x10101010,
454 0x10101010,
455 0x10101010,
456 0x10101010,
457 0x10101010,
458 0x10101010,
459 0x10101010,
460 0x10101010,
461 0x10101010,
462 0x10101010,
463 0x10101010,
464 0x10101010,
465 0x10101010,
466 0x10101010,
467 0x10101010,
468 0x10101010,
469 0x10101010,
470 0x10101010,
471 0x10101010,
472 0x10101010,
473 0x10101010,
474 0x10101010,
475 0x10101010,
476 0x10101010
477 }
478};
479
2166f0fa 480
73192b37 481// =======================================================================
482// function : OpenGl_LineAttributes
483// purpose :
484// =======================================================================
485OpenGl_LineAttributes::OpenGl_LineAttributes()
ac116c22 486: myPatternBase(0)
2166f0fa 487{
73192b37 488 //
489}
490
491// =======================================================================
492// function : ~OpenGl_LineAttributes
493// purpose :
494// =======================================================================
495OpenGl_LineAttributes::~OpenGl_LineAttributes()
496{
497 Release (NULL);
498}
499
500// =======================================================================
501// function : Release
502// purpose :
503// =======================================================================
10b9c7df 504void OpenGl_LineAttributes::Release (OpenGl_Context* theGlCtx)
73192b37 505{
73192b37 506 // Delete surface patterns
507 if (myPatternBase != 0)
508 {
509 if (theGlCtx->IsValid())
510 {
ca3c13d1 511 #if !defined(GL_ES_VERSION_2_0)
73192b37 512 glDeleteLists ((GLuint )myPatternBase, TEL_HS_USER_DEF_START);
ca3c13d1 513 #endif
73192b37 514 }
515 myPatternBase = 0;
516 }
517}
2166f0fa 518
73192b37 519// =======================================================================
520// function : Init
521// purpose :
522// =======================================================================
523void OpenGl_LineAttributes::Init (const Handle(OpenGl_Context)& theGlCtx)
524{
525 // Return if already initialized
ac116c22 526 if (myPatternBase != 0)
73192b37 527 {
528 return;
529 }
2166f0fa 530
ca3c13d1 531#if !defined(GL_ES_VERSION_2_0)
4e1523ef 532 if (theGlCtx->core11 == NULL)
533 {
534 return;
535 }
536
73192b37 537 // GL_POLYGON_STIPPLE need 32x32 stipple patterns
538 const int nbi = sizeof(myInteriors) / (32 * sizeof(unsigned int));
2166f0fa 539 myPatternBase = glGenLists(TEL_HS_USER_DEF_START);
73192b37 540 for (int i = 1; i < TEL_HS_USER_DEF_START; i++)
2166f0fa 541 {
73192b37 542 glNewList ((GLuint )myPatternBase + i, GL_COMPILE);
543 glPolygonStipple ((const GLubyte* )myInteriors[i < nbi ? i : 0]);
2166f0fa
SK
544 glEndList();
545 }
ca3c13d1 546#endif
2166f0fa
SK
547}
548
73192b37 549// =======================================================================
73192b37 550// function : SetTypeOfHatch
551// purpose :
552// =======================================================================
553void OpenGl_LineAttributes::SetTypeOfHatch (const int theType) const
2166f0fa 554{
ca3c13d1 555#if !defined(GL_ES_VERSION_2_0)
79f4f036 556 if (myPatternBase == 0)
557 {
558 return;
559 }
560
73192b37 561 if (theType != 0)
2166f0fa 562 {
73192b37 563 glCallList ((GLuint )myPatternBase + (GLuint )theType);
564 glEnable (GL_POLYGON_STIPPLE);
2166f0fa
SK
565 }
566 else
73192b37 567 glDisable (GL_POLYGON_STIPPLE);
ca3c13d1 568#endif
2166f0fa 569}