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 <Visual3d_TypeOfSurfaceDetail.hxx>
39 #include <OpenGl_LayerList.hxx>
40 #include <OpenGl_Light.hxx>
42 #include <Handle_OpenGl_Context.hxx>
43 #include <Handle_OpenGl_GraphicDriver.hxx>
44 #include <Handle_OpenGl_Display.hxx>
45 #include <Handle_OpenGl_Workspace.hxx>
46 #include <Handle_OpenGl_View.hxx>
47 #include <Handle_OpenGl_Texture.hxx>
49 struct OPENGL_BG_TEXTURE
54 Aspect_FillMethod Style;
57 struct OPENGL_BG_GRADIENT
61 Aspect_GradientFillMethod type;
67 Standard_Boolean IsOn;
68 Standard_ShortReal Limit; /* in the range [0., 1.] */
71 Standard_Boolean IsOn;
72 Standard_ShortReal Limit; /* in the range [0., 1.] */
78 Standard_Boolean IsOn;
79 Standard_ShortReal Front; /* in the range [0., 1.] */
80 Standard_ShortReal Back; /* in the range [0., 1.] */
85 class OpenGl_GraduatedTrihedron;
86 class OpenGl_Structure;
87 class OpenGl_Trihedron;
88 class Handle(OpenGl_PrinterContext);
89 class OpenGl_StateCounter;
91 class OpenGl_View : public MMgt_TShared
94 OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext, OpenGl_StateCounter* theCounter);
95 virtual ~OpenGl_View ();
97 void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx);
99 void SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
100 const Handle(Graphic3d_TextureEnv)& theTexture);
101 void SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail AMode);
102 void SetBackfacing (const Standard_Integer AMode);
103 void SetLights (const CALL_DEF_VIEWCONTEXT &AContext);
104 void SetAntiAliasing (const Standard_Boolean AMode) { myAntiAliasing = AMode; }
105 void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane &thePlanes) { myClipPlanes = thePlanes; }
106 void SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext);
108 void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; }
110 void SetClipLimit (const Graphic3d_CView& theCView);
112 void SetFog (const Graphic3d_CView& theCView, const Standard_Boolean theFlag);
114 void TriedronDisplay (const Handle(OpenGl_Context)& theCtx,
115 const Aspect_TypeOfTriedronPosition thePosition,
116 const Quantity_NameOfColor theColor,
117 const Standard_Real theScale,
118 const Standard_Boolean theAsWireframe);
119 void TriedronErase (const Handle(OpenGl_Context)& theCtx);
121 void GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx,
122 const Graphic3d_CGraduatedTrihedron& theCubic);
123 void GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx);
125 Standard_Real Height () const { return myCamera->ViewDimensions().X(); }
126 Standard_Real Width () const { return myCamera->ViewDimensions().Y(); }
128 Standard_Integer Backfacing () const { return myBackfacing; }
130 const TEL_TRANSFORM_PERSISTENCE * BeginTransformPersistence (const Handle(OpenGl_Context)& theCtx,
131 const TEL_TRANSFORM_PERSISTENCE *theTransPers);
132 void EndTransformPersistence (const Handle(OpenGl_Context)& theCtx);
134 //! Add structure to display list with specified priority.
135 //! The structure will be added to associated with it z layer.
136 //! If the z layer is not presented in the view, the structure will
137 //! be displayed in default bottom-level z layer.
138 void DisplayStructure (const OpenGl_Structure* theStructure,
139 const Standard_Integer thePriority);
141 //! Erase structure from display list.
142 void EraseStructure (const OpenGl_Structure* theStructure);
144 //! Add structure to the list of immediate structures.
145 void DisplayImmediateStructure (const OpenGl_Structure* theStructure);
147 //! Erase structure from display list.
148 void EraseImmediateStructure (const OpenGl_Structure* theStructure);
150 //! Insert a new top-level z layer with ID <theLayerId>
151 void AddZLayer (const Standard_Integer theLayerId);
153 //! Remove a z layer with ID <theLayerId>
154 void RemoveZLayer (const Standard_Integer theLayerId);
156 //! Display structure in z layer with ID <theNewLayerId>
157 //! If the layer with ID <theNewLayerId> is not presented in the view,
158 //! the structure will be displayed in default bottom-level layer.
159 void ChangeZLayer (const OpenGl_Structure *theStructure,
160 const Standard_Integer theNewLayerId);
162 void CreateBackgroundTexture (const Standard_CString AFileName, const Aspect_FillMethod AFillStyle);
163 void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle);
164 void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType);
165 void SetBackgroundGradientType (const Aspect_GradientFillMethod AType);
167 void Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
168 const Handle(OpenGl_Workspace)& theWorkspace,
169 const Graphic3d_CView& theCView,
170 const Aspect_CLayer2d& theCUnderLayer,
171 const Aspect_CLayer2d& theCOverLayer);
174 void DrawBackground (OpenGl_Workspace& theWorkspace);
176 //! Returns list of OpenGL Z-layers.
177 const OpenGl_LayerList& LayerList() const { return myZLayers; }
179 //! Returns list of openGL light sources.
180 const OpenGl_ListOfLight& LightList() const { return myLights; }
182 //! Returns OpenGL environment map.
183 const Handle(OpenGl_Texture)& TextureEnv() const { return myTextureEnv; }
185 //! Returns visualization mode for objects in the view.
186 Visual3d_TypeOfSurfaceDetail SurfaceDetail() const { return mySurfaceDetail; }
188 void GetMatrices (TColStd_Array2OfReal& theMatOrient,
189 TColStd_Array2OfReal& theMatMapping) const;
191 //! Returns list of immediate structures rendered on top of main presentation
192 const OpenGl_SequenceOfStructure& ImmediateStructures() const
194 return myImmediateList;
197 //! Returns modification state for ray-tracing.
198 Standard_Size ModificationState() const { return myModificationState; }
202 void RenderStructs (const Handle(OpenGl_Workspace) &AWorkspace);
203 void RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext,
204 const Graphic3d_CView& theCView,
205 const Aspect_CLayer2d& theCLayer);
207 //! Redraw contents of model scene: clipping planes,
208 //! lights, structures. The peculiar properties of "scene" is that
209 //! it requires empty Z-Buffer and uses projection and orientation
210 //! matrices supplied by 3d view.
211 //! @param thePrintCtx [in] printer context which facilitates tiled printing.
212 //! @param theWorkspace [in] rendering workspace.
213 //! @param theCView [in] view data.
214 //! @param theProjection [in] view projection matrix.
215 //! @param theOrientation [in] view orientation matrix.
216 void RedrawScene (const Handle(OpenGl_PrinterContext)& thePrintContext,
217 const Handle(OpenGl_Workspace)& theWorkspace,
218 const OpenGl_Matrix* theProjection,
219 const OpenGl_Matrix* theOrientation);
221 Handle(OpenGl_Texture) myTextureEnv;
222 Visual3d_TypeOfSurfaceDetail mySurfaceDetail; //WSSurfaceDetail
223 Standard_Integer myBackfacing; //WSBackfacing
225 OPENGL_BG_TEXTURE myBgTexture; //WSBgTexture
226 OPENGL_BG_GRADIENT myBgGradient; //WSBgGradient
228 OPENGL_ZCLIP myZClip;
230 Graphic3d_SequenceOfHClipPlane myClipPlanes;
232 Handle(Graphic3d_Camera) myCamera;
235 OpenGl_Trihedron* myTrihedron;
236 OpenGl_GraduatedTrihedron* myGraduatedTrihedron;
238 //View_LABViewContext
240 int myIntShadingMethod;
243 OpenGl_ListOfLight myLights;
247 Standard_Boolean myAntiAliasing;
249 //View_LABDepthCueing - fixed index used
251 OpenGl_LayerList myZLayers; //!< main list of displayed structure, sorted by layers
252 OpenGl_SequenceOfStructure myImmediateList; //!< list of immediate structures rendered on top of main presentation
254 const TEL_TRANSFORM_PERSISTENCE *myTransPers;
255 Standard_Boolean myIsTransPers;
257 //! Modification state
258 Standard_Size myProjectionState;
259 Standard_Size myModelViewState;
260 OpenGl_StateCounter* myStateCounter;
262 Standard_Size myCurrLightSourceState;
264 typedef std::pair<Standard_Size, Standard_Size> StateInfo;
266 StateInfo myLastOrientationState;
267 StateInfo myLastViewMappingState;
268 StateInfo myLastLightSourceState;
270 Standard_Size myModificationState;
274 DEFINE_STANDARD_ALLOC
275 DEFINE_STANDARD_RTTI(OpenGl_View) // Type definition
279 #endif // _OpenGl_View_Header