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