1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _OpenGl_View_Header
17 #define _OpenGl_View_Header
19 #include <MMgt_TShared.hxx>
20 #include <Standard_DefineHandle.hxx>
22 #include <TColStd_Array2OfReal.hxx>
23 #include <NCollection_List.hxx>
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>
31 #include <InterfaceGraphic_Graphic3d.hxx>
32 #include <InterfaceGraphic_Visual3d.hxx>
34 #include <Graphic3d_CView.hxx>
35 #include <Graphic3d_CGraduatedTrihedron.hxx>
36 #include <Graphic3d_SequenceOfHClipPlane.hxx>
37 #include <Graphic3d_ZLayerSettings.hxx>
38 #include <Visual3d_TypeOfSurfaceDetail.hxx>
39 #include <Visual3d_TypeOfModel.hxx>
41 #include <OpenGl_BVHTreeSelector.hxx>
42 #include <OpenGl_LayerList.hxx>
43 #include <OpenGl_Light.hxx>
44 #include <OpenGl_LineAttributes.hxx>
46 #include <Handle_OpenGl_Context.hxx>
47 #include <Handle_OpenGl_GraphicDriver.hxx>
48 #include <Handle_OpenGl_Workspace.hxx>
49 #include <Handle_OpenGl_View.hxx>
50 #include <Handle_OpenGl_Texture.hxx>
52 struct OPENGL_BG_TEXTURE
57 Aspect_FillMethod Style;
60 struct OPENGL_BG_GRADIENT
64 Aspect_GradientFillMethod type;
70 Standard_Boolean IsOn;
71 Standard_ShortReal Limit; /* in the range [0., 1.] */
74 Standard_Boolean IsOn;
75 Standard_ShortReal Limit; /* in the range [0., 1.] */
81 Standard_Boolean IsOn;
82 Standard_ShortReal Front; /* in the range [0., 1.] */
83 Standard_ShortReal Back; /* in the range [0., 1.] */
88 class OpenGl_GraduatedTrihedron;
89 class OpenGl_Structure;
90 class OpenGl_Trihedron;
91 class Handle(OpenGl_PrinterContext);
92 class OpenGl_StateCounter;
94 class OpenGl_View : public MMgt_TShared
97 OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext, OpenGl_StateCounter* theCounter);
98 virtual ~OpenGl_View ();
100 void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx);
102 void SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
103 const Handle(Graphic3d_TextureEnv)& theTexture);
104 void SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail AMode);
105 void SetBackfacing (const Standard_Integer AMode);
106 void SetLights (const CALL_DEF_VIEWCONTEXT &AContext);
107 void SetAntiAliasing (const Standard_Boolean AMode) { myAntiAliasing = AMode; }
108 void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane &thePlanes) { myClipPlanes = thePlanes; }
109 void SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext);
111 const Handle(Graphic3d_Camera)& Camera() { return myCamera; }
112 void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; }
114 void SetClipLimit (const Graphic3d_CView& theCView);
116 void SetFog (const Graphic3d_CView& theCView, const Standard_Boolean theFlag);
118 void TriedronDisplay (const Handle(OpenGl_Context)& theCtx,
119 const Aspect_TypeOfTriedronPosition thePosition,
120 const Quantity_NameOfColor theColor,
121 const Standard_Real theScale,
122 const Standard_Boolean theAsWireframe);
123 void TriedronErase (const Handle(OpenGl_Context)& theCtx);
125 void GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx,
126 const Graphic3d_CGraduatedTrihedron& theCubic);
127 void GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx);
129 Standard_Real Height () const { return myCamera->ViewDimensions().X(); }
130 Standard_Real Width () const { return myCamera->ViewDimensions().Y(); }
132 Standard_Integer Backfacing () const { return myBackfacing; }
134 const TEL_TRANSFORM_PERSISTENCE * BeginTransformPersistence (const Handle(OpenGl_Context)& theCtx,
135 const TEL_TRANSFORM_PERSISTENCE *theTransPers);
136 void EndTransformPersistence (const Handle(OpenGl_Context)& theCtx);
138 //! Add structure to display list with specified priority.
139 //! The structure will be added to associated with it z layer.
140 //! If the z layer is not presented in the view, the structure will
141 //! be displayed in default bottom-level z layer.
142 void DisplayStructure (const OpenGl_Structure* theStructure,
143 const Standard_Integer thePriority);
145 //! Erase structure from display list.
146 void EraseStructure (const OpenGl_Structure* theStructure);
148 //! Add structure to the list of immediate structures.
149 void DisplayImmediateStructure (const OpenGl_Structure* theStructure);
151 //! Erase structure from display list.
152 void EraseImmediateStructure (const OpenGl_Structure* theStructure);
154 //! Insert a new top-level z layer with ID <theLayerId>
155 void AddZLayer (const Standard_Integer theLayerId);
157 //! Remove a z layer with ID <theLayerId>
158 void RemoveZLayer (const Standard_Integer theLayerId);
160 //! Display structure in z layer with ID <theNewLayerId>
161 //! If the layer with ID <theNewLayerId> is not presented in the view,
162 //! the structure will be displayed in default bottom-level layer.
163 void ChangeZLayer (const OpenGl_Structure *theStructure,
164 const Standard_Integer theNewLayerId);
166 //! Sets the settings for a single Z layer of specified view.
167 void SetZLayerSettings (const Standard_Integer theLayerId,
168 const Graphic3d_ZLayerSettings theSettings);
170 //! Changes the priority of a structure within its ZLayer
171 void ChangePriority (const OpenGl_Structure *theStructure,
172 const Standard_Integer theNewPriority);
174 void CreateBackgroundTexture (const Standard_CString AFileName, const Aspect_FillMethod AFillStyle);
175 void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle);
176 void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType);
177 void SetBackgroundGradientType (const Aspect_GradientFillMethod AType);
179 void Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
180 const Handle(OpenGl_Workspace)& theWorkspace,
181 const Graphic3d_CView& theCView,
182 const Aspect_CLayer2d& theCUnderLayer,
183 const Aspect_CLayer2d& theCOverLayer);
186 void DrawBackground (OpenGl_Workspace& theWorkspace);
188 //! Returns list of OpenGL Z-layers.
189 const OpenGl_LayerList& LayerList() const { return myZLayers; }
191 //! Returns list of openGL light sources.
192 const OpenGl_ListOfLight& LightList() const { return myLights; }
194 //! Returns OpenGL environment map.
195 const Handle(OpenGl_Texture)& TextureEnv() const { return myTextureEnv; }
197 //! Returns visualization mode for objects in the view.
198 Visual3d_TypeOfSurfaceDetail SurfaceDetail() const { return mySurfaceDetail; }
200 //! Returns selector for BVH tree, providing a possibility to store information
201 //! about current view volume and to detect which objects are overlapping it.
202 OpenGl_BVHTreeSelector& BVHTreeSelector() { return myBVHSelector; }
204 //! Marks BVH tree for given priority list as dirty and
205 //! marks primitive set for rebuild.
206 void InvalidateBVHData (const Standard_Integer theLayerId);
208 //! Returns view-mapping and orientation matrices.
209 void GetMatrices (OpenGl_Mat4& theOrientation,
210 OpenGl_Mat4& theViewMapping) const;
212 //! Returns list of immediate structures rendered on top of main presentation
213 const OpenGl_SequenceOfStructure& ImmediateStructures() const
215 return myImmediateList;
218 //! Returns modification state for ray-tracing.
219 Standard_Size ModificationState() const { return myModificationState; }
223 void RenderStructs (const Handle(OpenGl_Workspace) &AWorkspace);
224 void RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext,
225 const Handle(OpenGl_Workspace) &theWorkspace,
226 const Graphic3d_CView& theCView,
227 const Aspect_CLayer2d& theCLayer);
228 void RedrawTrihedron (const Handle(OpenGl_Workspace) &theWorkspace);
230 //! Redraw contents of model scene: clipping planes,
231 //! lights, structures. The peculiar properties of "scene" is that
232 //! it requires empty Z-Buffer and uses projection and orientation
233 //! matrices supplied by 3d view.
234 //! @param thePrintCtx [in] printer context which facilitates tiled printing.
235 //! @param theWorkspace [in] rendering workspace.
236 //! @param theCView [in] view data.
237 //! @param theProjection [in] view projection matrix.
238 //! @param theOrientation [in] view orientation matrix.
239 void RedrawScene (const Handle(OpenGl_PrinterContext)& thePrintContext,
240 const Handle(OpenGl_Workspace)& theWorkspace);
242 Handle(OpenGl_LineAttributes) myLineAttribs;
243 Handle(OpenGl_Texture) myTextureEnv;
244 Visual3d_TypeOfSurfaceDetail mySurfaceDetail;
245 Standard_Integer myBackfacing;
247 OPENGL_BG_TEXTURE myBgTexture;
248 OPENGL_BG_GRADIENT myBgGradient;
250 OPENGL_ZCLIP myZClip;
252 Graphic3d_SequenceOfHClipPlane myClipPlanes;
254 Handle(Graphic3d_Camera) myCamera;
257 OpenGl_Trihedron* myTrihedron;
258 OpenGl_GraduatedTrihedron* myGraduatedTrihedron;
260 //View_LABViewContext
262 Visual3d_TypeOfModel myShadingModel; //!< lighting shading model
265 OpenGl_ListOfLight myLights;
269 Standard_Boolean myAntiAliasing;
271 //View_LABDepthCueing - fixed index used
273 OpenGl_LayerList myZLayers; //!< main list of displayed structure, sorted by layers
274 OpenGl_SequenceOfStructure myImmediateList; //!< list of immediate structures rendered on top of main presentation
276 const TEL_TRANSFORM_PERSISTENCE *myTransPers;
277 Standard_Boolean myIsTransPers;
279 //! Modification state
280 Standard_Size myProjectionState;
281 Standard_Size myModelViewState;
282 OpenGl_StateCounter* myStateCounter;
284 Standard_Size myCurrLightSourceState;
286 typedef std::pair<Standard_Size, Standard_Size> StateInfo;
288 StateInfo myLastOrientationState;
289 StateInfo myLastViewMappingState;
290 StateInfo myLastLightSourceState;
292 //! Is needed for selection of overlapping objects and storage of the current view volume
293 OpenGl_BVHTreeSelector myBVHSelector;
295 Standard_Size myModificationState;
299 DEFINE_STANDARD_ALLOC
300 DEFINE_STANDARD_RTTI(OpenGl_View) // Type definition
302 friend class OpenGl_Workspace;
306 #endif // _OpenGl_View_Header