Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoWinGLWidget.h
Go to the documentation of this file.
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2023 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : VSG (MMM YYYY)
22**=======================================================================*/
23
24
25
26#ifndef _SO_WIN_GL_WIDGET_H_
27#define _SO_WIN_GL_WIDGET_H_
28
29
31
36
38
40
42
43#ifdef _WIN32
44#pragma warning(push)
45#pragma warning(disable:4251)
46#endif
47
49
51//
52// Class: SoWinGLWidget
53//
54//
56
80{
81 public:
82
85 {
89 FLOAT_16_COLOR_BUFFER = SoGuiGLWidget::FLOAT_16_COLOR_BUFFER,
93 FLOAT_32_COLOR_BUFFER = SoGuiGLWidget::FLOAT_32_COLOR_BUFFER
94 };
95
105
114 GLXContext getNormalContext() { return m_contextNormal->getGLContext(); }
115
116 virtual SoGLContext* getNormalSoContext() { return m_contextNormal.ptr(); }
117
122
123#ifndef HIDDEN_FROM_DOC
124 // Jim's thing for now, not really public
126#endif // HIDDEN_FROM_DOC
127
135 void setStealFocus( SbBool onOrOff ) { stealFocus = onOrOff; };
136
146
155 virtual void setNormalVisual( XVisualInfo* vis );
156
161
174 virtual void setPixelFormat( int format );
175
182
187
191 void setAntialiasing(SoAntialiasingParameters* advancedParameters);
192
197
202
207
213 void setDoubleBuffer( SbBool onOrOff );
214
218 SbBool isDoubleBuffer() { return m_guiGLWidget->isDoubleBuffer(); }
219
223 void setBorder( SbBool onOrOff );
224
228 int getBorderSize() { return m_guiGLWidget->getBorderSize(); }
229
233 SbBool isBorder() const { return m_guiGLWidget->isBorder(); }
234
240
244 SbBool isDrawToFrontBufferEnable() const { return m_guiGLWidget->isDrawToFrontBufferEnable(); }
245
254 void setCursor( Cursor newCursor );
255
261
267
272
273
278
283
288
304
309
335 bool saveSnapshot( const SbString& filename, bool overwrite = true );
336
337private:
338
339 // Starting with version 3.0, subclasses should no longer make direct
340 // calls to glXMakeCurrent, glXSwapBuffers and glFlush.
341 // For RemoteRendering we need to know when MakeCurrent is called
342 // (marking the beginning of a frame) and when SwapBuffers or glFlush
343 // is called (marking the end of a frame).
344 // Subclasses should always use these generic methods.
345 void flush();
346
347private:
348
349 SoGuiGLWidget* getGuiGLWidget() const;
350
351 // Synchronise current properties from this object with the current configuration.
352 void syncFromCurrentConfig();
353 // Synchronise the current template with current properties from this object.
354 void syncToCurrentConfigTemplate( PIXELFORMATDESCRIPTOR* newPFD );
355
356 SbBool currentGraphicConfigTemplateIsUsed;
357 SoGLGraphicConfigTemplate currentGraphicConfigTemplate;
358
359 // Gets the current graphic device.
360 SoGLGraphicDevice* getGraphicDevice();
361
362 // Gets the current graphic configuration.
363 SoGLGraphicConfig* getGraphicConfig();
364
365 virtual void posChanged( const SbVec2i32&, const SbVec2i32& );
366
367 // These variables are public for retro compatibility purposes only.
368 // Do not use them directly but call their accessors instead;
369 SbBool drawToFrontBuffer;
370 SbBool m_isFloatingPointRendering;
371 FloatColorBufferSize m_floatingPointRenderingPrecision;
372
373 // These two function are used by SoGui, to call the system dependent version of
374 // these functions. data is a SoWinGLWidget handle.
375 static SbBool swapNormalBuffersCB(void *data);
376 static SbBool bindNormalCurrentCB(void *data);
377 static SbBool unbindNormalCurrentCB(void *data);
378 static void* getNormalWindowCB(void *data);
379
380private:
381
382 // Update the current device and disable the current configuration.
383 // If the given hdc is the same than the current device, the current
384 // device is kept and the current configuration is updated with the
385 // current template.
386 // If the given hdc is NULL, the current device and configuration are
387 // freed and set to NULL.
388 void updateCurrentDeviceAndConfig( HDC hdc );
389
390 SbBool currentGraphicConfigIsUsed;
391 SoGLGraphicConfig* currentGraphicConfig;
392 SbBool currentGraphicDeviceIsUsed;
393 SoGLGraphicDevice* currentGraphicDevice;
394
395 // Subclasses can pass in a bitwise OR specifying the GL modes
396 // (e.g. SO_GLX_RGB | SO_GLX_DOUBLE | SO_GLX_ZBUFFER)
397 // If buildNow is FALSE, this will not build its widget tree until
398 // buildWidget() is explicity called; else, buildWidget() is called here.
399 SoWinGLWidget( SoWidget parent = NULL,
400 const char* name = NULL,
401 SbBool buildInsideParent = TRUE,
402 int glModes = SO_GLX_RGB,
403 SbBool buildNow = TRUE,
404 SbBool sync = TRUE );
405
406 SoWinGLWidget( SoWidget parent,
407 const char* name,
408 SbBool buildInsideParent,
409 int glModes,
410 SbBool buildNow,
411 SbBool sync,
412 SoGuiGLWidget* guiGLWidget );
413
414 virtual ~SoWinGLWidget();
415
416 // subclasses MUST redefine redraw() to draw in the normal bit planes.
417 virtual void redraw() = 0;
418 virtual void processEvent( XAnyEvent* anyevent );
419
420 // subclasses can redefine these to do something useful.
421 // initGraphic() is called whenever a GLX window gets created
422 // sizeChanged() is called whenever the window changes size
423 // widgetChanged() is called whenever the widget is changed (i.e. at
424 // initialization or after switching from single->double buffer)
425 virtual void initGraphic();
426 virtual void sizeChanged( const SbVec2s& newSize );
427 virtual void widgetChanged( SoWidget newWidget );
428
429 // sets/gets the size of the glx widget(s) - Note this size could be
430 // different from the SoWinComponent::getSize() method which return
431 // the size of the component, not necessary the same as the glx widget
432 // window (because of extra stuff like the decoration in the viewers).
433 void setGlxSize( SbVec2s newSize );
434 const SbVec2s& getGlxSize() const { return m_guiGLWidget->getGlxSize(); }
435
436 // subclasses can use this routine as the event handler for any
437 // devices they wish to get input from.
438 static void eventHandler( SoWidget w, SoWinGLWidget* p, XAnyEvent* e, Boolean* b );
439
440 // set/get stereo buffering visual. This routine (like setDoubleBuffer)
441 // can be called interactively, althought slower since a new window
442 // with the needed visual is always created on the fly.
443 void setStereoBuffer( SbBool flag );
444 SbBool isStereoBuffer() const;
445
446 // returns TRUE if main window is in rgb mode, else FALSE for color index mode
447 SbBool isRGBMode() const;
448
449 // returns the display lists share group for given context:
450 int getDisplayListShareGroup( SoGLContext* ctx );
451
452 // set when color index is used
453 Colormap getColorMap() const
454 { return m_guiGLWidget->getColorMap(); }
455
456
457 SbBool waitForExpose; // prevent redraws until an expose is received
458
459 // make those methods protected so enable the SoWinRenderArea to use them
460 // directly when it needs to build the widget and get its resources.
461 SoWidget buildWidget( SoWidget parent );
462 SoWidget getGlxMgrWidget() { return mgrWidget; }
463
464 // _WIN32
465 // Add some convenience functions that reduce the number of ifdef's in
466 // viewers by hiding these platform dependent operations.
467 // We should add these to the UNIX version too.
468 void changeCursor( Cursor newCursor );
469
470 // Set/get thread this context belongs to
471 DWORD getThreadId() { return dwThreadId; };
472 void setThreadId( DWORD id ) { dwThreadId=id; };
473
475
476 virtual void onExpose();
477
478 void destroyNormalWindows(SbBool normalCall=TRUE);
479
480 private:
481
482 void constructorCommon( int glModes, SbBool buildNow, SoWidget parent );
483
484 static SbBool onGLFormatChangeCallback( SoGLFormat& format, void* userData );
485
486 HWND createWindow( SoGLFormat* format );
487
488 void destroyWindow( HWND handle );
489
490 void initGLXWidget( SoWidget glx, SoGLFormat* format );
491
492 // local vars
493 SoWidget mgrWidget;
494 SoWidget m_widgetNormal;
495
496 SoRef<SoGLContext> m_contextNormal;
497
498 SoGuiGLWidget* m_guiGLWidget; //Implementation class for SoXxGLWidget
499
500 // Note for _WIN32:
501 // 1) All the "SoWidget" values above are actually type "HWND".
502 // 2) The "GLXContext" values above are actually type "HGLRC".
503
504 // For _WIN32 we need a GL context *and* a device context for each
505 // GL drawing window (we don't need one for the mgr because we don't
506 // plan to ever draw in it). These correspond to the "ctx..." vars.
507 // Note: This plan depends on use of the CS_OWNDC style.
508 Hdc m_hdcNormal;
509
510 // For _WIN32 we also need a logical color palette for each drawing
511 // area if we happen to running on an 8bit device...
512 HPALETTE palNormal;
513
514 // For _WIN32 we also need to remember our parent and our
515 // "ancestor" (the toplevel window that we're descended from).
516 SoWidget parent;
517 SoWidget ancestor;
518
519 // For _WIN32 we have to simulate the "focus follows pointer" behavior
520 // that X provides for free. Otherwise the app would have to be
521 // responsible for giving focus to the GL window and/or the user
522 // would have to keep clicking to get focus in the GL window. Focus
523 // is required for the 1-button mouse viewer behaviors like Ctrl-Left
524 // Button and so on. This variable tracks whether we have focus
525 // based on the WM_SETFOCUS/WM_KILLFOCUS messages (see glxWindowProc).
526 int haveFocus;
527
528 // This flag tracks whether "focus follows pointer" is enabled.
529 int stealFocus;
530
531 // For _WIN32 we have to simulate the behavior of X where getting a
532 // mouse button down event guarantees you will also get the
533 // corresponding button up event. Otherwise examiner viewer windows
534 // get out of sync if a mouse button is released outside the window.
535 UINT mouseCaptured;
536
537 // For _WIN32 we have to know the handle of the cursor that's supposed
538 // to be displayed currently in the drawing window. The explanation
539 // is too long to fit here... :-) OK, actually it's because the
540 // viewers want to change the cursor periodically but we can't change
541 // the cursor in the class defn or it will change for *all* the GL
542 // windows (yuck). So we have to process the WM_SETCURSOR message in
543 // the glxWindowProc.
544 HCURSOR currentCursor;
545
546 // We also need (globally for the class) the default cursor to use.
547 static HCURSOR defaultCursor;
548
549 DWORD dwThreadId; // thread to which this context belongs -- mmh Apr-99
550
551 int* attribList;
552
553 // specify if sizeChanged() should be called when an expose event
554 // is received (as opposed to when a resize event is received, where
555 // the window hasn't yet been maped to the new size).
556 // ??? a GlxDraw bug ?
557 SbBool windowResized;
558
559 bool m_isMouseTracking;
560
561 // creates a GLX widget of the correct current type and get the current
562 // set of windows, color maps, etc...
563 void buildNormalGLXWidget( SoGLFormat* format = NULL );
564 void destroyGLXWidget( SoWidget& w, SoRef<SoGLContext>& ctx, SbBool normalWindow );
565
566 // callbacks from glx widget
567 static void ginitCB( SoWidget w, SoWinGLWidget* p, XtPointer );
568 static void exposeCB( SoWidget w, SoWinGLWidget* p, XtPointer ptr );
569 static void resizeCB( SoWidget w, SoWinGLWidget* p, XtPointer ptr );
570 static void mgrStructureNotifyCB( SoWidget w, SoWinGLWidget* p, XAnyEvent* e, Boolean* b );
571
572 // Window proc for SoWinGL "manager widget" windows
573 static LRESULT CALLBACK mgrWindowProc( Hwnd hwnd, UINT message,
574 WPARAM wParam, LPARAM lParam );
575
576 // Window proc for SoWinGL drawing windows
577 static LRESULT CALLBACK glxWindowProc( Hwnd hwnd, UINT message,
578 WPARAM wParam, LPARAM lParam );
579};
580
581inline void
582SoWinGLWidget::posChanged( const SbVec2i32&, const SbVec2i32& )
583{};
584
585
587
588#ifdef _WIN32
589#pragma warning(pop)
590#endif
591
592#endif // _SO_WIN_GL_WIDGET_H_
593
594
#define TRUE
Possible value of SbBool.
Definition SbBase.h:77
char Boolean
Definition SoQtDef.h:119
void * XtPointer
Definition SoQtDef.h:118
#define SoWidget
Definition SoQtDef.h:40
#define SO_GLX_RGB
virtual void enable(QWidget *w, XtEventHandler f, XtPointer data, void *unused=NULL)
uint32_t DWORD
#define Window
Definition SoWinDef.h:81
#define Colormap
Definition SoWinDef.h:40
#define Hdc
Definition SoWinDef.h:84
#define Hwnd
Definition SoWinDef.h:83
#define GLXContext
Definition SoWinDef.h:55
#define XVisualInfo
Definition SoWinDef.h:141
#define XAnyEvent
Definition SoWinDef.h:100
#define Cursor
Definition SoWinDef.h:42
Hdc copyWindowBits()
#define PIXELFORMATDESCRIPTOR
Class for smart character strings.
Definition SbString.h:202
2D vector class.
Definition SbVec.h:517
2D vector class.
Definition SbVec.h:700
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Antialiasing par...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> OpenGL context m...
const SbGlContextHelper::GLContext & getGLContext() const
Returns the OpenGL rendering context of this SoGLContext.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> OpenGL pixel for...
Definition SoGLFormat.h:55
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Defines an OpenG...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Defines an OpenG...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Represents an Op...
Smart pointer for any class inheriting SoRefCounter.
Definition SoRef.h:90
T * ptr() const
Cast to C pointer.
Definition SoRef.h:167
AntialiasingMode
Enum which indicates the desired antialiasing algorithm.
@ AUTO
This is the default mode for antialiasing.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Component for Op...
virtual void setNormalVisual(XVisualInfo *vis)
Specifies the exact pixel format descriptor for the normal window.
int getPixelFormat()
Returns the current pixel format.
virtual void setPixelFormat(int format)
Sets the current pixel format.
SoGLGraphicConfigTemplate * getGraphicConfigTemplate()
Gets the current graphics configuration template.
Cursor getCursor()
Returns the current cursor.
void setAntialiasing(SoAntialiasingParameters *advancedParameters)
Enable (or disable) antialiasing with specific parameters.
XVisualInfo * getNormalVisual()
Returns the pixel format descriptor for the normal window.
void setGraphicConfigTemplate(SoGLGraphicConfigTemplate *gTemplate)
Sets a new graphics configuration template.
FloatColorBufferSize
FloatColorBufferSize.
@ FLOAT_32_COLOR_BUFFER
32-bit rendering per component.
@ FLOAT_16_COLOR_BUFFER
16-bit rendering per component.
SoSceneManager::AntialiasingMode getAntialiasingMode() const
Returns the antialiasing mode set using the setAntialiasing(float,AntialiasingMode) method.
SbBool isDoubleBuffer()
Returns whether double buffering is on or off.
virtual Window getNormalWindow()
Gets the normal GL window, which is needed as an argument to SbGlContextHelper::makeCurrent() when dr...
float getAntialiasingQuality() const
Returns the antialiasing quality set using the setAntialiasing(float,AntialiasingMode) method.
SoWidget getNormalWidget() const
Gets the normal window handle, which is needed as an argument to SbGlContextHelper::makeCurrent() whe...
void setCursor(Cursor newCursor)
Sets the current cursor.
void setDrawToFrontBufferEnable(SbBool enableFlag)
Sets drawing to the front buffer.
virtual SbBool unbindNormalContext()
unbind the current context (previously bind with bindNormalContext );
virtual SbBool swapNormalBuffers()
Swaps the normal front and back buffers.
int getBorderSize()
Included for portability only.
Hdc getNormalDC() const
Returns the device context (which is needed for SbGlContextHelper::makeCurrent).
SbBool isDrawToFrontBufferEnable() const
Returns whether drawing to the front buffer is enabled.
void setStealFocus(SbBool onOrOff)
By default the GLWidget "steals" focus whenever the cursor moves over it.
virtual void getFloatingColorBuffer(SbBool &enable, FloatColorBufferSize &size)
Returns TRUE if floating point rendering is used and its precision.
virtual void setFloatingColorBuffer(SbBool enable, FloatColorBufferSize size=FLOAT_16_COLOR_BUFFER)
Enables/disables floating point rendering using 16- or 32-bit components.
virtual SbBool bindNormalContext()
Makes the normal rendering context the current context.
void setBorder(SbBool onOrOff)
Included for portability only.
SoAntialiasingParameters * getAntialiasingParameters() const
Returns the antialiasing parameters set using the setAntialiasing(SoAntialiasingParameters*) method.
virtual SoGLContext * getNormalSoContext()
void setAntialiasing(const float quality, const SoSceneManager::AntialiasingMode mode=SoSceneManager::AUTO)
Enable (or disable) antialiasing with specified quality and mode.
GLXContext getNormalContext()
Gets the normal context, which is needed as an argument to SbGlContextHelper::makeCurrent() when draw...
void setDoubleBuffer(SbBool onOrOff)
Routine that dynamically changes between single and double buffering.
bool saveSnapshot(const SbString &filename, bool overwrite=true)
Save a snapshot of the current image displayed in the viewer.
SbBool isBorder() const
Included for portability only.
int SbBool
Boolean type.
Definition SbBase.h:87
unsigned int UINT
Definition port.h:357
#define CALLBACK
Definition port.h:345
#define HDC
Definition port.h:351