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