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_STEREO (1<<4)
00057 #define SO_GLX_STENCIL (1<<5)
00058
00059 class QVBoxLayout;
00060 class QCursor;
00061 class SoGLContext;
00062
00063 class SoQGLContextProxy;
00064 class SoQGLWidgetProxy;
00065 class QGLFormat;
00066 class QGLContext;
00067
00089 class SoQtGLWidget : public SoQtComponent
00090 {
00091 Q_OBJECT
00092
00093 public:
00094
00096 enum FloatColorBufferSize
00097 {
00101 FLOAT_16_COLOR_BUFFER = SoGuiGLWidget::FLOAT_16_COLOR_BUFFER,
00105 FLOAT_32_COLOR_BUFFER = SoGuiGLWidget::FLOAT_32_COLOR_BUFFER
00106 };
00107
00111 int getColorMapSize();
00112
00116 void setColorMapSize( int size );
00117
00127 virtual WindowQt getNormalWindow();
00128
00138 QOpenGLContext* getQOpenGLContext();
00139
00149 SoGLContext* getNormalSoContext();
00150
00166 QWidget* getNormalWidget();
00167
00171 QSurfaceFormat getQSurfaceFormat();
00172
00184 virtual void setNormalVisual( QSurfaceFormat vis );
00185
00197 virtual void setNormalVisual( const SoGLFormat& format );
00198
00202 virtual void show();
00203
00207 virtual void hide();
00208
00214 virtual void setDoubleBuffer( SbBool onOrOff );
00215
00219 SbBool isDoubleBuffer() { return m_guiGLWidget->isDoubleBuffer(); }
00220
00224 void setBorder( SbBool onOrOff );
00225
00229 int getBorderSize() { return m_guiGLWidget->getBorderSize(); }
00230
00234 SbBool isBorder() const { return m_guiGLWidget->isBorder(); }
00235
00240 void setDrawToFrontBufferEnable( SbBool enableFlag );
00241
00245 SbBool isDrawToFrontBufferEnable() const { return m_guiGLWidget->isDrawToFrontBufferEnable(); }
00246
00251 virtual SbBool bindNormalContext();
00252
00256 virtual SbBool unbindNormalContext();
00257
00261 virtual SbBool swapNormalBuffers();
00262
00270 virtual void setCursor( const QCursor& newCursor );
00271
00275 QCursor getCursor() const;
00276
00280 void setAntialiasing(const float quality, const SoSceneManager::AntialiasingMode mode = SoSceneManager::AUTO);
00281
00285 void setAntialiasing(SoAntialiasingParameters* advancedParameters);
00286
00290 float getAntialiasingQuality() const;
00291
00295 SoSceneManager::AntialiasingMode getAntialiasingMode() const;
00296
00300 SoAntialiasingParameters* getAntialiasingParameters() const;
00301
00304 bool saveSnapshot( const SbString& filename, bool overwrite = true );
00305
00312 int getFrameBufferObjectId() const;
00313
00314 #if 1 SoDEPRECATED
00320 virtual SbBool makeNormalCurrent();
00321 SoDEPRECATED
00326 SbBool isFsaaSupported();
00327
00328 #endif
00330 #if 1 SoDEPRECATED
00352 SbBool setFullSceneAntialiasing( SbBool enable,
00353 float quality = -1.0,
00354 int filterMask = SoFullSceneAntialiasing::ALL );
00355 SoDEPRECATED
00360 SbBool isFullSceneAntialiasingEnabled() const;
00361 SoDEPRECATED
00366 SbBool getFullSceneAntialiasing( float& quality );
00367 SoDEPRECATED
00372 SbBool isFullSceneAntialiasingAvailable() const;
00373 SoDEPRECATED
00378 SbBool isFullSceneAntialiasingHQAvailable() const;
00379 SoDEPRECATED
00384 SbBool setFullSceneAntialiasingHQ( SbBool enable );
00385 SoDEPRECATED
00390 SbBool isFullSceneAntialiasingHQEnabled() const;
00391
00392 #endif
00394 private:
00395 #if !defined(_WIN32) && !defined(__APPLE__) //UNIX
00396
00397
00398 void setAttribList( const int* newAttribList );
00399 int* getAttribList() const;
00400 #endif // UNIX
00401
00402 SoGuiGLWidget* getGuiGLWidget() const;
00403
00404 QWidget* getQtWidget() const { return m_openGLWidget; }
00405
00406
00407
00408 SbBool drawToFrontBuffer;
00409
00410
00411
00412 static SbBool swapNormalBuffersCB( void *data );
00413 static SbBool bindNormalCurrentCB( void *data );
00414 static SbBool unbindNormalCurrentCB( void *data );
00415 static void* getNormalWindowCB( void *data );
00416 static void* getCurrentDisplayCB(void *data);
00417
00423 float getPixelRatio();
00424
00425 private:
00426
00427
00428
00429
00430
00431
00432
00433 void flush();
00434
00435 #if !defined(__APPLE__) && !defined(_WIN32) //UNIX
00436
00437
00438
00439
00440 void setRemoteRenderPbufferEnable( SbBool enable )
00441 { m_remoteRenderPbufferEnable = enable; }
00442
00443 SbBool isRemoteRenderPbufferEnable() const
00444 { return m_remoteRenderPbufferEnable; }
00445
00446 float getLowResPercent() {return m_lowResPercent;}
00447 #endif
00448
00449 private:
00450
00451 SoQtGLWidget( QWidget* parent = NULL,
00452 const char* name = NULL,
00453 SbBool buildInsideParent = TRUE,
00454 int glModes = SO_GLX_RGB,
00455 SbBool buildNow = TRUE,
00456 SbBool sync = TRUE );
00457
00458 SoQtGLWidget( QWidget* parent,
00459 const char* name,
00460 SbBool buildInsideParent,
00461 int glModes,
00462 SbBool buildNow,
00463 SbBool sync,
00464 SoGuiGLWidget* guiGLWidget );
00465
00466 #if defined(__linux__)
00467 SoQtGLWidget( QWidget* parent,
00468 const char* name,
00469 SbBool buildInsideParent,
00470 int glModes,
00471 SbBool buildNow,
00472 SbBool sync,
00473 SbBool connectionType );
00474
00475 SoQtGLWidget( QWidget* parent,
00476 const char* name,
00477 SbBool buildInsideParent,
00478 int glModes,
00479 SbBool buildNow,
00480 SbBool sync,
00481 SbBool connectionType,
00482 SoGuiGLWidget* guiGLWidget );
00483 #endif
00484
00485 virtual ~SoQtGLWidget();
00486
00488
00489
00490 #if 1 SoDEPRECATED
00493 virtual void paintEvent( QPaintEvent* ) {}
00494 SoDEPRECATED
00496 virtual void resizeEvent( QResizeEvent* ) {}
00497 #endif
00499 virtual void resize( int w, int h );
00500
00501 virtual void closeEvent( QCloseEvent* );
00502
00503 virtual void focusInEvent( QFocusEvent* );
00504
00505 virtual void focusOutEvent( QFocusEvent* );
00506
00507 virtual void showEvent( QShowEvent* );
00508
00509 virtual void hideEvent( QHideEvent* );
00510
00511 virtual void moveEvent( QMoveEvent* );
00512
00513 virtual void keyPressEvent( QKeyEvent* );
00514
00515 virtual void keyReleaseEvent( QKeyEvent* );
00516
00517 virtual void mouseMoveEvent( QMouseEvent* );
00518
00519 virtual void mousePressEvent( QMouseEvent* );
00520
00521 virtual void mouseReleaseEvent( QMouseEvent* );
00522
00523 virtual void mouseDoubleClickEvent( QMouseEvent* );
00524
00525 virtual void wheelEvent( QWheelEvent* );
00526
00527 bool eventFilter( QObject* object, QEvent* event );
00528
00529
00530
00531 static void eventHandler( QWidget* w, SoQtGLWidget* glw, QEvent* qe, bool* b );
00532
00533
00534 virtual void onFocusEvent(SbBool hasFocus);
00535
00537
00538
00539
00540
00541
00542 virtual void redraw() = 0;
00543
00544 virtual void processEvent( QEvent* anyevent );
00545
00546 void performPaint();
00547
00548
00549
00550
00551
00552
00553 virtual void initGraphic();
00554 virtual void sizeChanged( const SbVec2s& size );
00555 virtual void posChanged( const SbVec2i32&, const SbVec2i32& ) {};
00556 virtual void widgetChanged( QWidget* w );
00557
00558
00559
00560
00561
00562 void setGlxSize( SbVec2s newSize );
00563 const SbVec2s& getGlxSize() const { return m_guiGLWidget->getGlxSize(); }
00564
00565
00566
00567
00568 void setStereoBuffer( SbBool flag );
00569 SbBool isStereoBuffer() { return (m_guiGLWidget->getGLModes() & SO_GLX_STEREO); }
00570
00571
00572 SbBool isRGBMode() { return (m_guiGLWidget->getGLModes() & SO_GLX_RGB); }
00573
00574 #if defined(__linux__)
00575 void allocCell( Display* display, Colormap cmap, XColorPointer colorcells,
00576 int ncolors, int colorMapSize );
00577 #endif
00578
00579 SbBool waitForExpose;
00580
00581 QWidget* buildWidget( QWidget* parent );
00582 void changeCursor( QCursor newCursor );
00583 QWidget* getGlxMgrWidget() { return m_containerWidget; }
00584
00585 virtual void onExpose();
00586
00587
00588
00589 SbBool m_initialFsaaValueChanged;
00590
00591 #if !defined(_WIN32) && !defined(__APPLE__)
00592 enum RemoteRenderEnabled
00593 {
00594 OFF,
00595 ON,
00596 AUTO
00597 };
00598 RemoteRenderEnabled m_remoteRenderMode;
00599 SoQtRemoteRenderInfo* m_remoteRenderInfo;
00600 SbBool m_remoteRenderPbufferEnable;
00601 SbBool m_lowResRender;
00602 float m_lowResLowPercent;
00603 float m_lowResHighPercent;
00604 float m_lowResPercent;
00605
00606 void remoteRenderInit();
00607 void remoteRenderCleanup();
00608 void remoteRenderGinitCB( QWidget* );
00609 GLXContext remoteRenderLowResRenderGinitCB( QWidget* );
00610 void remoteRenderResizeCB();
00611 void remoteRenderSendImage();
00612 void remoteRenderSendLowResRender();
00613 SbGlContextHelper::VisualInfo remoteRenderChooseVisual();
00614 void remoteRenderFatalError( const char* methodName, const char* message );
00615
00616 void setLowResLowPercent( float percent ) { m_lowResLowPercent = percent; }
00617 void setLowResHighPercent( float percent ) { m_lowResHighPercent = percent; }
00618 float getLowResLowPercent() const { return m_lowResLowPercent; }
00619 float getLowResHighPercent() const { return m_lowResHighPercent;}
00620
00621 virtual void setLowResPercent( float newLowres ) { m_lowResPercent = newLowres; }
00622 #endif
00623
00624 private:
00625
00626 void constructorCommon( SbBool buildNow, SbBool connectionType );
00627 SoGuiGLWidget* m_guiGLWidget;
00628
00629
00630 QPointer<QWidget> m_containerWidget;
00631 QPointer<QVBoxLayout> m_containerLayout;
00632 QPointer<QWidget> m_openGLWidget;
00633
00634 SoQGLContextProxy* m_context;
00635
00636
00637 bool m_stereoActiveDelayed;
00638 bool m_stereoBufferFlag;
00639
00640 #if defined(__linux__)
00641 SbBool directConnection;
00642 #endif
00643
00644 QCursor currentCursor;
00645 int* attribList;
00646
00647 SbBool windowResized;
00648
00649 int m_frameBufferObjectId;
00650
00651
00652 void buildNormalGLXWidget( SoGLFormat* format = NULL );
00653
00654 virtual void initializeGL();
00655
00656 void destroyNormalWindows();
00657 void destroyGLXWidget( SbBool normalCall );
00658
00659 void destroyNormalWidget( SbBool normalCall );
00660
00661 void notifyProxyDestruction( QWidget* widget );
00662
00663 friend class SoQGLWidgetProxy;
00664
00665
00666 static void ginitCB( QWidget* w, SoQtGLWidget* glw, void* v );
00667 static void exposeCB( QWidget* w, SoQtGLWidget* glw, void* v );
00668 static void resizeCB( QWidget* w, SoQtGLWidget* glw, void* v );
00669
00670 static SbBool onGLFormatChangeCallback( SoGLFormat& format, void* userData );
00671
00672 SbBool remoteRenderGinitCB_pbuffer( QWidget* );
00673
00674 private Q_SLOTS:
00675 void destroyedQtContext();
00676 };
00677
00678 #endif // _SO_QT_GLWIDGET_
00679
00680