0024001: Stereographic rendering support
[occt.git] / src / OpenGl / OpenGl_Display_2.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//
973c2be1 7// This library is free software; you can redistribute it and / or modify it
8// under the terms of the GNU Lesser General Public version 2.1 as published
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
2166f0fa
SK
18#include <OpenGl_Display.hxx>
19
498ce577 20#ifdef HAVE_CONFIG_H
e276548b 21 #include <config.h>
498ce577 22#endif
23
2166f0fa 24#ifdef HAVE_GL2PS
5f8b738e 25 #include <gl2ps.h>
2166f0fa
SK
26#endif
27
2166f0fa
SK
28#define DOT_LS 0xCCCC
29#define DASH_DOT_LS 0xFF18
30#define DASH_LS 0xFFC0
31#define DASH_DDOT_LS 0xFF24
32
33static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
34{
35 //TEL_HS_SOLID
36 {
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 0xFFFFFFFF,
58 0xFFFFFFFF,
59 0xFFFFFFFF,
60 0xFFFFFFFF,
61 0xFFFFFFFF,
62 0xFFFFFFFF,
63 0xFFFFFFFF,
64 0xFFFFFFFF,
65 0xFFFFFFFF,
66 0xFFFFFFFF,
67 0xFFFFFFFF,
68 0xFFFFFFFF
69 },
70 //TEL_HS_CROSS
71 {
72 0xFFFFFFFF,
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 0xEEEEEEEE,
93 0xBBBBBBBB,
94 0xEEEEEEEE,
95 0xBBBBBBBB,
96 0xEEEEEEEE,
97 0xBBBBBBBB,
98 0xEEEEEEEE,
99 0xBBBBBBBB,
100 0xEEEEEEEE,
101 0xBBBBBBBB,
102 0xEEEEEEEE,
103 0xBBBBBBBB
104 },
105 //TEL_HS_CROSS_SPARSE
106 {
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 0x81818181,
128 0x24242424,
129 0x18181818,
130 0x42424242,
131 0x81818181,
132 0x24242424,
133 0x18181818,
134 0x42424242,
135 0x81818181,
136 0x24242424,
137 0x18181818,
138 0x42424242
139 },
140 //TEL_HS_GRID
141 {
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 0xFFFFFFFF,
163 0x88888888,
164 0xFFFFFFFF,
165 0x88888888,
166 0xFFFFFFFF,
167 0x88888888,
168 0xFFFFFFFF,
169 0x88888888,
170 0xFFFFFFFF,
171 0x88888888,
172 0xFFFFFFFF,
173 0x88888888
174 },
175 //TEL_HS_GRID_SPARSE
176 {
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 0xFFFFFFFF,
198 0x80808080,
199 0x80808080,
200 0x80808080,
201 0xFFFFFFFF,
202 0x80808080,
203 0x80808080,
204 0x80808080,
205 0xFFFFFFFF,
206 0x80808080,
207 0x80808080,
208 0x80808080
209 },
210 //TEL_HS_DIAG_45
211 {
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 0x88888888,
233 0x22222222,
234 0x88888888,
235 0x22222222,
236 0x88888888,
237 0x22222222,
238 0x88888888,
239 0x22222222,
240 0x88888888,
241 0x22222222,
242 0x88888888,
243 0x22222222
244 },
245 //TEL_HS_DIAG_135
246 {
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 0x11111111,
268 0x44444444,
269 0x11111111,
270 0x44444444,
271 0x11111111,
272 0x44444444,
273 0x11111111,
274 0x44444444,
275 0x11111111,
276 0x44444444,
277 0x11111111,
278 0x44444444
279 },
280 //TEL_HS_HORIZONTAL
281 {
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 0xFFFFFFFF,
303 0x00000000,
304 0xFFFFFFFF,
305 0x00000000,
306 0xFFFFFFFF,
307 0x00000000,
308 0xFFFFFFFF,
309 0x00000000,
310 0xFFFFFFFF,
311 0x00000000,
312 0xFFFFFFFF,
313 0x00000000
314 },
315 //TEL_HS_VERTICAL
316 {
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 0x11111111,
338 0x11111111,
339 0x11111111,
340 0x11111111,
341 0x11111111,
342 0x11111111,
343 0x11111111,
344 0x11111111,
345 0x11111111,
346 0x11111111,
347 0x11111111,
348 0x11111111
349 },
350 //TEL_HS_DIAG_45_SPARSE
351 {
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 0x80808080,
373 0x20202020,
374 0x08080808,
375 0x02020202,
376 0x80808080,
377 0x20202020,
378 0x08080808,
379 0x02020202,
380 0x80808080,
381 0x20202020,
382 0x08080808,
383 0x02020202
384 },
385 //TEL_HS_DIAG_135_SPARSE
386 {
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 0x01010101,
408 0x04040404,
409 0x10101010,
410 0x40404040,
411 0x01010101,
412 0x04040404,
413 0x10101010,
414 0x40404040,
415 0x01010101,
416 0x04040404,
417 0x10101010,
418 0x40404040
419 },
420 //TEL_HS_HORIZONTAL_SPARSE
421 {
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 0xFFFFFFFF,
443 0x00000000,
444 0x00000000,
445 0x00000000,
446 0xFFFFFFFF,
447 0x00000000,
448 0x00000000,
449 0x00000000,
450 0xFFFFFFFF,
451 0x00000000,
452 0x00000000,
453 0x00000000
454 },
455 //TEL_HS_VERTICAL_SPARSE
456 {
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 0x10101010,
478 0x10101010,
479 0x10101010,
480 0x10101010,
481 0x10101010,
482 0x10101010,
483 0x10101010,
484 0x10101010,
485 0x10101010,
486 0x10101010,
487 0x10101010,
488 0x10101010
489 }
490};
491
2166f0fa
SK
492/*----------------------------------------------------------------------*/
493
494//TsmInitAttributes
495void OpenGl_Display::InitAttributes ()
496{
497 // Return if already initialized
498 if (myLinestyleBase) return;
499
500 myLinestyleBase = glGenLists(5);
501
502 /* Line */
503
504 glNewList( (GLuint)myLinestyleBase+(GLuint)Aspect_TOL_DASH, GL_COMPILE );
505 glLineStipple(1, DASH_LS );
506 glEndList();
507
508 glNewList( (GLuint)myLinestyleBase+(GLuint)Aspect_TOL_DOT, GL_COMPILE );
509 glLineStipple(1, DOT_LS );
510 glEndList();
511
512 glNewList( (GLuint)myLinestyleBase+(GLuint)Aspect_TOL_DOTDASH, GL_COMPILE );
513 glLineStipple(1, DASH_DOT_LS );
514 glEndList();
515
516 glNewList( (GLuint)myLinestyleBase+(GLuint)Aspect_TOL_USERDEFINED, GL_COMPILE );
517 glLineStipple(1, DASH_DDOT_LS );
518 glEndList();
519
520 /* FSXXX
521 * GL_POLYGON_STIPPLE
522 * need 32x32 stipple patterns
523 */
524 const int nbi = sizeof(myInteriors)/(32*sizeof(unsigned int));
525 myPatternBase = glGenLists(TEL_HS_USER_DEF_START);
526 int i;
527 for( i = 1; i < TEL_HS_USER_DEF_START; i++ )
528 {
529 glNewList( (GLuint)myPatternBase + i, GL_COMPILE );
530 glPolygonStipple((const GLubyte *) (myInteriors[i<nbi? i : 0]));
531 glEndList();
532 }
533
534 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
2166f0fa
SK
535}
536
537/*----------------------------------------------------------------------*/
538
539void OpenGl_Display::SetTypeOfLine (const Aspect_TypeOfLine AType) const
540{
541 if (AType != Aspect_TOL_SOLID)
542 {
543 glCallList((GLuint)myLinestyleBase+(GLuint)AType);
544 glEnable( GL_LINE_STIPPLE );
545#ifdef HAVE_GL2PS
546 gl2psEnable( GL2PS_LINE_STIPPLE );
547#endif
548 }
549 else
550 {
551 glDisable( GL_LINE_STIPPLE );
552#ifdef HAVE_GL2PS
553 gl2psDisable( GL2PS_LINE_STIPPLE );
554#endif
555 }
556}
557
558/*----------------------------------------------------------------------*/
559
560void OpenGl_Display::SetTypeOfHatch (const int AType) const
561{
562 if (AType)
563 {
564 glCallList((GLuint)myPatternBase+(GLuint)AType);
565 glEnable( GL_POLYGON_STIPPLE );
566 }
567 else
568 glDisable( GL_POLYGON_STIPPLE );
569}
570
571/*----------------------------------------------------------------------*/