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