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