0026434: Visualization - Textured objects should have priority over the environment...
[occt.git] / src / OpenGl / OpenGl_View.hxx
1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _OpenGl_View_Header
17 #define _OpenGl_View_Header
18
19 #include <MMgt_TShared.hxx>
20 #include <Standard_Type.hxx>
21
22 #include <TColStd_Array2OfReal.hxx>
23 #include <NCollection_List.hxx>
24 #include <math_BullardGenerator.hxx>
25
26 #include <Quantity_NameOfColor.hxx>
27 #include <Aspect_FillMethod.hxx>
28 #include <Aspect_GradientFillMethod.hxx>
29 #include <Aspect_TypeOfTriedronPosition.hxx>
30
31 #include <InterfaceGraphic_Graphic3d.hxx>
32
33 #include <Graphic3d_CView.hxx>
34 #include <Graphic3d_GraduatedTrihedron.hxx>
35 #include <Graphic3d_SequenceOfHClipPlane.hxx>
36 #include <Graphic3d_TypeOfShadingModel.hxx>
37 #include <Graphic3d_WorldViewProjState.hxx>
38 #include <Graphic3d_ZLayerSettings.hxx>
39
40 #include <OpenGl_AspectFace.hxx>
41 #include <OpenGl_BackgroundArray.hxx>
42 #include <OpenGl_BVHTreeSelector.hxx>
43 #include <OpenGl_Context.hxx>
44 #include <OpenGl_FrameBuffer.hxx>
45 #include <OpenGl_GraduatedTrihedron.hxx>
46 #include <OpenGl_LayerList.hxx>
47 #include <OpenGl_Light.hxx>
48 #include <OpenGl_LineAttributes.hxx>
49 #include <OpenGl_SceneGeometry.hxx>
50 #include <OpenGl_Structure.hxx>
51 #include <OpenGl_Trihedron.hxx>
52 #include <OpenGl_Window.hxx>
53 #include <OpenGl_Workspace.hxx>
54
55 #include <map>
56 #include <set>
57
58 struct OPENGL_ZCLIP
59 {
60   struct {
61     Standard_Boolean   IsOn;
62     Standard_ShortReal Limit; /* in the range [0., 1.] */
63   } Back;
64   struct {
65     Standard_Boolean   IsOn;
66     Standard_ShortReal Limit; /* in the range [0., 1.] */
67   } Front;
68 };
69
70 struct OPENGL_FOG
71 {
72   Standard_Boolean   IsOn;
73   Standard_ShortReal Front; /* in the range [0., 1.] */
74   Standard_ShortReal Back; /* in the range [0., 1.] */
75   TEL_COLOUR         Color;
76 };
77
78 struct OpenGl_Matrix;
79
80 class Graphic3d_StructureManager;
81 class OpenGl_GraphicDriver;
82 class OpenGl_StateCounter;
83 class OpenGl_RaytraceMaterial;
84 class OpenGl_TriangleSet;
85 class OpenGl_Workspace;
86 class OpenGl_View;
87 DEFINE_STANDARD_HANDLE(OpenGl_View,Graphic3d_CView)
88
89 //! Implementation of OpenGl view.
90 class OpenGl_View : public Graphic3d_CView
91 {
92
93 public:
94
95   //! Constructor.
96   Standard_EXPORT OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
97                                const Handle(OpenGl_GraphicDriver)& theDriver,
98                                const Handle(OpenGl_Caps)& theCaps,
99                                Standard_Boolean& theDeviceLostFlag,
100                                OpenGl_StateCounter* theCounter);
101
102   //! Default destructor.
103   Standard_EXPORT virtual ~OpenGl_View();
104
105   Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx);
106
107   //! Deletes and erases the view.
108   Standard_EXPORT virtual void Remove() Standard_OVERRIDE;
109
110   //! @param theDrawToFrontBuffer Advanced option to modify rendering mode:
111   //! 1. TRUE.  Drawing immediate mode structures directly to the front buffer over the scene image.
112   //! Fast, so preferred for interactive work (used by default).
113   //! However these extra drawings will be missed in image dump since it is performed from back buffer.
114   //! Notice that since no pre-buffering used the V-Sync will be ignored and rendering could be seen
115   //! in run-time (in case of slow hardware) and/or tearing may appear.
116   //! So this is strongly recommended to draw only simple (fast) structures.
117   //! 2. FALSE. Drawing immediate mode structures to the back buffer.
118   //! The complete scene is redrawn first, so this mode is slower if scene contains complex data and/or V-Sync
119   //! is turned on. But it works in any case and is especially useful for view dump because the dump image is read
120   //! from the back buffer.
121   //! @return previous mode.
122   Standard_EXPORT Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer) Standard_OVERRIDE;
123
124   //! Creates and maps rendering window to the view.
125   //! @param theWindow [in] the window.
126   //! @param theContext [in] the rendering context. If NULL the context will be created internally.
127   Standard_EXPORT virtual void SetWindow (const Handle(Aspect_Window)&  theWindow,
128                                           const Aspect_RenderingContext theContext) Standard_OVERRIDE;
129
130   //! Returns window associated with the view.
131   virtual Handle(Aspect_Window) Window() const Standard_OVERRIDE
132   { return myWindow->PlatformWindow(); }
133
134   //! Returns True if the window associated to the view is defined.
135   virtual Standard_Boolean IsDefined() const Standard_OVERRIDE
136   { return !myWindow.IsNull(); }
137
138   //! Handle changing size of the rendering window.
139   Standard_EXPORT virtual void Resized() Standard_OVERRIDE;
140
141   //! Redraw content of the view.
142   Standard_EXPORT virtual void Redraw() Standard_OVERRIDE;
143
144   //! Redraw immediate content of the view.
145   Standard_EXPORT virtual void RedrawImmediate() Standard_OVERRIDE;
146
147   //! Marks BVH tree for given priority list as dirty and marks primitive set for rebuild.
148   Standard_EXPORT virtual void Invalidate() Standard_OVERRIDE;
149
150   //! Return true if view content cache has been invalidated.
151   virtual Standard_Boolean IsInvalidated() Standard_OVERRIDE { return !myBackBufferRestored; }
152
153   //! Displays z-buffer trihedron.
154   Standard_EXPORT virtual void TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition = Aspect_TOTP_CENTER,
155                                                 const Quantity_NameOfColor theColor = Quantity_NOC_WHITE,
156                                                 const Standard_Real theScale = 0.02,
157                                                 const Standard_Boolean theAsWireframe = Standard_True) Standard_OVERRIDE;
158
159   //! Erases z-buffer trihedron.
160   Standard_EXPORT virtual void TriedronErase() Standard_OVERRIDE;
161
162   //! Setup parameters of z-buffer trihedron.
163   Standard_EXPORT virtual void ZBufferTriedronSetup (const Quantity_NameOfColor theXColor = Quantity_NOC_RED,
164                                                      const Quantity_NameOfColor theYColor = Quantity_NOC_GREEN,
165                                                      const Quantity_NameOfColor theZColor = Quantity_NOC_BLUE1,
166                                                      const Standard_Real theSizeRatio = 0.8,
167                                                      const Standard_Real theAxisDiametr = 0.05,
168                                                      const Standard_Integer theNbFacettes = 12) Standard_OVERRIDE;
169
170   //! Displays trihedron echo.
171   Standard_EXPORT virtual void TriedronEcho (const Aspect_TypeOfTriedronEcho theType = Aspect_TOTE_NONE) Standard_OVERRIDE;
172
173   //! Returns data of a graduated trihedron
174   const Graphic3d_GraduatedTrihedron& GetGraduatedTrihedron() Standard_OVERRIDE
175   { return myGTrihedronData; }
176
177   //! Displays Graduated Trihedron.
178   Standard_EXPORT virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) Standard_OVERRIDE;
179
180   //! Erases Graduated Trihedron.
181   Standard_EXPORT virtual void GraduatedTrihedronErase() Standard_OVERRIDE;
182
183   //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in graphic view object.
184   //! @param theMin [in] the minimum point of scene.
185   //! @param theMax [in] the maximum point of scene.
186   Standard_EXPORT virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) Standard_OVERRIDE;
187
188   //! Dump active rendering buffer into specified memory buffer.
189   Standard_EXPORT virtual Standard_Boolean BufferDump (Image_PixMap& theImage,
190                                                        const Graphic3d_BufferType& theBufferType) Standard_OVERRIDE;
191
192   //! Print the contents of the view to the printer.
193   //! @param thePrinterDC        pass the PrinterDeviceContext (HDC)
194   //! @param theToShowBackground when set to FALSE then print the view without background
195   //!                            color (background is white) else set to TRUE for printing
196   //!                            with current background color
197   //! @param theFileName         if != NULL, then the view will be printed to a file
198   //! @param thePrintAlgorithm   select print algorithm: stretch, tile
199   //! @param theScaleFactor      scaling coefficient, used internally to scale the printings
200   //!                            accordingly to the scale factor selected in the printer properties dialog
201   //! @return Standard_True if the data is passed to the printer, otherwise Standard_False if
202   //! the print operation failed due to the printer errors, or lack of system memory. This might be related
203   //! to insufficient memory or some internal errors.
204   //! All this errors are indicated by the message boxes (on level of OpenGl_GraphicDriver).
205   //! Warning: This function can reuse FBO assigned to the view, please take it into account
206   //! if you use it for your purposes.
207   Standard_EXPORT virtual Standard_Boolean Print (const Aspect_Handle    thePrinterDC,
208                                                   const Standard_Boolean theToShowBackground,
209                                                   const Standard_CString theFileName,
210                                                   const Aspect_PrintAlgo thePrintAlgorithm = Aspect_PA_STRETCH,
211                                                   const Standard_Real    theScaleFactor = 1.0) Standard_OVERRIDE;
212
213   //! Export scene into the one of the Vector graphics formats (SVG, PS, PDF...).
214   //! In contrast to Bitmaps, Vector graphics is scalable (so you may got quality benefits
215   //! on printing to laser printer). Notice however that results may differ a lot and
216   //! do not contain some elements.
217   Standard_EXPORT virtual Standard_Boolean Export (const Standard_CString theFileName,
218                                                    const Graphic3d_ExportFormat theFormat,
219                                                    const Graphic3d_SortType theSortType = Graphic3d_ST_BSP_Tree) Standard_OVERRIDE;
220
221   //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId as outdated.
222   Standard_EXPORT virtual void InvalidateBVHData (const Standard_Integer theLayerId) Standard_OVERRIDE;
223
224   //! Insert a new top-level z layer with the given ID.
225   Standard_EXPORT virtual void AddZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
226
227   //! Remove a z layer with the given ID.
228   Standard_EXPORT virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
229
230   //! Sets the settings for a single Z layer of specified view.
231   Standard_EXPORT virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
232                                                   const Graphic3d_ZLayerSettings& theSettings) Standard_OVERRIDE;
233
234   //! Returns pointer to an assigned framebuffer object.
235   Standard_EXPORT virtual Handle(Standard_Transient) FBO() const Standard_OVERRIDE;
236
237   //! Sets framebuffer object for offscreen rendering.
238   Standard_EXPORT virtual void SetFBO (const Handle(Standard_Transient)& theFbo) Standard_OVERRIDE;
239
240   //! Generate offscreen FBO in the graphic library.
241   //! If not supported on hardware returns NULL.
242   Standard_EXPORT virtual Handle(Standard_Transient) FBOCreate (const Standard_Integer theWidth,
243                                                                 const Standard_Integer theHeight) Standard_OVERRIDE;
244
245   //! Remove offscreen FBO from the graphic library
246   Standard_EXPORT virtual void FBORelease (Handle(Standard_Transient)& theFbo) Standard_OVERRIDE;
247
248   //! Read offscreen FBO configuration.
249   Standard_EXPORT virtual void FBOGetDimensions (const Handle(Standard_Transient)& theFbo,
250                                                  Standard_Integer& theWidth,
251                                                  Standard_Integer& theHeight,
252                                                  Standard_Integer& theWidthMax,
253                                                  Standard_Integer& theHeightMax) Standard_OVERRIDE;
254
255   //! Change offscreen FBO viewport.
256   Standard_EXPORT virtual void FBOChangeViewport (const Handle(Standard_Transient)& theFbo,
257                                                   const Standard_Integer theWidth,
258                                                   const Standard_Integer theHeight) Standard_OVERRIDE;
259
260 public:
261
262   //! Returns true if anti-aliasing is enabled for the view.
263   Standard_Boolean virtual IsAntialiasingEnabled() const Standard_OVERRIDE { return myAntiAliasing; }
264
265   //! Enable or disable anti-aliasing in the view.
266   virtual void SetAntialiasingEnabled (const Standard_Boolean theIsEnabled) Standard_OVERRIDE { myAntiAliasing = theIsEnabled; }
267
268   //! Returns background  fill color.
269   Standard_EXPORT virtual Aspect_Background Background() const Standard_OVERRIDE;
270
271   //! Sets background fill color.
272   Standard_EXPORT virtual void SetBackground (const Aspect_Background& theBackground) Standard_OVERRIDE;
273
274   //! Returns gradient background fill colors.
275   Standard_EXPORT virtual Aspect_GradientBackground GradientBackground() const Standard_OVERRIDE;
276
277   //! Sets gradient background fill colors.
278   Standard_EXPORT virtual void SetGradientBackground (const Aspect_GradientBackground& theBackground) Standard_OVERRIDE;
279
280   //! Returns background image texture file path.
281   Standard_EXPORT virtual TCollection_AsciiString BackgroundImage() Standard_OVERRIDE { return myBackgroundImagePath; }
282
283   //! Sets background image texture file path.
284   Standard_EXPORT virtual void SetBackgroundImage (const TCollection_AsciiString& theFilePath) Standard_OVERRIDE;
285
286   //! Returns background image fill style.
287   Standard_EXPORT virtual Aspect_FillMethod BackgroundImageStyle() const Standard_OVERRIDE;
288
289   //! Sets background image fill style.
290   Standard_EXPORT virtual void SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle) Standard_OVERRIDE;
291
292   //! Returns environment texture set for the view.
293   Standard_EXPORT virtual Handle(Graphic3d_TextureEnv) TextureEnv() const Standard_OVERRIDE { return myTextureEnvData; }
294
295   //! Sets environment texture for the view.
296   Standard_EXPORT virtual void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv) Standard_OVERRIDE;
297
298   //! Returns the state of frustum culling optimization.
299   virtual Standard_Boolean IsCullingEnabled() const Standard_OVERRIDE { return myCulling; }
300
301   //! Enables or disables frustum culling optimization.
302   virtual void SetCullingEnabled (const Standard_Boolean theIsEnabled) Standard_OVERRIDE { myCulling = theIsEnabled; }
303
304   //! Returns shading model of the view.
305   virtual Graphic3d_TypeOfShadingModel ShadingModel() const Standard_OVERRIDE { return myShadingModel; }
306
307   //! Sets shading model of the view.
308   virtual void SetShadingModel (const Graphic3d_TypeOfShadingModel theModel) Standard_OVERRIDE { myShadingModel = theModel; }
309
310   //! Return backfacing model used for the view.
311   virtual Graphic3d_TypeOfBackfacingModel BackfacingModel() const Standard_OVERRIDE { return myBackfacing; }
312
313   //! Sets backfacing model for the view.
314   virtual void SetBackfacingModel (const Graphic3d_TypeOfBackfacingModel theModel) Standard_OVERRIDE { myBackfacing = theModel; }
315
316   //! Returns camera object of the view.
317   virtual const Handle(Graphic3d_Camera)& Camera() const Standard_OVERRIDE { return myCamera; }
318
319   //! Sets camera used by the view.
320   virtual void SetCamera (const Handle(Graphic3d_Camera)& theCamera) Standard_OVERRIDE { myCamera = theCamera; }
321
322   //! Returns the activity of back z-clipping plane.
323   virtual Standard_Boolean BackZClippingIsOn() const Standard_OVERRIDE { return myZClip.Back.IsOn; }
324
325   //! Activates the back Z-clipping plane.
326   virtual void SetBackZClippingOn (const Standard_Boolean theIsOn) Standard_OVERRIDE { myZClip.Back.IsOn = theIsOn; }
327
328   //! Returns the definition of the back Z-clipping plane.
329   virtual Standard_Real ZClippingBackPlane() const Standard_OVERRIDE { return myZClip.Back.Limit; }
330
331   //! Sets the definition of the back Z-clipping plane.
332   virtual void SetZClippingBackPlane (const Standard_Real theValue) Standard_OVERRIDE
333   {
334     myZClip.Back.Limit = static_cast<Standard_ShortReal> (theValue);
335   }
336
337   //! Returns the activity of front z-clipping plane.
338   virtual Standard_Boolean FrontZClippingIsOn() const Standard_OVERRIDE { return myZClip.Front.IsOn; }
339
340   //! Activates the front Z-clipping plane.
341   virtual void SetFrontZClippingOn (const Standard_Boolean theIsOn) Standard_OVERRIDE{ myZClip.Front.IsOn = theIsOn; }
342
343   //! Returns the definition of the front Z-clipping plane.
344   virtual Standard_Real ZClippingFrontPlane() const Standard_OVERRIDE { return myZClip.Front.Limit; }
345
346   //! Sets the definition of the front Z-clipping plane.
347   virtual void SetZClippingFrontPlane (const Standard_Real theValue) Standard_OVERRIDE
348   {
349     myZClip.Front.Limit = static_cast<Standard_ShortReal> (theValue);
350   }
351
352   //! Returns the activity of depth cueing.
353   virtual Standard_Boolean DepthCueingIsOn() const Standard_OVERRIDE { return myFog.IsOn; }
354
355   //! Sets the activity of depth cueing.
356   virtual void SetDepthCueingOn (const Standard_Boolean theIsOn) Standard_OVERRIDE { myFog.IsOn = theIsOn; }
357
358   //! Returns the back depth cueing plane.
359   virtual Standard_Real DepthCueingBackPlane() const Standard_OVERRIDE { return myFog.Back; }
360
361   //! Set the back depth cueing plane.
362   virtual void SetDepthCueingBackPlane (const Standard_Real theValue) Standard_OVERRIDE
363   {
364     myFog.Back = static_cast<Standard_ShortReal> (theValue);
365   }
366
367   //! Returns the front depth cueing plane.
368   virtual Standard_Real DepthCueingFrontPlane() const Standard_OVERRIDE { return myFog.Front; }
369
370   //! Set the front depth cueing plane.
371   virtual void SetDepthCueingFrontPlane (const Standard_Real theValue) Standard_OVERRIDE
372   {
373     myFog.Front = static_cast<Standard_ShortReal> (theValue);
374   }
375
376   //! Returns true if GL lighting is enabled.
377   virtual Standard_Boolean IsGLLightEnabled() const Standard_OVERRIDE { return myUseGLLight; }
378
379   //! Sets GL lighting enabled or disable state.
380   virtual void SetGLLightEnabled (const Standard_Boolean theIsEnabled) Standard_OVERRIDE { myUseGLLight = theIsEnabled; }
381
382   //! Returns list of lights of the view.
383   virtual const Graphic3d_ListOfCLight& Lights() const Standard_OVERRIDE { return myLights; }
384
385   //! Sets list of lights for the view.
386   virtual void SetLights (const Graphic3d_ListOfCLight& theLights) Standard_OVERRIDE
387   {
388     myLights = theLights;
389     myCurrLightSourceState = myStateCounter->Increment();
390   }
391
392   //! Returns list of clip planes set for the view.
393   virtual const Graphic3d_SequenceOfHClipPlane& ClipPlanes() const Standard_OVERRIDE { return myClipPlanes; }
394
395   //! Sets list of clip planes for the view.
396   virtual void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes) Standard_OVERRIDE { myClipPlanes = thePlanes; }
397
398 public:
399
400   //! Returns background color.
401   const TEL_COLOUR& BackgroundColor() const { return myBgColor; }
402
403   //! Change trihedron.
404   OpenGl_Trihedron& ChangeTrihedron() { return myTrihedron; }
405
406   //! Change graduated trihedron.
407   OpenGl_GraduatedTrihedron& ChangeGraduatedTrihedron() { return myGraduatedTrihedron; }
408
409   void SetTextureEnv (const Handle(OpenGl_Context)&       theCtx,
410                       const Handle(Graphic3d_TextureEnv)& theTexture);
411
412   //! Returns height of view volume.
413   Standard_Real Height () const { return myCamera->ViewDimensions().X(); }
414
415   //! Returns width of view volume.
416   Standard_Real Width () const { return myCamera->ViewDimensions().Y(); }
417
418   void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle);
419
420   void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType);
421
422   void SetBackgroundGradientType (const Aspect_GradientFillMethod AType);
423
424   //! Returns list of OpenGL Z-layers.
425   const OpenGl_LayerList& LayerList() const { return myZLayers; }
426
427   //! Returns list of openGL light sources.
428   const OpenGl_ListOfLight& LightList() const { return myLights; }
429
430   //! Returns OpenGL window implementation.
431   const Handle(OpenGl_Window) GlWindow() const { return myWindow; }
432
433   //! Returns OpenGL environment map.
434   const Handle(OpenGl_Texture)& GlTextureEnv() const { return myTextureEnv; }
435
436   //! Returns selector for BVH tree, providing a possibility to store information
437   //! about current view volume and to detect which objects are overlapping it.
438   OpenGl_BVHTreeSelector& BVHTreeSelector() { return myBVHSelector; }
439
440   //! Returns true if there are immediate structures to display
441   bool HasImmediateStructures() const
442   {
443     return myZLayers.NbImmediateStructures() != 0;
444   }
445
446 protected: //! @name Internal methods for managing GL resources
447
448   //! Initializes OpenGl resource for environment texture.
449   void initTextureEnv (const Handle(OpenGl_Context)& theContext);
450
451 protected: //! @name low-level redrawing sub-routines
452
453   //! Redraws view for the given monographic camera projection, or left/right eye.
454   Standard_EXPORT virtual void redraw (const Graphic3d_Camera::Projection theProjection,
455                                        OpenGl_FrameBuffer*                theReadDrawFbo);
456
457   //! Redraws view for the given monographic camera projection, or left/right eye.
458   //!
459   //! Method will blit snapshot containing main scene (myMainSceneFbos or BackBuffer)
460   //! into presentation buffer (myMainSceneFbos -> offscreen FBO or
461   //! myMainSceneFbos -> BackBuffer or BackBuffer -> FrontBuffer),
462   //! and redraw immediate structures on top.
463   //!
464   //! When scene caching is disabled (myTransientDrawToFront, no double buffer in window, etc.),
465   //! the first step (blitting) will be skipped.
466   //!
467   //! @return false if immediate structures has been rendered directly into FrontBuffer
468   //! and Buffer Swap should not be called.
469   Standard_EXPORT virtual bool redrawImmediate (const Graphic3d_Camera::Projection theProjection,
470                                                 OpenGl_FrameBuffer* theReadFbo,
471                                                 OpenGl_FrameBuffer* theDrawFbo,
472                                                 const Standard_Boolean theIsPartialUpdate = Standard_False);
473
474   //! Blit image from/to specified buffers.
475   Standard_EXPORT bool blitBuffers (OpenGl_FrameBuffer*    theReadFbo,
476                                     OpenGl_FrameBuffer*    theDrawFbo,
477                                     const Standard_Boolean theToFlip = Standard_False);
478
479   //! Setup default FBO.
480   Standard_EXPORT void bindDefaultFbo (OpenGl_FrameBuffer* theCustomFbo = NULL);
481
482 protected: //! @name Rendering of GL graphics (with prepared drawing buffer).
483
484   //! Renders the graphical contents of the view into the preprepared window or framebuffer.
485   //! @param theProjection [in] the projection that should be used for rendering.
486   //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
487   //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
488   Standard_EXPORT virtual void render (Graphic3d_Camera::Projection theProjection,
489                                        OpenGl_FrameBuffer*          theReadDrawFbo,
490                                        const Standard_Boolean       theToDrawImmediate);
491
492   //! Renders the graphical scene.
493   //! @param theProjection [in] the projection that is used for rendering.
494   //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
495   //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
496   Standard_EXPORT virtual void renderScene (Graphic3d_Camera::Projection theProjection,
497                                             OpenGl_FrameBuffer*    theReadDrawFbo,
498                                             const Standard_Boolean theToDrawImmediate);
499
500   //! Draw background (gradient / image)
501   Standard_EXPORT virtual void drawBackground (const Handle(OpenGl_Workspace)& theWorkspace);
502
503   //! Render set of structures presented in the view.
504   //! @param theProjection [in] the projection that is used for rendering.
505   //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
506   //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
507   Standard_EXPORT virtual void renderStructs (Graphic3d_Camera::Projection theProjection,
508                                               OpenGl_FrameBuffer*    theReadDrawFbo,
509                                               const Standard_Boolean theToDrawImmediate);
510
511   //! Renders trihedron.
512   void renderTrihedron (const Handle(OpenGl_Workspace) &theWorkspace);
513
514 private:
515
516   //! Adds the structure to display lists of the view.
517   Standard_EXPORT virtual void displayStructure (const Handle(Graphic3d_CStructure)& theStructure,
518                                                  const Standard_Integer thePriority) Standard_OVERRIDE;
519
520   //! Erases the structure from display lists of the view.
521   Standard_EXPORT virtual void eraseStructure (const Handle(Graphic3d_CStructure)& theStructure) Standard_OVERRIDE;
522
523   //! Change Z layer of a structure already presented in view.
524   Standard_EXPORT virtual void changeZLayer (const Handle(Graphic3d_CStructure)& theCStructure,
525                                              const Graphic3d_ZLayerId theNewLayerId) Standard_OVERRIDE;
526
527   //! Changes the priority of a structure within its Z layer in the specified view.
528   Standard_EXPORT virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure,
529                                                const Standard_Integer theNewPriority) Standard_OVERRIDE;
530
531 private:
532
533   //! Copy content of Back buffer to the Front buffer.
534   void copyBackToFront();
535
536   //! Initialize blit quad.
537   OpenGl_VertexBuffer* initBlitQuad (const Standard_Boolean theToFlip);
538
539   //! Blend together views pair into stereo image.
540   void drawStereoPair (OpenGl_FrameBuffer* theDrawFbo);
541
542 protected:
543
544   OpenGl_GraphicDriver*    myDriver;
545   Handle(OpenGl_Window)    myWindow;
546   Handle(OpenGl_Workspace) myWorkspace;
547   Handle(OpenGl_Caps)      myCaps;
548   Standard_Boolean&        myDeviceLostFlag;
549   Standard_Boolean         myWasRedrawnGL;
550
551   Standard_Boolean                myAntiAliasing;
552   Standard_Boolean                myCulling;
553   Graphic3d_TypeOfShadingModel    myShadingModel;
554   Graphic3d_TypeOfBackfacingModel myBackfacing;
555   TEL_COLOUR                      myBgColor;
556   OPENGL_FOG                      myFog;
557   OPENGL_ZCLIP                    myZClip;
558   Graphic3d_SequenceOfHClipPlane  myClipPlanes;
559   Handle(Graphic3d_Camera)        myCamera;
560   Handle(OpenGl_FrameBuffer)      myFBO;
561   Standard_Boolean                myUseGLLight;
562   Standard_Boolean                myToShowTrihedron;
563   Standard_Boolean                myToShowGradTrihedron;
564   TCollection_AsciiString         myBackgroundImagePath;
565   Handle(Graphic3d_TextureEnv)    myTextureEnvData;
566   Graphic3d_GraduatedTrihedron    myGTrihedronData;
567
568   OpenGl_ListOfLight              myLights;
569   OpenGl_LayerList                myZLayers; //!< main list of displayed structure, sorted by layers
570
571   Graphic3d_WorldViewProjState    myWorldViewProjState; //!< camera modification state
572   OpenGl_StateCounter*            myStateCounter;
573   Standard_Size                   myCurrLightSourceState;
574
575   typedef std::pair<Standard_Size, Standard_Size> StateInfo;
576
577   StateInfo myLastOrientationState;
578   StateInfo myLastViewMappingState;
579   StateInfo myLastLightSourceState;
580
581   //! Is needed for selection of overlapping objects and storage of the current view volume
582   OpenGl_BVHTreeSelector myBVHSelector;
583
584   OpenGl_Trihedron          myTrihedron;
585   OpenGl_GraduatedTrihedron myGraduatedTrihedron;
586
587   Handle(OpenGl_Texture) myTextureEnv;
588
589 protected: //! @name Rendering properties
590
591   //! Two framebuffers (left and right views) store cached main presentation
592   //! of the view (without presentation of immediate layers).
593   GLint                      myFboColorFormat;        //!< sized format for color attachments
594   GLint                      myFboDepthFormat;        //!< sized format for depth-stencil attachments
595   Handle(OpenGl_FrameBuffer) myMainSceneFbos[2];
596   Handle(OpenGl_FrameBuffer) myImmediateSceneFbos[2]; //!< Additional buffers for immediate layer in stereo mode.
597   OpenGl_VertexBuffer        myFullScreenQuad;        //!< Vertices for full-screen quad rendering.
598   OpenGl_VertexBuffer        myFullScreenQuadFlip;
599   Standard_Boolean           myToFlipOutput;          //!< Flag to draw result image upside-down
600   unsigned int               myFrameCounter;          //!< redraw counter, for debugging
601   Standard_Boolean           myHasFboBlit;
602   Standard_Boolean           myTransientDrawToFront; //!< optimization flag for immediate mode (to render directly to the front buffer)
603   Standard_Boolean           myBackBufferRestored;
604   Standard_Boolean           myIsImmediateDrawn;     //!< flag indicates that immediate mode buffer contains some data
605
606 protected: //! @name Background parameters
607
608   OpenGl_AspectFace*      myTextureParams;   //!< Stores texture and its parameters for textured background
609   OpenGl_BackgroundArray* myBgGradientArray; //!< Primitive array for gradient background
610   OpenGl_BackgroundArray* myBgTextureArray;  //!< Primitive array for texture  background
611
612 protected: //! @name data types related to ray-tracing
613
614   //! Result of OpenGL shaders initialization.
615   enum RaytraceInitStatus
616   {
617     OpenGl_RT_NONE,
618     OpenGl_RT_INIT,
619     OpenGl_RT_FAIL
620   };
621
622   //! Describes update mode (state).
623   enum RaytraceUpdateMode
624   {
625     OpenGl_GUM_CHECK,   //!< check geometry state
626     OpenGl_GUM_PREPARE, //!< collect unchanged objects
627     OpenGl_GUM_REBUILD  //!< rebuild changed and new objects
628   };
629
630   //! Defines frequently used shader variables.
631   enum ShaderVariableIndex
632   {
633     OpenGl_RT_aPosition,
634
635     // camera position
636     OpenGl_RT_uOriginLT,
637     OpenGl_RT_uOriginLB,
638     OpenGl_RT_uOriginRT,
639     OpenGl_RT_uOriginRB,
640     OpenGl_RT_uDirectLT,
641     OpenGl_RT_uDirectLB,
642     OpenGl_RT_uDirectRT,
643     OpenGl_RT_uDirectRB,
644     OpenGl_RT_uViewMat,
645     OpenGl_RT_uUnviewMat,
646
647     // 3D scene params
648     OpenGl_RT_uSceneRad,
649     OpenGl_RT_uSceneEps,
650     OpenGl_RT_uLightAmbnt,
651     OpenGl_RT_uLightCount,
652
653     // background params
654     OpenGl_RT_uBackColorTop,
655     OpenGl_RT_uBackColorBot,
656
657     // ray-tracing params
658     OpenGl_RT_uShadowsEnabled,
659     OpenGl_RT_uReflectEnabled,
660     OpenGl_RT_uSphereMapEnabled,
661     OpenGl_RT_uSphereMapForBack,
662     OpenGl_RT_uTexSamplersArray,
663     OpenGl_RT_uBlockedRngEnabled,
664
665     // sampled frame params
666     OpenGl_RT_uSampleWeight,
667     OpenGl_RT_uFrameRndSeed,
668
669     // adaptive FSAA params
670     OpenGl_RT_uOffsetX,
671     OpenGl_RT_uOffsetY,
672     OpenGl_RT_uSamples,
673
674     OpenGl_RT_NbVariables // special field
675   };
676
677   //! Defines texture samplers.
678   enum ShaderSamplerNames
679   {
680     OpenGl_RT_SceneNodeInfoTexture  = 0,
681     OpenGl_RT_SceneMinPointTexture  = 1,
682     OpenGl_RT_SceneMaxPointTexture  = 2,
683     OpenGl_RT_SceneTransformTexture = 3,
684
685     OpenGl_RT_GeometryVertexTexture = 4,
686     OpenGl_RT_GeometryNormalTexture = 5,
687     OpenGl_RT_GeometryTexCrdTexture = 6,
688     OpenGl_RT_GeometryTriangTexture = 7,
689
690     OpenGl_RT_EnvironmentMapTexture = 8,
691
692     OpenGl_RT_RaytraceMaterialTexture = 9,
693     OpenGl_RT_RaytraceLightSrcTexture = 10,
694
695     OpenGl_RT_FsaaInputTexture = 11,
696     OpenGl_RT_PrevAccumTexture = 12,
697     OpenGl_RT_DepthTexture = 13,
698
699     OpenGl_RT_OpenGlColorTexture = 14,
700     OpenGl_RT_OpenGlDepthTexture = 15
701   };
702
703   //! Tool class for management of shader sources.
704   class ShaderSource
705   {
706   public:
707
708     //! Default shader prefix - empty string.
709     static const TCollection_AsciiString EMPTY_PREFIX;
710
711     //! Creates new uninitialized shader source.
712     ShaderSource()
713     {
714       //
715     }
716
717   public:
718
719     //! Returns error description in case of load fail.
720     const TCollection_AsciiString& ErrorDescription() const
721     {
722       return myError;
723     }
724
725     //! Returns prefix to insert before the source.
726     const TCollection_AsciiString& Prefix() const
727     {
728       return myPrefix;
729     }
730
731     //! Sets prefix to insert before the source.
732     void SetPrefix (const TCollection_AsciiString& thePrefix)
733     {
734       myPrefix = thePrefix;
735     }
736
737     //! Returns shader source combined with prefix.
738     TCollection_AsciiString Source() const;
739
740     //! Loads shader source from specified files.
741     Standard_Boolean Load (const TCollection_AsciiString* theFileNames, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX);
742
743   private:
744
745     TCollection_AsciiString mySource; //!< Source string of the shader object
746     TCollection_AsciiString myPrefix; //!< Prefix to insert before the source
747     TCollection_AsciiString myError;  //!< error state
748
749   };
750
751   //! Default ray-tracing depth.
752   static const Standard_Integer THE_DEFAULT_NB_BOUNCES = 3;
753
754   //! Default size of traversal stack.
755   static const Standard_Integer THE_DEFAULT_STACK_SIZE = 24;
756
757   //! Compile-time ray-tracing parameters.
758   struct RaytracingParams
759   {
760     //! Actual size of traversal stack in shader program.
761     Standard_Integer StackSize;
762
763     //! Actual ray-tracing depth (number of ray bounces).
764     Standard_Integer NbBounces;
765
766     //! Enables/disables light propagation through transparent media.
767     Standard_Boolean TransparentShadows;
768
769     //! Enables/disables global illumination (GI) effects.
770     Standard_Boolean GlobalIllumination;
771
772     //! Enables/disables the use of OpenGL bindless textures.
773     Standard_Boolean UseBindlessTextures;
774
775     //! Creates default compile-time ray-tracing parameters.
776     RaytracingParams()
777     : StackSize (THE_DEFAULT_STACK_SIZE),
778       NbBounces (THE_DEFAULT_NB_BOUNCES),
779       TransparentShadows (Standard_False),
780       GlobalIllumination  (Standard_False),
781       UseBindlessTextures (Standard_False)
782     {
783       //
784     }
785   };
786
787   //! Describes state of OpenGL structure.
788   struct StructState
789   {
790     Standard_Size StructureState;
791     Standard_Size InstancedState;
792
793     //! Creates new structure state.
794     StructState (const Standard_Size theStructureState = 0,
795                  const Standard_Size theInstancedState = 0)
796     : StructureState (theStructureState),
797       InstancedState (theInstancedState)
798     {
799       //
800     }
801
802     //! Creates new structure state.
803     StructState (const OpenGl_Structure* theStructure)
804     {
805       StructureState = theStructure->ModificationState();
806
807       InstancedState = theStructure->InstancedStructure() != NULL ?
808         theStructure->InstancedStructure()->ModificationState() : 0;
809     }
810   };
811
812 protected: //! @name methods related to ray-tracing
813
814   //! Updates 3D scene geometry for ray-tracing.
815   Standard_Boolean updateRaytraceGeometry (const RaytraceUpdateMode      theMode,
816                                            const Standard_Integer        theViewId,
817                                            const Handle(OpenGl_Context)& theGlContext);
818
819   //! Updates 3D scene light sources for ray-tracing.
820   Standard_Boolean updateRaytraceLightSources (const OpenGl_Mat4& theInvModelView, const Handle(OpenGl_Context)& theGlContext);
821
822   //! Updates environment map for ray-tracing.
823   Standard_Boolean updateRaytraceEnvironmentMap (const Handle(OpenGl_Context)& theGlContext);
824
825   //! Checks to see if the OpenGL structure is modified.
826   Standard_Boolean toUpdateStructure (const OpenGl_Structure* theStructure);
827
828   //! Adds OpenGL structure to ray-traced scene geometry.
829   Standard_Boolean addRaytraceStructure (const OpenGl_Structure*       theStructure,
830                                          const Handle(OpenGl_Context)& theGlContext);
831
832   //! Adds OpenGL groups to ray-traced scene geometry.
833   Standard_Boolean addRaytraceGroups (const OpenGl_Structure*        theStructure,
834                                       const OpenGl_RaytraceMaterial& theStructMat,
835                                       const Graphic3d_Mat4*          theTransform,
836                                       const Handle(OpenGl_Context)&  theGlContext);
837
838   //! Creates ray-tracing material properties.
839   OpenGl_RaytraceMaterial convertMaterial (const OpenGl_AspectFace*      theAspect,
840                                            const Handle(OpenGl_Context)& theGlContext);
841
842   //! Adds OpenGL primitive array to ray-traced scene geometry.
843   OpenGl_TriangleSet* addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray,
844                                                  const Standard_Integer       theMatID,
845                                                  const OpenGl_Mat4*           theTrans);
846
847   //! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry.
848   Standard_Boolean addRaytraceVertexIndices (OpenGl_TriangleSet&                  theSet,
849                                              const Standard_Integer               theMatID,
850                                              const Standard_Integer               theCount,
851                                              const Standard_Integer               theOffset,
852                                              const OpenGl_PrimitiveArray&         theArray);
853
854   //! Adds OpenGL triangle array to ray-traced scene geometry.
855   Standard_Boolean addRaytraceTriangleArray (OpenGl_TriangleSet&                  theSet,
856                                              const Standard_Integer               theMatID,
857                                              const Standard_Integer               theCount,
858                                              const Standard_Integer               theOffset,
859                                              const Handle(Graphic3d_IndexBuffer)& theIndices);
860
861   //! Adds OpenGL triangle fan array to ray-traced scene geometry.
862   Standard_Boolean addRaytraceTriangleFanArray (OpenGl_TriangleSet&                  theSet,
863                                                 const Standard_Integer               theMatID,
864                                                 const Standard_Integer               theCount,
865                                                 const Standard_Integer               theOffset,
866                                                 const Handle(Graphic3d_IndexBuffer)& theIndices);
867
868   //! Adds OpenGL triangle strip array to ray-traced scene geometry.
869   Standard_Boolean addRaytraceTriangleStripArray (OpenGl_TriangleSet&                  theSet,
870                                                   const Standard_Integer               theMatID,
871                                                   const Standard_Integer               theCount,
872                                                   const Standard_Integer               theOffset,
873                                                   const Handle(Graphic3d_IndexBuffer)& theIndices);
874
875   //! Adds OpenGL quadrangle array to ray-traced scene geometry.
876   Standard_Boolean addRaytraceQuadrangleArray (OpenGl_TriangleSet&                  theSet,
877                                                const Standard_Integer               theMatID,
878                                                const Standard_Integer               theCount,
879                                                const Standard_Integer               theOffset,
880                                                const Handle(Graphic3d_IndexBuffer)& theIndices);
881
882   //! Adds OpenGL quadrangle strip array to ray-traced scene geometry.
883   Standard_Boolean addRaytraceQuadrangleStripArray (OpenGl_TriangleSet&                  theSet,
884                                                     const Standard_Integer               theMatID,
885                                                     const Standard_Integer               theCount,
886                                                     const Standard_Integer               theOffset,
887                                                     const Handle(Graphic3d_IndexBuffer)& theIndices);
888
889   //! Adds OpenGL polygon array to ray-traced scene geometry.
890   Standard_Boolean addRaytracePolygonArray (OpenGl_TriangleSet&                  theSet,
891                                             const Standard_Integer               theMatID,
892                                             const Standard_Integer               theCount,
893                                             const Standard_Integer               theOffset,
894                                             const Handle(Graphic3d_IndexBuffer)& theIndices);
895
896   //! Uploads ray-trace data to the GPU.
897   Standard_Boolean uploadRaytraceData (const Handle(OpenGl_Context)& theGlContext);
898
899   //! Generates shader prefix based on current ray-tracing options.
900   TCollection_AsciiString generateShaderPrefix (const Handle(OpenGl_Context)& theGlContext) const;
901
902   //! Performs safe exit when shaders initialization fails.
903   Standard_Boolean safeFailBack (const TCollection_ExtendedString& theMessage,
904                                  const Handle(OpenGl_Context)&     theGlContext);
905
906   //! Loads and compiles shader object from specified source.
907   Handle(OpenGl_ShaderObject) initShader (const GLenum                  theType,
908                                           const ShaderSource&           theSource,
909                                           const Handle(OpenGl_Context)& theGlContext);
910
911   //! Creates shader program from the given vertex and fragment shaders.
912   Handle(OpenGl_ShaderProgram) initProgram (const Handle(OpenGl_Context)&      theGlContext,
913                                             const Handle(OpenGl_ShaderObject)& theVertShader,
914                                             const Handle(OpenGl_ShaderObject)& theFragShader);
915
916   //! Initializes OpenGL/GLSL shader programs.
917   Standard_Boolean initRaytraceResources (const Handle(OpenGl_Context)& theGlContext);
918
919   //! Releases OpenGL/GLSL shader programs.
920   void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext);
921
922   //! Updates auxiliary OpenGL frame buffers.
923   Standard_Boolean updateRaytraceBuffers (const Standard_Integer        theSizeX,
924                                           const Standard_Integer        theSizeY,
925                                           const Handle(OpenGl_Context)& theGlContext);
926
927   //! Generates viewing rays for corners of screen quad.
928   void updateCamera (const OpenGl_Mat4& theOrientation,
929                      const OpenGl_Mat4& theViewMapping,
930                      OpenGl_Vec3*       theOrigins,
931                      OpenGl_Vec3*       theDirects,
932                      OpenGl_Mat4&       theView,
933                      OpenGl_Mat4&       theUnView);
934
935   //! Binds ray-trace textures to corresponding texture units.
936   void bindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
937
938   //! Unbinds ray-trace textures from corresponding texture unit.
939   void unbindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
940
941   //! Sets uniform state for the given ray-tracing shader program.
942   Standard_Boolean setUniformState (const OpenGl_Vec3*            theOrigins,
943                                     const OpenGl_Vec3*            theDirects,
944                                     const OpenGl_Mat4&            theViewMat,
945                                     const OpenGl_Mat4&            theUnviewMat,
946                                     const Standard_Integer        theProgramId,
947                                     const Handle(OpenGl_Context)& theGlContext);
948
949   //! Runs ray-tracing shader programs.
950   Standard_Boolean runRaytraceShaders (const Standard_Integer        theSizeX,
951                                        const Standard_Integer        theSizeY,
952                                        const OpenGl_Vec3*            theOrigins,
953                                        const OpenGl_Vec3*            theDirects,
954                                        const OpenGl_Mat4&            theViewMat,
955                                        const OpenGl_Mat4&            theUnviewMat,
956                                        Graphic3d_Camera::Projection  theProjection,
957                                        OpenGl_FrameBuffer*           theReadDrawFbo,
958                                        const Handle(OpenGl_Context)& theGlContext);
959
960   //! Redraws the window using OpenGL/GLSL ray-tracing.
961   Standard_Boolean raytrace (const Standard_Integer        theSizeX,
962                              const Standard_Integer        theSizeY,
963                              Graphic3d_Camera::Projection  theProjection,
964                              OpenGl_FrameBuffer*           theReadDrawFbo,
965                              const Handle(OpenGl_Context)& theGlContext);
966
967 protected: //! @name fields related to ray-tracing
968
969   //! Result of shaders initialization.
970   RaytraceInitStatus myRaytraceInitStatus;
971
972   //! Is geometry data valid?
973   Standard_Boolean myIsRaytraceDataValid;
974
975   //! Warning about missing extension GL_ARB_bindless_texture has been displayed?
976   Standard_Boolean myIsRaytraceWarnTextures;
977
978   //! 3D scene geometry data for ray-tracing.
979   OpenGl_RaytraceGeometry myRaytraceGeometry;
980
981   //! Compile-time ray-tracing parameters.
982   RaytracingParams myRaytraceParameters;
983
984   //! Radius of bounding sphere of the scene.
985   Standard_ShortReal myRaytraceSceneRadius;
986   //! Scene epsilon to prevent self-intersections.
987   Standard_ShortReal myRaytraceSceneEpsilon;
988
989   //! OpenGL/GLSL source of ray-tracing fragment shader.
990   ShaderSource myRaytraceShaderSource;
991   //! OpenGL/GLSL source of adaptive-AA fragment shader.
992   ShaderSource myPostFSAAShaderSource;
993
994   //! OpenGL/GLSL ray-tracing fragment shader.
995   Handle(OpenGl_ShaderObject) myRaytraceShader;
996   //! OpenGL/GLSL adaptive-AA fragment shader.
997   Handle(OpenGl_ShaderObject) myPostFSAAShader;
998
999   //! OpenGL/GLSL ray-tracing shader program.
1000   Handle(OpenGl_ShaderProgram) myRaytraceProgram;
1001   //! OpenGL/GLSL adaptive-AA shader program.
1002   Handle(OpenGl_ShaderProgram) myPostFSAAProgram;
1003   //! OpenGL/GLSL program for displaying texture.
1004   Handle(OpenGl_ShaderProgram) myOutImageProgram;
1005
1006   //! Texture buffer of data records of bottom-level BVH nodes.
1007   Handle(OpenGl_TextureBufferArb) mySceneNodeInfoTexture;
1008   //! Texture buffer of minimum points of bottom-level BVH nodes.
1009   Handle(OpenGl_TextureBufferArb) mySceneMinPointTexture;
1010   //! Texture buffer of maximum points of bottom-level BVH nodes.
1011   Handle(OpenGl_TextureBufferArb) mySceneMaxPointTexture;
1012   //! Texture buffer of transformations of high-level BVH nodes.
1013   Handle(OpenGl_TextureBufferArb) mySceneTransformTexture;
1014
1015   //! Texture buffer of vertex coords.
1016   Handle(OpenGl_TextureBufferArb) myGeometryVertexTexture;
1017   //! Texture buffer of vertex normals.
1018   Handle(OpenGl_TextureBufferArb) myGeometryNormalTexture;
1019   //! Texture buffer of vertex UV coords.
1020   Handle(OpenGl_TextureBufferArb) myGeometryTexCrdTexture;
1021   //! Texture buffer of triangle indices.
1022   Handle(OpenGl_TextureBufferArb) myGeometryTriangTexture;
1023
1024   //! Texture buffer of material properties.
1025   Handle(OpenGl_TextureBufferArb) myRaytraceMaterialTexture;
1026   //! Texture buffer of light source properties.
1027   Handle(OpenGl_TextureBufferArb) myRaytraceLightSrcTexture;
1028
1029   //! 1st framebuffer (FBO) to perform adaptive FSAA.
1030   Handle(OpenGl_FrameBuffer) myRaytraceFBO1[2];
1031   //! 2nd framebuffer (FBO) to perform adaptive FSAA.
1032   Handle(OpenGl_FrameBuffer) myRaytraceFBO2[2];
1033   //! Framebuffer (FBO) for preliminary OpenGL output.
1034   Handle(OpenGl_FrameBuffer) myOpenGlFBO;
1035   Handle(OpenGl_FrameBuffer) myOpenGlFBO2;
1036
1037   //! Vertex buffer (VBO) for drawing dummy quad.
1038   OpenGl_VertexBuffer myRaytraceScreenQuad;
1039
1040   //! Cached locations of frequently used uniform variables.
1041   Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables];
1042
1043   //! State of OpenGL structures reflected to ray-tracing.
1044   std::map<const OpenGl_Structure*, StructState> myStructureStates;
1045
1046   //! PrimitiveArray to TriangleSet map for scene partial update.
1047   std::map<Standard_Size, OpenGl_TriangleSet*> myArrayToTrianglesMap;
1048
1049   //! Set of IDs of non-raytracable elements (to detect updates).
1050   std::set<Standard_Integer> myNonRaytraceStructureIDs;
1051
1052   //! Render filter to filter out all raytracable structures.
1053   Handle(OpenGl_RaytraceFilter) myRaytraceFilter;
1054
1055   //! Marks if environment map should be updated.
1056   Standard_Boolean myToUpdateEnvironmentMap;
1057
1058   //! State of OpenGL layer list.
1059   Standard_Size myLayerListState;
1060
1061   //! Number of accumulated frames (for progressive rendering).
1062   Standard_Integer myAccumFrames;
1063
1064   //! Stored ray origins used for detection of camera movements.
1065   OpenGl_Vec3 myPreviousOrigins[3];
1066
1067   //! Bullard RNG to produce random sequence.
1068   math_BullardGenerator myRNG;
1069
1070 public:
1071
1072   DEFINE_STANDARD_ALLOC
1073   DEFINE_STANDARD_RTTIEXT(OpenGl_View,Graphic3d_CView) // Type definition
1074
1075   friend class OpenGl_GraphicDriver;
1076   friend class OpenGl_Workspace;
1077 };
1078
1079 #endif // _OpenGl_View_Header