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 _WIN32
00053 # include <Inventor/Win/SoWinGLWidget.h>
00054 #else // _WIN32
00055
00056 #ifndef _SO_XT_GL_WIDGET_H_
00057 #define _SO_XT_GL_WIDGET_H_
00058
00059 #include <X11/Intrinsic.h>
00060 #include <Inventor/helpers/SbGlContextHelper.h>
00061 #include <Inventor/Xt/SoXtComponent.h>
00062 #include <Inventor/components/SoGLGraphicConfigTemplate.h>
00063 #include <Inventor/components/SoGLGraphicDevice.h>
00064 #include <Inventor/components/SoGLGraphicConfig.h>
00065 #include <Inventor/devices/SoGLFormat.h>
00066 #include <Inventor/threads/SbThread.h>
00067 #include <Inventor/nodes/SoFullSceneAntialiasing.h>
00068
00069 #include <Inventor/Gui/SoGuiGLWidget.h>
00070 #include <Inventor/devices/SoGLContext.h>
00071
00072 class SoXtRemoteRenderInfo;
00073
00075
00076
00077
00078
00080
00102 class SoXtGLWidget : public SoXtComponent
00103 {
00104
00105 public:
00106
00108 enum FloatColorBufferSize
00109 {
00113 FLOAT_16_COLOR_BUFFER = SoGuiGLWidget::FLOAT_16_COLOR_BUFFER,
00117 FLOAT_32_COLOR_BUFFER = SoGuiGLWidget::FLOAT_32_COLOR_BUFFER
00118 };
00119
00123 int getColorMapSize();
00124
00133 virtual Window getNormalWindow();
00134
00143 SbGlContextHelper::GLContext getNormalContext() const;
00144
00145 SoGLContext* getNormalSoContext() const;
00146
00155 SoWidget getNormalWidget() const;
00156
00166 virtual void setNormalVisual( XVisualInfo* vis );
00167
00171 XVisualInfo* getNormalVisual();
00172
00178 virtual void setDoubleBuffer( SbBool onOrOff );
00179
00183 SbBool isDoubleBuffer();
00184
00188 void setAntialiasing(const float quality, const SoSceneManager::AntialiasingMode mode = SoSceneManager::AUTO);
00189
00193 void setAntialiasing(SoAntialiasingParameters* advancedParameters);
00194
00198 float getAntialiasingQuality() const;
00199
00203 SoSceneManager::AntialiasingMode getAntialiasingMode() const;
00204
00208 SoAntialiasingParameters* getAntialiasingParameters() const;
00209
00214 void setBorder( SbBool onOrOff );
00215
00219 SbBool isBorder() const { return m_guiGLWidget->isBorder(); }
00220
00225 void setDrawToFrontBufferEnable( SbBool enableFlag );
00226
00230 SbBool isDrawToFrontBufferEnable() const { return m_guiGLWidget->isDrawToFrontBufferEnable(); }
00231
00236 virtual SbBool bindNormalContext();
00237
00241 virtual SbBool unbindNormalContext();
00242
00247 virtual SbBool swapNormalBuffers();
00248
00252 SoGLGraphicConfigTemplate* getGraphicConfigTemplate();
00253
00257 void setGraphicConfigTemplate( SoGLGraphicConfigTemplate* gTemplate );
00258
00272 void setFloatingColorBuffer( SbBool enable, FloatColorBufferSize size = FLOAT_16_COLOR_BUFFER );
00273
00278 void getFloatingColorBuffer( SbBool& enable, FloatColorBufferSize& size );
00279
00282 bool saveSnapshot( const SbString& filename, bool overwrite = true );
00283
00284 private:
00285
00286
00287
00288
00289
00290
00291
00292 void flush();
00293
00294
00295
00296
00297
00298 void setRemoteRenderPbufferEnable( SbBool enable ) { m_remoteRenderPbufferEnable = enable; }
00299 SbBool isRemoteRenderPbufferEnable() const { return m_remoteRenderPbufferEnable; }
00300
00301 float getLowResPercent() { return m_lowResPercent; }
00302
00303
00304 SbBool ctxIsDirect();
00305
00306 private:
00307
00308
00309 void syncFromCurrentConfig();
00310
00311
00312 void syncToCurrentConfigTemplate( XVisualInfo* newvis );
00313
00314 SbBool currentGraphicConfigTemplateIsUsed;
00315 SoGLGraphicConfigTemplate currentGraphicConfigTemplate;
00316
00317
00318 SoGLGraphicDevice* getGraphicDevice();
00319
00320
00321 SoGLGraphicConfig* getGraphicConfig();
00322
00323 SbBool isFsaaSupportHighQuality();
00324 SbBool isFsaaHighQuality();
00325
00326 SoGuiGLWidget* getGuiGLWidget() const;
00327
00328
00329 int getDisplayListShareGroup( SoGLContext* ctx );
00330
00331
00332
00333 SbBool drawToFrontBuffer;
00334 SbBool m_isFloatingPointRendering;
00335 FloatColorBufferSize m_floatingPointRenderingPrecision;
00336
00337
00338
00339 static SbBool swapNormalBuffersCB(void *data);
00340 static SbBool bindNormalCurrentCB(void *data);
00341 static SbBool unbindNormalCurrentCB(void *data);
00342 static void* getNormalWindowCB(void *data);
00343 static void* getCurrentDisplayCB(void *data);
00344
00345 private:
00346
00347
00348
00349
00350
00351
00352
00353 void updateCurrentDeviceAndConfig( Display* display );
00354
00355 SbBool currentGraphicConfigIsUsed;
00356 SoGLGraphicConfig* currentGraphicConfig;
00357 SbBool currentGraphicDeviceIsUsed;
00358 SoGLGraphicDevice* currentGraphicDevice;
00359
00360
00361
00362
00363
00364 SoXtGLWidget( SoWidget parent = NULL,
00365 const char* name = NULL,
00366 SbBool buildInsideParent = TRUE,
00367 int glModes = SO_GLX_RGB | SO_GLX_ZBUFFER | SO_GLX_STENCIL,
00368 SbBool buildNow = TRUE,
00369 SbBool sync = TRUE );
00370 SoXtGLWidget( SoWidget parent,
00371 const char* name,
00372 SbBool buildInsideParent,
00373 int glModes,
00374 SbBool buildNow,
00375 SbBool sync,
00376 SoGuiGLWidget* guiGLWidget );
00377
00378 virtual ~SoXtGLWidget();
00379
00380
00381
00382 virtual void redraw() = 0;
00383 virtual void processEvent( XAnyEvent* anyevent );
00384
00385
00386
00387
00388
00389
00390 virtual void initGraphic();
00391 virtual void sizeChanged( const SbVec2s& );
00392 virtual void posChanged( const SbVec2i32&, const SbVec2i32& );
00393 virtual void widgetChanged( SoWidget newWidget );
00394
00395
00396
00397
00398
00399 void setGlxSize( SbVec2s newSize );
00400 const SbVec2s& getGlxSize() const { return m_guiGLWidget->getGlxSize(); }
00401
00402
00403
00404 static void eventHandler( SoWidget w, SoXtGLWidget* p, XAnyEvent* xe, Boolean* b );
00405
00406
00407
00408
00409 void setStereoBuffer( SbBool flag );
00410 SbBool isStereoBuffer() { return (m_guiGLWidget->getGLModes() & SO_GLX_STEREO); }
00411
00412
00413 SbBool isRGBMode() { return (m_guiGLWidget->getGLModes() & SO_GLX_RGB); }
00414
00415 #if defined(__linux__)
00416 void allocCell( Display *display, Colormap cmap, XColor *colorcells, int ncolors, int colorMapSize );
00417 #endif
00418
00419
00420 Colormap getColorMap() const
00421 { return m_guiGLWidget->getColorMap(); }
00422
00423 SbBool waitForExpose;
00424
00425
00426
00427 SoWidget buildWidget( SoWidget parent );
00428 SoWidget getGlxMgrWidget() { return mgrWidget; }
00429
00430
00431 enum RemoteRenderEnabled
00432 {
00433 OFF,
00434 ON,
00435 AUTO
00436 };
00437 RemoteRenderEnabled m_remoteRenderMode;
00438 SbBool m_remoteRender;
00439 SoXtRemoteRenderInfo* m_remoteRenderInfo;
00440 SbBool m_remoteRenderPbufferEnable;
00441 SbBool m_lowResRender;
00442 float m_lowResLowPercent;
00443 float m_lowResHighPercent;
00444 float m_lowResPercent;
00445
00446 void remoteRenderInit();
00447 void remoteRenderCleanup();
00448 void remoteRenderGinitCB( SoWidget w );
00449 SbGlContextHelper::GLContext remoteRenderLowResRenderGinitCB( SoWidget w );
00450 void remoteRenderResizeCB();
00451 void remoteRenderSendImage();
00452 void remoteRenderSendLowResRender();
00453 XVisualInfo* remoteRenderChooseVisual();
00454 void remoteRenderFatalError( const char* methodName, const char* message );
00455
00456 void setLowResLowPercent( float percent ) { m_lowResLowPercent = percent;}
00457 void setLowResHighPercent( float percent ) { m_lowResHighPercent = percent;}
00458 float getLowResLowPercent() const { return m_lowResLowPercent;}
00459 float getLowResHighPercent() const { return m_lowResHighPercent;}
00460
00461 virtual void setLowResPercent( float newLowres ) {m_lowResPercent = newLowres;}
00462
00463
00464 SbThreadId_t dwThreadId;
00465 SbThreadId_t getThreadId() { return dwThreadId; };
00466 void setThreadId( SbThreadId_t id ) { dwThreadId=id; };
00467
00468 virtual void onExpose();
00469
00470 private:
00471
00472 SoWidget mgrWidget;
00473 SoWidget m_widgetNormal;
00474
00475 SoRef<SoGLContext> m_contextNormal;
00476
00477 int* attribList;
00478
00479
00480
00481
00482
00483 SbBool windowResized;
00484
00485 SbBool directConnection;
00486
00487
00488
00489 void buildNormalGLXWidget( XVisualInfo* vis = NULL );
00490 void destroyNormalWindows(SbBool normalCall=TRUE);
00491 void destroyGLXWidget( SoWidget& w, SoRef<SoGLContext>& ctx, SbBool normalWindow );
00492
00493 SoWidget createWindow( SoGLFormat* format );
00494 void destroyWindow( SoWidget widget );
00495
00496 static SbBool onGLFormatChangeCallback( SoGLFormat& format, void* userData );
00497
00498
00499 static void ginitCB( SoWidget w, SoXtGLWidget* v, XtPointer p );
00500 static void exposeCB( SoWidget w, SoXtGLWidget* v, XtPointer p );
00501 static void resizeCB( SoWidget glx, SoXtGLWidget* p, XtPointer pt );
00502
00503 int m_nPixelFormat;
00504
00505
00506 bool m_stereoActiveDelayed;
00507 bool m_stereoBufferFlag;
00508
00509 SbBool m_singleBufferExpected;
00510
00511 SoGuiGLWidget* m_guiGLWidget;
00512
00513 void constructorCommon( int glModes, SbBool buildNow );
00514
00515 SbBool remoteRenderGinitCB_pbuffer( SoWidget w );
00516 };
00517
00518 inline void
00519 SoXtGLWidget::posChanged( const SbVec2i32&, const SbVec2i32& )
00520 {}
00521
00522 #endif // _SO_XT_GL_WIDGET_H_
00523
00524 #endif // _WIN32
00525
00526
00527