0029353: Optimization of TPrsStd_AISPresentation::SetSelectionMode()
[occt.git] / src / OpenGl / OpenGl_LineAttributes.hxx
CommitLineData
73192b37 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>
640d5fe2 24#include <Graphic3d_HatchStyle.hxx>
25#include <NCollection_DataMap.hxx>
73192b37 26
640d5fe2 27typedef NCollection_DataMap<Handle(Graphic3d_HatchStyle), unsigned int> OpenGl_MapOfHatchStylesAndIds;
73192b37 28
640d5fe2 29class OpenGl_Context;
b6472664 30
6d0e6be5 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.
73192b37 43class OpenGl_LineAttributes : public OpenGl_Resource
44{
45public:
46
6d0e6be5 47 //! Default constructor.
48 //! By default the parameters are:
49 //! - IsEnabled (true),
50 //! - TypeOfHatch (0).
73192b37 51 OpenGl_LineAttributes();
6d0e6be5 52
53 //! Default destructor.
73192b37 54 virtual ~OpenGl_LineAttributes();
55
6d0e6be5 56 //! Release GL resources.
79104795 57 virtual void Release (OpenGl_Context* theGlCtx) Standard_OVERRIDE;
73192b37 58
6d0e6be5 59 //! Index of currently selected type of hatch.
60 int TypeOfHatch() const { return myTypeOfHatch; }
61
62 //! Sets type of the hatch.
640d5fe2 63 int SetTypeOfHatch (const OpenGl_Context* theGlCtx,
64 const Handle(Graphic3d_HatchStyle)& theStyle);
6d0e6be5 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);
73192b37 71
72protected:
73
640d5fe2 74 unsigned int init (const OpenGl_Context* theGlCtx,
75 const Handle(Graphic3d_HatchStyle)& theStyle);
76
77protected:
78
6d0e6be5 79 int myTypeOfHatch; //!< Currently activated type of hatch
80 bool myIsEnabled; //!< Current enabled state of hatching rasterization.
640d5fe2 81 OpenGl_MapOfHatchStylesAndIds myStyles; //!< Hatch patterns
73192b37 82
83public:
84
92efcf78 85 DEFINE_STANDARD_RTTIEXT(OpenGl_LineAttributes,OpenGl_Resource)
73192b37 86};
87
88DEFINE_STANDARD_HANDLE(OpenGl_LineAttributes, OpenGl_Resource)
89
90#endif // _OpenGl_LineAttributes_Header