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 // =======================================================================
24 // function : OpenGl_LineAttributes
26 // =======================================================================
27 OpenGl_LineAttributes::OpenGl_LineAttributes()
34 // =======================================================================
35 // function : ~OpenGl_LineAttributes
37 // =======================================================================
38 OpenGl_LineAttributes::~OpenGl_LineAttributes()
43 // =======================================================================
46 // =======================================================================
47 void OpenGl_LineAttributes::Release (OpenGl_Context* theGlCtx)
49 // Delete surface patterns
50 #if !defined(GL_ES_VERSION_2_0)
51 if (theGlCtx != NULL && theGlCtx->IsValid())
53 for (OpenGl_MapOfHatchStylesAndIds::Iterator anIter (myStyles); anIter.More(); anIter.Next())
55 theGlCtx->core11->glDeleteLists ((GLuint)anIter.Value(), 1);
64 // =======================================================================
67 // =======================================================================
68 unsigned int OpenGl_LineAttributes::init (const OpenGl_Context* theGlCtx,
69 const Handle(Graphic3d_HatchStyle)& theStyle)
71 #if !defined(GL_ES_VERSION_2_0)
72 if (theGlCtx->core11 == NULL)
77 const unsigned int aListId = glGenLists(1);
78 theGlCtx->core11->glNewList ((GLuint)aListId, GL_COMPILE);
79 theGlCtx->core11->glPolygonStipple ((const GLubyte*)theStyle->Pattern());
80 theGlCtx->core11->glEndList();
89 // =======================================================================
90 // function : SetTypeOfHatch
92 // =======================================================================
93 int OpenGl_LineAttributes::SetTypeOfHatch (const OpenGl_Context* theGlCtx,
94 const Handle(Graphic3d_HatchStyle)& theStyle)
96 // Return if not initialized
97 if (theStyle.IsNull())
102 const int anOldType = myTypeOfHatch;
104 unsigned int aGpuListId = 0;
105 if (!myStyles.Find (theStyle, aGpuListId))
107 aGpuListId = init (theGlCtx, theStyle);
108 myStyles.Bind (theStyle, aGpuListId);
111 #if !defined(GL_ES_VERSION_2_0)
112 if (theStyle->HatchType() != 0)
114 theGlCtx->core11->glCallList ((GLuint)aGpuListId);
118 theGlCtx->core11fwd->glEnable (GL_POLYGON_STIPPLE);
123 theGlCtx->core11fwd->glDisable (GL_POLYGON_STIPPLE);
128 myTypeOfHatch = theStyle->HatchType();
133 // =======================================================================
134 // function : SetEnabled
136 // =======================================================================
137 bool OpenGl_LineAttributes::SetEnabled (const OpenGl_Context* theGlCtx,
138 const bool theToEnable)
140 // Return if not initialized
141 if (myStyles.IsEmpty())
146 const bool anOldIsEnabled = myIsEnabled;
148 #if !defined(GL_ES_VERSION_2_0)
151 if (myTypeOfHatch != 0)
153 theGlCtx->core11fwd->glEnable (GL_POLYGON_STIPPLE);
158 theGlCtx->core11fwd->glDisable (GL_POLYGON_STIPPLE);
163 myIsEnabled = theToEnable;
165 return anOldIsEnabled;