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
00027 #ifndef _SO_QT_RENDERAREA_
00028 #define _SO_QT_RENDERAREA_
00029
00030 #include <QtOpenGL/QGLColormap>
00031
00032 #include <Inventor/Qt/OivQtCompat.h>
00033 #include <Inventor/Qt/SoQtGLWidget.h>
00034
00035 #include <Inventor/SbColor.h>
00036 #include <Inventor/SoSceneManager.h>
00037 #include <Inventor/actions/SoGLRenderAction.h>
00038 #include <Inventor/nodes/SoCamera.h>
00039 #include <Inventor/SbElapsedTime.h>
00040
00041 #include <Inventor/Gui/SoGuiRenderArea.h>
00042
00043 class SoSelection;
00044 class SoQtDevice;
00045 class SoNode;
00046 class SoQtMouse;
00047 class SoQtKeyboard;
00048 class SoQtRenderArea;
00049 class SoGuiAlgoViewers;
00050 class SoTimerSensor;
00051 class SoAntialiasingParameters;
00052
00056 typedef SbBool SoQtRenderAreaEventCB( void* userData, QEvent* anyevent );
00057
00061 typedef SbBool SoQtRenderAreaRenderCB( void* userData, SoQtRenderArea* rendArea );
00062
00101 class SoQtRenderArea : public SoQtGLWidget
00102 {
00103 Q_OBJECT
00104
00105 public:
00110 SoQtRenderArea( QWidget* parent = NULL,
00111 const char* name = NULL,
00112 SbBool buildInsideParent = TRUE,
00113 SbBool getMouseInput = TRUE,
00114 SbBool getKeyboardInput = TRUE );
00118 ~SoQtRenderArea();
00119
00123 virtual void setSceneGraph( SoNode* newScene );
00124
00128 virtual SoNode* getSceneGraph();
00129
00135 void registerDevice( SoQtDevice* d );
00136
00142 void unregisterDevice( SoQtDevice* d );
00143
00151 void setBackgroundColor( const SbColor& c );
00152
00156 SbColor getBackgroundColor() const { return m_guiRenderArea->getBackgroundColor(); }
00157
00162 void setBackgroundIndex( int index ) { m_guiRenderArea->setBackgroundIndex( index ); }
00163
00167 int getBackgroundIndex() const { return m_guiRenderArea->getBackgroundIndex(); }
00168
00173 void setColorMap( QGLColormap* cmap );
00174
00178 void setViewportRegion( const SbViewportRegion& newRegion )
00179 { m_guiRenderArea->setViewportRegion( newRegion ); }
00180
00184 const SbViewportRegion &getViewportRegion() const
00185 { return m_guiRenderArea->getViewportRegion(); }
00186
00196 void setTransparencyType( SoGLRenderAction::TransparencyType type );
00197
00202 SoGLRenderAction::TransparencyType getTransparencyType() const
00203 { return m_guiRenderArea->getTransparencyType(); }
00204
00213 void setFastEditSavePolicy( SoGLRenderAction::FastEditSavePolicy policy,
00214 SbBool fastEditDelayedObjects = FALSE);
00215
00219 SoGLRenderAction::FastEditSavePolicy getFastEditSavePolicy() const
00220 { return m_guiRenderArea->getFastEditSavePolicy(); }
00221
00237 void setInvalidateCacheMode( SoGLRenderAction::InvalidateCacheMode icm );
00238
00242 SoGLRenderAction::InvalidateCacheMode getInvalidateCacheMode();
00243
00251 void setClearBeforeRender( SbBool trueOrFalse, SbBool zbTrueOrFalse = TRUE )
00252 { m_guiRenderArea->setClearBeforeRender( trueOrFalse, zbTrueOrFalse ); }
00253
00257 SbBool isClearBeforeRender() const { return m_guiRenderArea->isClearBeforeRender(); }
00258
00263 SbBool isClearZBufferBeforeRender() const { return m_guiRenderArea->isClearZBufferBeforeRender(); }
00264
00272 void setAutoRedraw( SbBool trueOrFalse );
00273
00278 SbBool isAutoRedraw() const { return m_guiRenderArea->isAutoRedraw(); }
00279
00283 void setRedrawPriority( uint32_t priority ) { m_guiRenderArea->setRedrawPriority( priority ); }
00284
00288 uint32_t getRedrawPriority() const { return m_guiRenderArea->getRedrawPriority(); }
00289
00293 static uint32_t getDefaultRedrawPriority() { return SoSceneManager::getDefaultRedrawPriority(); }
00294
00299 void render() { redraw(); }
00300
00305 void scheduleRedraw();
00306
00317 void redrawOnSelectionChange( SoSelection* s );
00318
00330 void setEventCallback( SoQtRenderAreaEventCB *fcn, void* userData = NULL );
00331
00338 void setSceneManager( SoSceneManager* sm );
00339
00346 SoSceneManager* getSceneManager() const { return m_guiRenderArea->getSceneManager(); }
00347
00356 void setGLRenderAction( SoGLRenderAction* ra );
00357
00363 SoGLRenderAction* getGLRenderAction() const { return m_guiRenderArea->getGLRenderAction(); }
00364
00369 const SbGLShareContext getShareContext();
00370
00386 void setPostRenderCallback( SoQtRenderAreaRenderCB *fcn, void* userData = NULL )
00387 { appPostRenderCB = fcn; appPostRenderData = userData; }
00388
00393 SoQtRenderAreaRenderCB *getPostRenderCallback( const void* &userData ) const
00394 { userData = appPostRenderData; return appPostRenderCB; }
00395
00409 void setFloatingColorBuffer( SbBool enable,
00410 FloatColorBufferSize size = FLOAT_16_COLOR_BUFFER );
00411
00415 void getFloatingColorBuffer( SbBool& enable, FloatColorBufferSize& size );
00416
00420 static SbBool isFloatingColorBufferSupported();
00421
00425 void sendEvent( QEvent* anEvent );
00426
00432 virtual void setMPEGRecorder( SoMPEGRenderer* recorder )
00433 { m_guiRenderArea->setMPEGRecorder( recorder ); }
00434
00438 virtual SoMPEGRenderer* getMPEGRecorder() const
00439 { return m_guiRenderArea->getMPEGRecorder(); }
00440
00441 #if 1 SoDEPRECATED
00444 void setColorMap( int startIndex, int num, const SbColor* colors );
00445
00446 #endif
00448 #if 1 SoDEPRECATED
00469 void setAntialiasing( SbBool smoothing, int numPasses );
00470
00471 using SoQtGLWidget::setAntialiasing;
00472 SoDEPRECATED
00477 void getAntialiasing( SbBool& smoothing, int& numPasses) const;
00478
00479 #endif
00482 private:
00483 SoQtRenderArea( QWidget* parent,
00484 const char* name,
00485 SbBool buildInsideParent,
00486 SbBool getMouseInput,
00487 SbBool getKeyboardInput,
00488 SoGuiAlgoViewers* guiAlgos );
00489
00490 SoQtRenderArea( QWidget* parent,
00491 const char* name,
00492 SbBool buildInsideParent,
00493 SbBool getMouseInput,
00494 SbBool getKeyboardInput,
00495 SbBool buildNow,
00496 SbBool sync,
00497 SoGuiAlgoViewers* guiAlgos );
00498
00499 SoQtRenderArea( QWidget* parent,
00500 const char* name,
00501 SbBool buildInsideParent,
00502 SbBool getMouseInput,
00503 SbBool getKeyboardInput,
00504 SbBool buildNow,
00505 SoGuiAlgoViewers* guiAlgos );
00506
00510 SoGuiAlgoViewers* getGuiAlgoViewers() const { return (SoGuiAlgoViewers*)m_guiRenderArea; }
00511
00512 private:
00513 SoGuiRenderArea* getGuiRenderArea() const;
00514
00515 void setStereoMode( SoCamera::StereoMode stMode );
00516 void setStereoElement();
00517 virtual SbBool isInteractive() const;
00518 void redrawCleanUp();
00519
00520 SoQtRenderArea( QWidget* parent,
00521 const char* name,
00522 SbBool buildInsideParent,
00523 SbBool getMouseInput,
00524 SbBool getKeyboardInput,
00525 SbBool buildNow,
00526 SbBool sync );
00527
00528
00529 float stereoBalance, stereoOffset;
00530 SbBool stereoAbsoluteAdjustments;
00531 SoCamera::StereoMode stereoMode;
00532 SbBool stereoReversed;
00533
00534 private:
00535
00536
00537
00538
00539
00540
00541 SoQtRenderArea( QWidget* parent,
00542 const char* name,
00543 SbBool buildInsideParent,
00544 SbBool getMouseInput,
00545 SbBool getKeyboardInput,
00546 SbBool buildNow );
00547
00548
00549
00550 SoQtRenderArea( QWidget* parent,
00551 const char* name,
00552 SbBool buildInsideParent,
00553 SbBool getMouseInput,
00554 SbBool getKeyboardInput,
00555 SoGuiRenderArea* guiRenderArea );
00556
00557 SoQtRenderArea( QWidget* parent,
00558 const char* name,
00559 SbBool buildInsideParent,
00560 SbBool getMouseInput,
00561 SbBool getKeyboardInput,
00562 SbBool buildNow,
00563 SbBool sync,
00564 SoGuiRenderArea* guiRenderArea );
00565
00566 SoQtRenderArea( QWidget* parent,
00567 const char* name,
00568 SbBool buildInsideParent,
00569 SbBool getMouseInput,
00570 SbBool getKeyboardInput,
00571 SbBool buildNow,
00572 SoGuiRenderArea* guiRenderArea );
00573
00574
00575
00576
00577
00578
00579
00580
00581 virtual void redraw();
00582 virtual void actualRedraw();
00583
00584
00585
00586
00587 virtual void processEvent( QEvent* anyevent );
00588 virtual void initGraphic();
00589 virtual void sizeChanged( const SbVec2s& );
00590 virtual void posChanged( const SbVec2i32&, const SbVec2i32& );
00591 virtual void widgetChanged( QWidget* w );
00592
00593 QWidget* buildWidget(QWidget* parent);
00594
00595
00596 virtual SbString getDefaultWidgetName() const;
00597 virtual SbString getDefaultTitle() const;
00598 virtual SbString getDefaultIconTitle() const;
00599
00600
00601 SbPList* m_deviceList;
00602
00603
00604 static void renderCB( void* v, SoSceneManager* sm );
00605
00606
00607 SoQtRenderAreaEventCB *defaultAppEventHandler;
00608 void *defaultAppEventHandlerData;
00609 SoQtRenderAreaEventCB *appEventHandler;
00610 void *appEventHandlerData;
00611
00612
00613 SbBool invokeAppCB( QEvent* anyevent );
00614 SbBool processInventorEvent( QEvent* anyevent );
00615 const SoEvent* translateAnyEvent( QEvent* anyevent );
00616
00617
00618 SoQtRenderAreaRenderCB *appPostRenderCB;
00619 void *appPostRenderData;
00620
00621
00622 SbBool m_isFloatingPointRendering;
00623 FloatColorBufferSize m_floatingPointRenderingPrecision;
00624
00625
00626 void onFocusEvent(SbBool hasFocus);
00627
00628 private:
00629
00630
00631 #if defined(__linux__)
00632 XColorPointer m_mapColors;
00633 int m_mapColorNum;
00634 #endif
00635
00636 SoQtMouse* m_mouseDevice;
00637 SoQtKeyboard* m_keybdDevice;
00638 void reinstallDevices( QWidget* newWidget );
00639
00640 static void selectionChangeCB( void* userData, SoSelection* s );
00641 QWidget* m_deviceWidget;
00642
00643 SbBool m_firstEvent;
00644
00645 void activate();
00646 void deactivate();
00647
00648
00649 void constructorCommon( SbBool getMouseInput,
00650 SbBool getKeyboardInput,
00651 SbBool buildNow );
00652
00653 void constructorCommon2( SbBool getMouseInput,
00654 SbBool getKeyboardInput,
00655 SbBool buildNow );
00656
00657
00658 QPoint m_oldPos;
00659 QSize m_oldSize;
00660 QSize m_minimumSize;
00661 QSize m_maximumSize;
00662
00663 SoGuiRenderArea* m_guiRenderArea;
00664
00665
00666
00667
00668
00669 static SbBool s_abortRenderCallback(SoAction*,void*);
00670
00671 bool m_firstStdRedraw;
00672 bool m_firstConnectedRedraw;
00673 SoTimerSensor* m_viewerUpdaterSensor;
00674 static void viewerUpdaterCB( void*, SoSensor* );
00675 void updateFirstFrame();
00676
00677 SoAntialiasingParameters* m_accumulationParameters;
00678
00680 struct RenderAreaSaveRestore {
00681 RenderAreaSaveRestore();
00682 virtual ~RenderAreaSaveRestore();
00684 SbVec2i32 m_previousRenderingSize;
00686 GLuint m_backupFBOId;
00688 GLuint m_colorTextureId;
00690 GLuint m_depthStencilTextureId;
00692 SoRef<SoGLContext> m_context;
00693 };
00694
00696 void saveRenderArea();
00697
00699 void restoreRenderArea();
00700
00701 RenderAreaSaveRestore m_restoreFBO;
00702
00703 private Q_SLOTS:
00704 void visibilityChangeCB( SbBool visible );
00705
00706 };
00707
00708
00709 #endif // _SO_QT_RENDERAREA_
00710
00711
00712