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] =
60 // Aspect_HS_GRID_DIAGONAL
95 // Aspect_HS_GRID_DIAGONAL_WIDE
165 // Aspect_HS_GRID_WIDE
200 // Aspect_HS_DIAGONAL_45
235 // Aspect_HS_DIAGONAL_135
270 // Aspect_HS_HORIZONTAL
305 // Aspect_HS_VERTICAL
340 // Aspect_HS_DIAGONAL_45_WIDE
375 // Aspect_HS_DIAGONAL_135_WIDE
410 // Aspect_HS_HORIZONTAL_WIDE
445 // Aspect_HS_VERTICAL_WIDE
482 // =======================================================================
483 // function : OpenGl_LineAttributes
485 // =======================================================================
486 OpenGl_LineAttributes::OpenGl_LineAttributes()
494 // =======================================================================
495 // function : ~OpenGl_LineAttributes
497 // =======================================================================
498 OpenGl_LineAttributes::~OpenGl_LineAttributes()
503 // =======================================================================
504 // function : Release
506 // =======================================================================
507 void OpenGl_LineAttributes::Release (OpenGl_Context* theGlCtx)
509 // Delete surface patterns
510 if (myPatternBase != 0)
512 #if !defined(GL_ES_VERSION_2_0)
513 if (theGlCtx->IsValid())
515 theGlCtx->core11->glDeleteLists ((GLuint )myPatternBase, TEL_HS_USER_DEF_START);
524 // =======================================================================
527 // =======================================================================
528 void OpenGl_LineAttributes::Init (const OpenGl_Context* theGlCtx)
530 // Return if already initialized
531 if (myPatternBase != 0)
536 #if !defined(GL_ES_VERSION_2_0)
537 if (theGlCtx->core11 == NULL)
542 // GL_POLYGON_STIPPLE need 32x32 stipple patterns
543 const int nbi = sizeof(myInteriors) / (32 * sizeof(unsigned int));
544 myPatternBase = glGenLists(TEL_HS_USER_DEF_START);
545 for (int i = 1; i < TEL_HS_USER_DEF_START; i++)
547 theGlCtx->core11->glNewList ((GLuint )myPatternBase + i, GL_COMPILE);
548 theGlCtx->core11->glPolygonStipple ((const GLubyte* )myInteriors[i < nbi ? i : 0]);
549 theGlCtx->core11->glEndList();
556 // =======================================================================
557 // function : SetTypeOfHatch
559 // =======================================================================
560 int OpenGl_LineAttributes::SetTypeOfHatch (const OpenGl_Context* theGlCtx, const int theType)
562 // Return if not initialized
563 if (myPatternBase == 0)
568 const int anOldType = myTypeOfHatch;
570 #if !defined(GL_ES_VERSION_2_0)
573 theGlCtx->core11->glCallList ((GLuint )myPatternBase + (GLuint )theType);
577 theGlCtx->core11fwd->glEnable (GL_POLYGON_STIPPLE);
582 theGlCtx->core11fwd->glDisable (GL_POLYGON_STIPPLE);
587 myTypeOfHatch = theType;
592 // =======================================================================
593 // function : SetEnabled
595 // =======================================================================
596 bool OpenGl_LineAttributes::SetEnabled (const OpenGl_Context* theGlCtx,
597 const bool theToEnable)
599 // Return if not initialized
600 if (myPatternBase == 0)
605 const bool anOldIsEnabled = myIsEnabled;
607 #if !defined(GL_ES_VERSION_2_0)
610 if (myTypeOfHatch != 0)
612 theGlCtx->core11fwd->glEnable (GL_POLYGON_STIPPLE);
617 theGlCtx->core11fwd->glDisable (GL_POLYGON_STIPPLE);
622 myIsEnabled = theToEnable;
624 return anOldIsEnabled;