1 // Created on: 2011-10-25
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <OpenGl_GlCore11.hxx>
18 #include <OpenGl_LineAttributes.hxx>
19 #include <OpenGl_Context.hxx>
26 #define DASH_DOT_LS 0xFF18
27 #define DASH_LS 0xFFC0
28 #define DASH_DDOT_LS 0xFF24
30 static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
102 //TEL_HS_CROSS_SPARSE
347 //TEL_HS_DIAG_45_SPARSE
382 //TEL_HS_DIAG_135_SPARSE
417 //TEL_HS_HORIZONTAL_SPARSE
452 //TEL_HS_VERTICAL_SPARSE
489 IMPLEMENT_STANDARD_HANDLE (OpenGl_LineAttributes, OpenGl_Resource)
490 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_LineAttributes, OpenGl_Resource)
492 // =======================================================================
493 // function : OpenGl_LineAttributes
495 // =======================================================================
496 OpenGl_LineAttributes::OpenGl_LineAttributes()
497 : myLinestyleBase(0),
503 // =======================================================================
504 // function : ~OpenGl_LineAttributes
506 // =======================================================================
507 OpenGl_LineAttributes::~OpenGl_LineAttributes()
512 // =======================================================================
513 // function : Release
515 // =======================================================================
516 void OpenGl_LineAttributes::Release (OpenGl_Context* theGlCtx)
518 // Delete line styles
519 if (myLinestyleBase != 0)
521 if (theGlCtx->IsValid())
523 #if !defined(GL_ES_VERSION_2_0)
524 glDeleteLists ((GLuint )myLinestyleBase, 5);
529 // Delete surface patterns
530 if (myPatternBase != 0)
532 if (theGlCtx->IsValid())
534 #if !defined(GL_ES_VERSION_2_0)
535 glDeleteLists ((GLuint )myPatternBase, TEL_HS_USER_DEF_START);
542 // =======================================================================
545 // =======================================================================
546 void OpenGl_LineAttributes::Init (const Handle(OpenGl_Context)& theGlCtx)
548 // Return if already initialized
549 if (myLinestyleBase != 0)
554 #if !defined(GL_ES_VERSION_2_0)
555 myLinestyleBase = theGlCtx->core11->glGenLists (5);
558 glNewList ((GLuint )myLinestyleBase + (GLuint )Aspect_TOL_DASH, GL_COMPILE);
559 glLineStipple (1, DASH_LS);
562 glNewList ((GLuint )myLinestyleBase + (GLuint )Aspect_TOL_DOT, GL_COMPILE);
563 glLineStipple (1, DOT_LS);
566 glNewList ((GLuint )myLinestyleBase + (GLuint )Aspect_TOL_DOTDASH, GL_COMPILE);
567 glLineStipple (1, DASH_DOT_LS);
570 glNewList ((GLuint )myLinestyleBase + (GLuint )Aspect_TOL_USERDEFINED, GL_COMPILE);
571 glLineStipple (1, DASH_DDOT_LS);
574 // GL_POLYGON_STIPPLE need 32x32 stipple patterns
575 const int nbi = sizeof(myInteriors) / (32 * sizeof(unsigned int));
576 myPatternBase = glGenLists(TEL_HS_USER_DEF_START);
577 for (int i = 1; i < TEL_HS_USER_DEF_START; i++)
579 glNewList ((GLuint )myPatternBase + i, GL_COMPILE);
580 glPolygonStipple ((const GLubyte* )myInteriors[i < nbi ? i : 0]);
586 // =======================================================================
587 // function : SetTypeOfLine
589 // =======================================================================
590 void OpenGl_LineAttributes::SetTypeOfLine (const Aspect_TypeOfLine theType) const
592 #if !defined(GL_ES_VERSION_2_0)
593 if (theType != Aspect_TOL_SOLID)
595 glCallList ((GLuint )myLinestyleBase + (GLuint )theType);
596 glEnable (GL_LINE_STIPPLE);
598 gl2psEnable (GL2PS_LINE_STIPPLE);
603 glDisable (GL_LINE_STIPPLE);
605 gl2psDisable (GL2PS_LINE_STIPPLE);
611 // =======================================================================
612 // function : SetTypeOfHatch
614 // =======================================================================
615 void OpenGl_LineAttributes::SetTypeOfHatch (const int theType) const
617 #if !defined(GL_ES_VERSION_2_0)
620 glCallList ((GLuint )myPatternBase + (GLuint )theType);
621 glEnable (GL_POLYGON_STIPPLE);
624 glDisable (GL_POLYGON_STIPPLE);