File indexing completed on 2025-01-18 10:04:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef OpenGl_View_HeaderFile
0017 #define OpenGl_View_HeaderFile
0018
0019 #include <Graphic3d_CullingTool.hxx>
0020 #include <Graphic3d_WorldViewProjState.hxx>
0021 #include <math_BullardGenerator.hxx>
0022
0023 #include <OpenGl_FrameBuffer.hxx>
0024 #include <OpenGl_FrameStatsPrs.hxx>
0025 #include <OpenGl_GraduatedTrihedron.hxx>
0026 #include <OpenGl_LayerList.hxx>
0027 #include <OpenGl_SceneGeometry.hxx>
0028 #include <OpenGl_Structure.hxx>
0029 #include <OpenGl_TileSampler.hxx>
0030
0031 #include <map>
0032 #include <set>
0033
0034 class OpenGl_BackgroundArray;
0035 class OpenGl_DepthPeeling;
0036 class OpenGl_PBREnvironment;
0037 struct OpenGl_RaytraceMaterial;
0038 class OpenGl_ShadowMap;
0039 class OpenGl_ShadowMapArray;
0040 class OpenGl_ShaderObject;
0041 class OpenGl_TextureBuffer;
0042 class OpenGl_Workspace;
0043
0044 DEFINE_STANDARD_HANDLE(OpenGl_View,Graphic3d_CView)
0045
0046
0047 class OpenGl_View : public Graphic3d_CView
0048 {
0049
0050 public:
0051
0052
0053 Standard_EXPORT OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
0054 const Handle(OpenGl_GraphicDriver)& theDriver,
0055 const Handle(OpenGl_Caps)& theCaps,
0056 OpenGl_StateCounter* theCounter);
0057
0058
0059 Standard_EXPORT virtual ~OpenGl_View();
0060
0061
0062 Standard_EXPORT virtual void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx);
0063
0064
0065 Standard_EXPORT virtual void Remove() Standard_OVERRIDE;
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079 Standard_EXPORT Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer) Standard_OVERRIDE;
0080
0081
0082 Standard_EXPORT virtual void SetWindow (const Handle(Graphic3d_CView)& theParentVIew,
0083 const Handle(Aspect_Window)& theWindow,
0084 const Aspect_RenderingContext theContext) Standard_OVERRIDE;
0085
0086
0087 Standard_EXPORT virtual Handle(Aspect_Window) Window() const Standard_OVERRIDE;
0088
0089
0090 virtual Standard_Boolean IsDefined() const Standard_OVERRIDE
0091 { return !myWindow.IsNull(); }
0092
0093
0094 Standard_EXPORT virtual void Resized() Standard_OVERRIDE;
0095
0096
0097 Standard_EXPORT virtual void Redraw() Standard_OVERRIDE;
0098
0099
0100 Standard_EXPORT virtual void RedrawImmediate() Standard_OVERRIDE;
0101
0102
0103 Standard_EXPORT virtual void Invalidate() Standard_OVERRIDE;
0104
0105
0106 virtual Standard_Boolean IsInvalidated() Standard_OVERRIDE { return !myBackBufferRestored; }
0107
0108
0109
0110
0111 Standard_EXPORT virtual Standard_Boolean BufferDump (Image_PixMap& theImage,
0112 const Graphic3d_BufferType& theBufferType) Standard_OVERRIDE;
0113
0114
0115 Standard_EXPORT virtual void InvalidateBVHData (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
0116
0117
0118
0119
0120
0121 Standard_EXPORT virtual void InsertLayerBefore (const Graphic3d_ZLayerId theLayerId,
0122 const Graphic3d_ZLayerSettings& theSettings,
0123 const Graphic3d_ZLayerId theLayerAfter) Standard_OVERRIDE;
0124
0125
0126
0127
0128
0129 Standard_EXPORT virtual void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
0130 const Graphic3d_ZLayerSettings& theSettings,
0131 const Graphic3d_ZLayerId theLayerBefore) Standard_OVERRIDE;
0132
0133
0134 Standard_EXPORT virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
0135
0136
0137 Standard_EXPORT virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
0138 const Graphic3d_ZLayerSettings& theSettings) Standard_OVERRIDE;
0139
0140
0141
0142 Standard_EXPORT virtual Standard_Integer ZLayerMax() const Standard_OVERRIDE;
0143
0144
0145 Standard_EXPORT virtual const NCollection_List<Handle(Graphic3d_Layer)>& Layers() const Standard_OVERRIDE;
0146
0147
0148 Standard_EXPORT virtual Handle(Graphic3d_Layer) Layer (const Graphic3d_ZLayerId theLayerId) const Standard_OVERRIDE;
0149
0150
0151
0152
0153
0154
0155 Standard_EXPORT virtual Bnd_Box MinMaxValues (const Standard_Boolean theToIncludeAuxiliary) const Standard_OVERRIDE;
0156
0157
0158 Standard_EXPORT virtual Handle(Standard_Transient) FBO() const Standard_OVERRIDE;
0159
0160
0161 Standard_EXPORT virtual void SetFBO (const Handle(Standard_Transient)& theFbo) Standard_OVERRIDE;
0162
0163
0164
0165 Standard_EXPORT virtual Handle(Standard_Transient) FBOCreate (const Standard_Integer theWidth,
0166 const Standard_Integer theHeight) Standard_OVERRIDE;
0167
0168
0169 Standard_EXPORT virtual void FBORelease (Handle(Standard_Transient)& theFbo) Standard_OVERRIDE;
0170
0171
0172 Standard_EXPORT virtual void FBOGetDimensions (const Handle(Standard_Transient)& theFbo,
0173 Standard_Integer& theWidth,
0174 Standard_Integer& theHeight,
0175 Standard_Integer& theWidthMax,
0176 Standard_Integer& theHeightMax) Standard_OVERRIDE;
0177
0178
0179 Standard_EXPORT virtual void FBOChangeViewport (const Handle(Standard_Transient)& theFbo,
0180 const Standard_Integer theWidth,
0181 const Standard_Integer theHeight) Standard_OVERRIDE;
0182
0183
0184 const Handle(OpenGl_DepthPeeling)& DepthPeelingFbos() const { return myDepthPeelingFbos; }
0185
0186 public:
0187
0188
0189 Standard_EXPORT virtual Aspect_GradientBackground GradientBackground() const Standard_OVERRIDE;
0190
0191
0192 Standard_EXPORT virtual void SetGradientBackground (const Aspect_GradientBackground& theBackground) Standard_OVERRIDE;
0193
0194
0195
0196
0197
0198
0199 Standard_EXPORT virtual void SetBackgroundImage (const Handle(Graphic3d_TextureMap)& theTextureMap,
0200 Standard_Boolean theToUpdatePBREnv = Standard_True) Standard_OVERRIDE;
0201
0202
0203 Standard_EXPORT virtual void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv) Standard_OVERRIDE;
0204
0205
0206 Standard_EXPORT virtual Aspect_FillMethod BackgroundImageStyle() const Standard_OVERRIDE;
0207
0208
0209 Standard_EXPORT virtual void SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle) Standard_OVERRIDE;
0210
0211
0212
0213
0214
0215 Standard_EXPORT virtual void SetImageBasedLighting (Standard_Boolean theToEnableIBL) Standard_OVERRIDE;
0216
0217
0218
0219 Standard_EXPORT unsigned int SpecIBLMapLevels() const;
0220
0221
0222 const gp_XYZ& LocalOrigin() const { return myLocalOrigin; }
0223
0224
0225 Standard_EXPORT void SetLocalOrigin (const gp_XYZ& theOrigin);
0226
0227
0228 virtual const Handle(Graphic3d_LightSet)& Lights() const Standard_OVERRIDE { return myLights; }
0229
0230
0231 virtual void SetLights (const Handle(Graphic3d_LightSet)& theLights) Standard_OVERRIDE
0232 {
0233 myLights = theLights;
0234 myCurrLightSourceState = myStateCounter->Increment();
0235 }
0236
0237
0238 virtual const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const Standard_OVERRIDE { return myClipPlanes; }
0239
0240
0241 virtual void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) Standard_OVERRIDE { myClipPlanes = thePlanes; }
0242
0243
0244
0245
0246
0247
0248
0249
0250 Standard_EXPORT virtual void DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
0251 Graphic3d_DiagnosticInfo theFlags) const Standard_OVERRIDE;
0252
0253
0254 Standard_EXPORT virtual TCollection_AsciiString StatisticInformation() const Standard_OVERRIDE;
0255
0256
0257 Standard_EXPORT virtual void StatisticInformation (TColStd_IndexedDataMapOfStringString& theDict) const Standard_OVERRIDE;
0258
0259 public:
0260
0261
0262 const Quantity_ColorRGBA& BackgroundColor() const { return myBgColor; }
0263
0264
0265 OpenGl_GraduatedTrihedron& ChangeGraduatedTrihedron() { return myGraduatedTrihedron; }
0266
0267 void SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
0268 const Handle(Graphic3d_TextureEnv)& theTexture);
0269
0270 void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle);
0271
0272 void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType);
0273
0274 void SetBackgroundGradientType (const Aspect_GradientFillMethod AType);
0275
0276
0277 const OpenGl_LayerList& LayerList() const { return myZLayers; }
0278
0279
0280 const Handle(OpenGl_Window)& GlWindow() const { return myWindow; }
0281
0282
0283 const Handle(OpenGl_TextureSet)& GlTextureEnv() const { return myTextureEnv; }
0284
0285
0286
0287 const Graphic3d_CullingTool& BVHTreeSelector() const { return myBVHSelector; }
0288
0289
0290 bool HasImmediateStructures() const
0291 {
0292 return myZLayers.NbImmediateStructures() != 0;
0293 }
0294
0295 public:
0296
0297
0298 Standard_EXPORT virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) Standard_OVERRIDE;
0299
0300
0301 Standard_EXPORT virtual void GraduatedTrihedronErase() Standard_OVERRIDE;
0302
0303
0304
0305
0306 Standard_EXPORT virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) Standard_OVERRIDE;
0307
0308 protected:
0309
0310
0311 void initTextureEnv (const Handle(OpenGl_Context)& theContext);
0312
0313 protected:
0314
0315
0316 Standard_EXPORT virtual bool prepareFrameBuffers (Graphic3d_Camera::Projection& theProj);
0317
0318
0319 Standard_EXPORT virtual void redraw (const Graphic3d_Camera::Projection theProjection,
0320 OpenGl_FrameBuffer* theReadDrawFbo,
0321 OpenGl_FrameBuffer* theOitAccumFbo);
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335 Standard_EXPORT virtual bool redrawImmediate (const Graphic3d_Camera::Projection theProjection,
0336 OpenGl_FrameBuffer* theReadFbo,
0337 OpenGl_FrameBuffer* theDrawFbo,
0338 OpenGl_FrameBuffer* theOitAccumFbo,
0339 const Standard_Boolean theIsPartialUpdate = Standard_False);
0340
0341
0342 Standard_EXPORT bool blitSubviews (const Graphic3d_Camera::Projection theProjection,
0343 OpenGl_FrameBuffer* theDrawFbo);
0344
0345
0346 Standard_EXPORT bool blitBuffers (OpenGl_FrameBuffer* theReadFbo,
0347 OpenGl_FrameBuffer* theDrawFbo,
0348 const Standard_Boolean theToFlip = Standard_False);
0349
0350
0351 Standard_EXPORT void bindDefaultFbo (OpenGl_FrameBuffer* theCustomFbo = NULL);
0352
0353 protected:
0354
0355
0356
0357 Standard_EXPORT virtual void renderShadowMap (const Handle(OpenGl_ShadowMap)& theShadowMap);
0358
0359
0360
0361
0362
0363
0364 Standard_EXPORT virtual void render (Graphic3d_Camera::Projection theProjection,
0365 OpenGl_FrameBuffer* theReadDrawFbo,
0366 OpenGl_FrameBuffer* theOitAccumFbo,
0367 const Standard_Boolean theToDrawImmediate);
0368
0369
0370
0371
0372
0373
0374 Standard_EXPORT virtual void renderScene (Graphic3d_Camera::Projection theProjection,
0375 OpenGl_FrameBuffer* theReadDrawFbo,
0376 OpenGl_FrameBuffer* theOitAccumFbo,
0377 const Standard_Boolean theToDrawImmediate);
0378
0379
0380 Standard_EXPORT virtual void drawBackground (const Handle(OpenGl_Workspace)& theWorkspace,
0381 Graphic3d_Camera::Projection theProjection);
0382
0383
0384
0385
0386
0387
0388 Standard_EXPORT virtual void renderStructs (Graphic3d_Camera::Projection theProjection,
0389 OpenGl_FrameBuffer* theReadDrawFbo,
0390 OpenGl_FrameBuffer* theOitAccumFbo,
0391 const Standard_Boolean theToDrawImmediate);
0392
0393
0394 void renderTrihedron (const Handle(OpenGl_Workspace) &theWorkspace);
0395
0396
0397 void renderFrameStats();
0398
0399 private:
0400
0401
0402 Standard_EXPORT virtual void displayStructure (const Handle(Graphic3d_CStructure)& theStructure,
0403 const Graphic3d_DisplayPriority thePriority) Standard_OVERRIDE;
0404
0405
0406 Standard_EXPORT virtual void eraseStructure (const Handle(Graphic3d_CStructure)& theStructure) Standard_OVERRIDE;
0407
0408
0409 Standard_EXPORT virtual void changeZLayer (const Handle(Graphic3d_CStructure)& theCStructure,
0410 const Graphic3d_ZLayerId theNewLayerId) Standard_OVERRIDE;
0411
0412
0413 Standard_EXPORT virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure,
0414 const Graphic3d_DisplayPriority theNewPriority) Standard_OVERRIDE;
0415
0416 private:
0417
0418
0419 void releaseSrgbResources (const Handle(OpenGl_Context)& theCtx);
0420
0421
0422 bool copyBackToFront();
0423
0424
0425 OpenGl_VertexBuffer* initBlitQuad (const Standard_Boolean theToFlip);
0426
0427
0428 void drawStereoPair (OpenGl_FrameBuffer* theDrawFbo);
0429
0430
0431 bool checkOitCompatibility (const Handle(OpenGl_Context)& theGlContext,
0432 const Standard_Boolean theMSAA);
0433
0434 protected:
0435
0436 OpenGl_GraphicDriver* myDriver;
0437 Handle(OpenGl_Window) myWindow;
0438 Handle(OpenGl_Workspace) myWorkspace;
0439 Handle(OpenGl_Caps) myCaps;
0440 Standard_Boolean myWasRedrawnGL;
0441
0442 Handle(Graphic3d_SequenceOfHClipPlane) myClipPlanes;
0443 gp_XYZ myLocalOrigin;
0444 Handle(OpenGl_FrameBuffer) myFBO;
0445 Standard_Boolean myToShowGradTrihedron;
0446 Graphic3d_GraduatedTrihedron myGTrihedronData;
0447
0448 Handle(Graphic3d_LightSet) myNoShadingLight;
0449 Handle(Graphic3d_LightSet) myLights;
0450 OpenGl_LayerList myZLayers;
0451
0452 Graphic3d_WorldViewProjState myWorldViewProjState;
0453 OpenGl_StateCounter* myStateCounter;
0454 Standard_Size myCurrLightSourceState;
0455 Standard_Size myLightsRevision;
0456
0457 typedef std::pair<Standard_Size, Standard_Size> StateInfo;
0458
0459 StateInfo myLastOrientationState;
0460 StateInfo myLastViewMappingState;
0461 StateInfo myLastLightSourceState;
0462
0463
0464 Graphic3d_CullingTool myBVHSelector;
0465
0466 OpenGl_GraduatedTrihedron myGraduatedTrihedron;
0467 OpenGl_FrameStatsPrs myFrameStatsPrs;
0468
0469
0470 Handle(OpenGl_FrameBuffer) myOpenGlFBO;
0471 Handle(OpenGl_FrameBuffer) myOpenGlFBO2;
0472
0473 protected:
0474
0475
0476
0477 Standard_Integer mySRgbState;
0478 GLint myFboColorFormat;
0479 GLint myFboDepthFormat;
0480 OpenGl_ColorFormats myFboOitColorConfig;
0481 Handle(OpenGl_FrameBuffer) myMainSceneFbos[2];
0482 Handle(OpenGl_FrameBuffer) myMainSceneFbosOit[2];
0483 Handle(OpenGl_FrameBuffer) myImmediateSceneFbos[2];
0484 Handle(OpenGl_FrameBuffer) myImmediateSceneFbosOit[2];
0485 Handle(OpenGl_FrameBuffer) myXrSceneFbo;
0486 Handle(OpenGl_DepthPeeling) myDepthPeelingFbos;
0487 Handle(OpenGl_ShadowMapArray) myShadowMaps;
0488 OpenGl_VertexBuffer myFullScreenQuad;
0489 OpenGl_VertexBuffer myFullScreenQuadFlip;
0490 Standard_Boolean myToFlipOutput;
0491 unsigned int myFrameCounter;
0492 Standard_Boolean myHasFboBlit;
0493 Standard_Boolean myToDisableOIT;
0494 Standard_Boolean myToDisableOITMSAA;
0495 Standard_Boolean myToDisableMSAA;
0496 Standard_Boolean myTransientDrawToFront;
0497 Standard_Boolean myBackBufferRestored;
0498 Standard_Boolean myIsImmediateDrawn;
0499
0500 protected:
0501
0502 OpenGl_Aspects* myTextureParams;
0503 OpenGl_Aspects* myCubeMapParams;
0504 OpenGl_Aspects* myColoredQuadParams;
0505 OpenGl_BackgroundArray* myBackgrounds[Graphic3d_TypeOfBackground_NB];
0506 Handle(OpenGl_TextureSet) myTextureEnv;
0507 Handle(OpenGl_Texture) mySkydomeTexture;
0508
0509 protected:
0510
0511
0512 Standard_EXPORT void updateSkydomeBg (const Handle(OpenGl_Context)& theCtx);
0513
0514 protected:
0515
0516
0517 Standard_EXPORT Standard_Boolean checkPBRAvailability() const;
0518
0519
0520
0521 Standard_EXPORT void updatePBREnvironment (const Handle(OpenGl_Context)& theCtx);
0522
0523 protected:
0524
0525
0526 enum PBREnvironmentState
0527 {
0528 OpenGl_PBREnvState_NONEXISTENT,
0529 OpenGl_PBREnvState_UNAVAILABLE,
0530 OpenGl_PBREnvState_CREATED
0531 };
0532
0533 Handle(OpenGl_PBREnvironment) myPBREnvironment;
0534 PBREnvironmentState myPBREnvState;
0535 Standard_Boolean myPBREnvRequest;
0536
0537 protected:
0538
0539
0540 enum RaytraceInitStatus
0541 {
0542 OpenGl_RT_NONE,
0543 OpenGl_RT_INIT,
0544 OpenGl_RT_FAIL
0545 };
0546
0547
0548 enum RaytraceUpdateMode
0549 {
0550 OpenGl_GUM_CHECK,
0551 OpenGl_GUM_PREPARE,
0552 OpenGl_GUM_REBUILD
0553 };
0554
0555
0556 enum ShaderVariableIndex
0557 {
0558 OpenGl_RT_aPosition,
0559
0560
0561 OpenGl_RT_uOriginLT,
0562 OpenGl_RT_uOriginLB,
0563 OpenGl_RT_uOriginRT,
0564 OpenGl_RT_uOriginRB,
0565 OpenGl_RT_uDirectLT,
0566 OpenGl_RT_uDirectLB,
0567 OpenGl_RT_uDirectRT,
0568 OpenGl_RT_uDirectRB,
0569 OpenGl_RT_uViewPrMat,
0570 OpenGl_RT_uUnviewMat,
0571
0572
0573 OpenGl_RT_uSceneRad,
0574 OpenGl_RT_uSceneEps,
0575 OpenGl_RT_uLightAmbnt,
0576 OpenGl_RT_uLightCount,
0577
0578
0579 OpenGl_RT_uBackColorTop,
0580 OpenGl_RT_uBackColorBot,
0581
0582
0583 OpenGl_RT_uShadowsEnabled,
0584 OpenGl_RT_uReflectEnabled,
0585 OpenGl_RT_uEnvMapEnabled,
0586 OpenGl_RT_uEnvMapForBack,
0587 OpenGl_RT_uTexSamplersArray,
0588 OpenGl_RT_uBlockedRngEnabled,
0589
0590
0591 OpenGl_RT_uWinSizeX,
0592 OpenGl_RT_uWinSizeY,
0593
0594
0595 OpenGl_RT_uAccumSamples,
0596 OpenGl_RT_uFrameRndSeed,
0597
0598
0599 OpenGl_RT_uFsaaOffset,
0600 OpenGl_RT_uSamples,
0601
0602
0603 OpenGl_RT_uRenderImage,
0604 OpenGl_RT_uTilesImage,
0605 OpenGl_RT_uOffsetImage,
0606 OpenGl_RT_uTileSize,
0607 OpenGl_RT_uVarianceScaleFactor,
0608
0609
0610 OpenGl_RT_uMaxRadiance,
0611
0612 OpenGl_RT_NbVariables
0613 };
0614
0615
0616 enum ShaderImageNames
0617 {
0618 OpenGl_RT_OutputImage = 0,
0619 OpenGl_RT_VisualErrorImage = 1,
0620 OpenGl_RT_TileOffsetsImage = 2,
0621 OpenGl_RT_TileSamplesImage = 3
0622 };
0623
0624
0625 class ShaderSource
0626 {
0627 public:
0628
0629
0630 static const TCollection_AsciiString EMPTY_PREFIX;
0631
0632
0633 ShaderSource()
0634 {
0635
0636 }
0637
0638 public:
0639
0640
0641 const TCollection_AsciiString& ErrorDescription() const
0642 {
0643 return myError;
0644 }
0645
0646
0647 const TCollection_AsciiString& Prefix() const
0648 {
0649 return myPrefix;
0650 }
0651
0652
0653 void SetPrefix (const TCollection_AsciiString& thePrefix)
0654 {
0655 myPrefix = thePrefix;
0656 }
0657
0658
0659 TCollection_AsciiString Source (const Handle(OpenGl_Context)& theCtx,
0660 const GLenum theType) const;
0661
0662
0663 Standard_Boolean LoadFromFiles (const TCollection_AsciiString* theFileNames, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX);
0664
0665
0666 Standard_Boolean LoadFromStrings (const TCollection_AsciiString* theStrings, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX);
0667
0668 private:
0669
0670 TCollection_AsciiString mySource;
0671 TCollection_AsciiString myPrefix;
0672 TCollection_AsciiString myError;
0673
0674 };
0675
0676
0677 static const Standard_Integer THE_DEFAULT_NB_BOUNCES = 3;
0678
0679
0680 static const Standard_Integer THE_DEFAULT_STACK_SIZE = 10;
0681
0682
0683 struct RaytracingParams
0684 {
0685
0686 Standard_Integer StackSize;
0687
0688
0689 Standard_Integer NbBounces;
0690
0691
0692 Standard_Boolean IsZeroToOneDepth;
0693
0694
0695 Standard_Boolean TransparentShadows;
0696
0697
0698 Standard_Boolean GlobalIllumination;
0699
0700
0701 Standard_Boolean UseBindlessTextures;
0702
0703
0704 Standard_Boolean TwoSidedBsdfModels;
0705
0706
0707 Standard_Boolean AdaptiveScreenSampling;
0708
0709
0710 Standard_Boolean AdaptiveScreenSamplingAtomic;
0711
0712
0713 Standard_Boolean UseEnvMapForBackground;
0714
0715
0716 Standard_Boolean ToIgnoreNormalMap;
0717
0718
0719 Standard_ShortReal RadianceClampingValue;
0720
0721
0722 Standard_Boolean DepthOfField;
0723
0724
0725 Standard_Boolean CubemapForBack;
0726
0727
0728 Graphic3d_ToneMappingMethod ToneMappingMethod;
0729
0730
0731 RaytracingParams()
0732 : StackSize (THE_DEFAULT_STACK_SIZE),
0733 NbBounces (THE_DEFAULT_NB_BOUNCES),
0734 IsZeroToOneDepth (Standard_False),
0735 TransparentShadows (Standard_False),
0736 GlobalIllumination (Standard_False),
0737 UseBindlessTextures (Standard_False),
0738 TwoSidedBsdfModels (Standard_False),
0739 AdaptiveScreenSampling (Standard_False),
0740 AdaptiveScreenSamplingAtomic (Standard_False),
0741 UseEnvMapForBackground (Standard_False),
0742 ToIgnoreNormalMap (Standard_False),
0743 RadianceClampingValue (30.0),
0744 DepthOfField (Standard_False),
0745 CubemapForBack (Standard_False),
0746 ToneMappingMethod (Graphic3d_ToneMappingMethod_Disabled) { }
0747 };
0748
0749
0750 struct StructState
0751 {
0752 Standard_Size StructureState;
0753 Standard_Size InstancedState;
0754
0755
0756 StructState (const Standard_Size theStructureState = 0,
0757 const Standard_Size theInstancedState = 0)
0758 : StructureState (theStructureState),
0759 InstancedState (theInstancedState)
0760 {
0761
0762 }
0763
0764
0765 StructState (const OpenGl_Structure* theStructure)
0766 {
0767 StructureState = theStructure->ModificationState();
0768
0769 InstancedState = theStructure->InstancedStructure() != NULL ?
0770 theStructure->InstancedStructure()->ModificationState() : 0;
0771 }
0772 };
0773
0774 protected:
0775
0776
0777 Standard_Boolean updateRaytraceGeometry (const RaytraceUpdateMode theMode,
0778 const Standard_Integer theViewId,
0779 const Handle(OpenGl_Context)& theGlContext);
0780
0781
0782 Standard_Boolean updateRaytraceLightSources (const OpenGl_Mat4& theInvModelView, const Handle(OpenGl_Context)& theGlContext);
0783
0784
0785 Standard_Boolean toUpdateStructure (const OpenGl_Structure* theStructure);
0786
0787
0788 Standard_Boolean addRaytraceStructure (const OpenGl_Structure* theStructure,
0789 const Handle(OpenGl_Context)& theGlContext);
0790
0791
0792 Standard_Boolean addRaytraceGroups (const OpenGl_Structure* theStructure,
0793 const OpenGl_RaytraceMaterial& theStructMat,
0794 const Handle(TopLoc_Datum3D)& theTrsf,
0795 const Handle(OpenGl_Context)& theGlContext);
0796
0797
0798 OpenGl_RaytraceMaterial convertMaterial (const OpenGl_Aspects* theAspect,
0799 const Handle(OpenGl_Context)& theGlContext);
0800
0801
0802 Handle(OpenGl_TriangleSet) addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray,
0803 const Standard_Integer theMatID,
0804 const OpenGl_Mat4* theTrans);
0805
0806
0807 Standard_Boolean addRaytraceVertexIndices (OpenGl_TriangleSet& theSet,
0808 const Standard_Integer theMatID,
0809 const Standard_Integer theCount,
0810 const Standard_Integer theOffset,
0811 const OpenGl_PrimitiveArray& theArray);
0812
0813
0814 Standard_Boolean addRaytraceTriangleArray (OpenGl_TriangleSet& theSet,
0815 const Standard_Integer theMatID,
0816 const Standard_Integer theCount,
0817 const Standard_Integer theOffset,
0818 const Handle(Graphic3d_IndexBuffer)& theIndices);
0819
0820
0821 Standard_Boolean addRaytraceTriangleFanArray (OpenGl_TriangleSet& theSet,
0822 const Standard_Integer theMatID,
0823 const Standard_Integer theCount,
0824 const Standard_Integer theOffset,
0825 const Handle(Graphic3d_IndexBuffer)& theIndices);
0826
0827
0828 Standard_Boolean addRaytraceTriangleStripArray (OpenGl_TriangleSet& theSet,
0829 const Standard_Integer theMatID,
0830 const Standard_Integer theCount,
0831 const Standard_Integer theOffset,
0832 const Handle(Graphic3d_IndexBuffer)& theIndices);
0833
0834
0835 Standard_Boolean addRaytraceQuadrangleArray (OpenGl_TriangleSet& theSet,
0836 const Standard_Integer theMatID,
0837 const Standard_Integer theCount,
0838 const Standard_Integer theOffset,
0839 const Handle(Graphic3d_IndexBuffer)& theIndices);
0840
0841
0842 Standard_Boolean addRaytraceQuadrangleStripArray (OpenGl_TriangleSet& theSet,
0843 const Standard_Integer theMatID,
0844 const Standard_Integer theCount,
0845 const Standard_Integer theOffset,
0846 const Handle(Graphic3d_IndexBuffer)& theIndices);
0847
0848
0849 Standard_Boolean addRaytracePolygonArray (OpenGl_TriangleSet& theSet,
0850 const Standard_Integer theMatID,
0851 const Standard_Integer theCount,
0852 const Standard_Integer theOffset,
0853 const Handle(Graphic3d_IndexBuffer)& theIndices);
0854
0855
0856 Standard_Boolean uploadRaytraceData (const Handle(OpenGl_Context)& theGlContext);
0857
0858
0859 TCollection_AsciiString generateShaderPrefix (const Handle(OpenGl_Context)& theGlContext) const;
0860
0861
0862 Standard_Boolean safeFailBack (const TCollection_ExtendedString& theMessage,
0863 const Handle(OpenGl_Context)& theGlContext);
0864
0865
0866 Handle(OpenGl_ShaderObject) initShader (const GLenum theType,
0867 const ShaderSource& theSource,
0868 const Handle(OpenGl_Context)& theGlContext);
0869
0870
0871 Handle(OpenGl_ShaderProgram) initProgram (const Handle(OpenGl_Context)& theGlContext,
0872 const Handle(OpenGl_ShaderObject)& theVertShader,
0873 const Handle(OpenGl_ShaderObject)& theFragShader,
0874 const TCollection_AsciiString& theName);
0875
0876
0877 Standard_Boolean initRaytraceResources (const Standard_Integer theSizeX,
0878 const Standard_Integer theSizeY,
0879 const Handle(OpenGl_Context)& theGlContext);
0880
0881
0882 void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext,
0883 const Standard_Boolean theToRebuild = Standard_False);
0884
0885
0886 Standard_Boolean updateRaytraceBuffers (const Standard_Integer theSizeX,
0887 const Standard_Integer theSizeY,
0888 const Handle(OpenGl_Context)& theGlContext);
0889
0890
0891
0892 void updateCamera (const OpenGl_Mat4& theOrientation,
0893 const OpenGl_Mat4& theViewMapping,
0894 OpenGl_Vec3* theOrigins,
0895 OpenGl_Vec3* theDirects,
0896 OpenGl_Mat4& theView,
0897 OpenGl_Mat4& theUnView);
0898
0899
0900 void updatePerspCameraPT(const OpenGl_Mat4& theOrientation,
0901 const OpenGl_Mat4& theViewMapping,
0902 Graphic3d_Camera::Projection theProjection,
0903 OpenGl_Mat4& theViewPr,
0904 OpenGl_Mat4& theUnview,
0905 const int theWinSizeX,
0906 const int theWinSizeY);
0907
0908
0909 void bindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext,
0910 int theStereoView);
0911
0912
0913 void unbindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
0914
0915
0916 Standard_Boolean setUniformState (const Standard_Integer theProgramId,
0917 const Standard_Integer theSizeX,
0918 const Standard_Integer theSizeY,
0919 Graphic3d_Camera::Projection theProjection,
0920 const Handle(OpenGl_Context)& theGlContext);
0921
0922
0923 Standard_Boolean runRaytraceShaders (const Standard_Integer theSizeX,
0924 const Standard_Integer theSizeY,
0925 Graphic3d_Camera::Projection theProjection,
0926 OpenGl_FrameBuffer* theReadDrawFbo,
0927 const Handle(OpenGl_Context)& theGlContext);
0928
0929
0930 Standard_Boolean runRaytrace (const Standard_Integer theSizeX,
0931 const Standard_Integer theSizeY,
0932 Graphic3d_Camera::Projection theProjection,
0933 OpenGl_FrameBuffer* theReadDrawFbo,
0934 const Handle(OpenGl_Context)& theGlContext);
0935
0936
0937 Standard_Boolean runPathtrace (const Standard_Integer theSizeX,
0938 const Standard_Integer theSizeY,
0939 Graphic3d_Camera::Projection theProjection,
0940 const Handle(OpenGl_Context)& theGlContext);
0941
0942
0943 Standard_Boolean runPathtraceOut (Graphic3d_Camera::Projection theProjection,
0944 OpenGl_FrameBuffer* theReadDrawFbo,
0945 const Handle(OpenGl_Context)& theGlContext);
0946
0947
0948 Standard_Boolean raytrace (const Standard_Integer theSizeX,
0949 const Standard_Integer theSizeY,
0950 Graphic3d_Camera::Projection theProjection,
0951 OpenGl_FrameBuffer* theReadDrawFbo,
0952 const Handle(OpenGl_Context)& theGlContext);
0953
0954 protected:
0955
0956
0957 RaytraceInitStatus myRaytraceInitStatus;
0958
0959
0960 Standard_Boolean myIsRaytraceDataValid;
0961
0962
0963 Standard_Boolean myIsRaytraceWarnTextures;
0964
0965
0966 OpenGl_RaytraceGeometry myRaytraceGeometry;
0967
0968
0969 opencascade::handle<BVH_Builder<Standard_ShortReal, 3> > myRaytraceBVHBuilder;
0970
0971
0972 RaytracingParams myRaytraceParameters;
0973
0974
0975 Standard_ShortReal myRaytraceSceneRadius;
0976
0977 Standard_ShortReal myRaytraceSceneEpsilon;
0978
0979
0980 ShaderSource myRaytraceShaderSource;
0981
0982 ShaderSource myPostFSAAShaderSource;
0983
0984 ShaderSource myOutImageShaderSource;
0985
0986
0987 Handle(OpenGl_ShaderObject) myRaytraceShader;
0988
0989 Handle(OpenGl_ShaderObject) myPostFSAAShader;
0990
0991 Handle(OpenGl_ShaderObject) myOutImageShader;
0992
0993
0994 Handle(OpenGl_ShaderProgram) myRaytraceProgram;
0995
0996 Handle(OpenGl_ShaderProgram) myPostFSAAProgram;
0997
0998 Handle(OpenGl_ShaderProgram) myOutImageProgram;
0999
1000
1001 Handle(OpenGl_TextureBuffer) mySceneNodeInfoTexture;
1002
1003 Handle(OpenGl_TextureBuffer) mySceneMinPointTexture;
1004
1005 Handle(OpenGl_TextureBuffer) mySceneMaxPointTexture;
1006
1007 Handle(OpenGl_TextureBuffer) mySceneTransformTexture;
1008
1009
1010 Handle(OpenGl_TextureBuffer) myGeometryVertexTexture;
1011
1012 Handle(OpenGl_TextureBuffer) myGeometryNormalTexture;
1013
1014 Handle(OpenGl_TextureBuffer) myGeometryTexCrdTexture;
1015
1016 Handle(OpenGl_TextureBuffer) myGeometryTriangTexture;
1017
1018
1019 Handle(OpenGl_TextureBuffer) myRaytraceMaterialTexture;
1020
1021 Handle(OpenGl_TextureBuffer) myRaytraceLightSrcTexture;
1022
1023
1024
1025 Handle(OpenGl_FrameBuffer) myRaytraceFBO1[2];
1026
1027
1028 Handle(OpenGl_FrameBuffer) myRaytraceFBO2[2];
1029
1030
1031
1032 Handle(OpenGl_Texture) myRaytraceOutputTexture[2];
1033
1034
1035
1036 Handle(OpenGl_Texture) myRaytraceVisualErrorTexture[2];
1037
1038
1039 Handle(OpenGl_Texture) myRaytraceTileOffsetsTexture[2];
1040
1041
1042 Handle(OpenGl_Texture) myRaytraceTileSamplesTexture[2];
1043
1044
1045 OpenGl_VertexBuffer myRaytraceScreenQuad;
1046
1047
1048 Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables];
1049
1050
1051 std::map<const OpenGl_Structure*, StructState> myStructureStates;
1052
1053
1054 std::map<Standard_Size, OpenGl_TriangleSet*> myArrayToTrianglesMap;
1055
1056
1057 std::set<Standard_Integer> myNonRaytraceStructureIDs;
1058
1059
1060 Standard_Boolean myToUpdateEnvironmentMap;
1061
1062
1063 Standard_Size myRaytraceLayerListState;
1064
1065
1066 Standard_Integer myAccumFrames;
1067
1068
1069 OpenGl_Vec3 myPreviousOrigins[3];
1070
1071
1072 math_BullardGenerator myRNG;
1073
1074
1075 OpenGl_TileSampler myTileSampler;
1076
1077
1078 OpenGl_Vec3 myEyeOrig;
1079
1080
1081 OpenGl_Vec3 myEyeView;
1082
1083
1084 OpenGl_Vec3 myEyeVert;
1085
1086
1087 OpenGl_Vec3 myEyeSide;
1088
1089
1090 OpenGl_Vec2 myEyeSize;
1091
1092
1093 float myPrevCameraApertureRadius;
1094
1095
1096 float myPrevCameraFocalPlaneDist;
1097
1098 public:
1099
1100 DEFINE_STANDARD_ALLOC
1101 DEFINE_STANDARD_RTTIEXT(OpenGl_View,Graphic3d_CView)
1102
1103 friend class OpenGl_GraphicDriver;
1104 friend class OpenGl_Workspace;
1105 friend class OpenGl_LayerList;
1106 friend class OpenGl_FrameStats;
1107 };
1108
1109 #endif