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