Mudbox/kernel.h Source File

kernel.h
Go to the documentation of this file.
1 //**************************************************************************/
2 // Copyright (c) 2008 Autodesk, Inc.
3 // All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Autodesk license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 //
9 //**************************************************************************/
10 // DESCRIPTION:
11 // CREATED: October 2008
12 //**************************************************************************/
13 
14 class CIPModule;
15 
16 namespace mudbox {
17  class MBDLL_DECL Kernel; // declare Kernel as an incomplete type -- ptrs to it are allowed.
18 };
19 
20 // Now declare a naked C pointer to the Kernel. \b Please to not use this directly. Use the
21 // inline function just below it mudbox::Kernel() to get a pointer to the singleton
22 // instance of the mudbox Kernel class.
24 
25 
26 namespace mudbox {
27 
33 inline MBDLL_DECL class Kernel *Kernel( void )
34 {
36 };
37 
38 
42 {
44 
45  enum Type
46  {
49  typeBrowseForRead,
52  typeBrowseForWrite,
55  typePreRead,
57  typePostRead,
60  typePreWrite,
62  typePostWrite
63  } m_eType;
66  QString m_sFileName;
67 };
68 
69 //-----------------------------------------------------------------------------
77 {
79 
80 public:
84  virtual Texture* DoUnproject(int xSize, int ySize, bool want16BitFP = false, bool bTranparentBackground = true);
85 };
86 
87 //-----------------------------------------------------------------------------
88 
89 class Operation;
90 class XRef;
91 
92 #define NUM_CRASHFLAGS (128)
93 
94 // define module flags...
95 #define CRF_COMMAND 0
96 #define CRF_MENU_COMMAND 1
97 #define CRF_HARDWARE_RENDER 2
98 #define CRF_TEXTURE_PAINT 3
99 #define CRF_FAST_BRUSH 4
100 #define CRF_TEXTURE 5
101 #define CRF_IMAGE 6
102 #define CRF_SCENE_VIEW 7
103 #define CRF_MESH 8
104 #define CRF_SUBDIVIDE 9
105 #define CRF_TEXTURE_LAYERS 10
106 #define CRF_CURVE 11
107 #define CRF_PAINT_BUFFER 12
108 #define CRF_IBL_MATERIAL 13
109 #define CRF_MB_MATERIAL 14
110 #define CRF_HW_PICKER 15
111 #define CRF_GUI 16
112 #define CRF_CAMERA 17
113 #define CRF_CAMERA_2 18
114 #define CRF_INTERFACE_1 19
115 #define CRF_INTERFACE_2 20
116 #define CRF_INTERFACE_3 21
117 #define CRF_INTERFACE_4 22
118 #define CRF_DIALOGS_1 23
119 #define CRF_DIALOGS_2 24
120 #define CRF_DIALOGS_3 25
121 #define CRF_DIALOGS_4 26
122 #define CRF_DIALOGS_5 27
123 #define CRF_DIALOGS_6 28
124 #define CRF_CG_MATERIAL 29
125 #define CRF_CG_MATERIAL_2 30
126 #define CRF_SCENE_VIEW_2 31
127 #define CRF_SCENE 32
128 #define CRF_SCENE_2 33
129 #define CRF_IMAGE_BASE 34
130 
131 
132 
133 // define the 32 Power of 2 flags....
134 #define CRF_00 ((unsigned int)(1u ))
135 #define CRF_01 ((unsigned int)(1u<< 1))
136 #define CRF_02 ((unsigned int)(1u<< 2))
137 #define CRF_03 ((unsigned int)(1u<< 3))
138 #define CRF_04 ((unsigned int)(1u<< 4))
139 #define CRF_05 ((unsigned int)(1u<< 5))
140 #define CRF_06 ((unsigned int)(1u<< 6))
141 #define CRF_07 ((unsigned int)(1u<< 7))
142 #define CRF_08 ((unsigned int)(1u<< 8))
143 #define CRF_09 ((unsigned int)(1u<< 9))
144 #define CRF_10 ((unsigned int)(1u<<10))
145 #define CRF_11 ((unsigned int)(1u<<11))
146 #define CRF_12 ((unsigned int)(1u<<12))
147 #define CRF_13 ((unsigned int)(1u<<13))
148 #define CRF_14 ((unsigned int)(1u<<14))
149 #define CRF_15 ((unsigned int)(1u<<15))
150 #define CRF_16 ((unsigned int)(1u<<16))
151 #define CRF_17 ((unsigned int)(1u<<17))
152 #define CRF_18 ((unsigned int)(1u<<18))
153 #define CRF_19 ((unsigned int)(1u<<19))
154 #define CRF_20 ((unsigned int)(1u<<20))
155 #define CRF_21 ((unsigned int)(1u<<21))
156 #define CRF_22 ((unsigned int)(1u<<22))
157 #define CRF_23 ((unsigned int)(1u<<23))
158 #define CRF_24 ((unsigned int)(1u<<24))
159 #define CRF_25 ((unsigned int)(1u<<25))
160 #define CRF_26 ((unsigned int)(1u<<26))
161 #define CRF_27 ((unsigned int)(1u<<27))
162 #define CRF_28 ((unsigned int)(1u<<28))
163 #define CRF_29 ((unsigned int)(1u<<29))
164 #define CRF_30 ((unsigned int)(1u<<30))
165 #define CRF_31 ((unsigned int)(1u<<31))
166 
167 // this is a singleton. Used to create some breadcrumbs in the event of a crash
168 // so if the stack back-trace is corrupt, we have a chance of reproducing the problem.
170 {
171  private:
172  QString m_ProgressName;
173  unsigned int m_MaxProgress, m_CurProgress;
174 
175  QString m_CurrentHelp;
176 
177  unsigned int m_FlagArray[NUM_CRASHFLAGS]; // 512 bytes
178 
179  char m_RingBuffer[256][256]; // 64k bytes
180  int m_head, m_count, m_total;
181 
182  public:
183  MBCrashInfo() : m_MaxProgress(0), m_CurProgress(0), m_head(0), m_count(0), m_total(0)
184  { memset(m_FlagArray, 0, sizeof(m_FlagArray)); memset(m_RingBuffer, 0, sizeof(m_RingBuffer)); }
185 
186  void AddToFlag(int flagNum, unsigned int v) { m_FlagArray[flagNum] += v; }
187  void SubFromFlag(int flagNum, unsigned int v) { m_FlagArray[flagNum] -= v; }
188  unsigned int GetFlag(int flagNum) const { return m_FlagArray[flagNum]; }
189 
190  void AddStringToRingBuffer(const QString &prefix, const QString &entry);
191  void SetProgressName(const QString &name, unsigned int maxVal) { m_ProgressName = name; m_MaxProgress = maxVal; }
192  void SetProgressValue(unsigned int val) { m_CurProgress = val; }
193  void ClearProgress() { m_ProgressName = ""; m_MaxProgress = 0; m_CurProgress = 0; }
194 
195  void SetHelpString(const QString &st) { m_CurrentHelp = st; }
196 
197  friend class ::CIPModule;
198 };
199 
200 typedef QString (*DumpFcnTyp)(void);
201 
205 class MBDLL_DECL Kernel : public Node
206 {
209  class XRef* m_pXRef;
210 
211  DumpFcnTyp m_ImageStatsFcn;
212  DumpFcnTyp m_PaintBufferStatsFcn;
213  MBCrashInfo m_CrashInfo;
214 
215 public:
216 
218  Kernel( void );
219 
226  void Log(const QString &sMessage);
227 
228  DumpFcnTyp GetImageStatsFcn() const { return m_ImageStatsFcn; }
229  void SetImageStatsFcn(DumpFcnTyp f) { m_ImageStatsFcn = f; }
230  DumpFcnTyp GetPaintBufferStatsFcn() const { return m_PaintBufferStatsFcn; }
231  void SetPaintBufferStatsFcn(DumpFcnTyp f) { m_PaintBufferStatsFcn = f; }
232 
233  MBCrashInfo *GetCrashInfo() { return &m_CrashInfo; }
234 
235  void SetCrashHelpString(const QString &st) { m_CrashInfo.SetHelpString(st); }
236  void AddStringToCrashBuffer(const QString &prefix, const QString &entry)
237  { m_CrashInfo.AddStringToRingBuffer(prefix, entry); }
238 
240  void LogMemoryStatus(
241  bool bCompact = true
242  );
243 
248  void LogMemoryBlocks(
249  float fSizeLimit = 0.01
250  );
251 
255  bool CreateNewScene();
256 
257  // Automation
258 
289  void RecordCommand( const QString &sCommand );
290 
293 
295  class Scene *CreateDefaultScene( void );
296 
297  // plugin management
307  const ClassDesc *PreferredDescendant(
308  const ClassDesc *pClass //< [in] The ClassDesc of a base class (obtained via the StaticClass() function: myClass::StaticClass() )
309  ) const;
310 
315  Node *CreateClassInstance( const ClassDesc *pClass ) const;
316 
322  Image *LoadImage(
323  const QString &sFileName,
324  bool tiled = false
325  ) const;
326 
328  void GLCheckError(
329  const char *sSourceFileName,
330  const char *sFunctionName,
331  unsigned int iLine
332  ) const;
333 
335  void GLCheckStates(
336  const char *sSourceFileName,
337  const char *sFunctionName,
338  unsigned int iLine
339  ) const;
340 
341 
345  void Redraw( void );
346 
348  class Scene *Scene( void ) const;
349 
351  mudbox::Preferences *Preferences( void ) const;
352 
354  class mudbox::Interface *Interface( void ) const;
355 
357  class Statistics *Statistics( void ) const;
358 
360  class ViewPort *ViewPort( void ) const;
361 
363  QString MudboxVersionName( void ) const;
364 
366  QString MudboxBuildID( void ) const;
367 
369  void RegisterWindowPlugin(WindowPlugin* plugin) const;
370 
372  mudbox::TrayAccessor *TrayAccessor( void ) const;
373 
375  bool ExtractArchiveFile(QString sArchiveFilePath, QString sDestPath);
376  bool CreateArchiveFile(QString sArchiveFilePath, QStringList files);
377 
379  QString DataDirectory( void ) const;
380 
382  QString ApplicationDirectory( void ) const;
383 
385  QString ProjectFilesDirectory( void ) const;
386 
388  QString SafeWritableDirectory( void ) const;
389 
391  QString PluginDirectory( const QString& pluginName ) const;
392 
394  int CommandLineParameterCount( void ) const;
395 
397  QString CommandLineParameterName( int iIndex ) const;
398 
400  QString CommandLineParameterValue( int iIndex ) const;
401 
404  bool IsTestModeOn( void ) const;
405 
407  bool IsBetaVersion( void ) const;
408 
415 
416  Image *ExtractUnprojectedTextures(const QString &sChannel,
417  int iWidth,
418  int iHeight,
419  enum Image::Format fmt = Image::e8integer,
420  bool bTiledImg = false,
421  bool allLayers = false
422  );
423 
424  Image *ExtractUnprojectedTextures(int iWidth,
425  int iHeight,
426  enum Image::Format fmt = Image::e8integer,
427  bool bTiledImg = false,
428  bool allLayers = false
429  );
430 
431 
440 
441  Image *ExtractShadingMap(int iWidth,
442  int iHeight,
443  enum Image::Format fmt = Image::e8integer,
444  bool bTiledImg = false
445  );
446 
447 
449  class XRef* XRef() const;
450 
458  void ReportVideoMemoryUsage(
459  qint64 iSize
460  );
461 
463  qint64 VideoMemoryUsage( void ) const;
464 
466  qint64 TotalVideoMemory( void ) const;
467 
472  bool DoOperation(
473  Operation *pOp,
474  bool bMerge = false
475  );
476 
477  const QList<class ImageIOHandler *> &ExternalImageIOHandlers( void ) const;
478 
482  void FlushUndoQueue();
483 
486 
489 
492 
498 
502 
505 
519  QString TriggerFileEvent(
520  FileEventNotifier::Type eType,
521  const QString &sFileName
522  ) const;
523 
532  mutable aptr<FileEventNotifier> FileEvent;
533 
536 };
537 
538 // MBDLL_DECL Kernel *Kernel( void );
539 
541 
542 
545 {
546  int m_iIndex;
547 
548 public:
550  Timer( const char *sName, int &iIndex );
551  ~Timer( void );
553  static unsigned int Current( void );
556  static void ResetAll( void );
558  static void LogAll( void );
559 };
560 
561 
564 {
565 public:
566  void AddRenderedPolygonCount( unsigned int iPolygonCount );
567  int FrameCount( void ) const;
568 };
569 
575 template < typename c >
576 c* CreateInstance( void ) { return dynamic_cast<c *>( Kernel()->CreateClassInstance( c::StaticClass() ) ); };
577 
615 template < typename c >
617 {
618  c *m_pObject;
619 
620 public:
621  inline Instance( c* pObject ) : m_pObject( pObject ) {};
622  inline Instance( void ) { m_pObject = CreateInstance<c>(); };
623  inline ~Instance( void ) { if( m_pObject ) delete m_pObject; };
624  inline c *operator ->( void ) { return m_pObject; };
625  inline const c *operator ->( void ) const { return m_pObject; };
626  inline operator c*( void ) const { return m_pObject; };
627 
630  inline c * Release() { c* pTemp = m_pObject; m_pObject = 0; return pTemp; }
631 };
632 
635 {
636 public:
637 
645  static QString SanitizeFileName(
646  const QString& sName
647  );
648 };
649 
650 
651 
652 // use an instance this as a local variable to set/clear flags in a 32 bit word
653 // for the crash reporter I recommend using powers of 2 for the flag value.
654 // Flag numbers range from 0 to 127
656 {
657  private:
658  int m_flagNum;
659  unsigned int m_v;
660 
661  public:
662  MBCrashReporterFlag(int flagNum, unsigned int v = 1) : m_flagNum(flagNum), m_v(v)
663  { Kernel()->GetCrashInfo()->AddToFlag(flagNum, v); }
664 
666  { Kernel()->GetCrashInfo()->SubFromFlag(m_flagNum, m_v); m_flagNum = 0; m_v = 0; }
667 };
668 
669 
670 
671 }; // end of namespace mudbox
672 
673 
674 
c * CreateInstance(void)
This function provides an easy way to create objects based on interfaces.
Definition: kernel.h:576
aevent TangentMirrorUpdateEvent
This event is triggered when tangent mirror information is updated.
Definition: kernel.h:491
void ClearProgress()
Definition: kernel.h:193
#define MBDLL_TEMPLATE_DECL
Definition: dllinterface.h:44
aevent ScenePreDeletedEvent
This event is triggered before a scene is going to be deleted.
Definition: kernel.h:535
aevent LowMemoryEvent
This event is triggered when the memory status gets critical.
Definition: kernel.h:497
MBCrashInfo * GetCrashInfo()
Definition: kernel.h:233
The Scene class is the container object for all the data in a Mudbox scene.
Definition: scene.h:53
DumpFcnTyp GetImageStatsFcn() const
Definition: kernel.h:228
WindowPlugin is an interface to implement window based plugins.
Definition: plugin.h:56
Format
Image channel datatype type.
Definition: image.h:1522
void SetCrashHelpString(const QString &st)
Definition: kernel.h:235
long long qint64
Definition: qglobal.h:947
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
~Instance(void)
Definition: kernel.h:623
please do not access this pointer directly — Use the inline Kernel() function just below...
Definition: kernel.h:544
This is the base class for most classes in the Mudbox SDK.
Definition: node.h:740
void AddToFlag(int flagNum, unsigned int v)
Definition: kernel.h:186
unsigned int GetFlag(int flagNum) const
Definition: kernel.h:188
aevent StrokeEndEvent
This event is triggered when a stroke has ended. See the class EventGate for more details...
Definition: kernel.h:488
Instance(c *pObject)
Definition: kernel.h:621
void SetProgressValue(unsigned int val)
Definition: kernel.h:192
c * Release()
Take ownership of m_pObject.
Definition: kernel.h:630
This class is collects miscellaneous utility functions.
Definition: kernel.h:634
#define NUM_CRASHFLAGS
Definition: kernel.h:92
void SetHelpString(const QString &st)
Definition: kernel.h:195
MBDLL_DECL class mudbox::Kernel * _g_pKernel__DO_NOT_USE_THIS_DIRECTLY_
Definition: kernel.h:23
MBCrashReporterFlag(int flagNum, unsigned int v=1)
Definition: kernel.h:662
void AddStringToCrashBuffer(const QString &prefix, const QString &entry)
Definition: kernel.h:236
aevent RestoreMemoryEvent
This event is triggered when memory status is no longer critical.
Definition: kernel.h:501
void AddStringToRingBuffer(const QString &prefix, const QString &entry)
This structure represents and describes a class.
Definition: node.h:22
Instance(void)
Definition: kernel.h:622
aevent StrokeBeginEvent
This event is triggered when a new stroke is started. See the class EventGate for more details...
Definition: kernel.h:485
aptr< FileEventNotifier > FileEvent
This is a pointer to the latest file event.
Definition: kernel.h:532
This class represents an event receiver/triggerer point.
Definition: node.h:999
TrayAccessor allows plugins to access the trays in the GUI.
Definition: tray.h:22
void SetProgressName(const QString &name, unsigned int maxVal)
Definition: kernel.h:191
const GLdouble * v
Definition: GLee.h:1174
DumpFcnTyp GetPaintBufferStatsFcn() const
Definition: kernel.h:230
Holds useful information about the current session of Mudbox.
Definition: kernel.h:563
Represents a texture tile inside a texture pool.
Definition: material.h:716
const GLubyte * c
Definition: GLee.h:5419
GLuint const GLchar * name
Definition: GLee.h:1704
Class: ConvolutionKernel.
Definition: array.h:15
The base class of all operations.
Definition: operation.h:26
The main API access point to Mudbox, contains low level functions and data.
Definition: kernel.h:205
void SetImageStatsFcn(DumpFcnTyp f)
Definition: kernel.h:229
class MBDLL_DECL Kernel
Definition: kernel.h:17
Holds Mudbox application preferences.
Definition: preferences.h:70
QString(* DumpFcnTyp)(void)
Definition: kernel.h:200
This class will extract the unprojected current diffuse texture layer from the current camera positio...
Definition: kernel.h:76
#define DECLARE_CLASS
This macro should be used in declaration of classes which are inherited from the Node class (or any d...
Definition: node.h:91
The Interface class provides access to user interface related functions and events.
Definition: interface.h:43
void SubFromFlag(int flagNum, unsigned int v)
Definition: kernel.h:187
aevent PostUndoRedoEvent
This event is triggered after an undo or redo operation is completed.
Definition: kernel.h:504
This is the base image type defining the interface to images.
Definition: image.h:1504
GLclampf f
Definition: GLee.h:9303
#define Q_DECLARE_TR_FUNCTIONS(context)
Holds information about the a recent or in-progress file event.
Definition: kernel.h:41
XRef provides functionality to resolve relative paths to external files into absolute paths...
Definition: xref.h:18
#define MBDLL_DECL
Definition: dllinterface.h:35
This is a helper class to manage class instances implemented in plugins, provided for convenience...
Definition: kernel.h:616
Represents the 3D viewport where Mudbox renders the scene.
Definition: viewport.h:147
astring NextCommand
This attribute always contains the next command. Plugins can link their own attribute to this one...
Definition: kernel.h:292
void SetPaintBufferStatsFcn(DumpFcnTyp f)
Definition: kernel.h:231