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