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>
40 #include <OpenGl_LayerList.hxx>
41 #include <OpenGl_Light.hxx>
42 #include <OpenGl_LineAttributes.hxx>
44 #include <Handle_OpenGl_Context.hxx>
45 #include <Handle_OpenGl_GraphicDriver.hxx>
46 #include <Handle_OpenGl_Workspace.hxx>
47 #include <Handle_OpenGl_View.hxx>
48 #include <Handle_OpenGl_Texture.hxx>
50 struct OPENGL_BG_TEXTURE
55 Aspect_FillMethod Style;
58 struct OPENGL_BG_GRADIENT
62 Aspect_GradientFillMethod type;
68 Standard_Boolean IsOn;
69 Standard_ShortReal Limit; /* in the range [0., 1.] */
72 Standard_Boolean IsOn;
73 Standard_ShortReal Limit; /* in the range [0., 1.] */
79 Standard_Boolean IsOn;
80 Standard_ShortReal Front; /* in the range [0., 1.] */
81 Standard_ShortReal Back; /* in the range [0., 1.] */
86 class OpenGl_GraduatedTrihedron;
87 class OpenGl_Structure;
88 class OpenGl_Trihedron;
89 class Handle(OpenGl_PrinterContext);
90 class OpenGl_StateCounter;
92 class OpenGl_View : public MMgt_TShared
95 OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext, OpenGl_StateCounter* theCounter);
96 virtual ~OpenGl_View ();
98 void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx);
100 void SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
101 const Handle(Graphic3d_TextureEnv)& theTexture);
102 void SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail AMode);
103 void SetBackfacing (const Standard_Integer AMode);
104 void SetLights (const CALL_DEF_VIEWCONTEXT &AContext);
105 void SetAntiAliasing (const Standard_Boolean AMode) { myAntiAliasing = AMode; }
106 void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane &thePlanes) { myClipPlanes = thePlanes; }
107 void SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext);
109 void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; }
111 void SetClipLimit (const Graphic3d_CView& theCView);
113 void SetFog (const Graphic3d_CView& theCView, const Standard_Boolean theFlag);
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);
122 void GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx,
123 const Graphic3d_CGraduatedTrihedron& theCubic);
124 void GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx);
126 Standard_Real Height () const { return myCamera->ViewDimensions().X(); }
127 Standard_Real Width () const { return myCamera->ViewDimensions().Y(); }
129 Standard_Integer Backfacing () const { return myBackfacing; }
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);
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.
139 void DisplayStructure (const OpenGl_Structure* theStructure,
140 const Standard_Integer thePriority);
142 //! Erase structure from display list.
143 void EraseStructure (const OpenGl_Structure* theStructure);
145 //! Add structure to the list of immediate structures.
146 void DisplayImmediateStructure (const OpenGl_Structure* theStructure);
148 //! Erase structure from display list.
149 void EraseImmediateStructure (const OpenGl_Structure* theStructure);
151 //! Insert a new top-level z layer with ID <theLayerId>
152 void AddZLayer (const Standard_Integer theLayerId);
154 //! Remove a z layer with ID <theLayerId>
155 void RemoveZLayer (const Standard_Integer theLayerId);
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);
163 //! Sets the settings for a single Z layer of specified view.
164 void SetZLayerSettings (const Standard_Integer theLayerId,
165 const Graphic3d_ZLayerSettings theSettings);
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);
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);
179 void DrawBackground (OpenGl_Workspace& theWorkspace);
181 //! Returns list of OpenGL Z-layers.
182 const OpenGl_LayerList& LayerList() const { return myZLayers; }
184 //! Returns list of openGL light sources.
185 const OpenGl_ListOfLight& LightList() const { return myLights; }
187 //! Returns OpenGL environment map.
188 const Handle(OpenGl_Texture)& TextureEnv() const { return myTextureEnv; }
190 //! Returns visualization mode for objects in the view.
191 Visual3d_TypeOfSurfaceDetail SurfaceDetail() const { return mySurfaceDetail; }
193 void GetMatrices (TColStd_Array2OfReal& theMatOrient,
194 TColStd_Array2OfReal& theMatMapping) const;
196 //! Returns list of immediate structures rendered on top of main presentation
197 const OpenGl_SequenceOfStructure& ImmediateStructures() const
199 return myImmediateList;
202 //! Returns modification state for ray-tracing.
203 Standard_Size ModificationState() const { return myModificationState; }
207 void RenderStructs (const Handle(OpenGl_Workspace) &AWorkspace);
208 void RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext,
209 const Graphic3d_CView& theCView,
210 const Aspect_CLayer2d& theCLayer);
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);
226 Handle(OpenGl_LineAttributes) myLineAttribs;
227 Handle(OpenGl_Texture) myTextureEnv;
228 Visual3d_TypeOfSurfaceDetail mySurfaceDetail;
229 Standard_Integer myBackfacing;
231 OPENGL_BG_TEXTURE myBgTexture;
232 OPENGL_BG_GRADIENT myBgGradient;
234 OPENGL_ZCLIP myZClip;
236 Graphic3d_SequenceOfHClipPlane myClipPlanes;
238 Handle(Graphic3d_Camera) myCamera;
241 OpenGl_Trihedron* myTrihedron;
242 OpenGl_GraduatedTrihedron* myGraduatedTrihedron;
244 //View_LABViewContext
246 int myIntShadingMethod;
249 OpenGl_ListOfLight myLights;
253 Standard_Boolean myAntiAliasing;
255 //View_LABDepthCueing - fixed index used
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
260 const TEL_TRANSFORM_PERSISTENCE *myTransPers;
261 Standard_Boolean myIsTransPers;
263 //! Modification state
264 Standard_Size myProjectionState;
265 Standard_Size myModelViewState;
266 OpenGl_StateCounter* myStateCounter;
268 Standard_Size myCurrLightSourceState;
270 typedef std::pair<Standard_Size, Standard_Size> StateInfo;
272 StateInfo myLastOrientationState;
273 StateInfo myLastViewMappingState;
274 StateInfo myLastLightSourceState;
276 Standard_Size myModificationState;
280 DEFINE_STANDARD_ALLOC
281 DEFINE_STANDARD_RTTI(OpenGl_View) // Type definition
285 #endif // _OpenGl_View_Header