00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _SO_QT_GLWIDGET_
00027 #define _SO_QT_GLWIDGET_
00028
00029 #include <Inventor/Qt/SoQtComponent.h>
00030
00031 #include <Inventor/Qt/OivQtCompat.h>
00032 #include <Inventor/devices/SoGLFormat.h>
00033
00034 #include <Inventor/Gui/SoGuiGLWidget.h>
00035 #include <Inventor/nodes/SoFullSceneAntialiasing.h>
00036
00037 #include <Qt>
00038
00039
00040 typedef std::set<int, std::less<int> > SoSamplesList;
00041
00042 #if !defined(_WIN32)
00043 class SoQtRemoteRenderInfo;
00044 #endif // _WIN32
00045
00046 #include <QPointer>
00047 #include <QSurfaceFormat>
00048
00049
00050
00051
00052
00053 #define SO_GLX_RGB (1<<0)
00054 #define SO_GLX_DOUBLE (1<<1)
00055 #define SO_GLX_ZBUFFER (1<<2)
00056 #define SO_GLX_OVERLAY (1<<3)
00057 #define SO_GLX_STEREO (1<<4)
00058 #define SO_GLX_STENCIL (1<<5)
00059
00060 class QVBoxLayout;
00061 class QCursor;
00062 class SoGLContext;
00063
00064 class SoQGLContextProxy;
00065 class SoQGLWidgetProxy;
00066 class QGLFormat;
00067 class QGLContext;
00068 class QOpenGLWindow;
00069
00092 class SoQtGLWidget : public SoQtComponent
00093 {
00094 Q_OBJECT
00095
00096 public:
00097
00099 enum FloatColorBufferSize
00100 {
00104 FLOAT_16_COLOR_BUFFER = SoGuiGLWidget::FLOAT_16_COLOR_BUFFER,
00108 FLOAT_32_COLOR_BUFFER = SoGuiGLWidget::FLOAT_32_COLOR_BUFFER
00109 };
00110
00114 int getColorMapSize();
00115
00119 void setColorMapSize( int size );
00120
00130 virtual WindowQt getNormalWindow();
00131
00141 QOpenGLContext* getQOpenGLContext();
00142
00152 SoGLContext* getNormalSoContext();
00153
00169 QWidget* getNormalWidget();
00170
00174 QSurfaceFormat getQSurfaceFormat();
00175
00187 virtual void setNormalVisual( QSurfaceFormat vis );
00188
00200 virtual void setNormalVisual( const SoGLFormat& format );
00201
00205 virtual void show();
00206
00210 virtual void hide();
00211
00217 virtual void setDoubleBuffer( SbBool onOrOff );
00218
00222 SbBool isDoubleBuffer() { return m_guiGLWidget->isDoubleBuffer(); }
00223
00227 void setBorder( SbBool onOrOff );
00228
00232 int getBorderSize() { return m_guiGLWidget->getBorderSize(); }
00233
00237 SbBool isBorder() const { return m_guiGLWidget->isBorder(); }
00238
00243 void setDrawToFrontBufferEnable( SbBool enableFlag );
00244
00248 SbBool isDrawToFrontBufferEnable() const { return m_guiGLWidget->isDrawToFrontBufferEnable(); }
00249
00254 virtual SbBool bindNormalContext();
00255
00259 virtual SbBool unbindNormalContext();
00260
00264 virtual SbBool swapNormalBuffers();
00265
00266 #if 1 SoDEPRECATED
00271 unsigned long getOverlayTransparentPixel();
00272 SoDEPRECATED
00277 void setOverlayTransparentPixel( unsigned long pixel );
00278 SoDEPRECATED
00283 int getOverlayColorMapSize();
00284 SoDEPRECATED
00289 void setOverlayColorMapSize( int size );
00290 SoDEPRECATED
00303 WindowQt getOverlayWindow();
00304 SoDEPRECATED
00314 QGLContext* getOverlayContext();SoDEPRECATED
00316 SoGLContext* getOverlaySoContext();
00317 SoDEPRECATED
00330 QWidget* getOverlayWidget();
00331 SoDEPRECATED
00342 virtual void setOverlayVisual( QGLFormat* vis );
00343 SoDEPRECATED
00345 virtual void setOverlayVisual( const SoGLFormat& format );
00346 SoDEPRECATED
00351 QGLFormat* getOverlayVisual();
00352 SoDEPRECATED
00357 SbBool makeOverlayCurrent();
00358 SoDEPRECATED
00364 virtual SbBool bindOverlayContext();
00365 SoDEPRECATED
00370 virtual SbBool unbindOverlayContext();
00371 SoDEPRECATED
00376 SbBool swapOverlayBuffers();
00377 #endif
00379 #if 1 SoDEPRECATED
00390 QGLContext* getNormalContext() { return NULL; }
00391 SoDEPRECATED
00396 QGLFormat* getNormalFormat() { return NULL; }
00397 SoDEPRECATED
00402 QGLFormat* getNormalVisual() { return NULL; }
00403 SoDEPRECATED
00416 virtual void setNormalVisual( QGLFormat* ) {}
00417 #endif
00425 virtual void setCursor( const QCursor& newCursor );
00426
00430 QCursor getCursor() const;
00431
00435 void setAntialiasing(const float quality, const SoSceneManager::AntialiasingMode mode = SoSceneManager::AUTO);
00436
00440 void setAntialiasing(SoAntialiasingParameters* advancedParameters);
00441
00445 float getAntialiasingQuality() const;
00446
00450 SoSceneManager::AntialiasingMode getAntialiasingMode() const;
00451
00455 SoAntialiasingParameters* getAntialiasingParameters() const;
00456
00459 bool saveSnapshot( const SbString& filename, bool overwrite = true );
00460
00461 #if 1 SoDEPRECATED
00463 int getFrameBufferObjectId() const { return 0; }
00464 #endif
00466 #if 1 SoDEPRECATED
00469 virtual void setNormalVisual( SbGlContextHelper::VisualInfo vis );
00470 SoDEPRECATED
00472 virtual void setOverlayVisual( SbGlContextHelper::VisualInfo vis );
00473
00474 #endif
00476 #if 1 SoDEPRECATED
00482 virtual SbBool makeNormalCurrent();
00483 SoDEPRECATED
00488 SbBool isFsaaSupported();
00489
00490 #endif
00492 #if 1 SoDEPRECATED
00514 SbBool setFullSceneAntialiasing( SbBool enable,
00515 float quality = -1.0,
00516 int filterMask = SoFullSceneAntialiasing::ALL );
00517 SoDEPRECATED
00522 SbBool isFullSceneAntialiasingEnabled() const;
00523 SoDEPRECATED
00528 SbBool getFullSceneAntialiasing( float& quality );
00529 SoDEPRECATED
00534 SbBool isFullSceneAntialiasingAvailable() const;
00535 SoDEPRECATED
00542 SbBool isFullSceneAntialiasingHQAvailable() const;
00543 SoDEPRECATED
00550 SbBool setFullSceneAntialiasingHQ( SbBool enable );
00551 SoDEPRECATED
00556 SbBool isFullSceneAntialiasingHQEnabled() const;
00557
00558 #endif
00560 private:
00561 #if !defined(_WIN32) && !defined(__APPLE__) //UNIX
00562
00563
00564 void setAttribList( const int* newAttribList );
00565 int* getAttribList() const;
00566 #endif // UNIX
00567
00568 SoGuiGLWidget* getGuiGLWidget() const;
00569
00570
00571 QWindow* getInternalQWindow();
00572
00573
00574
00575 SbBool drawToFrontBuffer;
00576
00577
00578
00579 static SbBool swapNormalBuffersCB( void *data );
00580 static SbBool bindNormalCurrentCB( void *data );
00581 static SbBool unbindNormalCurrentCB( void *data );
00582 static void* getNormalWindowCB( void *data );
00583 static void* getCurrentDisplayCB(void *data);
00584
00590 float getPixelRatio();
00591
00596 void updateInternalOpenGLWindow( bool immediatUpdate );
00597
00598 private:
00599
00600
00601
00602
00603
00604
00605
00606 void flush();
00607
00608 #if !defined(__APPLE__) && !defined(_WIN32) //UNIX
00609
00610
00611
00612
00613 void setRemoteRenderPbufferEnable( SbBool enable )
00614 { m_remoteRenderPbufferEnable = enable; }
00615
00616 SbBool isRemoteRenderPbufferEnable() const
00617 { return m_remoteRenderPbufferEnable; }
00618
00619 float getLowResPercent() {return m_lowResPercent;}
00620 #endif
00621
00622 private:
00623
00624 SoQtGLWidget( QWidget* parent = NULL,
00625 const char* name = NULL,
00626 SbBool buildInsideParent = TRUE,
00627 int glModes = SO_GLX_RGB,
00628 SbBool buildNow = TRUE,
00629 SbBool sync = TRUE );
00630
00631 SoQtGLWidget( QWidget* parent,
00632 const char* name,
00633 SbBool buildInsideParent,
00634 int glModes,
00635 SbBool buildNow,
00636 SbBool sync,
00637 SoGuiGLWidget* guiGLWidget );
00638
00639 #if defined(sun) || defined(__linux__) || defined(__hpux)
00640 SoQtGLWidget( QWidget* parent,
00641 const char* name,
00642 SbBool buildInsideParent,
00643 int glModes,
00644 SbBool buildNow,
00645 SbBool sync,
00646 SbBool connectionType );
00647
00648 SoQtGLWidget( QWidget* parent,
00649 const char* name,
00650 SbBool buildInsideParent,
00651 int glModes,
00652 SbBool buildNow,
00653 SbBool sync,
00654 SbBool connectionType,
00655 SoGuiGLWidget* guiGLWidget );
00656 #endif
00657
00658 virtual ~SoQtGLWidget();
00659
00661
00662
00663 #if 1 SoDEPRECATED
00666 virtual void paintEvent( QPaintEvent* ) {}
00667 SoDEPRECATED
00669 virtual void resizeEvent( QResizeEvent* ) {}
00670 #endif
00672 virtual void resize( int w, int h );
00673
00674 virtual void closeEvent( QCloseEvent* );
00675
00676 virtual void focusInEvent( QFocusEvent* );
00677
00678 virtual void focusOutEvent( QFocusEvent* );
00679
00680 virtual void showEvent( QShowEvent* );
00681
00682 virtual void hideEvent( QHideEvent* );
00683
00684 virtual void moveEvent( QMoveEvent* );
00685
00686 virtual void keyPressEvent( QKeyEvent* );
00687
00688 virtual void keyReleaseEvent( QKeyEvent* );
00689
00690 virtual void mouseMoveEvent( QMouseEvent* );
00691
00692 virtual void mousePressEvent( QMouseEvent* );
00693
00694 virtual void mouseReleaseEvent( QMouseEvent* );
00695
00696 virtual void mouseDoubleClickEvent( QMouseEvent* );
00697
00698 virtual void wheelEvent( QWheelEvent* );
00699
00700 bool eventFilter( QObject* object, QEvent* event );
00701
00702
00703
00704 static void eventHandler( QWidget* w, SoQtGLWidget* glw, QEvent* qe, bool* b );
00705
00706
00707 virtual void onFocusEvent(SbBool hasFocus);
00708
00710
00711
00712
00713
00714
00715
00716 virtual void redraw() = 0;
00717 #if 1 SoDEPRECATED
00719 virtual void redrawOverlay();
00720 #endif
00722 virtual void processEvent( QEvent* anyevent );
00723
00724 void performPaint();
00725
00726
00727
00728
00729
00730
00731 virtual void initGraphic();
00732 #if 1 SoDEPRECATED
00734 virtual void initOverlayGraphic();
00735 #endif
00736 virtual void sizeChanged( const SbVec2s& size );
00737 virtual void posChanged( const SbVec2i32&, const SbVec2i32& ) {};
00738 virtual void widgetChanged( QWidget* w );
00739
00740
00741
00742
00743
00744 void setGlxSize( SbVec2s newSize );
00745 const SbVec2s& getGlxSize() const { return m_guiGLWidget->getGlxSize(); }
00746
00747
00748
00749
00750 void setStereoBuffer( SbBool flag );
00751 SbBool isStereoBuffer() { return (m_guiGLWidget->getGLModes() & SO_GLX_STEREO); }
00752
00753
00754 SbBool isRGBMode() { return (m_guiGLWidget->getGLModes() & SO_GLX_RGB); }
00755
00756 #if defined(sun) || defined(__linux__)
00757 void allocCell( Display* display, Colormap cmap, XColorPointer colorcells,
00758 int ncolors, int colorMapSize );
00759 #endif
00760
00761 SbBool waitForExpose;
00762
00763 QWidget* buildWidget( QWidget* parent );
00764 void changeCursor( QCursor newCursor );
00765 QWidget* getGlxMgrWidget() { return m_containerWidget; }
00766
00767 virtual void onExpose();
00768 #if 1 SoDEPRECATED
00770 virtual void onOverlayExpose();
00771 #endif
00774 // ----- RemoteRender additions (v3.0) -----
00775
00776 SbBool m_initialFsaaValueChanged;
00777
00778 #if !defined(_WIN32) && !defined(__APPLE__)
00779 enum RemoteRenderEnabled
00780 {
00781 OFF,
00782 ON,
00783 AUTO
00784 };
00785 RemoteRenderEnabled m_remoteRenderMode;
00786 SoQtRemoteRenderInfo* m_remoteRenderInfo;
00787 SbBool m_remoteRenderPbufferEnable;
00788 SbBool m_lowResRender;
00789 float m_lowResLowPercent;
00790 float m_lowResHighPercent;
00791 float m_lowResPercent;
00792
00793 void remoteRenderInit();
00794 void remoteRenderCleanup();
00795 void remoteRenderGinitCB( QWidget* );
00796 GLXContext remoteRenderLowResRenderGinitCB( QWidget* );
00797 void remoteRenderResizeCB();
00798 void remoteRenderSendImage();
00799 void remoteRenderSendLowResRender();
00800 SbGlContextHelper::VisualInfo remoteRenderChooseVisual();
00801 void remoteRenderFatalError( const char* methodName, const char* message );
00802
00803 void setLowResLowPercent( float percent ) { m_lowResLowPercent = percent; }
00804 void setLowResHighPercent( float percent ) { m_lowResHighPercent = percent; }
00805 float getLowResLowPercent() const { return m_lowResLowPercent; }
00806 float getLowResHighPercent() const { return m_lowResHighPercent;}
00807
00808 virtual void setLowResPercent( float newLowres ) { m_lowResPercent = newLowres; }
00809 #endif
00810
00811 private:
00812
00813 void constructorCommon( SbBool buildNow, SbBool connectionType );
00814 SoGuiGLWidget* m_guiGLWidget;
00815
00816 QPointer<QWidget> m_containerWidget;
00817 QPointer<QVBoxLayout> m_containerLayout;
00818 QPointer<QWidget> m_internalWidget;
00819 QPointer<QWindow> m_internalWindow;
00820
00821 SoQGLContextProxy* m_context;
00822
00823 SoGLFormat m_overlayVis;
00824
00825
00826 bool m_stereoActiveDelayed;
00827 bool m_stereoBufferFlag;
00828
00829 #if defined(sun) || defined(__linux__) || defined(__hpux)
00830 SbBool directConnection;
00831 #endif
00832
00833 QCursor currentCursor;
00834 int* attribList;
00835
00836 SbBool windowResized;
00837
00838
00839 void buildNormalGLXWidget( SoGLFormat* format = NULL );
00840 void buildOverlayGLXWidget( SoGLFormat* format = NULL );
00841
00842 virtual void initializeGL();
00843
00844 void destroyNormalWindows();
00845 void destroyGLXWidget( SbBool normalCall );
00846
00847 void destroyOverlayWidget( SbBool normalCall );
00848 void destroyNormalWidget( SbBool normalCall );
00849
00850 void notifyProxyDestruction( QWindow* window );
00851
00852 friend class SoQGLWidgetProxy;
00853
00854
00855 static void ginitCB( QWidget* w, SoQtGLWidget* glw, void* v );
00856 static void overlayGinitCB( QWidget* glx, SoQtGLWidget* p, void* v );
00857 static void exposeCB( QWidget* w, SoQtGLWidget* glw, void* v );
00858 static void overlayExposeCB( QWidget* w, SoQtGLWidget* glw, void* v );
00859 static void resizeCB( QWidget* w, SoQtGLWidget* glw, void* v );
00860
00861 static SbBool onGLFormatChangeCallback( SoGLFormat& format, void* userData );
00862
00863 SbBool remoteRenderGinitCB_pbuffer( QWidget* );
00864
00865
00866 bool m_firstRenderSync;
00867 static std::map<SoQtGLWidget*, bool> s_blackRendering;
00868 static std::map<SoQtGLWidget*, bool> s_widgetRendered;
00869
00870 private Q_SLOTS:
00871 void destroyedQtContext();
00872 };
00873
00874 #endif // _SO_QT_GLWIDGET_
00875
00876