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