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 class QOpenGLWindow;
00068
00090 class SoQtGLWidget : public SoQtComponent
00091 {
00092 Q_OBJECT
00093
00094 public:
00095
00097 enum FloatColorBufferSize
00098 {
00102 FLOAT_16_COLOR_BUFFER = SoGuiGLWidget::FLOAT_16_COLOR_BUFFER,
00106 FLOAT_32_COLOR_BUFFER = SoGuiGLWidget::FLOAT_32_COLOR_BUFFER
00107 };
00108
00112 int getColorMapSize();
00113
00117 void setColorMapSize( int size );
00118
00128 virtual WindowQt getNormalWindow();
00129
00138 QOpenGLContext* getQOpenGLContext();
00139
00148 SoGLContext* getNormalSoContext();
00149
00158 QWidget* getNormalWidget();
00159
00163 QSurfaceFormat getQSurfaceFormat();
00164
00176 virtual void setNormalVisual( QSurfaceFormat vis );
00177
00189 virtual void setNormalVisual( const SoGLFormat& format );
00190
00194 virtual void show();
00195
00199 virtual void hide();
00200
00206 virtual void setDoubleBuffer( SbBool onOrOff );
00207
00211 SbBool isDoubleBuffer() { return m_guiGLWidget->isDoubleBuffer(); }
00212
00216 void setBorder( SbBool onOrOff );
00217
00221 int getBorderSize() { return m_guiGLWidget->getBorderSize(); }
00222
00226 SbBool isBorder() const { return m_guiGLWidget->isBorder(); }
00227
00232 void setDrawToFrontBufferEnable( SbBool enableFlag );
00233
00237 SbBool isDrawToFrontBufferEnable() const { return m_guiGLWidget->isDrawToFrontBufferEnable(); }
00238
00243 virtual SbBool bindNormalContext();
00244
00248 virtual SbBool unbindNormalContext();
00249
00253 virtual SbBool swapNormalBuffers();
00254
00262 virtual void setCursor( const QCursor& newCursor );
00263
00267 QCursor getCursor() const;
00268
00272 void setAntialiasing(const float quality, const SoSceneManager::AntialiasingMode mode = SoSceneManager::AUTO);
00273
00277 void setAntialiasing(SoAntialiasingParameters* advancedParameters);
00278
00282 float getAntialiasingQuality() const;
00283
00287 SoSceneManager::AntialiasingMode getAntialiasingMode() const;
00288
00292 SoAntialiasingParameters* getAntialiasingParameters() const;
00293
00296 bool saveSnapshot( const SbString& filename, bool overwrite = true );
00297
00298 private:
00299 #if !defined(_WIN32) && !defined(__APPLE__) //UNIX
00300
00301
00302 void setAttribList( const int* newAttribList );
00303 int* getAttribList() const;
00304 #endif // UNIX
00305
00306 SoGuiGLWidget* getGuiGLWidget() const;
00307
00308
00309 QWindow* getInternalQWindow();
00310
00311
00312
00313 SbBool drawToFrontBuffer;
00314
00315
00316
00317 static SbBool swapNormalBuffersCB( void *data );
00318 static SbBool bindNormalCurrentCB( void *data );
00319 static SbBool unbindNormalCurrentCB( void *data );
00320 static void* getNormalWindowCB( void *data );
00321 static void* getCurrentDisplayCB(void *data);
00322
00328 float getPixelRatio();
00329
00334 void updateInternalOpenGLWindow( bool immediatUpdate );
00335
00336 private:
00337
00338
00339
00340
00341
00342
00343
00344 void flush();
00345
00346 #if !defined(__APPLE__) && !defined(_WIN32) //UNIX
00347
00348
00349
00350
00351 void setRemoteRenderPbufferEnable( SbBool enable )
00352 { m_remoteRenderPbufferEnable = enable; }
00353
00354 SbBool isRemoteRenderPbufferEnable() const
00355 { return m_remoteRenderPbufferEnable; }
00356
00357 float getLowResPercent() {return m_lowResPercent;}
00358 #endif
00359
00360 private:
00361
00362 SoQtGLWidget( QWidget* parent = NULL,
00363 const char* name = NULL,
00364 SbBool buildInsideParent = TRUE,
00365 int glModes = SO_GLX_RGB,
00366 SbBool buildNow = TRUE,
00367 SbBool sync = TRUE );
00368
00369 SoQtGLWidget( QWidget* parent,
00370 const char* name,
00371 SbBool buildInsideParent,
00372 int glModes,
00373 SbBool buildNow,
00374 SbBool sync,
00375 SoGuiGLWidget* guiGLWidget );
00376
00377 #if defined(__linux__)
00378 SoQtGLWidget( QWidget* parent,
00379 const char* name,
00380 SbBool buildInsideParent,
00381 int glModes,
00382 SbBool buildNow,
00383 SbBool sync,
00384 SbBool connectionType );
00385
00386 SoQtGLWidget( QWidget* parent,
00387 const char* name,
00388 SbBool buildInsideParent,
00389 int glModes,
00390 SbBool buildNow,
00391 SbBool sync,
00392 SbBool connectionType,
00393 SoGuiGLWidget* guiGLWidget );
00394 #endif
00395
00396 virtual ~SoQtGLWidget();
00397
00399
00400
00401 virtual void resize( int w, int h );
00402
00403 virtual void closeEvent( QCloseEvent* );
00404
00405 virtual void focusInEvent( QFocusEvent* );
00406
00407 virtual void focusOutEvent( QFocusEvent* );
00408
00409 virtual void showEvent( QShowEvent* );
00410
00411 virtual void hideEvent( QHideEvent* );
00412
00413 virtual void moveEvent( QMoveEvent* );
00414
00415 virtual void keyPressEvent( QKeyEvent* );
00416
00417 virtual void keyReleaseEvent( QKeyEvent* );
00418
00419 virtual void mouseMoveEvent( QMouseEvent* );
00420
00421 virtual void mousePressEvent( QMouseEvent* );
00422
00423 virtual void mouseReleaseEvent( QMouseEvent* );
00424
00425 virtual void mouseDoubleClickEvent( QMouseEvent* );
00426
00427 virtual void wheelEvent( QWheelEvent* );
00428
00429 bool eventFilter( QObject* object, QEvent* event );
00430
00431
00432
00433 static void eventHandler( QWidget* w, SoQtGLWidget* glw, QEvent* qe, bool* b );
00434
00435
00436 virtual void onFocusEvent(SbBool hasFocus);
00437
00439
00440
00441
00442
00443
00444 virtual void redraw() = 0;
00445
00446 virtual void processEvent( QEvent* anyevent );
00447
00448 void performPaint();
00449
00450
00451
00452
00453
00454
00455 virtual void initGraphic();
00456 virtual void sizeChanged( const SbVec2s& size );
00457 virtual void posChanged( const SbVec2i32&, const SbVec2i32& ) {};
00458 virtual void widgetChanged( QWidget* w );
00459
00460
00461
00462
00463
00464 void setGlxSize( SbVec2s newSize );
00465 const SbVec2s& getGlxSize() const { return m_guiGLWidget->getGlxSize(); }
00466
00467
00468
00469
00470 void setStereoBuffer( SbBool flag );
00471 SbBool isStereoBuffer() { return (m_guiGLWidget->getGLModes() & SO_GLX_STEREO); }
00472
00473
00474 SbBool isRGBMode() { return (m_guiGLWidget->getGLModes() & SO_GLX_RGB); }
00475
00476 #if defined(__linux__)
00477 void allocCell( Display* display, Colormap cmap, XColorPointer colorcells,
00478 int ncolors, int colorMapSize );
00479 #endif
00480
00481 SbBool waitForExpose;
00482
00483 QWidget* buildWidget( QWidget* parent );
00484 void changeCursor( QCursor newCursor );
00485 QWidget* getGlxMgrWidget() { return m_containerWidget; }
00486
00487 virtual void onExpose();
00488
00489
00490
00491 SbBool m_initialFsaaValueChanged;
00492
00493 #if !defined(_WIN32) && !defined(__APPLE__)
00494 enum RemoteRenderEnabled
00495 {
00496 OFF,
00497 ON,
00498 AUTO
00499 };
00500 RemoteRenderEnabled m_remoteRenderMode;
00501 SoQtRemoteRenderInfo* m_remoteRenderInfo;
00502 SbBool m_remoteRenderPbufferEnable;
00503 SbBool m_lowResRender;
00504 float m_lowResLowPercent;
00505 float m_lowResHighPercent;
00506 float m_lowResPercent;
00507
00508 void remoteRenderInit();
00509 void remoteRenderCleanup();
00510 void remoteRenderGinitCB( QWidget* );
00511 GLXContext remoteRenderLowResRenderGinitCB( QWidget* );
00512 void remoteRenderResizeCB();
00513 void remoteRenderSendImage();
00514 void remoteRenderSendLowResRender();
00515 SbGlContextHelper::VisualInfo remoteRenderChooseVisual();
00516 void remoteRenderFatalError( const char* methodName, const char* message );
00517
00518 void setLowResLowPercent( float percent ) { m_lowResLowPercent = percent; }
00519 void setLowResHighPercent( float percent ) { m_lowResHighPercent = percent; }
00520 float getLowResLowPercent() const { return m_lowResLowPercent; }
00521 float getLowResHighPercent() const { return m_lowResHighPercent;}
00522
00523 virtual void setLowResPercent( float newLowres ) { m_lowResPercent = newLowres; }
00524 #endif
00525
00526 private:
00527
00528 void constructorCommon( SbBool buildNow, SbBool connectionType );
00529 SoGuiGLWidget* m_guiGLWidget;
00530
00531 QPointer<QWidget> m_containerWidget;
00532 QPointer<QVBoxLayout> m_containerLayout;
00533 QPointer<QWidget> m_internalWidget;
00534 QPointer<QWindow> m_internalWindow;
00535
00536 SoQGLContextProxy* m_context;
00537
00538
00539 bool m_stereoActiveDelayed;
00540 bool m_stereoBufferFlag;
00541
00542 #if defined(__linux__)
00543 SbBool directConnection;
00544 #endif
00545
00546 QCursor currentCursor;
00547 int* attribList;
00548
00549 SbBool windowResized;
00550
00551
00552 void buildNormalGLXWidget( SoGLFormat* format = NULL );
00553
00554 virtual void initializeGL();
00555
00556 void destroyNormalWindows();
00557 void destroyGLXWidget( SbBool normalCall );
00558
00559 void destroyNormalWidget( SbBool normalCall );
00560
00561 void notifyProxyDestruction( QWindow* window );
00562
00563 friend class SoQGLWidgetProxy;
00564
00565
00566 static void ginitCB( QWidget* w, SoQtGLWidget* glw, void* v );
00567 static void exposeCB( QWidget* w, SoQtGLWidget* glw, void* v );
00568 static void resizeCB( QWidget* w, SoQtGLWidget* glw, void* v );
00569
00570 static SbBool onGLFormatChangeCallback( SoGLFormat& format, void* userData );
00571
00572 SbBool remoteRenderGinitCB_pbuffer( QWidget* );
00573
00574
00575 bool m_firstRenderSync;
00576 static std::map<SoQtGLWidget*, bool> s_blackRendering;
00577 static std::map<SoQtGLWidget*, bool> s_widgetRendered;
00578
00579 private Q_SLOTS:
00580 void destroyedQtContext();
00581 };
00582
00583 #endif // _SO_QT_GLWIDGET_
00584
00585