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