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
00091 class SoQtGLWidget : public SoQtComponent
00092 {
00093 Q_OBJECT
00094
00095 public:
00096
00098 enum FloatColorBufferSize
00099 {
00103 FLOAT_16_COLOR_BUFFER = SoGuiGLWidget::FLOAT_16_COLOR_BUFFER,
00107 FLOAT_32_COLOR_BUFFER = SoGuiGLWidget::FLOAT_32_COLOR_BUFFER
00108 };
00109
00113 int getColorMapSize();
00114
00118 void setColorMapSize( int size );
00119
00129 virtual WindowQt getNormalWindow();
00130
00140 QOpenGLContext* getQOpenGLContext();
00141
00151 SoGLContext* getNormalSoContext();
00152
00168 QWidget* getNormalWidget();
00169
00173 QSurfaceFormat getQSurfaceFormat();
00174
00186 virtual void setNormalVisual( QSurfaceFormat vis );
00187
00199 virtual void setNormalVisual( const SoGLFormat& format );
00200
00204 virtual void show();
00205
00209 virtual void hide();
00210
00216 virtual void setDoubleBuffer( SbBool onOrOff );
00217
00221 SbBool isDoubleBuffer() { return m_guiGLWidget->isDoubleBuffer(); }
00222
00226 void setBorder( SbBool onOrOff );
00227
00231 int getBorderSize() { return m_guiGLWidget->getBorderSize(); }
00232
00236 SbBool isBorder() const { return m_guiGLWidget->isBorder(); }
00237
00242 void setDrawToFrontBufferEnable( SbBool enableFlag );
00243
00247 SbBool isDrawToFrontBufferEnable() const { return m_guiGLWidget->isDrawToFrontBufferEnable(); }
00248
00253 virtual SbBool bindNormalContext();
00254
00258 virtual SbBool unbindNormalContext();
00259
00263 virtual SbBool swapNormalBuffers();
00264
00265 #if 1 SoDEPRECATED
00270 unsigned long getOverlayTransparentPixel();
00271 SoDEPRECATED
00276 void setOverlayTransparentPixel( unsigned long pixel );
00277 SoDEPRECATED
00282 int getOverlayColorMapSize();
00283 SoDEPRECATED
00288 void setOverlayColorMapSize( int size );
00289 SoDEPRECATED
00302 WindowQt getOverlayWindow();
00303 SoDEPRECATED
00313 QGLContext* getOverlayContext();SoDEPRECATED
00315 SoGLContext* getOverlaySoContext();
00316 SoDEPRECATED
00329 QWidget* getOverlayWidget();
00330 SoDEPRECATED
00341 virtual void setOverlayVisual( QGLFormat* vis );
00342 SoDEPRECATED
00344 virtual void setOverlayVisual( const SoGLFormat& format );
00345 SoDEPRECATED
00350 QGLFormat* getOverlayVisual();
00351 SoDEPRECATED
00356 SbBool makeOverlayCurrent();
00357 SoDEPRECATED
00363 virtual SbBool bindOverlayContext();
00364 SoDEPRECATED
00369 virtual SbBool unbindOverlayContext();
00370 SoDEPRECATED
00375 SbBool swapOverlayBuffers();
00376 #endif
00378 #if 1 SoDEPRECATED
00389 QGLContext* getNormalContext() { return NULL; }
00390 SoDEPRECATED
00395 QGLFormat* getNormalFormat() { return NULL; }
00396 SoDEPRECATED
00401 QGLFormat* getNormalVisual() { return NULL; }
00402 SoDEPRECATED
00415 virtual void setNormalVisual( QGLFormat* ) {}
00416 #endif
00424 virtual void setCursor( const QCursor& newCursor );
00425
00429 QCursor getCursor() const;
00430
00434 void setAntialiasing(const float quality, const SoSceneManager::AntialiasingMode mode = SoSceneManager::AUTO);
00435
00439 void setAntialiasing(SoAntialiasingParameters* advancedParameters);
00440
00444 float getAntialiasingQuality() const;
00445
00449 SoSceneManager::AntialiasingMode getAntialiasingMode() const;
00450
00454 SoAntialiasingParameters* getAntialiasingParameters() const;
00455
00458 bool saveSnapshot( const SbString& filename, bool overwrite = true );
00459
00466 int getFrameBufferObjectId() const;
00467
00468 #if 1 SoDEPRECATED
00471 virtual void setNormalVisual( SbGlContextHelper::VisualInfo vis );
00472 SoDEPRECATED
00474 virtual void setOverlayVisual( SbGlContextHelper::VisualInfo vis );
00475
00476 #endif
00478 #if 1 SoDEPRECATED
00484 virtual SbBool makeNormalCurrent();
00485 SoDEPRECATED
00490 SbBool isFsaaSupported();
00491
00492 #endif
00494 #if 1 SoDEPRECATED
00516 SbBool setFullSceneAntialiasing( SbBool enable,
00517 float quality = -1.0,
00518 int filterMask = SoFullSceneAntialiasing::ALL );
00519 SoDEPRECATED
00524 SbBool isFullSceneAntialiasingEnabled() const;
00525 SoDEPRECATED
00530 SbBool getFullSceneAntialiasing( float& quality );
00531 SoDEPRECATED
00536 SbBool isFullSceneAntialiasingAvailable() const;
00537 SoDEPRECATED
00544 SbBool isFullSceneAntialiasingHQAvailable() const;
00545 SoDEPRECATED
00552 SbBool setFullSceneAntialiasingHQ( SbBool enable );
00553 SoDEPRECATED
00558 SbBool isFullSceneAntialiasingHQEnabled() const;
00559
00560 #endif
00562 private:
00563 #if !defined(_WIN32) && !defined(__APPLE__) //UNIX
00564
00565
00566 void setAttribList( const int* newAttribList );
00567 int* getAttribList() const;
00568 #endif // UNIX
00569
00570 SoGuiGLWidget* getGuiGLWidget() const;
00571
00572 QWidget* getQtWidget() const { return m_openGLWidget; }
00573
00574
00575
00576 SbBool drawToFrontBuffer;
00577
00578
00579
00580 static SbBool swapNormalBuffersCB( void *data );
00581 static SbBool bindNormalCurrentCB( void *data );
00582 static SbBool unbindNormalCurrentCB( void *data );
00583 static void* getNormalWindowCB( void *data );
00584 static void* getCurrentDisplayCB(void *data);
00585
00591 float getPixelRatio();
00592
00593 private:
00594
00595
00596
00597
00598
00599
00600
00601 void flush();
00602
00603 #if !defined(__APPLE__) && !defined(_WIN32) //UNIX
00604
00605
00606
00607
00608 void setRemoteRenderPbufferEnable( SbBool enable )
00609 { m_remoteRenderPbufferEnable = enable; }
00610
00611 SbBool isRemoteRenderPbufferEnable() const
00612 { return m_remoteRenderPbufferEnable; }
00613
00614 float getLowResPercent() {return m_lowResPercent;}
00615 #endif
00616
00617 private:
00618
00619 SoQtGLWidget( QWidget* parent = NULL,
00620 const char* name = NULL,
00621 SbBool buildInsideParent = TRUE,
00622 int glModes = SO_GLX_RGB,
00623 SbBool buildNow = TRUE,
00624 SbBool sync = TRUE );
00625
00626 SoQtGLWidget( QWidget* parent,
00627 const char* name,
00628 SbBool buildInsideParent,
00629 int glModes,
00630 SbBool buildNow,
00631 SbBool sync,
00632 SoGuiGLWidget* guiGLWidget );
00633
00634 #if defined(sun) || defined(__linux__) || defined(__hpux)
00635 SoQtGLWidget( QWidget* parent,
00636 const char* name,
00637 SbBool buildInsideParent,
00638 int glModes,
00639 SbBool buildNow,
00640 SbBool sync,
00641 SbBool connectionType );
00642
00643 SoQtGLWidget( QWidget* parent,
00644 const char* name,
00645 SbBool buildInsideParent,
00646 int glModes,
00647 SbBool buildNow,
00648 SbBool sync,
00649 SbBool connectionType,
00650 SoGuiGLWidget* guiGLWidget );
00651 #endif
00652
00653 virtual ~SoQtGLWidget();
00654
00656
00657
00658 #if 1 SoDEPRECATED
00661 virtual void paintEvent( QPaintEvent* ) {}
00662 SoDEPRECATED
00664 virtual void resizeEvent( QResizeEvent* ) {}
00665 #endif
00667 virtual void resize( int w, int h );
00668
00669 virtual void closeEvent( QCloseEvent* );
00670
00671 virtual void focusInEvent( QFocusEvent* );
00672
00673 virtual void focusOutEvent( QFocusEvent* );
00674
00675 virtual void showEvent( QShowEvent* );
00676
00677 virtual void hideEvent( QHideEvent* );
00678
00679 virtual void moveEvent( QMoveEvent* );
00680
00681 virtual void keyPressEvent( QKeyEvent* );
00682
00683 virtual void keyReleaseEvent( QKeyEvent* );
00684
00685 virtual void mouseMoveEvent( QMouseEvent* );
00686
00687 virtual void mousePressEvent( QMouseEvent* );
00688
00689 virtual void mouseReleaseEvent( QMouseEvent* );
00690
00691 virtual void mouseDoubleClickEvent( QMouseEvent* );
00692
00693 virtual void wheelEvent( QWheelEvent* );
00694
00695 bool eventFilter( QObject* object, QEvent* event );
00696
00697
00698
00699 static void eventHandler( QWidget* w, SoQtGLWidget* glw, QEvent* qe, bool* b );
00700
00701
00702 virtual void onFocusEvent(SbBool hasFocus);
00703
00705
00706
00707
00708
00709
00710
00711 virtual void redraw() = 0;
00712 #if 1 SoDEPRECATED
00714 virtual void redrawOverlay();
00715 #endif
00717 virtual void processEvent( QEvent* anyevent );
00718
00719 void performPaint();
00720
00721
00722
00723
00724
00725
00726 virtual void initGraphic();
00727 #if 1 SoDEPRECATED
00729 virtual void initOverlayGraphic();
00730 #endif
00731 virtual void sizeChanged( const SbVec2s& size );
00732 virtual void posChanged( const SbVec2i32&, const SbVec2i32& ) {};
00733 virtual void widgetChanged( QWidget* w );
00734
00735
00736
00737
00738
00739 void setGlxSize( SbVec2s newSize );
00740 const SbVec2s& getGlxSize() const { return m_guiGLWidget->getGlxSize(); }
00741
00742
00743
00744
00745 void setStereoBuffer( SbBool flag );
00746 SbBool isStereoBuffer() { return (m_guiGLWidget->getGLModes() & SO_GLX_STEREO); }
00747
00748
00749 SbBool isRGBMode() { return (m_guiGLWidget->getGLModes() & SO_GLX_RGB); }
00750
00751 #if defined(sun) || defined(__linux__)
00752 void allocCell( Display* display, Colormap cmap, XColorPointer colorcells,
00753 int ncolors, int colorMapSize );
00754 #endif
00755
00756 SbBool waitForExpose;
00757
00758 QWidget* buildWidget( QWidget* parent );
00759 void changeCursor( QCursor newCursor );
00760 QWidget* getGlxMgrWidget() { return m_containerWidget; }
00761
00762 virtual void onExpose();
00763 #if 1 SoDEPRECATED
00765 virtual void onOverlayExpose();
00766 #endif
00769 // ----- RemoteRender additions (v3.0) -----
00770
00771 SbBool m_initialFsaaValueChanged;
00772
00773 #if !defined(_WIN32) && !defined(__APPLE__)
00774 enum RemoteRenderEnabled
00775 {
00776 OFF,
00777 ON,
00778 AUTO
00779 };
00780 RemoteRenderEnabled m_remoteRenderMode;
00781 SoQtRemoteRenderInfo* m_remoteRenderInfo;
00782 SbBool m_remoteRenderPbufferEnable;
00783 SbBool m_lowResRender;
00784 float m_lowResLowPercent;
00785 float m_lowResHighPercent;
00786 float m_lowResPercent;
00787
00788 void remoteRenderInit();
00789 void remoteRenderCleanup();
00790 void remoteRenderGinitCB( QWidget* );
00791 GLXContext remoteRenderLowResRenderGinitCB( QWidget* );
00792 void remoteRenderResizeCB();
00793 void remoteRenderSendImage();
00794 void remoteRenderSendLowResRender();
00795 SbGlContextHelper::VisualInfo remoteRenderChooseVisual();
00796 void remoteRenderFatalError( const char* methodName, const char* message );
00797
00798 void setLowResLowPercent( float percent ) { m_lowResLowPercent = percent; }
00799 void setLowResHighPercent( float percent ) { m_lowResHighPercent = percent; }
00800 float getLowResLowPercent() const { return m_lowResLowPercent; }
00801 float getLowResHighPercent() const { return m_lowResHighPercent;}
00802
00803 virtual void setLowResPercent( float newLowres ) { m_lowResPercent = newLowres; }
00804 #endif
00805
00806 private:
00807
00808 void constructorCommon( SbBool buildNow, SbBool connectionType );
00809 SoGuiGLWidget* m_guiGLWidget;
00810
00811
00812 QPointer<QWidget> m_containerWidget;
00813 QPointer<QVBoxLayout> m_containerLayout;
00814 QPointer<QWidget> m_openGLWidget;
00815
00816 SoQGLContextProxy* m_context;
00817
00818 SoGLFormat m_overlayVis;
00819
00820
00821 bool m_stereoActiveDelayed;
00822 bool m_stereoBufferFlag;
00823
00824 #if defined(sun) || defined(__linux__) || defined(__hpux)
00825 SbBool directConnection;
00826 #endif
00827
00828 QCursor currentCursor;
00829 int* attribList;
00830
00831 SbBool windowResized;
00832
00833 int m_frameBufferObjectId;
00834
00835
00836 void buildNormalGLXWidget( SoGLFormat* format = NULL );
00837 void buildOverlayGLXWidget( SoGLFormat* format = NULL );
00838
00839 virtual void initializeGL();
00840
00841 void destroyNormalWindows();
00842 void destroyGLXWidget( SbBool normalCall );
00843
00844 void destroyOverlayWidget( SbBool normalCall );
00845 void destroyNormalWidget( SbBool normalCall );
00846
00847 void notifyProxyDestruction( QWidget* widget );
00848
00849 friend class SoQGLWidgetProxy;
00850
00851
00852 static void ginitCB( QWidget* w, SoQtGLWidget* glw, void* v );
00853 static void overlayGinitCB( QWidget* glx, SoQtGLWidget* p, void* v );
00854 static void exposeCB( QWidget* w, SoQtGLWidget* glw, void* v );
00855 static void overlayExposeCB( QWidget* w, SoQtGLWidget* glw, void* v );
00856 static void resizeCB( QWidget* w, SoQtGLWidget* glw, void* v );
00857
00858 static SbBool onGLFormatChangeCallback( SoGLFormat& format, void* userData );
00859
00860 SbBool remoteRenderGinitCB_pbuffer( QWidget* );
00861
00862 private Q_SLOTS:
00863 void destroyedQtContext();
00864 };
00865
00866 #endif // _SO_QT_GLWIDGET_
00867
00868