0024252: GCC warnings on breakage of strict-aliasing rules
[occt.git] / src / OpenGl / OpenGl_Clipping.hxx
CommitLineData
4269bd1b 1// Created on: 2013-09-05
2// Created by: Anton POLETAEV
3// Copyright (c) 2013 OPEN CASCADE SAS
4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
4269bd1b 6//
973c2be1 7// This library is free software; you can redistribute it and / or modify it
8// under the terms of the GNU Lesser General Public 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.
4269bd1b 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
4269bd1b 15
30f0ad28 16#ifndef _OpenGl_Clipping_H__
17#define _OpenGl_Clipping_H__
4269bd1b 18
19#include <Aspect_GenId.hxx>
20#include <Graphic3d_ClipPlane.hxx>
51b10cd4 21#include <Graphic3d_SequenceOfHClipPlane.hxx>
4269bd1b 22#include <NCollection_DataMap.hxx>
23#include <NCollection_Handle.hxx>
24#include <Standard_TypeDef.hxx>
25#include <OpenGl_Matrix.hxx>
b859a34d 26#include <Handle_OpenGl_Workspace.hxx>
4269bd1b 27
28//! This class contains logics related to tracking and modification of clipping plane
29//! state for particular OpenGl context. It contains information about enabled
30//! clipping planes and provides method to change clippings in context. The methods
31//! should be executed within OpenGl context associated with instance of this
32//! class.
30f0ad28 33class OpenGl_Clipping
4269bd1b 34{
35public:
36
b859a34d 37 //! Enumerates supported equation coordinate spaces.
38 enum EquationCoords
39 {
40 EquationCoords_View,
41 EquationCoords_World
42 };
43
44public: //! @name general methods
45
4269bd1b 46 //! Default constructor.
30f0ad28 47 Standard_EXPORT OpenGl_Clipping();
4269bd1b 48
49 //! Initialize.
50 //! @param theMaxPlanes [in] number of clipping planes supported by OpenGl context.
51 Standard_EXPORT void Init (const Standard_Integer theMaxPlanes);
52
b859a34d 53public: //! @name non-modifying getters
4269bd1b 54
b859a34d 55 //! Check whether the clipping plane has been added to the current context state.
4269bd1b 56 //! @param thePlane [in] the plane to check.
57 //! @return True if plane is set.
b859a34d 58 inline Standard_Boolean Contains (const Handle(Graphic3d_ClipPlane)& thePlane) const
59 {
60 return myPlaneStates.IsBound (thePlane);
61 }
62
63 //! Get clip planes defined for context.
64 //! @return sequence of set clipping planes.
51b10cd4 65 inline const Graphic3d_SequenceOfHClipPlane& Planes() const
b859a34d 66 {
67 return myPlanes;
68 }
69
70 //! @return kind of equation coordinate space used for the clip plane.
71 inline EquationCoords GetEquationSpace (const Handle(Graphic3d_ClipPlane)& thePlane) const
72 {
73 return myPlaneStates.Find (thePlane).CoordSpace;
74 }
4269bd1b 75
76 //! Check whether the clipping plane has been set and enabled for the current context state.
77 //! @param thePlane [in] the plane to check.
78 //! @return True if plane is enabled.
b859a34d 79 inline Standard_Boolean IsEnabled (const Handle(Graphic3d_ClipPlane)& thePlane) const
80 {
81 return myPlaneStates.Find (thePlane).IsEnabled;
82 }
83
84public: //! @name clipping state modification commands
85
86 //! Add planes to the context clipping at the specified system of coordinates.
87 //! This methods loads appropriate transformation matrix from workspace to
88 //! to transform equation coordinates. The planes become enabled in the context.
89 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
90 //! are simply ignored.
91 //! @param thePlanes [in/out] the list of planes to be added.
92 //! The list then provides information on which planes were really added to clipping state.
93 //! This list then can be used to fall back to previous state.
94 //! @param theCoordSpace [in] the equation definition space.
95 //! @param theWS [in] the workspace to access the matrices.
51b10cd4 96 Standard_EXPORT void Add (Graphic3d_SequenceOfHClipPlane& thePlanes,
b859a34d 97 const EquationCoords& theCoordSpace,
98 const Handle(OpenGl_Workspace)& theWS);
99
100 //! Add planes to the context clipping at the specified system of coordinates.
101 //! This method assumes that appropriate matrix is already set in context state.
102 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
103 //! are simply ignored.
104 //! @param thePlanes [in/out] the list of planes to be added.
105 //! The list then provides information on which planes were really added to clipping state.
106 //! This list then can be used to fall back to previous state.
107 //! @param theCoordSpace [in] the equation definition space.
51b10cd4 108 Standard_EXPORT void Add (Graphic3d_SequenceOfHClipPlane& thePlanes,
b859a34d 109 const EquationCoords& theCoordSpace);
110
111 //! Remove the passed set of clipping planes from the context state.
112 //! @param thePlanes [in] the planes to remove from list.
51b10cd4 113 Standard_EXPORT void Remove (const Graphic3d_SequenceOfHClipPlane& thePlanes);
b859a34d 114
115 //! Enable or disable clipping plane in the OpenGl context.
116 //! @param thePlane [in] the plane to affect.
117 //! @param theIsEnabled [in] the state of the plane.
118 Standard_EXPORT void SetEnabled (const Handle(Graphic3d_ClipPlane)& thePlane,
119 const Standard_Boolean theIsEnabled);
120
121public: //! @name Short-cuts
122
123 //! Add planes to the context clipping at the view system of coordinates.
124 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
125 //! are simply ignored.
126 //! @param thePlanes [in/out] the list of planes to be added.
127 //! The list then provides information on which planes were really added to clipping state.
128 //! This list then can be used to fall back to previous state.
129 //! @param theWS [in] the workspace to access the matrices.
51b10cd4 130 inline void AddView (Graphic3d_SequenceOfHClipPlane& thePlanes, const Handle(OpenGl_Workspace)& theWS)
b859a34d 131 {
132 Add (thePlanes, EquationCoords_View, theWS);
133 }
134
135 //! Add planes to the context clipping at the view system of coordinates.
136 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
137 //! are simply ignored.
138 //! @param thePlanes [in/out] the list of planes to be added.
139 //! The list then provides information on which planes were really added to clipping state.
140 //! This list then can be used to fall back to previous state.
51b10cd4 141 inline void AddView (Graphic3d_SequenceOfHClipPlane& thePlanes)
b859a34d 142 {
143 Add (thePlanes, EquationCoords_View);
144 }
145
146 //! Add planes to the context clipping at the world system of coordinates.
147 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
148 //! are simply ignored.
149 //! @param thePlanes [in/out] the list of planes to be added.
150 //! The list then provides information on which planes were really added to clipping state.
151 //! This list then can be used to fall back to previous state.
152 //! @param theWS [in] the workspace to access the matrices.
51b10cd4 153 inline void AddWorld (Graphic3d_SequenceOfHClipPlane& thePlanes, const Handle(OpenGl_Workspace)& theWS)
b859a34d 154 {
155 Add (thePlanes, EquationCoords_World, theWS);
156 }
157
158 //! Add planes to the context clipping at the world system of coordinates.
159 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
160 //! are simply ignored.
161 //! @param thePlanes [in/out] the list of planes to be added.
162 //! The list then provides information on which planes were really added to clipping state.
163 //! This list then can be used to fall back to previous state.
51b10cd4 164 inline void AddWorld (Graphic3d_SequenceOfHClipPlane& thePlanes)
b859a34d 165 {
166 Add (thePlanes, EquationCoords_World);
167 }
168
169 //! Remove all of the planes from context state.
170 inline void RemoveAll()
171 {
172 Remove (Planes());
173 }
174
175private:
4269bd1b 176
b859a34d 177 struct PlaneProps
178 {
179 // declare default constructor
180 // to allow compilation of template collections
181 PlaneProps() {}
182 PlaneProps (const EquationCoords theCoords,
183 const Standard_Integer theID,
184 const Standard_Boolean theIsEnabled)
185 {
186 CoordSpace = theCoords;
187 ContextID = theID;
188 IsEnabled = theIsEnabled;
189 }
190
191 EquationCoords CoordSpace;
192 Standard_Integer ContextID;
193 Standard_Boolean IsEnabled;
194 };
4269bd1b 195
196private:
197
b859a34d 198 typedef NCollection_DataMap<Handle(Graphic3d_ClipPlane), PlaneProps> OpenGl_MapOfPlaneStates;
4269bd1b 199 typedef NCollection_Handle<Aspect_GenId> OpenGl_EmptyPlaneIds;
200
51b10cd4 201 Graphic3d_SequenceOfHClipPlane myPlanes; //!< defined clipping planes.
202 OpenGl_MapOfPlaneStates myPlaneStates; //!< map of clip planes bound for the props.
203 OpenGl_EmptyPlaneIds myEmptyPlaneIds; //!< generator of empty ids.
4269bd1b 204
205private:
206
207 //! Copying allowed only within Handles
30f0ad28 208 OpenGl_Clipping (const OpenGl_Clipping& );
209 OpenGl_Clipping& operator= (const OpenGl_Clipping& );
4269bd1b 210};
211
212#endif