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