1 // Created on: 2011-09-20
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 #ifndef _OpenGl_LineAttributes_Header
17 #define _OpenGl_LineAttributes_Header
19 #include <OpenGl_Resource.hxx>
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>
27 typedef NCollection_DataMap<Handle(Graphic3d_HatchStyle), unsigned int> OpenGl_MapOfHatchStylesAndIds;
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
47 //! Default constructor.
48 //! By default the parameters are:
49 //! - IsEnabled (true),
50 //! - TypeOfHatch (0).
51 OpenGl_LineAttributes();
53 //! Default destructor.
54 virtual ~OpenGl_LineAttributes();
56 //! Release GL resources.
57 virtual void Release (OpenGl_Context* theGlCtx) Standard_OVERRIDE;
59 //! Returns estimated GPU memory usage - not implemented.
60 virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE { return 0; }
62 //! Index of currently selected type of hatch.
63 int TypeOfHatch() const { return myTypeOfHatch; }
65 //! Sets type of the hatch.
66 int SetTypeOfHatch (const OpenGl_Context* theGlCtx,
67 const Handle(Graphic3d_HatchStyle)& theStyle);
69 //! Current enabled state of the hatching rasterization.
70 bool IsEnabled() const { return myIsEnabled; }
72 //! Turns on/off the hatching rasterization rasterization.
73 bool SetEnabled (const OpenGl_Context* theGlCtx, const bool theToEnable);
77 unsigned int init (const OpenGl_Context* theGlCtx,
78 const Handle(Graphic3d_HatchStyle)& theStyle);
82 int myTypeOfHatch; //!< Currently activated type of hatch
83 bool myIsEnabled; //!< Current enabled state of hatching rasterization.
84 OpenGl_MapOfHatchStylesAndIds myStyles; //!< Hatch patterns
88 DEFINE_STANDARD_RTTIEXT(OpenGl_LineAttributes,OpenGl_Resource)
91 DEFINE_STANDARD_HANDLE(OpenGl_LineAttributes, OpenGl_Resource)
93 #endif // _OpenGl_LineAttributes_Header