0024192: Adding support for shaders to OCCT visualization toolkit
[occt.git] / src / OpenGl / OpenGl_View.hxx
1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20 #ifndef _OpenGl_View_Header
21 #define _OpenGl_View_Header
22
23 #include <MMgt_TShared.hxx>
24 #include <Standard_DefineHandle.hxx>
25
26 #include <TColStd_Array2OfReal.hxx>
27 #include <NCollection_List.hxx>
28
29 #include <Quantity_NameOfColor.hxx>
30 #include <Aspect_FillMethod.hxx>
31 #include <Aspect_GradientFillMethod.hxx>
32 #include <Aspect_TypeOfTriedronPosition.hxx>
33 #include <Aspect_CLayer2d.hxx>
34
35 #include <InterfaceGraphic_Graphic3d.hxx>
36 #include <InterfaceGraphic_Visual3d.hxx>
37
38 #include <Graphic3d_CView.hxx>
39 #include <Graphic3d_CGraduatedTrihedron.hxx>
40 #include <Graphic3d_SetOfHClipPlane.hxx>
41 #include <Visual3d_TypeOfSurfaceDetail.hxx>
42
43 #include <OpenGl_telem_view.hxx>
44 #include <OpenGl_LayerList.hxx>
45 #include <OpenGl_Light.hxx>
46
47 #include <Handle_OpenGl_Context.hxx>
48 #include <Handle_OpenGl_Display.hxx>
49 #include <Handle_OpenGl_Workspace.hxx>
50 #include <Handle_OpenGl_View.hxx>
51 #include <Handle_OpenGl_Texture.hxx>
52
53 struct OPENGL_BG_TEXTURE
54 {
55   Tuint             TexId;
56   Tint              Width;
57   Tint              Height;
58   Aspect_FillMethod Style;
59 };
60
61 struct OPENGL_BG_GRADIENT
62 {
63   TEL_COLOUR color1;
64   TEL_COLOUR color2;
65   Aspect_GradientFillMethod type;
66 };
67
68 struct OPENGL_EXTRA_REP
69 {
70   Tfloat  vrp[3];
71   Tfloat  vpn[3];
72   Tfloat  vup[3];
73   TEL_VIEW_MAPPING map;
74   Tfloat  scaleFactors[3];
75 };
76
77 struct OPENGL_ZCLIP
78 {
79   struct {
80     Standard_Boolean   IsOn;
81     Standard_ShortReal Limit; /* in the range [0., 1.] */
82   } Back;
83   struct {
84     Standard_Boolean   IsOn;
85     Standard_ShortReal Limit; /* in the range [0., 1.] */
86   } Front;
87 };
88
89 struct OPENGL_FOG
90 {
91   Standard_Boolean   IsOn;
92   Standard_ShortReal Front; /* in the range [0., 1.] */
93   Standard_ShortReal Back; /* in the range [0., 1.] */
94   TEL_COLOUR         Color;
95 };
96
97 class OpenGl_GraduatedTrihedron;
98 class OpenGl_Structure;
99 class OpenGl_Trihedron;
100 class Handle(OpenGl_PrinterContext);
101
102 class OpenGl_View : public MMgt_TShared
103 {
104  public:
105   OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext);
106   virtual ~OpenGl_View ();
107
108   void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx);
109
110   void SetTextureEnv (const Handle(OpenGl_Context)&       theCtx,
111                       const Handle(Graphic3d_TextureEnv)& theTexture);
112   void SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail AMode) { mySurfaceDetail = AMode; }
113   void SetBackfacing (const Standard_Integer AMode);
114   void SetLights (const CALL_DEF_VIEWCONTEXT &AContext);
115   void SetAntiAliasing (const Standard_Boolean AMode) { myAntiAliasing = AMode; }
116   void SetClipPlanes (const Graphic3d_SetOfHClipPlane &thePlanes) { myClipPlanes = thePlanes; }
117   void SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext);
118
119   void SetClipLimit (const Graphic3d_CView& theCView);
120   void SetMapping (const Handle(OpenGl_Display)& theGlDisplay, const Graphic3d_CView& theCView);
121   void SetOrientation (const Graphic3d_CView& theCView);
122
123   void SetFog (const Graphic3d_CView& theCView, const Standard_Boolean theFlag);
124
125   void TriedronDisplay (const Handle(OpenGl_Context)&       theCtx,
126                         const Aspect_TypeOfTriedronPosition thePosition,
127                         const Quantity_NameOfColor          theColor,
128                         const Standard_Real                 theScale,
129                         const Standard_Boolean              theAsWireframe);
130   void TriedronErase (const Handle(OpenGl_Context)& theCtx);
131
132   void GraduatedTrihedronDisplay (const Handle(OpenGl_Context)&        theCtx,
133                                   const Graphic3d_CGraduatedTrihedron& theCubic);
134   void GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx);
135
136   Standard_Boolean ProjectObjectToRaster (const Standard_Integer w, const Standard_Integer h,
137                                           const Standard_ShortReal x, const Standard_ShortReal y, const Standard_ShortReal z,
138                                           Standard_ShortReal &xr, Standard_ShortReal &yr);
139   Standard_Boolean ProjectRasterToObject (const Standard_Integer w, const Standard_Integer h,
140                                           const Standard_Integer xr, const Standard_Integer yr,
141                                           Standard_ShortReal &x, Standard_ShortReal &y, Standard_ShortReal &z);
142   Standard_Boolean ProjectRasterToObjectWithRay (const Standard_Integer w, const Standard_Integer h,
143                                                  const Standard_Integer xr, const Standard_Integer yr,
144                                                  Standard_ShortReal &x, Standard_ShortReal &y, Standard_ShortReal &z,
145                                                  Standard_ShortReal &dx, Standard_ShortReal &dy, Standard_ShortReal &dz);
146   void GetMatrices (TColStd_Array2OfReal&  theMatOrient,
147                     TColStd_Array2OfReal&  theMatMapping,
148                     const Standard_Boolean theIsCustom) const;
149
150   Standard_Real Height () const { return (myExtra.map.window.xmax - myExtra.map.window.xmin); }
151   Standard_Real Width () const { return (myExtra.map.window.ymax - myExtra.map.window.ymin); }
152
153   Standard_Integer Backfacing () const { return myBackfacing; }
154
155   const TEL_TRANSFORM_PERSISTENCE * BeginTransformPersistence (const Handle(OpenGl_Context)& theCtx,
156                                                                const TEL_TRANSFORM_PERSISTENCE *theTransPers);
157   void EndTransformPersistence (const Handle(OpenGl_Context)& theCtx);
158
159   //! Add structure to display list with specified priority.
160   //! The structure will be added to associated with it z layer.
161   //! If the z layer is not presented in the view, the structure will
162   //! be displayed in default bottom-level z layer.
163   void DisplayStructure (const OpenGl_Structure *theStructure,
164                          const Standard_Integer  thePriority);
165
166   //! Erase structure from display list.
167   void EraseStructure (const OpenGl_Structure *theStructure);
168
169   //! Insert a new top-level z layer with ID <theLayerId>
170   void AddZLayer (const Standard_Integer theLayerId);
171
172   //! Remove a z layer with ID <theLayerId>
173   void RemoveZLayer (const Standard_Integer theLayerId);
174
175   //! Display structure in z layer with ID <theNewLayerId>
176   //! If the layer with ID <theNewLayerId> is not presented in the view,
177   //! the structure will be displayed in default bottom-level layer.
178   void ChangeZLayer (const OpenGl_Structure *theStructure,
179                      const Standard_Integer  theNewLayerId);
180
181   void CreateBackgroundTexture (const Standard_CString AFileName, const Aspect_FillMethod AFillStyle);
182   void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle);
183   void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType);
184   void SetBackgroundGradientType (const Aspect_GradientFillMethod AType);
185
186   void Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
187                const Handle(OpenGl_Workspace)&      theWorkspace,
188                const Graphic3d_CView&               theCView,
189                const Aspect_CLayer2d&               theCUnderLayer,
190                const Aspect_CLayer2d&               theCOverLayer);
191
192 public:
193
194   DEFINE_STANDARD_RTTI(OpenGl_View) // Type definition
195
196  protected:
197
198   void RenderStructs (const Handle(OpenGl_Workspace) &AWorkspace);
199   void RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext,
200                       const Graphic3d_CView&               theCView,
201                       const Aspect_CLayer2d&               theCLayer);
202
203   Handle(OpenGl_Texture) myTextureEnv;
204   Visual3d_TypeOfSurfaceDetail mySurfaceDetail; //WSSurfaceDetail
205   Standard_Integer myBackfacing; //WSBackfacing
206
207   OPENGL_BG_TEXTURE myBgTexture; //WSBgTexture
208   OPENGL_BG_GRADIENT myBgGradient; //WSBgGradient
209
210   //{ myViewRep
211   Tmatrix3    myOrientationMatrix;
212   Tmatrix3    myMappingMatrix;
213
214   //Tint        shield_indicator;
215   //TEL_COLOUR  shield_colour;
216   //Tint        border_indicator;
217   //TEL_COLOUR  border_colour;
218   //Tint        active_status;
219
220   OPENGL_ZCLIP   myZClip;
221   OPENGL_EXTRA_REP myExtra;
222   //}
223
224   Graphic3d_SetOfHClipPlane myClipPlanes;
225   
226   OPENGL_FOG myFog;
227   OpenGl_Trihedron*          myTrihedron;
228   OpenGl_GraduatedTrihedron* myGraduatedTrihedron;
229
230   //View_LABViewContext
231   int myVisualization;
232   int myIntShadingMethod;
233
234   //View_LABLight
235   OpenGl_ListOfLight myLights;
236
237   //View_LABPlane
238   //View_LABAliasing
239   Standard_Boolean myAntiAliasing;
240
241   //View_LABDepthCueing - fixed index used
242
243   OpenGl_LayerList myZLayers;
244
245   const TEL_TRANSFORM_PERSISTENCE *myTransPers;
246   Standard_Boolean myIsTransPers;
247
248   //! Modification flags.
249   Standard_Boolean myOrientationChanged;
250   Standard_Boolean myViewMappingChanged;
251   Standard_Boolean myLightSourcesChanged;
252
253  public:
254   DEFINE_STANDARD_ALLOC
255 };
256
257 #endif //_OpenGl_View_Header