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>
30 #define DASH_DOT_LS 0xFF18
31 #define DASH_LS 0xFFC0
32 #define DASH_DDOT_LS 0xFF24
34 static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
106 //TEL_HS_CROSS_SPARSE
351 //TEL_HS_DIAG_45_SPARSE
386 //TEL_HS_DIAG_135_SPARSE
421 //TEL_HS_HORIZONTAL_SPARSE
456 //TEL_HS_VERTICAL_SPARSE
493 IMPLEMENT_STANDARD_HANDLE (OpenGl_LineAttributes, OpenGl_Resource)
494 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_LineAttributes, OpenGl_Resource)
496 // =======================================================================
497 // function : OpenGl_LineAttributes
499 // =======================================================================
500 OpenGl_LineAttributes::OpenGl_LineAttributes()
501 : myLinestyleBase(0),
507 // =======================================================================
508 // function : ~OpenGl_LineAttributes
510 // =======================================================================
511 OpenGl_LineAttributes::~OpenGl_LineAttributes()
516 // =======================================================================
517 // function : Release
519 // =======================================================================
520 void OpenGl_LineAttributes::Release (const OpenGl_Context* theGlCtx)
522 // Delete line styles
523 if (myLinestyleBase != 0)
525 if (theGlCtx->IsValid())
527 glDeleteLists ((GLuint )myLinestyleBase, 5);
531 // Delete surface patterns
532 if (myPatternBase != 0)
534 if (theGlCtx->IsValid())
536 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 myLinestyleBase = theGlCtx->core11->glGenLists (5);
557 glNewList ((GLuint )myLinestyleBase + (GLuint )Aspect_TOL_DASH, GL_COMPILE);
558 glLineStipple (1, DASH_LS);
561 glNewList ((GLuint )myLinestyleBase + (GLuint )Aspect_TOL_DOT, GL_COMPILE);
562 glLineStipple (1, DOT_LS);
565 glNewList ((GLuint )myLinestyleBase + (GLuint )Aspect_TOL_DOTDASH, GL_COMPILE);
566 glLineStipple (1, DASH_DOT_LS);
569 glNewList ((GLuint )myLinestyleBase + (GLuint )Aspect_TOL_USERDEFINED, GL_COMPILE);
570 glLineStipple (1, DASH_DDOT_LS);
573 // GL_POLYGON_STIPPLE need 32x32 stipple patterns
574 const int nbi = sizeof(myInteriors) / (32 * sizeof(unsigned int));
575 myPatternBase = glGenLists(TEL_HS_USER_DEF_START);
576 for (int i = 1; i < TEL_HS_USER_DEF_START; i++)
578 glNewList ((GLuint )myPatternBase + i, GL_COMPILE);
579 glPolygonStipple ((const GLubyte* )myInteriors[i < nbi ? i : 0]);
584 // =======================================================================
585 // function : SetTypeOfLine
587 // =======================================================================
588 void OpenGl_LineAttributes::SetTypeOfLine (const Aspect_TypeOfLine theType) const
590 if (theType != Aspect_TOL_SOLID)
592 glCallList ((GLuint )myLinestyleBase + (GLuint )theType);
593 glEnable (GL_LINE_STIPPLE);
595 gl2psEnable (GL2PS_LINE_STIPPLE);
600 glDisable (GL_LINE_STIPPLE);
602 gl2psDisable (GL2PS_LINE_STIPPLE);
607 // =======================================================================
608 // function : SetTypeOfHatch
610 // =======================================================================
611 void OpenGl_LineAttributes::SetTypeOfHatch (const int theType) const
615 glCallList ((GLuint )myPatternBase + (GLuint )theType);
616 glEnable (GL_POLYGON_STIPPLE);
619 glDisable (GL_POLYGON_STIPPLE);