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_GraduatedTrihedron.hxx>
36 #include <Graphic3d_SequenceOfHClipPlane.hxx>
37 #include <Graphic3d_ZLayerSettings.hxx>
38 #include <Visual3d_TypeOfSurfaceDetail.hxx>
39 #include <Visual3d_TypeOfModel.hxx>
41 #include <OpenGl_AspectFace.hxx>
42 #include <OpenGl_BackgroundArray.hxx>
43 #include <OpenGl_BVHTreeSelector.hxx>
44 #include <OpenGl_LayerList.hxx>
45 #include <OpenGl_Light.hxx>
46 #include <OpenGl_LineAttributes.hxx>
47 #include <OpenGl_Trihedron.hxx>
48 #include <OpenGl_GraduatedTrihedron.hxx>
50 #include <Handle_OpenGl_Context.hxx>
51 #include <Handle_OpenGl_GraphicDriver.hxx>
52 #include <Handle_OpenGl_Workspace.hxx>
53 #include <Handle_OpenGl_View.hxx>
54 #include <Handle_OpenGl_Texture.hxx>
59 Standard_Boolean IsOn;
60 Standard_ShortReal Limit; /* in the range [0., 1.] */
63 Standard_Boolean IsOn;
64 Standard_ShortReal Limit; /* in the range [0., 1.] */
70 Standard_Boolean IsOn;
71 Standard_ShortReal Front; /* in the range [0., 1.] */
72 Standard_ShortReal Back; /* in the range [0., 1.] */
77 class OpenGl_Structure;
78 class Handle(OpenGl_PrinterContext);
79 class OpenGl_StateCounter;
81 class OpenGl_View : public MMgt_TShared
84 OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext, OpenGl_StateCounter* theCounter);
85 virtual ~OpenGl_View ();
87 void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx);
89 void SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
90 const Handle(Graphic3d_TextureEnv)& theTexture);
91 void SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail AMode);
92 void SetBackfacing (const Standard_Integer AMode);
93 void SetLights (const CALL_DEF_VIEWCONTEXT &AContext);
94 void SetAntiAliasing (const Standard_Boolean AMode) { myAntiAliasing = AMode; }
95 void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane &thePlanes) { myClipPlanes = thePlanes; }
96 void SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext);
98 const Handle(Graphic3d_Camera)& Camera() { return myCamera; }
99 void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; }
101 void SetClipLimit (const Graphic3d_CView& theCView);
103 void SetFog (const Graphic3d_CView& theCView, const Standard_Boolean theFlag);
105 OpenGl_Trihedron& ChangeTrihedron() { return myTrihedron; }
106 void TriedronDisplay (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);
112 OpenGl_GraduatedTrihedron& ChangeGraduatedTrihedron() { return myGraduatedTrihedron; }
113 void GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx,
114 const Graphic3d_GraduatedTrihedron& theCubic);
115 void GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx);
117 Standard_Real Height () const { return myCamera->ViewDimensions().X(); }
118 Standard_Real Width () const { return myCamera->ViewDimensions().Y(); }
120 Standard_Integer Backfacing () const { return myBackfacing; }
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);
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.
130 void DisplayStructure (const Handle(Graphic3d_Structure)& theStructure,
131 const Standard_Integer thePriority);
133 //! Erase structure from display list.
134 void EraseStructure (const Handle(Graphic3d_Structure)& theStructure);
136 //! Add structure to the list of immediate structures.
137 void DisplayImmediateStructure (const Handle(Graphic3d_Structure)& theStructure);
139 //! Erase structure from display list.
140 void EraseImmediateStructure (const OpenGl_Structure* theStructure);
142 //! Insert a new top-level z layer with ID <theLayerId>
143 void AddZLayer (const Graphic3d_ZLayerId theLayerId);
145 //! Remove a z layer with ID <theLayerId>
146 void RemoveZLayer (const Graphic3d_ZLayerId theLayerId);
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.
151 void ChangeZLayer (const OpenGl_Structure* theStructure,
152 const Graphic3d_ZLayerId theNewLayerId);
154 //! Sets the settings for a single Z layer of specified view.
155 void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
156 const Graphic3d_ZLayerSettings& theSettings);
158 //! Changes the priority of a structure within its ZLayer
159 void ChangePriority (const OpenGl_Structure* theStructure,
160 const Standard_Integer theNewPriority);
162 void CreateBackgroundTexture (const Standard_CString AFileName,
163 const Aspect_FillMethod AFillStyle);
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);
169 void Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
170 const Handle(OpenGl_Workspace)& theWorkspace,
171 const Graphic3d_CView& theCView,
172 const Aspect_CLayer2d& theCUnderLayer,
173 const Aspect_CLayer2d& theCOverLayer,
174 const Standard_Boolean theToDrawImmediate);
177 void DrawBackground (const Handle(OpenGl_Workspace)& theWorkspace);
179 //! Returns list of OpenGL Z-layers.
180 const OpenGl_LayerList& LayerList() const { return myZLayers; }
182 //! Returns list of openGL light sources.
183 const OpenGl_ListOfLight& LightList() const { return myLights; }
185 //! Returns OpenGL environment map.
186 const Handle(OpenGl_Texture)& TextureEnv() const { return myTextureEnv; }
188 //! Returns visualization mode for objects in the view.
189 Visual3d_TypeOfSurfaceDetail SurfaceDetail() const { return mySurfaceDetail; }
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; }
195 //! Marks BVH tree for given priority list as dirty and
196 //! marks primitive set for rebuild.
197 void InvalidateBVHData (const Standard_Integer theLayerId);
199 //! Returns view-mapping and orientation matrices.
200 void GetMatrices (OpenGl_Mat4& theOrientation,
201 OpenGl_Mat4& theViewMapping) const;
203 //! Returns list of immediate structures rendered on top of main presentation
204 const OpenGl_SequenceOfStructure& ImmediateStructures() const
206 return myImmediateList;
209 //! Returns true if there are immediate structures to display
210 bool HasImmediateStructures() const
212 return !myImmediateList.IsEmpty()
213 || myZLayers.NbImmediateStructures() != 0;
216 //! Returns modification state for ray-tracing.
217 Standard_Size ModificationState() const { return myModificationState; }
221 void RenderStructs (const Handle(OpenGl_Workspace)& theWorkspace,
222 const Standard_Boolean theToDrawImmediate);
223 void RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext,
224 const Handle(OpenGl_Workspace) &theWorkspace,
225 const Graphic3d_CView& theCView,
226 const Aspect_CLayer2d& theCLayer);
227 void RedrawTrihedron (const Handle(OpenGl_Workspace) &theWorkspace);
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.
233 void RedrawScene (const Handle(OpenGl_PrinterContext)& thePrintContext,
234 const Handle(OpenGl_Workspace)& theWorkspace,
235 const Standard_Boolean theToDrawImmediate);
237 Handle(OpenGl_LineAttributes) myLineAttribs;
238 Handle(OpenGl_Texture) myTextureEnv;
239 Visual3d_TypeOfSurfaceDetail mySurfaceDetail;
240 Standard_Integer myBackfacing;
242 OPENGL_ZCLIP myZClip;
244 Graphic3d_SequenceOfHClipPlane myClipPlanes;
246 Handle(Graphic3d_Camera) myCamera;
249 OpenGl_Trihedron myTrihedron;
250 OpenGl_GraduatedTrihedron myGraduatedTrihedron;
251 bool myToShowTrihedron;
252 bool myToShowGradTrihedron;
254 //View_LABViewContext
256 Visual3d_TypeOfModel myShadingModel; //!< lighting shading model
259 OpenGl_ListOfLight myLights;
263 Standard_Boolean myAntiAliasing;
265 //View_LABDepthCueing - fixed index used
267 OpenGl_LayerList myZLayers; //!< main list of displayed structure, sorted by layers
268 OpenGl_SequenceOfStructure myImmediateList; //!< list of immediate structures rendered on top of main presentation
270 const TEL_TRANSFORM_PERSISTENCE *myTransPers;
271 Standard_Boolean myIsTransPers;
273 //! Modification state
274 Standard_Size myProjectionState;
275 Standard_Size myModelViewState;
276 OpenGl_StateCounter* myStateCounter;
278 Standard_Size myCurrLightSourceState;
280 typedef std::pair<Standard_Size, Standard_Size> StateInfo;
282 StateInfo myLastOrientationState;
283 StateInfo myLastViewMappingState;
284 StateInfo myLastLightSourceState;
286 //! Is needed for selection of overlapping objects and storage of the current view volume
287 OpenGl_BVHTreeSelector myBVHSelector;
289 Standard_Size myModificationState;
291 protected: //! @name Background parameters
293 OpenGl_AspectFace* myTextureParams; //!< Stores texture and its parameters for textured background
294 OpenGl_BackgroundArray* myBgGradientArray; //!< Primitive array for gradient background
295 OpenGl_BackgroundArray* myBgTextureArray; //!< Primitive array for texture background
299 DEFINE_STANDARD_ALLOC
300 DEFINE_STANDARD_RTTI(OpenGl_View) // Type definition
302 friend class OpenGl_Workspace;
306 #endif // _OpenGl_View_Header