Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
SoGLContext.h
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-2024 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : VSG (MMM YYYY)
22**=======================================================================*/
23#if !defined SOGLCONTEXT_H
24#define SOGLCONTEXT_H
25
26#include <Inventor/devices/SoDeviceContext.h>
27#include <Inventor/devices/SoGLFormat.h>
28#include <Inventor/devices/SoGLGlew.h>
29#include <Inventor/STL/vector>
30#include <Inventor/STL/list>
31#include <Inventor/STL/map>
32#include <Inventor/helpers/SbGlContextHelper.h>
33#include <Inventor/threads/SbThreadLocalStorage.h>
34#include <Inventor/threads/SbThreadSpinlock.h>
35#include <Inventor/errors/SoError.h>
36#include <Inventor/image/SbRasterImage.h>
37#include <Inventor/threads/SbThreadLocalStorage.h>
38
39
40#include <Inventor/SbPList.h> // For SbStringList
41#include <Inventor/STL/stack>
42
43#include <Inventor/helpers/SbGPUCapabilities.h>
44
45#if defined(_WIN32)
46#include <windows.h>
47#endif
48
49
50#ifdef _MSC_VER
51#pragma warning( push )
52#pragma warning(disable:4251)
53#endif
54
55class SbThreadMutex;
56struct GLEWContextStruct;
57
59class FunctionRedirector;
185{
186public:
187
214
224 SoGLContext( bool shared );
225
241
252
260 SoGLContext( const SoGLFormat& format, SbGlContextHelper::Drawable drawable = 0 );
261
285 bool shared = true );
286
293 SoGLContext( SoGLContext* context, bool shared );
294
303 SoGLContext( SoGLContext* context, const SoGLFormat& format, SbGlContextHelper::Drawable drawable = 0 );
304
309 virtual void bind();
310
311
316 virtual bool tryBind();
317
321 virtual void unbind();
322
328 bool isSharedWith( const SoDeviceContext* context ) const;
329
331 virtual bool isValid() const;
332
339
346 int getId() const;
347
357 virtual bool isCompatible( SoDeviceContext* context ) const;
358
363 virtual bool isCurrent() const;
364
380 static SoGLContext* getCurrent( bool checkGLState = false );
381
388
395
401#if defined(_WIN32)
402 typedef int SharedGroupDescription;
403#else
405#endif
407
414
421
428 const SoGLFormat& getFormat() const;
429
436 static SoGLContext* getContextFromId( int id );
437
444 static SoGLContext* getContextFromSharedId( int sharedIdGroup );
445
450 bool isValidForCurrent() const;
451
455 void assertContext() const;
456
461
471
474
481 void setNoGLContextDelete() { m_noOGLContextDelete = true; }
482
488
494
495private:
496
497 SB_THREAD_TLS_HEADER();
498
499 static void initClass();
500 static void exitClass();
501
503 enum GPUVendorType
504 {
505 GPU_TYPE_NOT_INITIALIZED = -1,
506 GPU_NVIDIA = 0,
507 GPU_ATI = 1,
508 GPU_INTEL = 2,
509 GPU_FIREPRO_MAC = 3
510 };
511
512 /* Returns the GPU vendor type */
513 static GPUVendorType getGPUVendorType();
514
526 static SoGLContext* getActualCurrentContext( SoGLContext* supposedContext );
527
531 void setUserData( void* data )
532 { m_userData = data; }
533
535 void* getUserData() const
536 { return m_userData; }
537
540 bool setSharedWith( SoGLContext* sharedContext );
541
542 // internally used by PBuffer to change the display.
543 void forceDisplay( const SbGlContextHelper::Display& display );
544
545 // Used internally in remote to update the drawable (Linux only)
546 void forceDrawable( const SbGlContextHelper::Drawable& drawable );
547
548 // Used internally to avoid the destruction of the context
549 // in some cases, like Qt because Qt destroy the context.
550 void forceContext( const SbGlContextHelper::GLContext& context )
551 { m_context = context; }
552
553 //Allow to change the no delete flag since the public method is one way only
554 inline void forceNoGLContextDelete(bool flag) { m_noOGLContextDelete = flag; }
555
556 // Used internally to get the drawable of this context
557 const SbGlContextHelper::Drawable& getDrawable() const
558 { return m_drawable;}
559
560 virtual SbString getInfos();
561
562 //Provides the name of the graphic card used by the context.
563 SbString getDeviceName() const;
564
568 void printInformation();
569
573 static void printCurrentContextInformation();
574
578 static void printContextsInformation();
579
585 static void invalidateDrawable(SbGlContextHelper::Drawable drawable);
586
592 static void invalidateDisplay(SbGlContextHelper::Display display);
593
612 bool setVSyncEnabled(bool SO_UNUSED_PARAM(on));
613
619 bool isVSyncEnabled();
620
622 bool isBinded();
623
624 static GLEWContextStruct* glewGetCurrentContext();
625 static SoGLGlew::GlewContextNative* glewGetCurrentContextNative();
626
627private:
631 virtual ~SoGLContext();
632
638 void removeSharedObjects();
639
640private:
641
643 void checkRefCount() const;
644
645 virtual bool setSharedWith( SoDeviceContext* sourceCtx );
646
652 void setSwapInterval(int interval);
653
654 // Class static thread local storage
655 struct MTstruct
656 {
657 typedef std::vector<SoGLContext*> ContextVec;
659 ContextVec* m_bindedContexts;
660 };
661
662 bool initContext( SoGLContext* sourceContext, bool shared );
663 void preInitContext();
664 bool postInitContext();
665
666 void checkContextParameters( const char* function );
667
669
670 typedef std::list< SoGLContext* > SoGLContextList;
671
673 static SoGLContextList s_contexts;
674
676 static int s_firstAvailableId;
677
679 static SbThreadSpinlock s_contextsMutex;
680
682 int m_id;
683
686
691 SbGlContextHelper::GLContext m_savedContextForDelete;
692
693 SoGLFormat m_format;
694
695 void* m_userData;
696
697 static GPUVendorType m_GpuVendorType;
698
699 bool m_noOGLContextDelete;
700
701 bool m_drawableIsValid;
702 bool m_displayIsValid;
703
704 static int s_checkContext;
705
706 static int s_oivCompatibilityMode;
707
709 static SharedGroupPolicy s_sharedGroupPolicy;
710
711 // True if all content of shared group is removed.
712 bool m_sharedObjectsRemoved;
713
715 bool m_displayWarning;
716
717 static SoGLContext* findSoGLContext(SbGlContextHelper::GLContext ctx);
718 void pushInBindedList();
719 static void updateBindedList();
720 static void updateBindedList(SbGlContextHelper::Display display, SbGlContextHelper::Drawable drawable, SbGlContextHelper::GLContext context);
721 static SoGLContext* popBindedList();
722
723 bool m_thirdPartyContext;
724 bool m_isBeingDestroyed;
725 SbGPUCapabilities* m_graphicCapabilities;
726 static FunctionRedirector s_deleteContextRedirector;
727
728 static bool callOriginalDeleteContext(SbGlContextHelper::Display display, SbGlContextHelper::GLContext context, int& returnValue);
729 static int commonDeleteContextHook(SbGlContextHelper::Display dpy, SbGlContextHelper::GLContext ctx);
730
731#if defined(WIN32)
732 static int _stdcall deleteContextHook(SbGlContextHelper::GLContext context);
733#elif defined(__APPLE__)
734 static int deleteContextHook(SbGlContextHelper::GLContext context);
735#else
736 static int deleteContextHook(SbGlContextHelper::Display dpy, SbGlContextHelper::GLContext ctx);
737#endif
738
739 static MTstruct::ContextVec& getBindedContextsList();
740};
741
742#ifdef _MSC_VER
743#pragma warning( pop )
744#endif
745
746
747#endif //SOGLCONTEXT_H
748
List of common graphics capabilities of the device used by a SoGLContext.
Class for smart character strings.
Definition SbString.h:202
Maintains a list of pointers to SbString instances.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable mutex c...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable spinloc...
<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> OpenGL context m...
virtual void bind()
Bind the OpenGL context to the current thread.
virtual bool isValid() const
Returns true if this context is valid.
virtual bool tryBind()
Try to bind the OpenGL context to the current thread.
bool isValidForCurrent() const
Returns true if the context is the current active context or if it is shared with the current active ...
SharedGroupPolicy
Sharing Policy.
@ CONSERVATIVE
Conservative sharing (not available on Unix) Only add context to a share group containing contexts ...
@ AGGRESSIVE
Aggressive sharing (default) Tries to share contexts, independent of their sharing constraint.
@ DISABLED
Disables context sharing (same behavior as v2.6 and older)
virtual bool isCurrent() const
Returns true if this context is valid and currently active.
SoGLContext(SoGLContext *context, bool shared)
Constructor which creates an SoGLContext based on the attributes of the specified context.
int getId() const
Returns the internal id for this context.
static SoGLContext * getContextFromId(int id)
Returns the context corresponding to an internal id.
static SoGLContext * findGLContext(SbGlContextHelper::GLContext)
Returns the first SoGLContext associated with the specified OpenGL context.
void invalidate()
Set this context as invalid so it won't be used anymore.
static const SbGPUCapabilities & getGraphicsCapabilities()
Retrieve graphics capabilities from the current bound context, if any.
static SoGLContext * getCurrent(bool checkGLState=false)
Returns the current active OpenGL context (if any).
SbGlContextHelper::Display SharedGroupDescription
Returns an SoGLContext that matches the specified SharedGroupDescription.
SoGLContext(SbGlContextHelper::Display dpy, SbGlContextHelper::VisualInfo vis, SbGlContextHelper::Drawable drawable, SbGlContextHelper::GLContext ctx)
Constructor which creates an SoGLContext based on the specifed parameters.
bool swapBuffers()
Swaps the buffers with the value stored in the SoGLFormat, which is set to the main plane by default.
const SbGlContextHelper::VisualInfo & getVisualInfo() const
Returns the VisualInfo of this SoGLContext.
void setNoGLContextDelete()
Prevent deletion of the native OpenGL context by SoGLContext.
const SbGlContextHelper::GLContext & getGLContext() const
Returns the OpenGL rendering context of this SoGLContext.
SoGLContext(SoGLContext *context, const SoGLFormat &format, SbGlContextHelper::Drawable drawable=0)
Constructor which creates a SoGLContext shared with a specific context, but attached to the display s...
bool isSharedWith(const SoDeviceContext *context) const
Returns true if the specified context and this context are shared.
const SbGlContextHelper::Display & getDisplay() const
Returns the Display of this SoGLContext.
const SbGPUCapabilities & getContextGraphicsCapabilities()
Retrieve graphics capabilities from this context.
SoGLContext(SbGlContextHelper::Display dpy, SbGlContextHelper::VisualInfo vis, SbGlContextHelper::Drawable drawable, bool shared=true)
Constructor which creates a SoGLContext based on the specified parameters.
const SoGLFormat & getFormat() const
Returns the SoGLFormat associated to the SoGLContext.
SoGLContext(bool shared)
Constructor which creates an SoGLContext based on the attributes of the current context.
static SharedGroupPolicy getSharedGroupPolicy()
Returns the current sharedGroupPolicy.
virtual bool isCompatible(SoDeviceContext *context) const
Returns true if the specified context and this one are compatible.
virtual void unbind()
Unbind the OpenGL context from the current thread.
SoGLContext(const SoGLFormat &format, SbGlContextHelper::Drawable drawable=0)
Constructor which creates a SoGLContext based on the specifed format.
void assertContext() const
Assert this context and the current active context are the same.
static SoGLContext * getContextFromSharedId(int sharedIdGroup)
Returns the first context that belongs to the specified sharedIdGroup.
SoGLContext(const SoGLFormat &format, SbGlContextHelper::GLContext ctx, SbGlContextHelper::Drawable drawable=0)
Constructor which creates a SoGLContext based on the specified parameters.
SbStringList getSupportedExtensions()
Returns an SbString containing the supported extensions for this context.
static SoGLContext * findSharedContext(SharedGroupDescription)
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> OpenGL pixel for...
Definition SoGLFormat.h:55