Warnings on vc14 were eliminated
[occt.git] / src / OpenGl / OpenGl_LineAttributes.hxx
1 // Created on: 2011-09-20
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 #ifndef _OpenGl_LineAttributes_Header
17 #define _OpenGl_LineAttributes_Header
18
19 #include <OpenGl_Resource.hxx>
20
21 #include <Aspect_TypeOfLine.hxx>
22 #include <Aspect_TypeOfMarker.hxx>
23 #include <Font_FontAspect.hxx>
24 #include <Graphic3d_HatchStyle.hxx>
25 #include <NCollection_DataMap.hxx>
26
27 typedef NCollection_DataMap<Handle(Graphic3d_HatchStyle), unsigned int> OpenGl_MapOfHatchStylesAndIds;
28
29 class OpenGl_Context;
30
31 //! Utility class to manage OpenGL state of polygon hatching rasterization
32 //! and keeping its cached state. The hatching rasterization is implemented
33 //! using glPolygonStipple function of OpenGL. State of hatching is controlled
34 //! by two parameters - type of hatching and IsEnabled parameter.
35 //! The hatching rasterization is enabled only if non-zero index pattern type
36 //! is selected (zero by default is reserved for solid filling) and if
37 //! IsEnabled flag is set to true. The IsEnabled parameter is useful for temporarily
38 //! turning on/off the hatching rasterization without making any costly GL calls
39 //! for changing the hatch pattern. This is a sharable resource class - it creates
40 //! OpenGL context objects for each hatch pattern to achieve quicker switching between
41 //! them, thesse GL objects are freed when the resource is released by owner context.
42 //! @note The implementation is not supported by Core Profile and by ES version.
43 class OpenGl_LineAttributes : public OpenGl_Resource
44 {
45 public:
46
47   //! Default constructor.
48   //! By default the parameters are:
49   //! - IsEnabled (true),
50   //! - TypeOfHatch (0).
51   OpenGl_LineAttributes();
52
53   //! Default destructor.
54   virtual ~OpenGl_LineAttributes();
55
56   //! Release GL resources.
57   virtual void Release (OpenGl_Context* theGlCtx) Standard_OVERRIDE;
58
59   //! Index of currently selected type of hatch.
60   int TypeOfHatch() const { return myTypeOfHatch; }
61
62   //! Sets type of the hatch.
63   int SetTypeOfHatch (const OpenGl_Context*               theGlCtx,
64                       const Handle(Graphic3d_HatchStyle)& theStyle);
65
66   //! Current enabled state of the hatching rasterization.
67   bool IsEnabled() const { return myIsEnabled; }
68
69   //! Turns on/off the hatching rasterization rasterization.
70   bool SetEnabled (const OpenGl_Context* theGlCtx, const bool theToEnable);
71
72 protected:
73
74   unsigned int init (const OpenGl_Context* theGlCtx,
75                      const Handle(Graphic3d_HatchStyle)& theStyle);
76
77 protected:
78
79   int myTypeOfHatch; //!< Currently activated type of hatch
80   bool myIsEnabled; //!< Current enabled state of hatching rasterization.
81   OpenGl_MapOfHatchStylesAndIds myStyles; //!< Hatch patterns
82
83 public:
84
85   DEFINE_STANDARD_RTTIEXT(OpenGl_LineAttributes,OpenGl_Resource)
86 };
87
88 DEFINE_STANDARD_HANDLE(OpenGl_LineAttributes, OpenGl_Resource)
89
90 #endif // _OpenGl_LineAttributes_Header