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
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #ifdef SOQT
00051 # include <Inventor/Qt/SoQtGLWidget.h>
00052 #elif defined(SOWX)
00053 # include <Inventor/Wx/SoWxGLWidget.h>
00054 #elif defined _WIN32
00055 # include <Inventor/Win/SoWinGLWidget.h>
00056 #else // _WIN32
00057
00058 #ifndef _SO_XT_GL_WIDGET_H_
00059 #define _SO_XT_GL_WIDGET_H_
00060
00061 #include <X11/Intrinsic.h>
00062 #include <Inventor/helpers/SbGlContextHelper.h>
00063 #include <Inventor/Xt/SoXtComponent.h>
00064 #include <Inventor/components/SoGLGraphicConfigTemplate.h>
00065 #include <Inventor/components/SoGLGraphicDevice.h>
00066 #include <Inventor/components/SoGLGraphicConfig.h>
00067 #include <Inventor/devices/SoGLFormat.h>
00068 #include <Inventor/threads/SbThread.h>
00069 #include <Inventor/nodes/SoFullSceneAntialiasing.h>
00070
00071 #include <Inventor/Gui/SoGuiGLWidget.h>
00072
00073 #if defined(sun) || defined(__linux__)
00074 # define NUM_OVERLAY_PIXELS 8
00075 #endif
00076
00077 class SoXtRemoteRenderInfo;
00078 class SoGLContext;
00079
00081
00082
00083
00084
00086
00109 class SoXtGLWidget : public SoXtComponent
00110 {
00111
00112 public:
00113
00115 enum FloatColorBufferSize
00116 {
00120 FLOAT_16_COLOR_BUFFER = SoGuiGLWidget::FLOAT_16_COLOR_BUFFER,
00124 FLOAT_32_COLOR_BUFFER = SoGuiGLWidget::FLOAT_32_COLOR_BUFFER
00125 };
00126
00130 int getColorMapSize();
00131
00140 virtual Window getNormalWindow();
00141
00150 SbGlContextHelper::GLContext getNormalContext() const;
00151
00152 SoGLContext* getNormalSoContext() const;
00153
00154 SoGLContext* getOverlaySoContext() const;
00155
00164 SoWidget getNormalWidget() const;
00165
00175 virtual void setNormalVisual( XVisualInfo* vis );
00176
00180 XVisualInfo* getNormalVisual();
00181
00187 virtual void setDoubleBuffer( SbBool onOrOff );
00188
00192 SbBool isDoubleBuffer();
00193
00197 void setAntialiasing(const float quality, const SoSceneManager::AntialiasingMode mode = SoSceneManager::AUTO);
00198
00202 void setAntialiasing(SoAntialiasingParameters* advancedParameters);
00203
00207 float getAntialiasingQuality() const;
00208
00212 SoSceneManager::AntialiasingMode getAntialiasingMode() const;
00213
00217 SoAntialiasingParameters* getAntialiasingParameters() const;
00218
00223 void setBorder( SbBool onOrOff );
00224
00228 SbBool isBorder() const { return m_guiGLWidget->isBorder(); }
00229
00234 void setDrawToFrontBufferEnable( SbBool enableFlag );
00235
00239 SbBool isDrawToFrontBufferEnable() const { return m_guiGLWidget->isDrawToFrontBufferEnable(); }
00240
00245 virtual SbBool bindNormalContext();
00246
00250 virtual SbBool unbindNormalContext();
00251
00256 virtual SbBool swapNormalBuffers();
00257
00258 #if 1 SoDEPRECATED
00263 unsigned long getOverlayTransparentPixel();
00264 SoDEPRECATED
00269 int getOverlayColorMapSize();
00270 SoDEPRECATED
00280 Window getOverlayWindow();
00281 SoDEPRECATED
00291 SbGlContextHelper::GLContext getOverlayContext() const;
00292 SoDEPRECATED
00302 SoWidget getOverlayWidget() const;
00303
00310 #if defined(sun) || defined(__linux__)
00311 SoDEPRECATED
00312 virtual void setSunOverlayBackgroundIndex();
00313 #endif
00314 SoDEPRECATED
00325 virtual void setOverlayVisual( XVisualInfo* vis );
00326 SoDEPRECATED
00331 XVisualInfo* getOverlayVisual();
00332 SoDEPRECATED
00338 SbBool makeOverlayCurrent();
00339 SoDEPRECATED
00345 SbBool swapOverlayBuffers();
00346 #endif
00351 SoGLGraphicConfigTemplate* getGraphicConfigTemplate();
00352
00356 void setGraphicConfigTemplate( SoGLGraphicConfigTemplate* gTemplate );
00357
00371 void setFloatingColorBuffer( SbBool enable, FloatColorBufferSize size = FLOAT_16_COLOR_BUFFER );
00372
00377 void getFloatingColorBuffer( SbBool& enable, FloatColorBufferSize& size );
00378
00381 bool saveSnapshot( const SbString& filename, bool overwrite = true );
00382
00383 #if 1 SoDEPRECATED
00389 SbBool isFsaaSupported();
00390 SoDEPRECATED
00395 virtual SbBool makeNormalCurrent();
00396
00397 #endif
00399 #if 1 SoDEPRECATED
00422 SbBool setFullSceneAntialiasing ( SbBool enable,
00423 float quality = -1.0,
00424 int filterMask = SoFullSceneAntialiasing::ALL );
00425 SoDEPRECATED
00430 SbBool isFullSceneAntialiasingEnabled() const;
00431 SoDEPRECATED
00436 SbBool getFullSceneAntialiasing( float& quality );
00437 SoDEPRECATED
00442 SbBool isFullSceneAntialiasingAvailable() const;
00443 SoDEPRECATED
00448 SbBool isFullSceneAntialiasingHQAvailable() const;
00449 SoDEPRECATED
00456 SbBool setFullSceneAntialiasingHQ( SbBool enable );
00457 SoDEPRECATED
00462 SbBool isFullSceneAntialiasingHQEnabled() const;
00463
00464 #endif
00466 private:
00467
00468
00469
00470
00471
00472
00473
00474 void flush();
00475
00476
00477
00478
00479
00480 void setRemoteRenderPbufferEnable( SbBool enable ) { m_remoteRenderPbufferEnable = enable; }
00481 SbBool isRemoteRenderPbufferEnable() const { return m_remoteRenderPbufferEnable; }
00482
00483 float getLowResPercent() { return m_lowResPercent; }
00484
00485
00486 SbBool ctxIsDirect();
00487
00488 private:
00489
00490
00491 void syncFromCurrentConfig();
00492
00493
00494 void syncToCurrentConfigTemplate( XVisualInfo* newvis );
00495
00496 SbBool currentGraphicConfigTemplateIsUsed;
00497 SoGLGraphicConfigTemplate currentGraphicConfigTemplate;
00498
00499
00500 SoGLGraphicDevice* getGraphicDevice();
00501
00502
00503 SoGLGraphicConfig* getGraphicConfig();
00504
00505 SbBool isFsaaSupportHighQuality();
00506 SbBool isFsaaHighQuality();
00507
00508 SoGuiGLWidget* getGuiGLWidget() const;
00509
00510
00511 int getDisplayListShareGroup( SoGLContext* ctx );
00512
00513
00514
00515 SbBool drawToFrontBuffer;
00516 SbBool m_isFloatingPointRendering;
00517 FloatColorBufferSize m_floatingPointRenderingPrecision;
00518
00519
00520
00521 static SbBool swapNormalBuffersCB(void *data);
00522 static SbBool bindNormalCurrentCB(void *data);
00523 static SbBool unbindNormalCurrentCB(void *data);
00524 static void* getNormalWindowCB(void *data);
00525 static void* getCurrentDisplayCB(void *data);
00526
00527 private:
00528
00529
00530
00531
00532
00533
00534
00535 void updateCurrentDeviceAndConfig( Display* display );
00536
00537 SbBool currentGraphicConfigIsUsed;
00538 SoGLGraphicConfig* currentGraphicConfig;
00539 SbBool currentGraphicDeviceIsUsed;
00540 SoGLGraphicDevice* currentGraphicDevice;
00541
00542
00543
00544
00545
00546 SoXtGLWidget( SoWidget parent = NULL,
00547 const char* name = NULL,
00548 SbBool buildInsideParent = TRUE,
00549 int glModes = SO_GLX_RGB | SO_GLX_ZBUFFER | SO_GLX_STENCIL,
00550 SbBool buildNow = TRUE,
00551 SbBool sync = TRUE );
00552 SoXtGLWidget( SoWidget parent,
00553 const char* name,
00554 SbBool buildInsideParent,
00555 int glModes,
00556 SbBool buildNow,
00557 SbBool sync,
00558 SoGuiGLWidget* guiGLWidget );
00559
00560 virtual ~SoXtGLWidget();
00561
00562
00563
00564
00565
00566 virtual void redraw() = 0;
00567 #if 1 SoDEPRECATED
00569 virtual void redrawOverlay();
00570 #endif
00571 virtual void processEvent( XAnyEvent* anyevent );
00572
00573
00574
00575
00576
00577
00578 virtual void initGraphic();
00579 #if 1 SoDEPRECATED
00581 virtual void initOverlayGraphic();
00582 #endif
00583 virtual void sizeChanged( const SbVec2s& );
00584 virtual void posChanged( const SbVec2i32&, const SbVec2i32& );
00585 virtual void widgetChanged( SoWidget newWidget );
00586
00587
00588
00589
00590
00591 void setGlxSize( SbVec2s newSize );
00592 const SbVec2s& getGlxSize() const { return m_guiGLWidget->getGlxSize(); }
00593
00594
00595
00596 static void eventHandler( SoWidget w, SoXtGLWidget* p, XAnyEvent* xe, Boolean* b );
00597
00598
00599
00600
00601 void setStereoBuffer( SbBool flag );
00602 SbBool isStereoBuffer() { return (m_guiGLWidget->getGLModes() & SO_GLX_STEREO); }
00603
00604
00605 SbBool isRGBMode() { return (m_guiGLWidget->getGLModes() & SO_GLX_RGB); }
00606
00607 #if defined(sun) || defined(__linux__)
00608 void allocCell( Display *display, Colormap cmap, XColor *colorcells, int ncolors, int colorMapSize );
00609 #endif
00610
00611
00612 Colormap getColorMap() const
00613 { return m_guiGLWidget->getColorMap(); }
00614
00615 #if 1
00616 // set when overlay is used
00617 SoDEPRECATED
00618 Colormap getOverlayColorMap() const { return m_guiGLWidget->getOverlayColorMap(); }
00619 #endif
00621 SbBool waitForExpose; // prevent redraws until an expose is received
00622
00623
00624
00625 SoWidget buildWidget( SoWidget parent );
00626 SoWidget getGlxMgrWidget() { return mgrWidget; }
00627
00628
00629 enum RemoteRenderEnabled
00630 {
00631 OFF,
00632 ON,
00633 AUTO
00634 };
00635 RemoteRenderEnabled m_remoteRenderMode;
00636 SbBool m_remoteRender;
00637 SoXtRemoteRenderInfo* m_remoteRenderInfo;
00638 SbBool m_remoteRenderPbufferEnable;
00639 SbBool m_lowResRender;
00640 float m_lowResLowPercent;
00641 float m_lowResHighPercent;
00642 float m_lowResPercent;
00643
00644 void remoteRenderInit();
00645 void remoteRenderCleanup();
00646 void remoteRenderGinitCB( SoWidget w );
00647 SbGlContextHelper::GLContext remoteRenderLowResRenderGinitCB( SoWidget w );
00648 void remoteRenderResizeCB();
00649 void remoteRenderSendImage();
00650 void remoteRenderSendLowResRender();
00651 XVisualInfo* remoteRenderChooseVisual();
00652 void remoteRenderFatalError( const char* methodName, const char* message );
00653
00654 void setLowResLowPercent( float percent ) { m_lowResLowPercent = percent;}
00655 void setLowResHighPercent( float percent ) { m_lowResHighPercent = percent;}
00656 float getLowResLowPercent() const { return m_lowResLowPercent;}
00657 float getLowResHighPercent() const { return m_lowResHighPercent;}
00658
00659 virtual void setLowResPercent( float newLowres ) {m_lowResPercent = newLowres;}
00660
00661
00662 SbThreadId_t dwThreadId;
00663 SbThreadId_t getThreadId() { return dwThreadId; };
00664 void setThreadId( SbThreadId_t id ) { dwThreadId=id; };
00665
00666 virtual void onExpose();
00667 #if 1 SoDEPRECATED
00669 virtual void onOverlayExpose();
00670 #endif
00672 SbBool m_initialFsaaEnable;
00673 int m_initialFsaaFilterMask;
00674 SbBool m_initialFsaaValueChanged;
00675
00676 private:
00677
00678 SoWidget mgrWidget;
00679 SoWidget m_widgetNormal, m_widgetOverlay;
00680
00681 SoGLContext* m_contextNormal;
00682 SoGLContext* m_contextOverlay;
00683
00684 int* attribList;
00685
00686
00687
00688
00689
00690 SbBool windowResized;
00691
00692 SbBool directConnection;
00693
00694
00695
00696 void buildNormalGLXWidget( XVisualInfo* vis = NULL );
00697 void buildOverlayGLXWidget( XVisualInfo* vis = NULL );
00698 #if defined(sun) || defined(__linux__)
00699 void buildSunOverlayWindow( SoWidget glx, SoXtGLWidget* p );
00700 #endif
00701 void destroyNormalWindows(SbBool normalCall=TRUE);
00702 void destroyGLXWidget( SoWidget& w, SoGLContext*& ctx, SbBool normalWindow );
00703
00704 SoWidget createWindow( SoGLFormat* format );
00705 void destroyWindow( SoWidget widget );
00706
00707 static SbBool onGLFormatChangeCallback( SoGLFormat& format, void* userData );
00708
00709
00710 static void ginitCB( SoWidget w, SoXtGLWidget* v, XtPointer p );
00711 static void overlayGinitCB( SoWidget glx, SoXtGLWidget* p, XtPointer pt );
00712 static void exposeCB( SoWidget w, SoXtGLWidget* v, XtPointer p );
00713 static void overlayExposeCB( SoWidget w, SoXtGLWidget* v, XtPointer p );
00714 static void resizeCB( SoWidget glx, SoXtGLWidget* p, XtPointer pt );
00715
00716 int m_nPixelFormat;
00717
00718 SbBool m_supportFSAA;
00719 SbBool m_isFsaaEnable;
00720 SbBool m_currentConfigSupportFsaa;
00721
00722
00723 bool m_stereoActiveDelayed;
00724 bool m_stereoBufferFlag;
00725
00726 SbBool m_singleBufferExpected;
00727
00728 SoGuiGLWidget* m_guiGLWidget;
00729
00730 void constructorCommon( int glModes, SbBool buildNow );
00731
00732 SbBool remoteRenderGinitCB_pbuffer( SoWidget w );
00733 };
00734
00735 inline void
00736 SoXtGLWidget::posChanged( const SbVec2i32&, const SbVec2i32& )
00737 {}
00738
00739 #endif // _SO_XT_GL_WIDGET_H_
00740
00741 #endif // _WIN32
00742
00743
00744