Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoXtGLWidget.h
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Alain Dumesny (MMM yyyy)
25** Modified by : David Mott (MMM yyyy)
26**=======================================================================*/
27/*=======================================================================
28 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
29 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
30 *** ***
31 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
32 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
33 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
34 *** ***
35 *** RESTRICTED RIGHTS LEGEND ***
36 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
37 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
38 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
39 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
40 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
41 *** ***
42 *** COPYRIGHT (C) 1996-2023 BY FEI S.A.S, ***
43 *** BORDEAUX, FRANCE ***
44 *** ALL RIGHTS RESERVED ***
45**=======================================================================*/
46/*=======================================================================
47** Modified by : VSG (MMM YYYY)
48**=======================================================================*/
49
50#ifdef SOQT
51# include <Inventor/Qt/SoQtGLWidget.h>
52#elif defined _WIN32
53# include <Inventor/Win/SoWinGLWidget.h>
54#else // _WIN32
55
56#ifndef _SO_XT_GL_WIDGET_H_
57#define _SO_XT_GL_WIDGET_H_
58
59#include <X11/Intrinsic.h>
60#include <Inventor/helpers/SbGlContextHelper.h>
61#include <Inventor/Xt/SoXtComponent.h>
62#include <Inventor/components/SoGLGraphicConfigTemplate.h>
63#include <Inventor/components/SoGLGraphicDevice.h>
64#include <Inventor/components/SoGLGraphicConfig.h>
65#include <Inventor/devices/SoGLFormat.h>
66#include <Inventor/threads/SbThread.h>
67#include <Inventor/nodes/SoFullSceneAntialiasing.h>
68
69#include <Inventor/Gui/SoGuiGLWidget.h>
70#include <Inventor/devices/SoGLContext.h>
71
72class SoXtRemoteRenderInfo;
73
75//
76// Class: SoXtGLWidget
77//
78//
80
103{
104
105 public:
106
109 {
113 FLOAT_16_COLOR_BUFFER = SoGuiGLWidget::FLOAT_16_COLOR_BUFFER,
117 FLOAT_32_COLOR_BUFFER = SoGuiGLWidget::FLOAT_32_COLOR_BUFFER
118 };
119
124
133 virtual Window getNormalWindow();
134
144
146
155 SoWidget getNormalWidget() const;
156
166 virtual void setNormalVisual( XVisualInfo* vis );
167
171 XVisualInfo* getNormalVisual();
172
178 virtual void setDoubleBuffer( SbBool onOrOff );
179
184
189
193 void setAntialiasing(SoAntialiasingParameters* advancedParameters);
194
199
204
209
214 void setBorder( SbBool onOrOff );
215
219 SbBool isBorder() const { return m_guiGLWidget->isBorder(); }
220
226
230 SbBool isDrawToFrontBufferEnable() const { return m_guiGLWidget->isDrawToFrontBufferEnable(); }
231
237
242
248
253
258
272 void setFloatingColorBuffer( SbBool enable, FloatColorBufferSize size = FLOAT_16_COLOR_BUFFER );
273
279
282 bool saveSnapshot( const SbString& filename, bool overwrite = true );
283
284private:
285
286 // Starting with version 3.0, subclasses should no longer make direct
287 // calls to glXMakeCurrent, glXSwapBuffers and glFlush.
288 // For RemoteRendering we need to know when MakeCurrent is called
289 // (marking the beginning of a frame) and when SwapBuffers or glFlush
290 // is called (marking the end of a frame).
291 // Subclasses should always use these generic methods.
292 void flush();
293
294 // Pbuffers are a limited resource. By default use of Pbuffers for
295 // remote rendering is enabled, but it might make sense to disable
296 // it for less important windows (like UI components drawn with OpenGL).
297 // Must be called after creating the widget but before it is realized.
298 void setRemoteRenderPbufferEnable( SbBool enable ) { m_remoteRenderPbufferEnable = enable; }
299 SbBool isRemoteRenderPbufferEnable() const { return m_remoteRenderPbufferEnable; }
300
301 float getLowResPercent() { return m_lowResPercent; }
302
303 // check if the context is direct
304 SbBool ctxIsDirect();
305
306 private:
307
308 // Synchronise current properties from this object with the current configuration.
309 void syncFromCurrentConfig();
310
311 // Synchronise the current template with current properties from this object.
312 void syncToCurrentConfigTemplate( XVisualInfo* newvis );
313
314 SbBool currentGraphicConfigTemplateIsUsed;
315 SoGLGraphicConfigTemplate currentGraphicConfigTemplate;
316
317 // Gets the current graphic device.
318 SoGLGraphicDevice* getGraphicDevice();
319
320 // Gets the current graphic configuration.
321 SoGLGraphicConfig* getGraphicConfig();
322
323 SbBool isFsaaSupportHighQuality();
324 SbBool isFsaaHighQuality();
325
326 SoGuiGLWidget* getGuiGLWidget() const;
327
328 // returns the display lists share group for given context:
329 int getDisplayListShareGroup( SoGLContext* ctx );
330
331 // These variables are public for retro compatibility purposes only.
332 // Do not use them directly but call their accessors instead;
333 SbBool drawToFrontBuffer;
334 SbBool m_isFloatingPointRendering;
335 FloatColorBufferSize m_floatingPointRenderingPrecision;
336
337 // These two function are used by SoGui, to call the system dependent version of
338 // these functions. data is a SoWinGLWidget handle.
339 static SbBool swapNormalBuffersCB(void *data);
340 static SbBool bindNormalCurrentCB(void *data);
341 static SbBool unbindNormalCurrentCB(void *data);
342 static void* getNormalWindowCB(void *data);
343 static void* getCurrentDisplayCB(void *data);
344
345 private:
346
347 // Update the current device and disable the current configuration.
348 // If the given display is the same than the current device, the current
349 // device is kept and the current configuration is updated with the
350 // current template.
351 // If the given display is NULL, the current device and configuration are
352 // freed and set to NULL.
353 void updateCurrentDeviceAndConfig( Display* display );
354
355 SbBool currentGraphicConfigIsUsed;
356 SoGLGraphicConfig* currentGraphicConfig;
357 SbBool currentGraphicDeviceIsUsed;
358 SoGLGraphicDevice* currentGraphicDevice;
359
360 // Subclasses can pass in a bitwise OR specifying the GL modes
361 // (e.g. SO_GLX_RGB | SO_GLX_DOUBLE | SO_GLX_ZBUFFER)
362 // If buildNow is FALSE, this will not build its widget tree until
363 // buildWidget() is explicity called; else, buildWidget() is called here.
364 SoXtGLWidget( SoWidget parent = NULL,
365 const char* name = NULL,
366 SbBool buildInsideParent = TRUE,
367 int glModes = SO_GLX_RGB | SO_GLX_ZBUFFER | SO_GLX_STENCIL,
368 SbBool buildNow = TRUE,
369 SbBool sync = TRUE );
370 SoXtGLWidget( SoWidget parent,
371 const char* name,
372 SbBool buildInsideParent,
373 int glModes,
374 SbBool buildNow,
375 SbBool sync,
376 SoGuiGLWidget* guiGLWidget );
377
378 virtual ~SoXtGLWidget();
379
380 // subclasses MUST redefine redraw() to draw in the normal bit planes.
381 // processEvent() should be defined if X events are being received (see eventMask).
382 virtual void redraw() = 0;
383 virtual void processEvent( XAnyEvent* anyevent );
384
385 // subclasses can redefine these to do something useful.
386 // initGraphic() is called whenever a GLX window gets created
387 // sizeChanged() is called whenever the window changes size
388 // widgetChanged() is called whenever the widget is changed (i.e. at
389 // initialization or after switching from single->double buffer)
390 virtual void initGraphic();
391 virtual void sizeChanged( const SbVec2s& );
392 virtual void posChanged( const SbVec2i32&, const SbVec2i32& );
393 virtual void widgetChanged( SoWidget newWidget );
394
395 // sets/gets the size of the glx widget(s) - Note this size could be
396 // different from the SoXtComponent::getSize() method which return
397 // the size of the component, not necessary the same as the glx widget
398 // window (because of extra stuff like the decoration in the viewers).
399 void setGlxSize( SbVec2s newSize );
400 const SbVec2s& getGlxSize() const { return m_guiGLWidget->getGlxSize(); }
401
402 // subclasses can use this routine as the event handler for any
403 // devices they wish to get input from.
404 static void eventHandler( SoWidget w, SoXtGLWidget* p, XAnyEvent* xe, Boolean* b );
405
406 // set/get stereo buffering visual. This routine (like setDoubleBuffer)
407 // can be called interactively, althought slower since a new window
408 // with the needed visual is always created on the fly.
409 void setStereoBuffer( SbBool flag );
410 SbBool isStereoBuffer() { return (m_guiGLWidget->getGLModes() & SO_GLX_STEREO); }
411
412 // returns TRUE if main window is in rgb mode (FALSE if color index)
413 SbBool isRGBMode() { return (m_guiGLWidget->getGLModes() & SO_GLX_RGB); }
414
415#if defined(__linux__)
416 void allocCell( Display *display, Colormap cmap, XColor *colorcells, int ncolors, int colorMapSize );
417#endif
418
419 // set when color index is used
420 Colormap getColorMap() const
421 { return m_guiGLWidget->getColorMap(); }
422
423 SbBool waitForExpose; // prevent redraws until an expose is received
424
425 // make those methods protected to enable the SoXtRenderArea to use them
426 // directly when it needs to build the widget and get its resources.
427 SoWidget buildWidget( SoWidget parent );
428 SoWidget getGlxMgrWidget() { return mgrWidget; }
429
430 // ----- RemoteRender additions (v3.0) -----
431 enum RemoteRenderEnabled // Possible values for remote rendering
432 {
433 OFF, // Never use remote rendering
434 ON, // Always try to use remote rendering
435 AUTO // Use if remote does not support GLX (default)
436 };
437 RemoteRenderEnabled m_remoteRenderMode; // See possible values above
438 SbBool m_remoteRender; // Is remote rendering being used?
439 SoXtRemoteRenderInfo* m_remoteRenderInfo; // Opaque type for internal state
440 SbBool m_remoteRenderPbufferEnable; // Can we use a Pbuffer?
441 SbBool m_lowResRender; //Is Low Resolution Render Mode in use?
442 float m_lowResLowPercent; //lowest value of m_lowResPercent
443 float m_lowResHighPercent; //highest value of m_lowResPercent
444 float m_lowResPercent; //percent of the window sent thru the network
445
446 void remoteRenderInit(); // Init member vars
447 void remoteRenderCleanup(); // Free allocated resources
448 void remoteRenderGinitCB( SoWidget w ); // Create pixmap and other stuff
449 SbGlContextHelper::GLContext remoteRenderLowResRenderGinitCB( SoWidget w ); //Same for LowResRender configuration : return Remote Context
450 void remoteRenderResizeCB(); // Resize pixmap
451 void remoteRenderSendImage(); // Send rendered image to remote display
452 void remoteRenderSendLowResRender(); // send low Resolution image to remote display
453 XVisualInfo* remoteRenderChooseVisual(); // Find visual for remote window
454 void remoteRenderFatalError( const char* methodName, const char* message );
455
456 void setLowResLowPercent( float percent ) { m_lowResLowPercent = percent;}
457 void setLowResHighPercent( float percent ) { m_lowResHighPercent = percent;}
458 float getLowResLowPercent() const { return m_lowResLowPercent;}
459 float getLowResHighPercent() const { return m_lowResHighPercent;}
460
461 virtual void setLowResPercent( float newLowres ) {m_lowResPercent = newLowres;}
462
463 // Set/get thread this context belongs to
464 SbThreadId_t dwThreadId; // thread to which this context belongs
465 SbThreadId_t getThreadId() { return dwThreadId; };
466 void setThreadId( SbThreadId_t id ) { dwThreadId=id; };
467
468 virtual void onExpose();
469
470 private:
471 // local vars
472 SoWidget mgrWidget;
473 SoWidget m_widgetNormal;
474
475 SoRef<SoGLContext> m_contextNormal;
476
477 int* attribList;
478
479 // specify if sizeChanged() should be called when an expose event
480 // is received (as opposed to when a resize event is received, where
481 // the window hasn't yet been maped to the new size).
482 // ??? a GlxDraw bug ?
483 SbBool windowResized;
484
485 SbBool directConnection;
486
487 // creates a GLX widget of the correct current type and get the current
488 // set of windows, color maps, etc...
489 void buildNormalGLXWidget( XVisualInfo* vis = NULL );
490 void destroyNormalWindows(SbBool normalCall=TRUE);
491 void destroyGLXWidget( SoWidget& w, SoRef<SoGLContext>& ctx, SbBool normalWindow );
492
493 SoWidget createWindow( SoGLFormat* format );
494 void destroyWindow( SoWidget widget );
495
496 static SbBool onGLFormatChangeCallback( SoGLFormat& format, void* userData );
497
498 // callbacks from glx widget
499 static void ginitCB( SoWidget w, SoXtGLWidget* v, XtPointer p );
500 static void exposeCB( SoWidget w, SoXtGLWidget* v, XtPointer p );
501 static void resizeCB( SoWidget glx, SoXtGLWidget* p, XtPointer pt );
502
503 int m_nPixelFormat;
504
505 // Flags used when the stereo is set from environment variables.
506 bool m_stereoActiveDelayed;
507 bool m_stereoBufferFlag;
508
509 SbBool m_singleBufferExpected;
510
511 SoGuiGLWidget* m_guiGLWidget; //Implementation class for SoXxGLWidget
512
513 void constructorCommon( int glModes, SbBool buildNow );
514
515 SbBool remoteRenderGinitCB_pbuffer( SoWidget w );
516};
517
518inline void
519SoXtGLWidget::posChanged( const SbVec2i32&, const SbVec2i32& )
520{}
521
522#endif // _SO_XT_GL_WIDGET_H_
523
524#endif // _WIN32
525
526
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...
<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
AntialiasingMode
Enum which indicates the desired antialiasing algorithm.
@ AUTO
This is the default mode for antialiasing.
Abstract base class for all Open Inventor components.
Component for OpenGL rendering.
void getFloatingColorBuffer(SbBool &enable, FloatColorBufferSize &size)
Returns TRUE if floating point rendering is used and its precision.
virtual SbBool bindNormalContext()
Makes the normal rendering context the current context.
SoAntialiasingParameters * getAntialiasingParameters() const
Returns the antialiasing parameters set using the setAntialiasing(SoAntialiasingParameters*) method.
void setAntialiasing(const float quality, const SoSceneManager::AntialiasingMode mode=SoSceneManager::AUTO)
Enable (or disable) antialiasing with specified quality and mode.
virtual Window getNormalWindow()
Gets the current normal GL window, which is needed as an argument to glXMakeCurrent() when drawing in...
SoGLGraphicConfigTemplate * getGraphicConfigTemplate()
Gets the current graphics configuration template.
SbBool isDoubleBuffer()
Returns whether double buffering is on or off.
float getAntialiasingQuality() const
Returns the antialiasing quality set using the setAntialiasing(float,AntialiasingMode) method.
virtual void setDoubleBuffer(SbBool onOrOff)
Routine that dynamically changes between single and double buffering.
SbBool isBorder() const
Returns whether the border is on or off.
void setDrawToFrontBufferEnable(SbBool enableFlag)
Sets drawing to the front buffer.
void setAntialiasing(SoAntialiasingParameters *advancedParameters)
Enable (or disable) antialiasing with specific parameters.
SoSceneManager::AntialiasingMode getAntialiasingMode() const
Returns the antialiasing mode set using the setAntialiasing(float,AntialiasingMode) method.
virtual SbBool unbindNormalContext()
unbind the current context (previously bind with bindNormalContext );
void setBorder(SbBool onOrOff)
Shows/hides a border of thickness 3 around the glX widgets.
virtual void setNormalVisual(XVisualInfo *vis)
Specify exactly what the visual should be for the normal window.
virtual SbBool swapNormalBuffers()
Swaps the normal front and back buffers.
bool saveSnapshot(const SbString &filename, bool overwrite=true)
Save a snapshot of the current image displayed in the viewer.
XVisualInfo * getNormalVisual()
Returns the visual for the normal window.
SoWidget getNormalWidget() const
Gets the current normal widget, which is needed as an argument to glXMakeCurrent() when drawing in th...
SbGlContextHelper::GLContext getNormalContext() const
Gets the current normal context, which is needed as an argument to glXMakeCurrent() when drawing in t...
FloatColorBufferSize
FloatColorBufferSize.
@ FLOAT_16_COLOR_BUFFER
16-bit rendering per component.
@ FLOAT_32_COLOR_BUFFER
32-bit rendering per component.
void setGraphicConfigTemplate(SoGLGraphicConfigTemplate *gTemplate)
Sets a new graphics configuration template.
SbBool isDrawToFrontBufferEnable() const
Queries drawing to the front buffer.
void setFloatingColorBuffer(SbBool enable, FloatColorBufferSize size=FLOAT_16_COLOR_BUFFER)
Enables/disables floating point rendering using 16- or 32-bit components.
int getColorMapSize()
Returns the color map size.
SoGLContext * getNormalSoContext() const
int SbBool
Boolean type.
Definition SbBase.h:87
char Boolean
Definition SoQtDef.h:124
void * XtPointer
Definition SoQtDef.h:122