0025040: Visualization - capping plane is drawn at wrong position when created by...
[occt.git] / src / OpenGl / OpenGl_View.hxx
CommitLineData
b311480e 1// Created on: 2011-09-20
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
2166f0fa
SK
16#ifndef _OpenGl_View_Header
17#define _OpenGl_View_Header
18
19#include <MMgt_TShared.hxx>
20#include <Standard_DefineHandle.hxx>
21
22#include <TColStd_Array2OfReal.hxx>
23#include <NCollection_List.hxx>
24
25#include <Quantity_NameOfColor.hxx>
26#include <Aspect_FillMethod.hxx>
27#include <Aspect_GradientFillMethod.hxx>
28#include <Aspect_TypeOfTriedronPosition.hxx>
29#include <Aspect_CLayer2d.hxx>
30
31#include <InterfaceGraphic_Graphic3d.hxx>
32#include <InterfaceGraphic_Visual3d.hxx>
33
34#include <Graphic3d_CView.hxx>
35#include <Graphic3d_CGraduatedTrihedron.hxx>
51b10cd4 36#include <Graphic3d_SequenceOfHClipPlane.hxx>
c5751993 37#include <Graphic3d_ZLayerSettings.hxx>
2166f0fa
SK
38#include <Visual3d_TypeOfSurfaceDetail.hxx>
39
b7cd4ba7 40#include <OpenGl_BVHTreeSelector.hxx>
59f45b7c 41#include <OpenGl_LayerList.hxx>
2166f0fa 42#include <OpenGl_Light.hxx>
73192b37 43#include <OpenGl_LineAttributes.hxx>
2166f0fa 44
bf75be98 45#include <Handle_OpenGl_Context.hxx>
392ac980 46#include <Handle_OpenGl_GraphicDriver.hxx>
2166f0fa
SK
47#include <Handle_OpenGl_Workspace.hxx>
48#include <Handle_OpenGl_View.hxx>
bf75be98 49#include <Handle_OpenGl_Texture.hxx>
2166f0fa
SK
50
51struct OPENGL_BG_TEXTURE
52{
53 Tuint TexId;
54 Tint Width;
55 Tint Height;
56 Aspect_FillMethod Style;
57};
58
59struct OPENGL_BG_GRADIENT
60{
61 TEL_COLOUR color1;
62 TEL_COLOUR color2;
63 Aspect_GradientFillMethod type;
64};
65
2166f0fa
SK
66struct OPENGL_ZCLIP
67{
68 struct {
69 Standard_Boolean IsOn;
70 Standard_ShortReal Limit; /* in the range [0., 1.] */
71 } Back;
72 struct {
73 Standard_Boolean IsOn;
74 Standard_ShortReal Limit; /* in the range [0., 1.] */
75 } Front;
76};
77
78struct OPENGL_FOG
79{
80 Standard_Boolean IsOn;
81 Standard_ShortReal Front; /* in the range [0., 1.] */
82 Standard_ShortReal Back; /* in the range [0., 1.] */
83 TEL_COLOUR Color;
84};
85
b5ac8292 86struct OpenGl_Matrix;
a174a3c5 87class OpenGl_GraduatedTrihedron;
2166f0fa 88class OpenGl_Structure;
a174a3c5 89class OpenGl_Trihedron;
90class Handle(OpenGl_PrinterContext);
392ac980 91class OpenGl_StateCounter;
2166f0fa
SK
92
93class OpenGl_View : public MMgt_TShared
94{
95 public:
392ac980 96 OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext, OpenGl_StateCounter* theCounter);
2166f0fa
SK
97 virtual ~OpenGl_View ();
98
bf75be98 99 void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx);
100
101 void SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
102 const Handle(Graphic3d_TextureEnv)& theTexture);
e276548b 103 void SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail AMode);
2166f0fa
SK
104 void SetBackfacing (const Standard_Integer AMode);
105 void SetLights (const CALL_DEF_VIEWCONTEXT &AContext);
106 void SetAntiAliasing (const Standard_Boolean AMode) { myAntiAliasing = AMode; }
51b10cd4 107 void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane &thePlanes) { myClipPlanes = thePlanes; }
2166f0fa
SK
108 void SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext);
109
b5ac8292 110 void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; }
111
bf75be98 112 void SetClipLimit (const Graphic3d_CView& theCView);
2166f0fa 113
bf75be98 114 void SetFog (const Graphic3d_CView& theCView, const Standard_Boolean theFlag);
2166f0fa 115
a174a3c5 116 void TriedronDisplay (const Handle(OpenGl_Context)& theCtx,
117 const Aspect_TypeOfTriedronPosition thePosition,
118 const Quantity_NameOfColor theColor,
119 const Standard_Real theScale,
120 const Standard_Boolean theAsWireframe);
121 void TriedronErase (const Handle(OpenGl_Context)& theCtx);
2166f0fa 122
a174a3c5 123 void GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx,
124 const Graphic3d_CGraduatedTrihedron& theCubic);
125 void GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx);
2166f0fa 126
b5ac8292 127 Standard_Real Height () const { return myCamera->ViewDimensions().X(); }
128 Standard_Real Width () const { return myCamera->ViewDimensions().Y(); }
2166f0fa
SK
129
130 Standard_Integer Backfacing () const { return myBackfacing; }
131
30f0ad28 132 const TEL_TRANSFORM_PERSISTENCE * BeginTransformPersistence (const Handle(OpenGl_Context)& theCtx,
133 const TEL_TRANSFORM_PERSISTENCE *theTransPers);
134 void EndTransformPersistence (const Handle(OpenGl_Context)& theCtx);
2166f0fa 135
59f45b7c 136 //! Add structure to display list with specified priority.
137 //! The structure will be added to associated with it z layer.
138 //! If the z layer is not presented in the view, the structure will
139 //! be displayed in default bottom-level z layer.
679ecdee 140 void DisplayStructure (const OpenGl_Structure* theStructure,
59f45b7c 141 const Standard_Integer thePriority);
142
143 //! Erase structure from display list.
679ecdee 144 void EraseStructure (const OpenGl_Structure* theStructure);
145
146 //! Add structure to the list of immediate structures.
147 void DisplayImmediateStructure (const OpenGl_Structure* theStructure);
148
149 //! Erase structure from display list.
150 void EraseImmediateStructure (const OpenGl_Structure* theStructure);
59f45b7c 151
152 //! Insert a new top-level z layer with ID <theLayerId>
153 void AddZLayer (const Standard_Integer theLayerId);
154
155 //! Remove a z layer with ID <theLayerId>
156 void RemoveZLayer (const Standard_Integer theLayerId);
157
158 //! Display structure in z layer with ID <theNewLayerId>
159 //! If the layer with ID <theNewLayerId> is not presented in the view,
160 //! the structure will be displayed in default bottom-level layer.
161 void ChangeZLayer (const OpenGl_Structure *theStructure,
162 const Standard_Integer theNewLayerId);
2166f0fa 163
c5751993 164 //! Sets the settings for a single Z layer of specified view.
165 void SetZLayerSettings (const Standard_Integer theLayerId,
166 const Graphic3d_ZLayerSettings theSettings);
167
b7cd4ba7 168 //! Changes the priority of a structure within its ZLayer
169 void ChangePriority (const OpenGl_Structure *theStructure,
170 const Standard_Integer theNewPriority);
171
2166f0fa
SK
172 void CreateBackgroundTexture (const Standard_CString AFileName, const Aspect_FillMethod AFillStyle);
173 void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle);
174 void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType);
175 void SetBackgroundGradientType (const Aspect_GradientFillMethod AType);
176
a174a3c5 177 void Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
178 const Handle(OpenGl_Workspace)& theWorkspace,
179 const Graphic3d_CView& theCView,
180 const Aspect_CLayer2d& theCUnderLayer,
181 const Aspect_CLayer2d& theCOverLayer);
2166f0fa 182
e276548b 183
fc73a202 184 void DrawBackground (OpenGl_Workspace& theWorkspace);
e276548b 185
186 //! Returns list of OpenGL Z-layers.
187 const OpenGl_LayerList& LayerList() const { return myZLayers; }
188
189 //! Returns list of openGL light sources.
190 const OpenGl_ListOfLight& LightList() const { return myLights; }
191
192 //! Returns OpenGL environment map.
193 const Handle(OpenGl_Texture)& TextureEnv() const { return myTextureEnv; }
194
195 //! Returns visualization mode for objects in the view.
196 Visual3d_TypeOfSurfaceDetail SurfaceDetail() const { return mySurfaceDetail; }
197
b7cd4ba7 198 //! Returns selector for BVH tree, providing a possibility to store information
199 //! about current view volume and to detect which objects are overlapping it.
200 OpenGl_BVHTreeSelector& BVHTreeSelector() { return myBVHSelector; }
201
202 //! Marks BVH tree for given priority list as dirty and
203 //! marks primitive set for rebuild.
204 void InvalidateBVHData (const Standard_Integer theLayerId);
205
b5ac8292 206 void GetMatrices (TColStd_Array2OfReal& theMatOrient,
207 TColStd_Array2OfReal& theMatMapping) const;
208
679ecdee 209 //! Returns list of immediate structures rendered on top of main presentation
210 const OpenGl_SequenceOfStructure& ImmediateStructures() const
211 {
212 return myImmediateList;
213 }
214
e276548b 215 //! Returns modification state for ray-tracing.
216 Standard_Size ModificationState() const { return myModificationState; }
e276548b 217
679ecdee 218protected:
2166f0fa
SK
219
220 void RenderStructs (const Handle(OpenGl_Workspace) &AWorkspace);
a174a3c5 221 void RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext,
a174a3c5 222 const Graphic3d_CView& theCView,
223 const Aspect_CLayer2d& theCLayer);
2166f0fa 224
b5ac8292 225 //! Redraw contents of model scene: clipping planes,
226 //! lights, structures. The peculiar properties of "scene" is that
227 //! it requires empty Z-Buffer and uses projection and orientation
228 //! matrices supplied by 3d view.
229 //! @param thePrintCtx [in] printer context which facilitates tiled printing.
230 //! @param theWorkspace [in] rendering workspace.
231 //! @param theCView [in] view data.
232 //! @param theProjection [in] view projection matrix.
233 //! @param theOrientation [in] view orientation matrix.
234 void RedrawScene (const Handle(OpenGl_PrinterContext)& thePrintContext,
235 const Handle(OpenGl_Workspace)& theWorkspace,
236 const OpenGl_Matrix* theProjection,
237 const OpenGl_Matrix* theOrientation);
238
73192b37 239 Handle(OpenGl_LineAttributes) myLineAttribs;
240 Handle(OpenGl_Texture) myTextureEnv;
241 Visual3d_TypeOfSurfaceDetail mySurfaceDetail;
242 Standard_Integer myBackfacing;
2166f0fa 243
73192b37 244 OPENGL_BG_TEXTURE myBgTexture;
245 OPENGL_BG_GRADIENT myBgGradient;
2166f0fa 246
2166f0fa 247 OPENGL_ZCLIP myZClip;
2166f0fa 248
51b10cd4 249 Graphic3d_SequenceOfHClipPlane myClipPlanes;
4269bd1b 250
b5ac8292 251 Handle(Graphic3d_Camera) myCamera;
252
2166f0fa 253 OPENGL_FOG myFog;
a174a3c5 254 OpenGl_Trihedron* myTrihedron;
255 OpenGl_GraduatedTrihedron* myGraduatedTrihedron;
2166f0fa
SK
256
257 //View_LABViewContext
258 int myVisualization;
259 int myIntShadingMethod;
260
261 //View_LABLight
262 OpenGl_ListOfLight myLights;
263
264 //View_LABPlane
265 //View_LABAliasing
266 Standard_Boolean myAntiAliasing;
267
268 //View_LABDepthCueing - fixed index used
269
679ecdee 270 OpenGl_LayerList myZLayers; //!< main list of displayed structure, sorted by layers
271 OpenGl_SequenceOfStructure myImmediateList; //!< list of immediate structures rendered on top of main presentation
2166f0fa 272
2166f0fa
SK
273 const TEL_TRANSFORM_PERSISTENCE *myTransPers;
274 Standard_Boolean myIsTransPers;
275
b5ac8292 276 //! Modification state
277 Standard_Size myProjectionState;
278 Standard_Size myModelViewState;
392ac980 279 OpenGl_StateCounter* myStateCounter;
280
392ac980 281 Standard_Size myCurrLightSourceState;
282
283 typedef std::pair<Standard_Size, Standard_Size> StateInfo;
284
285 StateInfo myLastOrientationState;
286 StateInfo myLastViewMappingState;
287 StateInfo myLastLightSourceState;
30f0ad28 288
b7cd4ba7 289 //! Is needed for selection of overlapping objects and storage of the current view volume
290 OpenGl_BVHTreeSelector myBVHSelector;
291
e276548b 292 Standard_Size myModificationState;
e276548b 293
679ecdee 294public:
295
1c35b92f 296 DEFINE_STANDARD_ALLOC
679ecdee 297 DEFINE_STANDARD_RTTI(OpenGl_View) // Type definition
298
2166f0fa
SK
299};
300
679ecdee 301#endif // _OpenGl_View_Header