0032217: Visualization, TKOpenGl - drop propagation of unused FFP functions
[occt.git] / src / OpenGl / OpenGl_LineAttributes.cxx
1 // Created on: 2011-10-25
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <OpenGl_GlCore11.hxx>
17
18 #include <OpenGl_LineAttributes.hxx>
19 #include <OpenGl_Context.hxx>
20
21 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_LineAttributes,OpenGl_Resource)
22
23 // =======================================================================
24 // function : OpenGl_LineAttributes
25 // purpose  :
26 // =======================================================================
27 OpenGl_LineAttributes::OpenGl_LineAttributes()
28 {
29   //
30 }
31
32 // =======================================================================
33 // function : ~OpenGl_LineAttributes
34 // purpose  :
35 // =======================================================================
36 OpenGl_LineAttributes::~OpenGl_LineAttributes()
37 {
38   Release (NULL);
39 }
40
41 // =======================================================================
42 // function : Release
43 // purpose  :
44 // =======================================================================
45 void OpenGl_LineAttributes::Release (OpenGl_Context* theGlCtx)
46 {
47 #if !defined(GL_ES_VERSION_2_0)
48   if (theGlCtx != NULL
49    && theGlCtx->IsValid())
50   {
51     for (OpenGl_MapOfHatchStylesAndIds::Iterator anIter (myStyles); anIter.More(); anIter.Next())
52     {
53       theGlCtx->core11ffp->glDeleteLists ((GLuint)anIter.Value(), 1);
54     }
55   }
56 #else
57   (void )theGlCtx;
58 #endif
59   myStyles.Clear();
60 }
61
62 // =======================================================================
63 // function : init
64 // purpose  :
65 // =======================================================================
66 unsigned int OpenGl_LineAttributes::init (const OpenGl_Context* theGlCtx,
67                                           const Handle(Graphic3d_HatchStyle)& theStyle)
68 {
69 #if !defined(GL_ES_VERSION_2_0)
70   const unsigned int aListId = theGlCtx->core11ffp->glGenLists(1);
71   theGlCtx->core11ffp->glNewList ((GLuint)aListId, GL_COMPILE);
72   theGlCtx->core11ffp->glPolygonStipple ((const GLubyte*)theStyle->Pattern());
73   theGlCtx->core11ffp->glEndList();
74   return aListId;
75 #else
76   (void )theGlCtx;
77   (void )theStyle;
78   return 0;
79 #endif
80 }
81
82 // =======================================================================
83 // function : SetTypeOfHatch
84 // purpose  :
85 // =======================================================================
86 bool OpenGl_LineAttributes::SetTypeOfHatch (const OpenGl_Context*               theGlCtx,
87                                             const Handle(Graphic3d_HatchStyle)& theStyle)
88 {
89   if (theStyle.IsNull()
90    || theStyle->HatchType() == Aspect_HS_SOLID
91    || theGlCtx->core11ffp == NULL)
92   {
93     return false;
94   }
95
96   unsigned int aGpuListId = 0;
97   if (!myStyles.Find (theStyle, aGpuListId))
98   {
99     aGpuListId = init (theGlCtx, theStyle);
100     myStyles.Bind (theStyle, aGpuListId);
101   }
102
103 #if !defined(GL_ES_VERSION_2_0)
104   theGlCtx->core11ffp->glCallList ((GLuint)aGpuListId);
105 #endif
106   return true;
107 }