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_WIN_GL_WIDGET_H_
00027 #define _SO_WIN_GL_WIDGET_H_
00028 
00029 
00030 #include <Inventor/Win/SoWinBeginStrict.h>
00031 
00032 #include <Inventor/Win/SoWinComponent.h>
00033 #include <Inventor/components/SoGLGraphicConfigTemplate.h>
00034 #include <Inventor/components/SoGLGraphicDevice.h>
00035 #include <Inventor/components/SoGLGraphicConfig.h>
00036 
00037 #include <Inventor/devices/SoGLContext.h>
00038 
00039 #include <Inventor/nodes/SoFullSceneAntialiasing.h>
00040 
00041 #include <Inventor/Gui/SoGuiGLWidget.h>
00042 
00043 #ifdef _WIN32
00044 #pragma warning(push)
00045 #pragma warning(disable:4251)
00046 #endif
00047 
00048 class SoAntialiasingParameters;
00049 
00051 
00052 
00053 
00054 
00056 
00079 class  SoWinGLWidget : public SoWinComponent 
00080 {
00081  public:
00082    
00084    enum FloatColorBufferSize 
00085    {
00089     FLOAT_16_COLOR_BUFFER = SoGuiGLWidget::FLOAT_16_COLOR_BUFFER,
00093     FLOAT_32_COLOR_BUFFER = SoGuiGLWidget::FLOAT_32_COLOR_BUFFER
00094   };
00095 
00104   virtual Window getNormalWindow();
00105     
00114   GLXContext  getNormalContext() { return m_contextNormal->getGLContext(); }
00115 
00116   virtual SoGLContext* getNormalSoContext() { return m_contextNormal.ptr(); }
00117 
00121   Hdc getNormalDC() const;
00122 
00123 #ifndef HIDDEN_FROM_DOC
00124   
00125   Hdc copyWindowBits() ;
00126 #endif // HIDDEN_FROM_DOC
00127 
00135   void setStealFocus( SbBool onOrOff ) { stealFocus = onOrOff; };
00136     
00145   SoWidget getNormalWidget() const;
00146     
00155   virtual void setNormalVisual( XVisualInfo* vis );
00156 
00160   XVisualInfo* getNormalVisual();
00161 
00174   virtual void setPixelFormat( int format );
00175 
00181   int getPixelFormat();
00182 
00186   void setAntialiasing(const float quality, const SoSceneManager::AntialiasingMode mode = SoSceneManager::AUTO);
00187 
00191   void setAntialiasing(SoAntialiasingParameters* advancedParameters);
00192 
00196   float getAntialiasingQuality() const;
00197 
00201   SoSceneManager::AntialiasingMode getAntialiasingMode() const;
00202 
00206   SoAntialiasingParameters* getAntialiasingParameters() const;
00207 
00213   void setDoubleBuffer( SbBool onOrOff );
00214 
00218   SbBool isDoubleBuffer() { return m_guiGLWidget->isDoubleBuffer(); }
00219     
00223   void setBorder( SbBool onOrOff );
00224 
00228   int getBorderSize() { return m_guiGLWidget->getBorderSize(); }
00229 
00233   SbBool isBorder() const { return m_guiGLWidget->isBorder(); }
00234     
00239   void setDrawToFrontBufferEnable( SbBool enableFlag );
00240 
00244   SbBool isDrawToFrontBufferEnable() const { return m_guiGLWidget->isDrawToFrontBufferEnable(); }
00245 
00254   void setCursor( Cursor newCursor );
00255 
00260   Cursor getCursor();
00261 
00266   virtual SbBool bindNormalContext();
00267 
00271   virtual SbBool unbindNormalContext();
00272 
00273 
00277   virtual SbBool swapNormalBuffers();
00278 
00282   SoGLGraphicConfigTemplate* getGraphicConfigTemplate();
00283 
00287   void setGraphicConfigTemplate( SoGLGraphicConfigTemplate* gTemplate );
00288 
00302   virtual void setFloatingColorBuffer( SbBool enable, 
00303                                        FloatColorBufferSize size = FLOAT_16_COLOR_BUFFER );
00304 
00308   virtual void getFloatingColorBuffer( SbBool& enable, FloatColorBufferSize& size );
00309 
00335   bool saveSnapshot( const SbString& filename, bool overwrite = true );
00336 
00337 private:
00338 
00339   
00340   
00341   
00342   
00343   
00344   
00345   void   flush();
00346 
00347 private:
00348 
00349   SoGuiGLWidget* getGuiGLWidget() const;
00350     
00351   
00352   void syncFromCurrentConfig();
00353   
00354   void syncToCurrentConfigTemplate( PIXELFORMATDESCRIPTOR* newPFD );
00355 
00356   SbBool currentGraphicConfigTemplateIsUsed;
00357   SoGLGraphicConfigTemplate currentGraphicConfigTemplate;
00358 
00359   
00360   SoGLGraphicDevice* getGraphicDevice();
00361 
00362   
00363   SoGLGraphicConfig* getGraphicConfig();
00364 
00365   virtual void posChanged( const SbVec2i32&, const SbVec2i32& );
00366 
00367   
00368   
00369   SbBool drawToFrontBuffer;
00370   SbBool m_isFloatingPointRendering;
00371   FloatColorBufferSize m_floatingPointRenderingPrecision;
00372 
00373   
00374   
00375   static SbBool swapNormalBuffersCB(void *data);
00376   static SbBool bindNormalCurrentCB(void *data);
00377   static SbBool unbindNormalCurrentCB(void *data);
00378   static void* getNormalWindowCB(void *data);
00379 
00380 private:
00381 
00382   
00383   
00384   
00385   
00386   
00387   
00388   void updateCurrentDeviceAndConfig( HDC hdc );
00389     
00390   SbBool currentGraphicConfigIsUsed;
00391   SoGLGraphicConfig* currentGraphicConfig;
00392   SbBool currentGraphicDeviceIsUsed;
00393   SoGLGraphicDevice* currentGraphicDevice;
00394 
00395   
00396   
00397   
00398   
00399   SoWinGLWidget( SoWidget parent = NULL,
00400                  const char* name = NULL, 
00401                  SbBool buildInsideParent = TRUE, 
00402                  int glModes = SO_GLX_RGB, 
00403                  SbBool buildNow = TRUE,
00404                  SbBool sync = TRUE );
00405 
00406   SoWinGLWidget( SoWidget parent,
00407                  const char* name, 
00408                  SbBool buildInsideParent, 
00409                  int glModes, 
00410                  SbBool buildNow,
00411                  SbBool sync,
00412                  SoGuiGLWidget* guiGLWidget );
00413 
00414   virtual ~SoWinGLWidget();
00415     
00416   
00417   virtual void redraw() = 0;
00418   virtual void processEvent( XAnyEvent* anyevent );
00419     
00420   
00421   
00422   
00423   
00424   
00425   virtual void initGraphic();
00426   virtual void sizeChanged( const SbVec2s& newSize );
00427   virtual void widgetChanged( SoWidget newWidget );
00428      
00429   
00430   
00431   
00432   
00433   void setGlxSize( SbVec2s newSize );
00434   const SbVec2s& getGlxSize() const { return m_guiGLWidget->getGlxSize(); }
00435     
00436   
00437   
00438   static void eventHandler( SoWidget w, SoWinGLWidget* p, XAnyEvent* e, Boolean* b );
00439     
00440   
00441   
00442   
00443   void setStereoBuffer( SbBool flag );
00444   SbBool isStereoBuffer() const;
00445     
00446   
00447   SbBool isRGBMode() const;
00448     
00449   
00450   int getDisplayListShareGroup( SoGLContext* ctx );
00451 
00452   
00453   Colormap getColorMap() const
00454   { return m_guiGLWidget->getColorMap(); }
00455 
00456 
00457   SbBool waitForExpose; 
00458     
00459   
00460   
00461   SoWidget buildWidget( SoWidget parent );
00462   SoWidget getGlxMgrWidget() { return mgrWidget; }
00463 
00464   
00465   
00466   
00467   
00468   void changeCursor( Cursor newCursor );
00469 
00470   
00471   DWORD getThreadId() { return dwThreadId; };
00472   void setThreadId( DWORD id ) { dwThreadId=id; };
00473 
00475 
00476   virtual void onExpose();
00477 
00478   void destroyNormalWindows(SbBool normalCall=TRUE);
00479 
00480  private:
00481 
00482    void constructorCommon( int glModes, SbBool buildNow, SoWidget parent );
00483 
00484    static SbBool onGLFormatChangeCallback( SoGLFormat& format, void* userData );
00485 
00486    HWND createWindow( SoGLFormat* format );
00487 
00488    void destroyWindow( HWND handle );
00489 
00490    void initGLXWidget( SoWidget glx, SoGLFormat* format );
00491   
00492   
00493   SoWidget mgrWidget;
00494   SoWidget m_widgetNormal;
00495   
00496   SoRef<SoGLContext> m_contextNormal;
00497 
00498   SoGuiGLWidget* m_guiGLWidget; 
00499 
00500   
00501   
00502   
00503 
00504   
00505   
00506   
00507   
00508   Hdc m_hdcNormal;
00509 
00510   
00511   
00512   HPALETTE palNormal;
00513 
00514   
00515   
00516   SoWidget parent;
00517   SoWidget ancestor;
00518 
00519   
00520   
00521   
00522   
00523   
00524   
00525   
00526   int haveFocus;
00527 
00528   
00529   int stealFocus;
00530 
00531   
00532   
00533   
00534   
00535   UINT mouseCaptured;
00536 
00537   
00538   
00539   
00540   
00541   
00542   
00543   
00544   HCURSOR currentCursor;
00545 
00546   
00547   static HCURSOR defaultCursor;
00548 
00549   DWORD dwThreadId; 
00550 
00551   int* attribList;
00552     
00553   
00554   
00555   
00556   
00557   SbBool windowResized;
00558 
00559   bool m_isMouseTracking;
00560     
00561   
00562   
00563   void buildNormalGLXWidget( SoGLFormat* format = NULL );
00564   void destroyGLXWidget( SoWidget& w, SoRef<SoGLContext>& ctx, SbBool normalWindow );
00565     
00566   
00567   static void ginitCB( SoWidget w, SoWinGLWidget* p, XtPointer );
00568   static void exposeCB( SoWidget w, SoWinGLWidget* p, XtPointer ptr );
00569   static void resizeCB( SoWidget w, SoWinGLWidget* p, XtPointer ptr );
00570   static void mgrStructureNotifyCB( SoWidget w, SoWinGLWidget* p, XAnyEvent* e, Boolean* b );
00571 
00572   
00573   static LRESULT CALLBACK mgrWindowProc( Hwnd hwnd, UINT message,
00574                                          WPARAM wParam, LPARAM lParam );
00575 
00576   
00577   static LRESULT CALLBACK glxWindowProc( Hwnd hwnd, UINT message,
00578                                          WPARAM wParam, LPARAM lParam );
00579 };
00580 
00581 inline void 
00582 SoWinGLWidget::posChanged( const SbVec2i32&, const SbVec2i32& )
00583 {};
00584 
00585 
00586 #include <Inventor/Win/SoWinEndStrict.h>
00587 
00588 #ifdef _WIN32
00589 #pragma warning(pop)
00590 #endif
00591 
00592 #endif // _SO_WIN_GL_WIDGET_H_
00593 
00594 
00595