0028824: Possibility to build OCCT 7.1.0 and above using Visual Studio 2008
[occt.git] / src / OpenGl / OpenGl_LineAttributes.cxx
CommitLineData
b311480e 1// Created on: 2011-10-25
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
2166f0fa 15
5f8b738e 16#include <OpenGl_GlCore11.hxx>
17
73192b37 18#include <OpenGl_LineAttributes.hxx>
19#include <OpenGl_Context.hxx>
2166f0fa 20
92efcf78 21IMPLEMENT_STANDARD_RTTIEXT(OpenGl_LineAttributes,OpenGl_Resource)
22
73192b37 23// =======================================================================
24// function : OpenGl_LineAttributes
25// purpose :
26// =======================================================================
27OpenGl_LineAttributes::OpenGl_LineAttributes()
640d5fe2 28: myTypeOfHatch (0),
6d0e6be5 29 myIsEnabled (true)
2166f0fa 30{
73192b37 31 //
32}
33
34// =======================================================================
35// function : ~OpenGl_LineAttributes
36// purpose :
37// =======================================================================
38OpenGl_LineAttributes::~OpenGl_LineAttributes()
39{
40 Release (NULL);
41}
42
43// =======================================================================
44// function : Release
45// purpose :
46// =======================================================================
10b9c7df 47void OpenGl_LineAttributes::Release (OpenGl_Context* theGlCtx)
73192b37 48{
73192b37 49 // Delete surface patterns
6d0e6be5 50#if !defined(GL_ES_VERSION_2_0)
640d5fe2 51 if (theGlCtx != NULL && theGlCtx->IsValid())
52 {
53 for (OpenGl_MapOfHatchStylesAndIds::Iterator anIter (myStyles); anIter.More(); anIter.Next())
73192b37 54 {
640d5fe2 55 theGlCtx->core11->glDeleteLists ((GLuint)anIter.Value(), 1);
73192b37 56 }
640d5fe2 57 }
6d0e6be5 58#else
59 (void )theGlCtx;
60#endif
640d5fe2 61 myStyles.Clear();
73192b37 62}
2166f0fa 63
73192b37 64// =======================================================================
640d5fe2 65// function : init
73192b37 66// purpose :
67// =======================================================================
640d5fe2 68unsigned int OpenGl_LineAttributes::init (const OpenGl_Context* theGlCtx,
69 const Handle(Graphic3d_HatchStyle)& theStyle)
73192b37 70{
ca3c13d1 71#if !defined(GL_ES_VERSION_2_0)
4e1523ef 72 if (theGlCtx->core11 == NULL)
73 {
640d5fe2 74 return 0;
4e1523ef 75 }
76
640d5fe2 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();
81 return aListId;
20aeeb7b 82#else
83 (void )theGlCtx;
640d5fe2 84 (void )theStyle;
85 return 0;
ca3c13d1 86#endif
2166f0fa
SK
87}
88
73192b37 89// =======================================================================
90// function : SetTypeOfHatch
91// purpose :
92// =======================================================================
640d5fe2 93int OpenGl_LineAttributes::SetTypeOfHatch (const OpenGl_Context* theGlCtx,
94 const Handle(Graphic3d_HatchStyle)& theStyle)
2166f0fa 95{
6d0e6be5 96 // Return if not initialized
640d5fe2 97 if (theStyle.IsNull())
79f4f036 98 {
6d0e6be5 99 return 0;
79f4f036 100 }
101
6d0e6be5 102 const int anOldType = myTypeOfHatch;
103
640d5fe2 104 unsigned int aGpuListId = 0;
105 if (!myStyles.Find (theStyle, aGpuListId))
106 {
107 aGpuListId = init (theGlCtx, theStyle);
108 myStyles.Bind (theStyle, aGpuListId);
109 }
110
6d0e6be5 111#if !defined(GL_ES_VERSION_2_0)
640d5fe2 112 if (theStyle->HatchType() != 0)
2166f0fa 113 {
640d5fe2 114 theGlCtx->core11->glCallList ((GLuint)aGpuListId);
6d0e6be5 115
116 if (myIsEnabled)
117 {
118 theGlCtx->core11fwd->glEnable (GL_POLYGON_STIPPLE);
119 }
120 }
121 else
122 {
123 theGlCtx->core11fwd->glDisable (GL_POLYGON_STIPPLE);
124 }
125#else
126 (void )theGlCtx;
127#endif
640d5fe2 128 myTypeOfHatch = theStyle->HatchType();
6d0e6be5 129
130 return anOldType;
131}
132
133// =======================================================================
134// function : SetEnabled
135// purpose :
136// =======================================================================
137bool OpenGl_LineAttributes::SetEnabled (const OpenGl_Context* theGlCtx,
138 const bool theToEnable)
139{
140 // Return if not initialized
640d5fe2 141 if (myStyles.IsEmpty())
6d0e6be5 142 {
143 return false;
144 }
145
146 const bool anOldIsEnabled = myIsEnabled;
147
148#if !defined(GL_ES_VERSION_2_0)
149 if (theToEnable)
150 {
151 if (myTypeOfHatch != 0)
152 {
153 theGlCtx->core11fwd->glEnable (GL_POLYGON_STIPPLE);
154 }
2166f0fa
SK
155 }
156 else
6d0e6be5 157 {
158 theGlCtx->core11fwd->glDisable (GL_POLYGON_STIPPLE);
159 }
20aeeb7b 160#else
6d0e6be5 161 (void )theGlCtx;
ca3c13d1 162#endif
6d0e6be5 163 myIsEnabled = theToEnable;
164
165 return anOldIsEnabled;
2166f0fa 166}