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 #include <Inventor/devices/SoGLContext.h>
00073
00074 class SoXtRemoteRenderInfo;
00075
00077
00078
00079
00080
00082
00104 class SoXtGLWidget : public SoXtComponent
00105 {
00106
00107 public:
00108
00110 enum FloatColorBufferSize
00111 {
00115 FLOAT_16_COLOR_BUFFER = SoGuiGLWidget::FLOAT_16_COLOR_BUFFER,
00119 FLOAT_32_COLOR_BUFFER = SoGuiGLWidget::FLOAT_32_COLOR_BUFFER
00120 };
00121
00125 int getColorMapSize();
00126
00135 virtual Window getNormalWindow();
00136
00145 SbGlContextHelper::GLContext getNormalContext() const;
00146
00147 SoGLContext* getNormalSoContext() const;
00148
00157 SoWidget getNormalWidget() const;
00158
00168 virtual void setNormalVisual( XVisualInfo* vis );
00169
00173 XVisualInfo* getNormalVisual();
00174
00180 virtual void setDoubleBuffer( SbBool onOrOff );
00181
00185 SbBool isDoubleBuffer();
00186
00190 void setAntialiasing(const float quality, const SoSceneManager::AntialiasingMode mode = SoSceneManager::AUTO);
00191
00195 void setAntialiasing(SoAntialiasingParameters* advancedParameters);
00196
00200 float getAntialiasingQuality() const;
00201
00205 SoSceneManager::AntialiasingMode getAntialiasingMode() const;
00206
00210 SoAntialiasingParameters* getAntialiasingParameters() const;
00211
00216 void setBorder( SbBool onOrOff );
00217
00221 SbBool isBorder() const { return m_guiGLWidget->isBorder(); }
00222
00227 void setDrawToFrontBufferEnable( SbBool enableFlag );
00228
00232 SbBool isDrawToFrontBufferEnable() const { return m_guiGLWidget->isDrawToFrontBufferEnable(); }
00233
00238 virtual SbBool bindNormalContext();
00239
00243 virtual SbBool unbindNormalContext();
00244
00249 virtual SbBool swapNormalBuffers();
00250
00254 SoGLGraphicConfigTemplate* getGraphicConfigTemplate();
00255
00259 void setGraphicConfigTemplate( SoGLGraphicConfigTemplate* gTemplate );
00260
00274 void setFloatingColorBuffer( SbBool enable, FloatColorBufferSize size = FLOAT_16_COLOR_BUFFER );
00275
00280 void getFloatingColorBuffer( SbBool& enable, FloatColorBufferSize& size );
00281
00284 bool saveSnapshot( const SbString& filename, bool overwrite = true );
00285
00286 #if 1 SoDEPRECATED
00292 SbBool isFsaaSupported();
00293 SoDEPRECATED
00298 virtual SbBool makeNormalCurrent();
00299
00300 #endif
00302 #if 1 SoDEPRECATED
00325 SbBool setFullSceneAntialiasing ( SbBool enable,
00326 float quality = -1.0,
00327 int filterMask = SoFullSceneAntialiasing::ALL );
00328 SoDEPRECATED
00333 SbBool isFullSceneAntialiasingEnabled() const;
00334 SoDEPRECATED
00339 SbBool getFullSceneAntialiasing( float& quality );
00340 SoDEPRECATED
00345 SbBool isFullSceneAntialiasingAvailable() const;
00346 SoDEPRECATED
00351 SbBool isFullSceneAntialiasingHQAvailable() const;
00352 SoDEPRECATED
00357 SbBool setFullSceneAntialiasingHQ( SbBool enable );
00358 SoDEPRECATED
00363 SbBool isFullSceneAntialiasingHQEnabled() const;
00364
00365 #endif
00367 private:
00368
00369
00370
00371
00372
00373
00374
00375 void flush();
00376
00377
00378
00379
00380
00381 void setRemoteRenderPbufferEnable( SbBool enable ) { m_remoteRenderPbufferEnable = enable; }
00382 SbBool isRemoteRenderPbufferEnable() const { return m_remoteRenderPbufferEnable; }
00383
00384 float getLowResPercent() { return m_lowResPercent; }
00385
00386
00387 SbBool ctxIsDirect();
00388
00389 private:
00390
00391
00392 void syncFromCurrentConfig();
00393
00394
00395 void syncToCurrentConfigTemplate( XVisualInfo* newvis );
00396
00397 SbBool currentGraphicConfigTemplateIsUsed;
00398 SoGLGraphicConfigTemplate currentGraphicConfigTemplate;
00399
00400
00401 SoGLGraphicDevice* getGraphicDevice();
00402
00403
00404 SoGLGraphicConfig* getGraphicConfig();
00405
00406 SbBool isFsaaSupportHighQuality();
00407 SbBool isFsaaHighQuality();
00408
00409 SoGuiGLWidget* getGuiGLWidget() const;
00410
00411
00412 int getDisplayListShareGroup( SoGLContext* ctx );
00413
00414
00415
00416 SbBool drawToFrontBuffer;
00417 SbBool m_isFloatingPointRendering;
00418 FloatColorBufferSize m_floatingPointRenderingPrecision;
00419
00420
00421
00422 static SbBool swapNormalBuffersCB(void *data);
00423 static SbBool bindNormalCurrentCB(void *data);
00424 static SbBool unbindNormalCurrentCB(void *data);
00425 static void* getNormalWindowCB(void *data);
00426 static void* getCurrentDisplayCB(void *data);
00427
00428 private:
00429
00430
00431
00432
00433
00434
00435
00436 void updateCurrentDeviceAndConfig( Display* display );
00437
00438 SbBool currentGraphicConfigIsUsed;
00439 SoGLGraphicConfig* currentGraphicConfig;
00440 SbBool currentGraphicDeviceIsUsed;
00441 SoGLGraphicDevice* currentGraphicDevice;
00442
00443
00444
00445
00446
00447 SoXtGLWidget( SoWidget parent = NULL,
00448 const char* name = NULL,
00449 SbBool buildInsideParent = TRUE,
00450 int glModes = SO_GLX_RGB | SO_GLX_ZBUFFER | SO_GLX_STENCIL,
00451 SbBool buildNow = TRUE,
00452 SbBool sync = TRUE );
00453 SoXtGLWidget( SoWidget parent,
00454 const char* name,
00455 SbBool buildInsideParent,
00456 int glModes,
00457 SbBool buildNow,
00458 SbBool sync,
00459 SoGuiGLWidget* guiGLWidget );
00460
00461 virtual ~SoXtGLWidget();
00462
00463
00464
00465 virtual void redraw() = 0;
00466 virtual void processEvent( XAnyEvent* anyevent );
00467
00468
00469
00470
00471
00472
00473 virtual void initGraphic();
00474 virtual void sizeChanged( const SbVec2s& );
00475 virtual void posChanged( const SbVec2i32&, const SbVec2i32& );
00476 virtual void widgetChanged( SoWidget newWidget );
00477
00478
00479
00480
00481
00482 void setGlxSize( SbVec2s newSize );
00483 const SbVec2s& getGlxSize() const { return m_guiGLWidget->getGlxSize(); }
00484
00485
00486
00487 static void eventHandler( SoWidget w, SoXtGLWidget* p, XAnyEvent* xe, Boolean* b );
00488
00489
00490
00491
00492 void setStereoBuffer( SbBool flag );
00493 SbBool isStereoBuffer() { return (m_guiGLWidget->getGLModes() & SO_GLX_STEREO); }
00494
00495
00496 SbBool isRGBMode() { return (m_guiGLWidget->getGLModes() & SO_GLX_RGB); }
00497
00498 #if defined(__linux__)
00499 void allocCell( Display *display, Colormap cmap, XColor *colorcells, int ncolors, int colorMapSize );
00500 #endif
00501
00502
00503 Colormap getColorMap() const
00504 { return m_guiGLWidget->getColorMap(); }
00505
00506 SbBool waitForExpose;
00507
00508
00509
00510 SoWidget buildWidget( SoWidget parent );
00511 SoWidget getGlxMgrWidget() { return mgrWidget; }
00512
00513
00514 enum RemoteRenderEnabled
00515 {
00516 OFF,
00517 ON,
00518 AUTO
00519 };
00520 RemoteRenderEnabled m_remoteRenderMode;
00521 SbBool m_remoteRender;
00522 SoXtRemoteRenderInfo* m_remoteRenderInfo;
00523 SbBool m_remoteRenderPbufferEnable;
00524 SbBool m_lowResRender;
00525 float m_lowResLowPercent;
00526 float m_lowResHighPercent;
00527 float m_lowResPercent;
00528
00529 void remoteRenderInit();
00530 void remoteRenderCleanup();
00531 void remoteRenderGinitCB( SoWidget w );
00532 SbGlContextHelper::GLContext remoteRenderLowResRenderGinitCB( SoWidget w );
00533 void remoteRenderResizeCB();
00534 void remoteRenderSendImage();
00535 void remoteRenderSendLowResRender();
00536 XVisualInfo* remoteRenderChooseVisual();
00537 void remoteRenderFatalError( const char* methodName, const char* message );
00538
00539 void setLowResLowPercent( float percent ) { m_lowResLowPercent = percent;}
00540 void setLowResHighPercent( float percent ) { m_lowResHighPercent = percent;}
00541 float getLowResLowPercent() const { return m_lowResLowPercent;}
00542 float getLowResHighPercent() const { return m_lowResHighPercent;}
00543
00544 virtual void setLowResPercent( float newLowres ) {m_lowResPercent = newLowres;}
00545
00546
00547 SbThreadId_t dwThreadId;
00548 SbThreadId_t getThreadId() { return dwThreadId; };
00549 void setThreadId( SbThreadId_t id ) { dwThreadId=id; };
00550
00551 virtual void onExpose();
00552
00553 private:
00554
00555 SoWidget mgrWidget;
00556 SoWidget m_widgetNormal;
00557
00558 SoRef<SoGLContext> m_contextNormal;
00559
00560 int* attribList;
00561
00562
00563
00564
00565
00566 SbBool windowResized;
00567
00568 SbBool directConnection;
00569
00570
00571
00572 void buildNormalGLXWidget( XVisualInfo* vis = NULL );
00573 void destroyNormalWindows(SbBool normalCall=TRUE);
00574 void destroyGLXWidget( SoWidget& w, SoRef<SoGLContext>& ctx, SbBool normalWindow );
00575
00576 SoWidget createWindow( SoGLFormat* format );
00577 void destroyWindow( SoWidget widget );
00578
00579 static SbBool onGLFormatChangeCallback( SoGLFormat& format, void* userData );
00580
00581
00582 static void ginitCB( SoWidget w, SoXtGLWidget* v, XtPointer p );
00583 static void exposeCB( SoWidget w, SoXtGLWidget* v, XtPointer p );
00584 static void resizeCB( SoWidget glx, SoXtGLWidget* p, XtPointer pt );
00585
00586 int m_nPixelFormat;
00587
00588
00589 bool m_stereoActiveDelayed;
00590 bool m_stereoBufferFlag;
00591
00592 SbBool m_singleBufferExpected;
00593
00594 SoGuiGLWidget* m_guiGLWidget;
00595
00596 void constructorCommon( int glModes, SbBool buildNow );
00597
00598 SbBool remoteRenderGinitCB_pbuffer( SoWidget w );
00599 };
00600
00601 inline void
00602 SoXtGLWidget::posChanged( const SbVec2i32&, const SbVec2i32& )
00603 {}
00604
00605 #endif // _SO_XT_GL_WIDGET_H_
00606
00607 #endif // _WIN32
00608
00609
00610