Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoQtGLWidget.h
Go to the documentation of this file.
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2023 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : Alain Dumesny (MMM yyyy)
22** Modified by : David Mott (MMM yyyy)
23**=======================================================================*/
24
25
26#ifndef _SO_QT_GLWIDGET_
27#define _SO_QT_GLWIDGET_
28
30
33
36
37#include <Qt>
38
39// FSAA
40typedef std::set<int, std::less<int> > SoSamplesList;
41
42#if !defined(_WIN32)
43class SoQtRemoteRenderInfo;
44#endif // _WIN32
45
46#include <QPointer>
47#include <QSurfaceFormat>
48
49/*
50 * Defines used when specifying the glModes flag to the constructor.
51 * (used instead of the glx.h defines which do overlap)
52 */
53#define SO_GLX_RGB (1<<0)
54#define SO_GLX_DOUBLE (1<<1)
55#define SO_GLX_ZBUFFER (1<<2)
56#define SO_GLX_STEREO (1<<4)
57#define SO_GLX_STENCIL (1<<5)
58
59class QVBoxLayout;
60class QCursor;
61class SoGLContext;
62
63class SoQGLContextProxy;
64class SoQGLWidgetProxy;
65class QGLFormat;
66class QGLContext;
67class QOpenGLWindow;
68
91{
92 Q_OBJECT
93
94public:
95
98 {
102 FLOAT_16_COLOR_BUFFER = SoGuiGLWidget::FLOAT_16_COLOR_BUFFER,
106 FLOAT_32_COLOR_BUFFER = SoGuiGLWidget::FLOAT_32_COLOR_BUFFER
107 };
108
113
117 void setColorMapSize( int size );
118
129
138 QOpenGLContext* getQOpenGLContext();
139
149
158 QWidget* getNormalWidget();
159
163 QSurfaceFormat getQSurfaceFormat();
164
176 virtual void setNormalVisual( QSurfaceFormat vis );
177
189 virtual void setNormalVisual( const SoGLFormat& format );
190
194 virtual void show();
195
199 virtual void hide();
200
206 virtual void setDoubleBuffer( SbBool onOrOff );
207
211 SbBool isDoubleBuffer() { return m_guiGLWidget->isDoubleBuffer(); }
212
216 void setBorder( SbBool onOrOff );
217
221 int getBorderSize() { return m_guiGLWidget->getBorderSize(); }
222
226 SbBool isBorder() const { return m_guiGLWidget->isBorder(); }
227
233
237 SbBool isDrawToFrontBufferEnable() const { return m_guiGLWidget->isDrawToFrontBufferEnable(); }
238
244
249
254
262 virtual void setCursor( const QCursor& newCursor );
263
267 QCursor getCursor() const;
268
273
277 void setAntialiasing(SoAntialiasingParameters* advancedParameters);
278
283
288
293
296 bool saveSnapshot( const SbString& filename, bool overwrite = true );
297
298private:
299#if !defined(_WIN32) && !defined(__APPLE__) //UNIX
300 // WARNING : Workaround only available for Amira/Avizo
301 // These methods should be removed when the GraphicConfigs will be implemented for Qt.
302 void setAttribList( const int* newAttribList );
303 int* getAttribList() const;
304#endif // UNIX
305
306 SoGuiGLWidget* getGuiGLWidget() const;
307
308 // Return the internal QWindow used to do the OpenGL rendering
309 QWindow* getInternalQWindow();
310
311 // These variables are public for retro compatibility purposes only.
312 // Do not use them directly but call their accessors instead;
313 SbBool drawToFrontBuffer;
314
315 // These two function are used by SoGui, to call the system dependent version of
316 // these functions. data is a SoWinGLWidget handle.
317 static SbBool swapNormalBuffersCB( void *data );
318 static SbBool bindNormalCurrentCB( void *data );
319 static SbBool unbindNormalCurrentCB( void *data );
320 static void* getNormalWindowCB( void *data );
321 static void* getCurrentDisplayCB(void *data);
322
328 float getPixelRatio();
329
334 void updateInternalOpenGLWindow( bool immediatUpdate );
335
336 private:
337
338 // Starting with version 3.0, subclasses should no longer make direct
339 // calls to glXMakeCurrent, glXSwapBuffers and glFlush.
340 // For RemoteRendering we need to know when MakeCurrent is called
341 // (marking the beginning of a frame) and when SwapBuffers or glFlush
342 // is called (marking the end of a frame).
343 // Subclasses should always use these generic methods.
344 void flush();
345
346#if !defined(__APPLE__) && !defined(_WIN32) //UNIX
347 // Pbuffers are a limited resource. By default use of Pbuffers for
348 // remote rendering is enabled, but it might make sense to disable
349 // it for less important windows (like UI components drawn with OpenGL).
350 // Must be called after creating the widget but before it is realized.
351 void setRemoteRenderPbufferEnable( SbBool enable )
352 { m_remoteRenderPbufferEnable = enable; }
353
354 SbBool isRemoteRenderPbufferEnable() const
355 { return m_remoteRenderPbufferEnable; }
356
357 float getLowResPercent() {return m_lowResPercent;}
358#endif
359
360private:
361
362 SoQtGLWidget( QWidget* parent = NULL,
363 const char* name = NULL,
364 SbBool buildInsideParent = TRUE,
365 int glModes = SO_GLX_RGB,
366 SbBool buildNow = TRUE,
367 SbBool sync = TRUE );
368
369 SoQtGLWidget( QWidget* parent,
370 const char* name,
371 SbBool buildInsideParent,
372 int glModes,
373 SbBool buildNow,
374 SbBool sync,
375 SoGuiGLWidget* guiGLWidget );
376
377#if defined(__linux__)
378 SoQtGLWidget( QWidget* parent,
379 const char* name,
380 SbBool buildInsideParent,
381 int glModes,
382 SbBool buildNow,
383 SbBool sync,
384 SbBool connectionType );
385
386 SoQtGLWidget( QWidget* parent,
387 const char* name,
388 SbBool buildInsideParent,
389 int glModes,
390 SbBool buildNow,
391 SbBool sync,
392 SbBool connectionType,
393 SoGuiGLWidget* guiGLWidget );
394#endif
395
396 virtual ~SoQtGLWidget();
397
399 // EVENTS
400
401 virtual void resize( int w, int h );
402
403 virtual void closeEvent( QCloseEvent* );
404
405 virtual void focusInEvent( QFocusEvent* );
406
407 virtual void focusOutEvent( QFocusEvent* );
408
409 virtual void showEvent( QShowEvent* );
410
411 virtual void hideEvent( QHideEvent* );
412
413 virtual void moveEvent( QMoveEvent* );
414
415 virtual void keyPressEvent( QKeyEvent* );
416
417 virtual void keyReleaseEvent( QKeyEvent* );
418
419 virtual void mouseMoveEvent( QMouseEvent* );
420
421 virtual void mousePressEvent( QMouseEvent* );
422
423 virtual void mouseReleaseEvent( QMouseEvent* );
424
425 virtual void mouseDoubleClickEvent( QMouseEvent* );
426
427 virtual void wheelEvent( QWheelEvent* );
428
429 bool eventFilter( QObject* object, QEvent* event );
430
431 // subclasses can use this routine as the event handler for any
432 // devices they wish to get input from.
433 static void eventHandler( QWidget* w, SoQtGLWidget* glw, QEvent* qe, bool* b );
434
435 // This function is overloaded by the render area to set the window element
436 virtual void onFocusEvent(SbBool hasFocus);
437
439
440
441 // subclasses MUST redefine redraw() to draw in the normal bit planes.
442 // processEvent() should be defined if X events are being
443 // received (see eventMask).
444 virtual void redraw() = 0;
445
446 virtual void processEvent( QEvent* anyevent );
447
448 void performPaint();
449
450 // subclasses can redefine these to do something useful.
451 // initGraphic() is called whenever a GLX window gets created
452 // sizeChanged() is called whenever the window changes size
453 // widgetChanged() is called whenever the widget is changed (i.e. at
454 // initialization or after switching from single->double buffer)
455 virtual void initGraphic();
456 virtual void sizeChanged( const SbVec2s& size );
457 virtual void posChanged( const SbVec2i32&, const SbVec2i32& ) {};
458 virtual void widgetChanged( QWidget* w );
459
460 // sets/gets the size of the glx widget(s) in pixels - Note this size could be
461 // different from the SoWinComponent::getSize() method which return
462 // the size of the component, not necessary the same as the glx widget
463 // window (because of extra stuff like the decoration in the viewers or pixel ratio).
464 void setGlxSize( SbVec2s newSize );
465 const SbVec2s& getGlxSize() const { return m_guiGLWidget->getGlxSize(); }
466
467 // set/get stereo buffering visual. This routine (like setDoubleBuffer)
468 // can be called interactively, althought slower since a new window
469 // with the needed visual is always created on the fly.
470 void setStereoBuffer( SbBool flag );
471 SbBool isStereoBuffer() { return (m_guiGLWidget->getGLModes() & SO_GLX_STEREO); }
472
473 // returns TRUE if main window is in rgb mode (FALSE if color index)
474 SbBool isRGBMode() { return (m_guiGLWidget->getGLModes() & SO_GLX_RGB); }
475
476#if defined(__linux__)
477 void allocCell( Display* display, Colormap cmap, XColorPointer colorcells,
478 int ncolors, int colorMapSize );
479#endif
480
481 SbBool waitForExpose;
482
483 QWidget* buildWidget( QWidget* parent );
484 void changeCursor( QCursor newCursor );
485 QWidget* getGlxMgrWidget() { return m_containerWidget; }
486
487 virtual void onExpose();
488
489 // ----- RemoteRender additions (v3.0) -----
490 // FSAA
491 SbBool m_initialFsaaValueChanged;
492
493#if !defined(_WIN32) && !defined(__APPLE__)
494 enum RemoteRenderEnabled // Possible values for remote rendering
495 {
496 OFF, // Never use remote rendering
497 ON, // Always try to use remote rendering
498 AUTO // Use if remote does not support GLX (default)
499 };
500 RemoteRenderEnabled m_remoteRenderMode; // See possible values above
501 SoQtRemoteRenderInfo* m_remoteRenderInfo; // Opaque type for internal state
502 SbBool m_remoteRenderPbufferEnable; // Can we use a Pbuffer?
503 SbBool m_lowResRender; //Is Low Resolution Render Mode in use?
504 float m_lowResLowPercent; //lowest value of m_lowResPercent
505 float m_lowResHighPercent; //highest value of m_lowResPercent
506 float m_lowResPercent; //percent of the window sent thru the network
507
508 void remoteRenderInit(); // Init member vars
509 void remoteRenderCleanup(); // Free allocated resources
510 void remoteRenderGinitCB( QWidget* ); // Create pixmap and other stuff
511 GLXContext remoteRenderLowResRenderGinitCB( QWidget* ); //Same for LowResRender configuration : return Remote Context
512 void remoteRenderResizeCB(); // Resize pixmap
513 void remoteRenderSendImage(); // Send rendered image to remote display
514 void remoteRenderSendLowResRender(); // send low Resolution image to remote display
515 SbGlContextHelper::VisualInfo remoteRenderChooseVisual(); // Find visual for remote window
516 void remoteRenderFatalError( const char* methodName, const char* message );
517
518 void setLowResLowPercent( float percent ) { m_lowResLowPercent = percent; }
519 void setLowResHighPercent( float percent ) { m_lowResHighPercent = percent; }
520 float getLowResLowPercent() const { return m_lowResLowPercent; }
521 float getLowResHighPercent() const { return m_lowResHighPercent;}
522
523 virtual void setLowResPercent( float newLowres ) { m_lowResPercent = newLowres; }
524#endif
525
526private:
527
528 void constructorCommon( SbBool buildNow, SbBool connectionType );
529 SoGuiGLWidget* m_guiGLWidget; //Implementation class for SoXxGLWidget
530
531 QPointer<QWidget> m_containerWidget;
532 QPointer<QVBoxLayout> m_containerLayout;
533 QPointer<QWidget> m_internalWidget;
534 QPointer<QWindow> m_internalWindow;
535
536 SoQGLContextProxy* m_context;
537
538 // Flags used when the stereo is set from environment variables.
539 bool m_stereoActiveDelayed;
540 bool m_stereoBufferFlag;
541
542#if defined(__linux__)
543 SbBool directConnection;
544#endif
545
546 QCursor currentCursor;
547 int* attribList;
548
549 SbBool windowResized;
550
551 // set of windows, color maps, etc...
552 void buildNormalGLXWidget( SoGLFormat* format = NULL );
553
554 virtual void initializeGL();
555
556 void destroyNormalWindows();
557 void destroyGLXWidget( SbBool normalCall );
558
559 void destroyNormalWidget( SbBool normalCall );
560
561 void notifyProxyDestruction( QWindow* window );
562
563 friend class SoQGLWidgetProxy;
564
565 // callbacks from glx widget
566 static void ginitCB( QWidget* w, SoQtGLWidget* glw, void* v );
567 static void exposeCB( QWidget* w, SoQtGLWidget* glw, void* v );
568 static void resizeCB( QWidget* w, SoQtGLWidget* glw, void* v );
569
570 static SbBool onGLFormatChangeCallback( SoGLFormat& format, void* userData );
571
572 SbBool remoteRenderGinitCB_pbuffer( QWidget* );
573
574 // Members used to synchronize first rendering (in case of OIV_SYNC_QTWIDGET_FIRSTRENDER == TRUE)
575 bool m_firstRenderSync;
576 static std::map<SoQtGLWidget*, bool> s_blackRendering;
577 static std::map<SoQtGLWidget*, bool> s_widgetRendered;
578
579private Q_SLOTS:
580 void destroyedQtContext();
581};
582
583#endif // _SO_QT_GLWIDGET_
584
#define TRUE
Possible value of SbBool.
Definition SbBase.h:77
void * XColorPointer
Definition SoQtDef.h:126
#define WindowQt
Definition SoQtDef.h:117
#define SO_GLX_RGB
std::set< int, std::less< int > > SoSamplesList
#define SO_GLX_STEREO
virtual void enable(QWidget *w, XtEventHandler f, XtPointer data, void *unused=NULL)
#define Colormap
Definition SoWinDef.h:40
#define GLXContext
Definition SoWinDef.h:55
Class for smart character strings.
Definition SbString.h:202
2D vector class.
Definition SbVec.h:517
2D vector class.
Definition SbVec.h:700
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Antialiasing par...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> OpenGL context m...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> OpenGL pixel for...
Definition SoGLFormat.h:55
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Component for Op...
virtual void setCursor(const QCursor &newCursor)
Sets the current cursor.
virtual void setNormalVisual(const SoGLFormat &format)
Sets the visual/pixel format for the normal window.
SbBool isDrawToFrontBufferEnable() const
Queries drawing to the front buffer.
QSurfaceFormat getQSurfaceFormat()
Returns the QSurfaceFormat currently used.
virtual SbBool bindNormalContext()
Makes the normal rendering context the current context.
float getAntialiasingQuality() const
Returns the antialiasing quality set using the setAntialiasing(float,AntialiasingMode) method.
void setBorder(SbBool onOrOff)
Included for portability only.
SoGLContext * getNormalSoContext()
Gets the current context, which is needed as an argument to glXMakeCurrent() (on Xt) or SbGlContextHe...
virtual SbBool unbindNormalContext()
unbind the current context (previously bind with bindNormalContext );
int getBorderSize()
Included for portability only.
virtual void setNormalVisual(QSurfaceFormat vis)
Sets the visual/pixel format for the normal window.
SbBool isBorder() const
Included for portability only.
QWidget * getNormalWidget()
Gets the current normal widget.
bool saveSnapshot(const SbString &filename, bool overwrite=true)
Save a snapshot of the current image displayed in the viewer.
void setColorMapSize(int size)
Sets the color map size.
void setAntialiasing(SoAntialiasingParameters *advancedParameters)
Enable (or disable) antialiasing with specific parameters.
QOpenGLContext * getQOpenGLContext()
Gets the current context, which is needed as an argument to glXMakeCurrent() (on Xt) or SbGlContextHe...
int getColorMapSize()
Returns the color map size.
SoAntialiasingParameters * getAntialiasingParameters() const
Returns the antialiasing parameters set using the setAntialiasing(SoAntialiasingParameters*) method.
SoSceneManager::AntialiasingMode getAntialiasingMode() const
Returns the antialiasing mode set using the setAntialiasing(float,AntialiasingMode) method.
virtual SbBool swapNormalBuffers()
Swaps the normal front and back buffers.
QCursor getCursor() const
Returns the current cursor.
friend class SoQGLWidgetProxy
virtual void setDoubleBuffer(SbBool onOrOff)
Routine that dynamically changes between single and double buffering.
virtual void show()
This shows the component.
SbBool isDoubleBuffer()
Returns whether double buffering is on or off.
virtual void hide()
This hides the component.
void setDrawToFrontBufferEnable(SbBool enableFlag)
Sets drawing to the front buffer.
virtual WindowQt getNormalWindow()
Gets the normal GL window (window system identifier of the widget), which is needed as an argument to...
void setAntialiasing(const float quality, const SoSceneManager::AntialiasingMode mode=SoSceneManager::AUTO)
Enable (or disable) antialiasing with specified quality and mode.
FloatColorBufferSize
FloatColorBufferSize.
@ FLOAT_16_COLOR_BUFFER
16-bit rendering per component.
@ FLOAT_32_COLOR_BUFFER
32-bit rendering per component.
AntialiasingMode
Enum which indicates the desired antialiasing algorithm.
@ AUTO
This is the default mode for antialiasing.
int SbBool
Boolean type.
Definition SbBase.h:87