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>
21 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_LineAttributes,OpenGl_Resource)
23 static const unsigned int myInteriors[TEL_HS_USER_DEF_START][32] =
340 //TEL_HS_DIAG_45_SPARSE
375 //TEL_HS_DIAG_135_SPARSE
410 //TEL_HS_HORIZONTAL_SPARSE
445 //TEL_HS_VERTICAL_SPARSE
483 // =======================================================================
484 // function : OpenGl_LineAttributes
486 // =======================================================================
487 OpenGl_LineAttributes::OpenGl_LineAttributes()
493 // =======================================================================
494 // function : ~OpenGl_LineAttributes
496 // =======================================================================
497 OpenGl_LineAttributes::~OpenGl_LineAttributes()
502 // =======================================================================
503 // function : Release
505 // =======================================================================
506 void OpenGl_LineAttributes::Release (OpenGl_Context* theGlCtx)
508 // Delete surface patterns
509 if (myPatternBase != 0)
511 if (theGlCtx->IsValid())
513 #if !defined(GL_ES_VERSION_2_0)
514 glDeleteLists ((GLuint )myPatternBase, TEL_HS_USER_DEF_START);
521 // =======================================================================
524 // =======================================================================
525 void OpenGl_LineAttributes::Init (const Handle(OpenGl_Context)& theGlCtx)
527 // Return if already initialized
528 if (myPatternBase != 0)
533 #if !defined(GL_ES_VERSION_2_0)
534 if (theGlCtx->core11 == NULL)
539 // GL_POLYGON_STIPPLE need 32x32 stipple patterns
540 const int nbi = sizeof(myInteriors) / (32 * sizeof(unsigned int));
541 myPatternBase = glGenLists(TEL_HS_USER_DEF_START);
542 for (int i = 1; i < TEL_HS_USER_DEF_START; i++)
544 glNewList ((GLuint )myPatternBase + i, GL_COMPILE);
545 glPolygonStipple ((const GLubyte* )myInteriors[i < nbi ? i : 0]);
553 // =======================================================================
554 // function : SetTypeOfHatch
556 // =======================================================================
557 void OpenGl_LineAttributes::SetTypeOfHatch (const int theType) const
559 #if !defined(GL_ES_VERSION_2_0)
560 if (myPatternBase == 0)
567 glCallList ((GLuint )myPatternBase + (GLuint )theType);
568 glEnable (GL_POLYGON_STIPPLE);
571 glDisable (GL_POLYGON_STIPPLE);