0026434: Visualization - Textured objects should have priority over the environment...
[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
568 OpenGl_ListOfLight myLights;
569 OpenGl_LayerList myZLayers; //!< main list of displayed structure, sorted by layers
570
571 Graphic3d_WorldViewProjState myWorldViewProjState; //!< camera modification state
572 OpenGl_StateCounter* myStateCounter;
573 Standard_Size myCurrLightSourceState;
392ac980 574
575 typedef std::pair<Standard_Size, Standard_Size> StateInfo;
576
577 StateInfo myLastOrientationState;
578 StateInfo myLastViewMappingState;
579 StateInfo myLastLightSourceState;
30f0ad28 580
b7cd4ba7 581 //! Is needed for selection of overlapping objects and storage of the current view volume
582 OpenGl_BVHTreeSelector myBVHSelector;
583
c357e426 584 OpenGl_Trihedron myTrihedron;
585 OpenGl_GraduatedTrihedron myGraduatedTrihedron;
586
587 Handle(OpenGl_Texture) myTextureEnv;
588
c357e426 589protected: //! @name Rendering properties
590
591 //! Two framebuffers (left and right views) store cached main presentation
592 //! of the view (without presentation of immediate layers).
3c4b62a4 593 GLint myFboColorFormat; //!< sized format for color attachments
594 GLint myFboDepthFormat; //!< sized format for depth-stencil attachments
c357e426 595 Handle(OpenGl_FrameBuffer) myMainSceneFbos[2];
596 Handle(OpenGl_FrameBuffer) myImmediateSceneFbos[2]; //!< Additional buffers for immediate layer in stereo mode.
597 OpenGl_VertexBuffer myFullScreenQuad; //!< Vertices for full-screen quad rendering.
598 OpenGl_VertexBuffer myFullScreenQuadFlip;
599 Standard_Boolean myToFlipOutput; //!< Flag to draw result image upside-down
600 unsigned int myFrameCounter; //!< redraw counter, for debugging
601 Standard_Boolean myHasFboBlit;
602 Standard_Boolean myTransientDrawToFront; //!< optimization flag for immediate mode (to render directly to the front buffer)
603 Standard_Boolean myBackBufferRestored;
604 Standard_Boolean myIsImmediateDrawn; //!< flag indicates that immediate mode buffer contains some data
605
0b0320e7 606protected: //! @name Background parameters
607
608 OpenGl_AspectFace* myTextureParams; //!< Stores texture and its parameters for textured background
609 OpenGl_BackgroundArray* myBgGradientArray; //!< Primitive array for gradient background
610 OpenGl_BackgroundArray* myBgTextureArray; //!< Primitive array for texture background
611
91c60b57 612protected: //! @name data types related to ray-tracing
613
614 //! Result of OpenGL shaders initialization.
615 enum RaytraceInitStatus
616 {
617 OpenGl_RT_NONE,
618 OpenGl_RT_INIT,
619 OpenGl_RT_FAIL
620 };
621
622 //! Describes update mode (state).
623 enum RaytraceUpdateMode
624 {
625 OpenGl_GUM_CHECK, //!< check geometry state
626 OpenGl_GUM_PREPARE, //!< collect unchanged objects
627 OpenGl_GUM_REBUILD //!< rebuild changed and new objects
628 };
629
630 //! Defines frequently used shader variables.
631 enum ShaderVariableIndex
632 {
633 OpenGl_RT_aPosition,
634
189f85a3 635 // camera position
91c60b57 636 OpenGl_RT_uOriginLT,
637 OpenGl_RT_uOriginLB,
638 OpenGl_RT_uOriginRT,
639 OpenGl_RT_uOriginRB,
640 OpenGl_RT_uDirectLT,
641 OpenGl_RT_uDirectLB,
642 OpenGl_RT_uDirectRT,
643 OpenGl_RT_uDirectRB,
1d865689 644 OpenGl_RT_uViewMat,
91c60b57 645 OpenGl_RT_uUnviewMat,
646
189f85a3 647 // 3D scene params
91c60b57 648 OpenGl_RT_uSceneRad,
649 OpenGl_RT_uSceneEps,
650 OpenGl_RT_uLightAmbnt,
651 OpenGl_RT_uLightCount,
652
189f85a3 653 // background params
654 OpenGl_RT_uBackColorTop,
655 OpenGl_RT_uBackColorBot,
91c60b57 656
189f85a3 657 // ray-tracing params
658 OpenGl_RT_uShadowsEnabled,
659 OpenGl_RT_uReflectEnabled,
660 OpenGl_RT_uSphereMapEnabled,
661 OpenGl_RT_uSphereMapForBack,
662 OpenGl_RT_uTexSamplersArray,
8c820969 663 OpenGl_RT_uBlockedRngEnabled,
189f85a3 664
665 // sampled frame params
666 OpenGl_RT_uSampleWeight,
667 OpenGl_RT_uFrameRndSeed,
668
669 // adaptive FSAA params
91c60b57 670 OpenGl_RT_uOffsetX,
671 OpenGl_RT_uOffsetY,
672 OpenGl_RT_uSamples,
91c60b57 673
674 OpenGl_RT_NbVariables // special field
675 };
676
677 //! Defines texture samplers.
678 enum ShaderSamplerNames
679 {
680 OpenGl_RT_SceneNodeInfoTexture = 0,
681 OpenGl_RT_SceneMinPointTexture = 1,
682 OpenGl_RT_SceneMaxPointTexture = 2,
683 OpenGl_RT_SceneTransformTexture = 3,
684
685 OpenGl_RT_GeometryVertexTexture = 4,
686 OpenGl_RT_GeometryNormalTexture = 5,
687 OpenGl_RT_GeometryTexCrdTexture = 6,
688 OpenGl_RT_GeometryTriangTexture = 7,
689
690 OpenGl_RT_EnvironmentMapTexture = 8,
691
692 OpenGl_RT_RaytraceMaterialTexture = 9,
693 OpenGl_RT_RaytraceLightSrcTexture = 10,
694
189f85a3 695 OpenGl_RT_FsaaInputTexture = 11,
696 OpenGl_RT_PrevAccumTexture = 12,
1d865689 697 OpenGl_RT_DepthTexture = 13,
91c60b57 698
1d865689 699 OpenGl_RT_OpenGlColorTexture = 14,
700 OpenGl_RT_OpenGlDepthTexture = 15
91c60b57 701 };
702
703 //! Tool class for management of shader sources.
704 class ShaderSource
705 {
706 public:
707
189f85a3 708 //! Default shader prefix - empty string.
709 static const TCollection_AsciiString EMPTY_PREFIX;
710
91c60b57 711 //! Creates new uninitialized shader source.
712 ShaderSource()
713 {
714 //
715 }
716
73722cc9 717 public:
189f85a3 718
73722cc9 719 //! Returns error description in case of load fail.
720 const TCollection_AsciiString& ErrorDescription() const
721 {
722 return myError;
91c60b57 723 }
724
91c60b57 725 //! Returns prefix to insert before the source.
726 const TCollection_AsciiString& Prefix() const
727 {
728 return myPrefix;
729 }
730
731 //! Sets prefix to insert before the source.
732 void SetPrefix (const TCollection_AsciiString& thePrefix)
733 {
734 myPrefix = thePrefix;
735 }
736
737 //! Returns shader source combined with prefix.
738 TCollection_AsciiString Source() const;
739
740 //! Loads shader source from specified files.
73722cc9 741 Standard_Boolean Load (const TCollection_AsciiString* theFileNames, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX);
91c60b57 742
743 private:
744
745 TCollection_AsciiString mySource; //!< Source string of the shader object
746 TCollection_AsciiString myPrefix; //!< Prefix to insert before the source
73722cc9 747 TCollection_AsciiString myError; //!< error state
91c60b57 748
749 };
750
751 //! Default ray-tracing depth.
752 static const Standard_Integer THE_DEFAULT_NB_BOUNCES = 3;
753
754 //! Default size of traversal stack.
755 static const Standard_Integer THE_DEFAULT_STACK_SIZE = 24;
756
757 //! Compile-time ray-tracing parameters.
758 struct RaytracingParams
759 {
760 //! Actual size of traversal stack in shader program.
761 Standard_Integer StackSize;
762
763 //! Actual ray-tracing depth (number of ray bounces).
764 Standard_Integer NbBounces;
765
f483f2ed 766 //! Enables/disables light propagation through transparent media.
91c60b57 767 Standard_Boolean TransparentShadows;
768
189f85a3 769 //! Enables/disables global illumination (GI) effects.
770 Standard_Boolean GlobalIllumination;
771
f483f2ed 772 //! Enables/disables the use of OpenGL bindless textures.
773 Standard_Boolean UseBindlessTextures;
774
91c60b57 775 //! Creates default compile-time ray-tracing parameters.
776 RaytracingParams()
777 : StackSize (THE_DEFAULT_STACK_SIZE),
778 NbBounces (THE_DEFAULT_NB_BOUNCES),
f483f2ed 779 TransparentShadows (Standard_False),
189f85a3 780 GlobalIllumination (Standard_False),
f483f2ed 781 UseBindlessTextures (Standard_False)
91c60b57 782 {
783 //
784 }
785 };
786
d4aaad5b 787 //! Describes state of OpenGL structure.
788 struct StructState
789 {
790 Standard_Size StructureState;
791 Standard_Size InstancedState;
792
793 //! Creates new structure state.
794 StructState (const Standard_Size theStructureState = 0,
795 const Standard_Size theInstancedState = 0)
796 : StructureState (theStructureState),
797 InstancedState (theInstancedState)
798 {
799 //
800 }
801
802 //! Creates new structure state.
803 StructState (const OpenGl_Structure* theStructure)
804 {
805 StructureState = theStructure->ModificationState();
806
807 InstancedState = theStructure->InstancedStructure() != NULL ?
808 theStructure->InstancedStructure()->ModificationState() : 0;
809 }
810 };
811
91c60b57 812protected: //! @name methods related to ray-tracing
813
814 //! Updates 3D scene geometry for ray-tracing.
815 Standard_Boolean updateRaytraceGeometry (const RaytraceUpdateMode theMode,
816 const Standard_Integer theViewId,
817 const Handle(OpenGl_Context)& theGlContext);
818
819 //! Updates 3D scene light sources for ray-tracing.
820 Standard_Boolean updateRaytraceLightSources (const OpenGl_Mat4& theInvModelView, const Handle(OpenGl_Context)& theGlContext);
821
822 //! Updates environment map for ray-tracing.
823 Standard_Boolean updateRaytraceEnvironmentMap (const Handle(OpenGl_Context)& theGlContext);
824
825 //! Checks to see if the OpenGL structure is modified.
826 Standard_Boolean toUpdateStructure (const OpenGl_Structure* theStructure);
827
828 //! Adds OpenGL structure to ray-traced scene geometry.
829 Standard_Boolean addRaytraceStructure (const OpenGl_Structure* theStructure,
830 const Handle(OpenGl_Context)& theGlContext);
831
832 //! Adds OpenGL groups to ray-traced scene geometry.
8c820969 833 Standard_Boolean addRaytraceGroups (const OpenGl_Structure* theStructure,
834 const OpenGl_RaytraceMaterial& theStructMat,
6bd94e0d 835 const Graphic3d_Mat4* theTransform,
8c820969 836 const Handle(OpenGl_Context)& theGlContext);
91c60b57 837
838 //! Creates ray-tracing material properties.
839 OpenGl_RaytraceMaterial convertMaterial (const OpenGl_AspectFace* theAspect,
840 const Handle(OpenGl_Context)& theGlContext);
841
842 //! Adds OpenGL primitive array to ray-traced scene geometry.
843 OpenGl_TriangleSet* addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray,
844 const Standard_Integer theMatID,
845 const OpenGl_Mat4* theTrans);
846
847 //! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry.
848 Standard_Boolean addRaytraceVertexIndices (OpenGl_TriangleSet& theSet,
849 const Standard_Integer theMatID,
850 const Standard_Integer theCount,
851 const Standard_Integer theOffset,
852 const OpenGl_PrimitiveArray& theArray);
853
854 //! Adds OpenGL triangle array to ray-traced scene geometry.
855 Standard_Boolean addRaytraceTriangleArray (OpenGl_TriangleSet& theSet,
856 const Standard_Integer theMatID,
857 const Standard_Integer theCount,
858 const Standard_Integer theOffset,
859 const Handle(Graphic3d_IndexBuffer)& theIndices);
860
861 //! Adds OpenGL triangle fan array to ray-traced scene geometry.
862 Standard_Boolean addRaytraceTriangleFanArray (OpenGl_TriangleSet& theSet,
863 const Standard_Integer theMatID,
864 const Standard_Integer theCount,
865 const Standard_Integer theOffset,
866 const Handle(Graphic3d_IndexBuffer)& theIndices);
867
868 //! Adds OpenGL triangle strip array to ray-traced scene geometry.
869 Standard_Boolean addRaytraceTriangleStripArray (OpenGl_TriangleSet& theSet,
870 const Standard_Integer theMatID,
871 const Standard_Integer theCount,
872 const Standard_Integer theOffset,
873 const Handle(Graphic3d_IndexBuffer)& theIndices);
874
875 //! Adds OpenGL quadrangle array to ray-traced scene geometry.
876 Standard_Boolean addRaytraceQuadrangleArray (OpenGl_TriangleSet& theSet,
877 const Standard_Integer theMatID,
878 const Standard_Integer theCount,
879 const Standard_Integer theOffset,
880 const Handle(Graphic3d_IndexBuffer)& theIndices);
881
882 //! Adds OpenGL quadrangle strip array to ray-traced scene geometry.
883 Standard_Boolean addRaytraceQuadrangleStripArray (OpenGl_TriangleSet& theSet,
884 const Standard_Integer theMatID,
885 const Standard_Integer theCount,
886 const Standard_Integer theOffset,
887 const Handle(Graphic3d_IndexBuffer)& theIndices);
888
889 //! Adds OpenGL polygon array to ray-traced scene geometry.
890 Standard_Boolean addRaytracePolygonArray (OpenGl_TriangleSet& theSet,
891 const Standard_Integer theMatID,
892 const Standard_Integer theCount,
893 const Standard_Integer theOffset,
894 const Handle(Graphic3d_IndexBuffer)& theIndices);
895
896 //! Uploads ray-trace data to the GPU.
897 Standard_Boolean uploadRaytraceData (const Handle(OpenGl_Context)& theGlContext);
898
899 //! Generates shader prefix based on current ray-tracing options.
900 TCollection_AsciiString generateShaderPrefix (const Handle(OpenGl_Context)& theGlContext) const;
901
902 //! Performs safe exit when shaders initialization fails.
903 Standard_Boolean safeFailBack (const TCollection_ExtendedString& theMessage,
904 const Handle(OpenGl_Context)& theGlContext);
905
906 //! Loads and compiles shader object from specified source.
907 Handle(OpenGl_ShaderObject) initShader (const GLenum theType,
908 const ShaderSource& theSource,
909 const Handle(OpenGl_Context)& theGlContext);
910
189f85a3 911 //! Creates shader program from the given vertex and fragment shaders.
912 Handle(OpenGl_ShaderProgram) initProgram (const Handle(OpenGl_Context)& theGlContext,
913 const Handle(OpenGl_ShaderObject)& theVertShader,
914 const Handle(OpenGl_ShaderObject)& theFragShader);
915
91c60b57 916 //! Initializes OpenGL/GLSL shader programs.
c357e426 917 Standard_Boolean initRaytraceResources (const Handle(OpenGl_Context)& theGlContext);
91c60b57 918
919 //! Releases OpenGL/GLSL shader programs.
920 void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext);
921
bf02aa7d 922 //! Updates auxiliary OpenGL frame buffers.
923 Standard_Boolean updateRaytraceBuffers (const Standard_Integer theSizeX,
91c60b57 924 const Standard_Integer theSizeY,
925 const Handle(OpenGl_Context)& theGlContext);
926
927 //! Generates viewing rays for corners of screen quad.
928 void updateCamera (const OpenGl_Mat4& theOrientation,
929 const OpenGl_Mat4& theViewMapping,
930 OpenGl_Vec3* theOrigins,
931 OpenGl_Vec3* theDirects,
1d865689 932 OpenGl_Mat4& theView,
91c60b57 933 OpenGl_Mat4& theUnView);
934
935 //! Binds ray-trace textures to corresponding texture units.
936 void bindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
937
938 //! Unbinds ray-trace textures from corresponding texture unit.
939 void unbindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
940
941 //! Sets uniform state for the given ray-tracing shader program.
c357e426 942 Standard_Boolean setUniformState (const OpenGl_Vec3* theOrigins,
91c60b57 943 const OpenGl_Vec3* theDirects,
1d865689 944 const OpenGl_Mat4& theViewMat,
91c60b57 945 const OpenGl_Mat4& theUnviewMat,
946 const Standard_Integer theProgramId,
947 const Handle(OpenGl_Context)& theGlContext);
948
949 //! Runs ray-tracing shader programs.
c357e426 950 Standard_Boolean runRaytraceShaders (const Standard_Integer theSizeX,
91c60b57 951 const Standard_Integer theSizeY,
952 const OpenGl_Vec3* theOrigins,
953 const OpenGl_Vec3* theDirects,
1d865689 954 const OpenGl_Mat4& theViewMat,
91c60b57 955 const OpenGl_Mat4& theUnviewMat,
bf02aa7d 956 Graphic3d_Camera::Projection theProjection,
38a0206f 957 OpenGl_FrameBuffer* theReadDrawFbo,
91c60b57 958 const Handle(OpenGl_Context)& theGlContext);
959
960 //! Redraws the window using OpenGL/GLSL ray-tracing.
c357e426 961 Standard_Boolean raytrace (const Standard_Integer theSizeX,
91c60b57 962 const Standard_Integer theSizeY,
bf02aa7d 963 Graphic3d_Camera::Projection theProjection,
38a0206f 964 OpenGl_FrameBuffer* theReadDrawFbo,
91c60b57 965 const Handle(OpenGl_Context)& theGlContext);
966
967protected: //! @name fields related to ray-tracing
968
969 //! Result of shaders initialization.
970 RaytraceInitStatus myRaytraceInitStatus;
971
972 //! Is geometry data valid?
973 Standard_Boolean myIsRaytraceDataValid;
974
975 //! Warning about missing extension GL_ARB_bindless_texture has been displayed?
976 Standard_Boolean myIsRaytraceWarnTextures;
977
978 //! 3D scene geometry data for ray-tracing.
979 OpenGl_RaytraceGeometry myRaytraceGeometry;
980
981 //! Compile-time ray-tracing parameters.
982 RaytracingParams myRaytraceParameters;
983
984 //! Radius of bounding sphere of the scene.
985 Standard_ShortReal myRaytraceSceneRadius;
986 //! Scene epsilon to prevent self-intersections.
987 Standard_ShortReal myRaytraceSceneEpsilon;
988
989 //! OpenGL/GLSL source of ray-tracing fragment shader.
990 ShaderSource myRaytraceShaderSource;
991 //! OpenGL/GLSL source of adaptive-AA fragment shader.
992 ShaderSource myPostFSAAShaderSource;
993
994 //! OpenGL/GLSL ray-tracing fragment shader.
995 Handle(OpenGl_ShaderObject) myRaytraceShader;
996 //! OpenGL/GLSL adaptive-AA fragment shader.
997 Handle(OpenGl_ShaderObject) myPostFSAAShader;
998
999 //! OpenGL/GLSL ray-tracing shader program.
1000 Handle(OpenGl_ShaderProgram) myRaytraceProgram;
1001 //! OpenGL/GLSL adaptive-AA shader program.
1002 Handle(OpenGl_ShaderProgram) myPostFSAAProgram;
189f85a3 1003 //! OpenGL/GLSL program for displaying texture.
1004 Handle(OpenGl_ShaderProgram) myOutImageProgram;
91c60b57 1005
1006 //! Texture buffer of data records of bottom-level BVH nodes.
1007 Handle(OpenGl_TextureBufferArb) mySceneNodeInfoTexture;
1008 //! Texture buffer of minimum points of bottom-level BVH nodes.
1009 Handle(OpenGl_TextureBufferArb) mySceneMinPointTexture;
1010 //! Texture buffer of maximum points of bottom-level BVH nodes.
1011 Handle(OpenGl_TextureBufferArb) mySceneMaxPointTexture;
1012 //! Texture buffer of transformations of high-level BVH nodes.
1013 Handle(OpenGl_TextureBufferArb) mySceneTransformTexture;
1014
1015 //! Texture buffer of vertex coords.
1016 Handle(OpenGl_TextureBufferArb) myGeometryVertexTexture;
1017 //! Texture buffer of vertex normals.
1018 Handle(OpenGl_TextureBufferArb) myGeometryNormalTexture;
1019 //! Texture buffer of vertex UV coords.
1020 Handle(OpenGl_TextureBufferArb) myGeometryTexCrdTexture;
1021 //! Texture buffer of triangle indices.
1022 Handle(OpenGl_TextureBufferArb) myGeometryTriangTexture;
1023
1024 //! Texture buffer of material properties.
1025 Handle(OpenGl_TextureBufferArb) myRaytraceMaterialTexture;
1026 //! Texture buffer of light source properties.
1027 Handle(OpenGl_TextureBufferArb) myRaytraceLightSrcTexture;
1028
1029 //! 1st framebuffer (FBO) to perform adaptive FSAA.
bf02aa7d 1030 Handle(OpenGl_FrameBuffer) myRaytraceFBO1[2];
91c60b57 1031 //! 2nd framebuffer (FBO) to perform adaptive FSAA.
bf02aa7d 1032 Handle(OpenGl_FrameBuffer) myRaytraceFBO2[2];
91c60b57 1033 //! Framebuffer (FBO) for preliminary OpenGL output.
1034 Handle(OpenGl_FrameBuffer) myOpenGlFBO;
3c4b62a4 1035 Handle(OpenGl_FrameBuffer) myOpenGlFBO2;
91c60b57 1036
1037 //! Vertex buffer (VBO) for drawing dummy quad.
1038 OpenGl_VertexBuffer myRaytraceScreenQuad;
1039
1040 //! Cached locations of frequently used uniform variables.
1041 Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables];
1042
1043 //! State of OpenGL structures reflected to ray-tracing.
d4aaad5b 1044 std::map<const OpenGl_Structure*, StructState> myStructureStates;
91c60b57 1045
1046 //! PrimitiveArray to TriangleSet map for scene partial update.
1047 std::map<Standard_Size, OpenGl_TriangleSet*> myArrayToTrianglesMap;
1048
189f85a3 1049 //! Set of IDs of non-raytracable elements (to detect updates).
1050 std::set<Standard_Integer> myNonRaytraceStructureIDs;
1051
1052 //! Render filter to filter out all raytracable structures.
91c60b57 1053 Handle(OpenGl_RaytraceFilter) myRaytraceFilter;
1054
1055 //! Marks if environment map should be updated.
1056 Standard_Boolean myToUpdateEnvironmentMap;
1057
1058 //! State of OpenGL layer list.
189f85a3 1059 Standard_Size myLayerListState;
1060
1061 //! Number of accumulated frames (for progressive rendering).
1062 Standard_Integer myAccumFrames;
1063
1064 //! Stored ray origins used for detection of camera movements.
1065 OpenGl_Vec3 myPreviousOrigins[3];
1066
1067 //! Bullard RNG to produce random sequence.
1068 math_BullardGenerator myRNG;
91c60b57 1069
679ecdee 1070public:
1071
1c35b92f 1072 DEFINE_STANDARD_ALLOC
92efcf78 1073 DEFINE_STANDARD_RTTIEXT(OpenGl_View,Graphic3d_CView) // Type definition
679ecdee 1074
c357e426 1075 friend class OpenGl_GraphicDriver;
a89742cf 1076 friend class OpenGl_Workspace;
2166f0fa
SK
1077};
1078
679ecdee 1079#endif // _OpenGl_View_Header