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