Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoGLDevice.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-2021 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : Tristan MEHAMLI (Aug 2009)
22**=======================================================================*/
23
24#ifndef SO_GL_DEVICE
25#define SO_GL_DEVICE
26
28//
29// Class: SoGLDevice
30//
31// Provides methods to retrieve the properties of a GPU.
32//
33//
35
36#include <Inventor/devices/SoDevice.h>
37#include <Inventor/devices/SoGLScreenDevice.h>
38#include <Inventor/STL/vector>
39#include <Inventor/devices/SoGLDeviceSettings.h>
40
62class SoGLDevice : public SoDevice
63{
64 // ----------------------- Public usage --------------------------------------
65public:
66
70 virtual unsigned long long getTotalMemory() const;
71
78 virtual unsigned long long getAvailableMemory() const;
79
84 virtual unsigned int getLogicalUnits() const;
85
89 virtual SbString getDriverVersion() const;
90
98
102 virtual SbString getDeviceName() const;
103
111
115 static unsigned int getDevicesCount();
116
122 static SoGLDevice* getDevice( int index );
123
129
133 unsigned int getScreenDevicesCount();
134
141
145 static void initClass();
146
150 static void exitClass();
151
155 friend std::ostream& operator << ( std::ostream& os, const SoGLDevice& dev )
156 {
157 unsigned long long allocatedMemory, availableMemory;
158 dev.getMemoryInfo( allocatedMemory, availableMemory );
159
160 return os << "[GPU name]: " << dev.m_name.toLatin1() << "\n" << \
161 "[Driver ver]: " << dev.m_drvVer.toLatin1() << "\n" << \
162 "[Vram size]: " << (dev.m_totalMemory)/(1024*1024) << "MB" << "\n" << // memory size returned in Mbytes.
163 "[Available Vram size]: " << availableMemory/(1024*1024) << "MB" << "\n" << // memory size returned in Mbytes.
164 "[LogicalUnits]: " << dev.m_logicalUnitsCount;
165 }
166
167 // ----------------------- Protected usage --------------------------------------
168private:
169
173 SoGLDevice();
174
178 virtual ~SoGLDevice();
179
183 static bool findFirstDeviceFunc( SoDevice* device );
184
185 // ----------------------- Private usage --------------------------------------
186private:
187
188 // Only used under Linux
190 enum VideoCardType
191 {
195 VC_ATI,
199 VC_NVIDIA,
203 VC_VIRTUALBOX,
207 VC_MESA,
211 VC_UNKNOWN
212 };
213
214 void getMemoryInfo( unsigned long long& allocatedMemory, unsigned long long& availableMemory ) const;
215
216 // Initializes the device with default parameters
217 static void defaultDeviceInit();
218
219 // Memory
220 unsigned long long m_totalMemory;
221
222 // Logical units
223 unsigned int m_logicalUnitsCount;
224
225 // GPU name
226 SbString m_name;
227
228 // Driver version
229 SbString m_drvVer;
230
231 VideoCardType m_vcType;
232
233 // List of GPU devices removed when this module is unlocked
234 static std::vector<SoGLDevice*> s_glDevices;
235
236 // List of screen devices attached to the GL device
237 std::vector<SoGLScreenDevice*> m_screenDevices;
238
239 // Thread mutex for initClass and exitClass
240 static SbThreadMutex s_initThreadMutex;
241
242 // Refs counter
243 static int s_initRefCount;
244};
245
246// ----------------------- Inline functions --------------------------------------
247inline unsigned long long
249{
250 return m_totalMemory;
251}
252
253inline unsigned int
255{
256 return m_logicalUnitsCount;
257}
258
259inline SbString
261{
262 return m_name;
263}
264
265#endif // SO_GL_DEVICE
266
267
Class for smart character strings.
Definition SbString.h:202
const char * toLatin1() const
Returns the string as a Latin-1/ASCII C string.
<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> Abstract device ...
Definition SoDevice.h:82
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> OpenGL device ma...
Definition SoGLDevice.h:63
static void initClass()
Initializes SoGLDevice.
static SoGLDevice * getDevice(int index)
Returns the SoGLDevice indicated by index (starting from 0).
static unsigned int getDevicesCount()
Returns the number of GPUs on the sytem.
static SoGLDevice * findFirstAvailableDevice()
Returns the first available device found in the system.
virtual SoGLDeviceSettings * getDeviceSettings() const
Returns an handle of the driver API allowing to modify profile of this device.
friend std::ostream & operator<<(std::ostream &os, const SoGLDevice &dev)
Prints information about this device.
Definition SoGLDevice.h:155
unsigned int getScreenDevicesCount()
Returns the number of screen devices connected to the GL device.
virtual unsigned int getLogicalUnits() const
Returns the number of logical units on this device (i.e.
Definition SoGLDevice.h:254
SoGLScreenDevice * getMainScreenDevice()
Returns the main screen device connected to the GL device.
virtual unsigned long long getTotalMemory() const
Returns the total memory of this device in bytes.
Definition SoGLDevice.h:248
virtual unsigned long long getAvailableMemory() const
Returns the currently available memory of this device in bytes.
SoGLScreenDevice * getScreenDevice(int index)
Returns the SoGLScreenDevice indicated by index (starting from 0).
static void exitClass()
Cleans SoGLDevice.
virtual SbString getDeviceName() const
Returns the name of this device.
Definition SoGLDevice.h:260
virtual SbString getDriverVersion() const
Returns the driver version of this GPU.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Device settings ...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> GL Screen device...