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