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