Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
4.6 KiB

  1. #ifndef GLMDEBUG_H
  2. #define GLMDEBUG_H
  3. #include "tier0/platform.h"
  4. #if defined( OSX )
  5. #include <stdarg.h>
  6. #endif
  7. // include this anywhere you need to be able to compile-out code related specifically to GLM debugging.
  8. // we expect DEBUG to be driven by the build system so you can include this header anywhere.
  9. // when we come out, GLMDEBUG will be defined to a value - 0, 1, or 2
  10. // 0 means no GLM debugging is possible
  11. // 1 means it's possible and resulted from being a debug build
  12. // 2 means it's possible and resulted from being manually forced on for a release build
  13. #ifdef POSIX
  14. #ifndef GLMDEBUG
  15. #ifdef DEBUG
  16. #define GLMDEBUG 1 // normally 1 here, testing
  17. #else
  18. // #define GLMDEBUG 2 // don't check this in enabled..
  19. #endif
  20. #ifndef GLMDEBUG
  21. #define GLMDEBUG 0
  22. #endif
  23. #endif
  24. #else
  25. #ifndef GLMDEBUG
  26. #define GLMDEBUG 0
  27. #endif
  28. #endif
  29. //===============================================================================
  30. // debug channels
  31. enum EGLMDebugChannel
  32. {
  33. ePrintf,
  34. eDebugger,
  35. eGLProfiler
  36. };
  37. #if GLMDEBUG
  38. // make all these prototypes disappear in non GLMDEBUG
  39. void GLMDebugInitialize( bool forceReinit=false );
  40. bool GLMDetectOGLP( void );
  41. bool GLMDetectGDB( void );
  42. uint GLMDetectAvailableChannels( void );
  43. uint GLMDebugChannelMask( uint *newValue = NULL );
  44. // note that GDB and OGLP can both come and go during run - forceCheck will allow that to be detected.
  45. // mask returned is in form of 1<<n, n from EGLMDebugChannel
  46. #endif
  47. //===============================================================================
  48. // debug message flavors
  49. enum EGLMDebugFlavor
  50. {
  51. eAllFlavors, // 0
  52. eDebugDump, // 1 debug dump flavor -D-
  53. eTenure, // 2 code tenures > <
  54. eComment, // 3 one off messages ---
  55. eMatrixData, // 4 matrix data -M-
  56. eShaderData, // 5 shader data (params) -S-
  57. eFrameBufData, // 6 FBO data (attachments) -F-
  58. eDXStuff, // 7 dxabstract spew -X-
  59. eAllocations, // 8 tracking allocs and frees -A-
  60. eSlowness, // 9 slow things happening (srgb flips..) -Z-
  61. eDefaultFlavor, // not specified (no marker)
  62. eFlavorCount
  63. };
  64. uint GLMDebugFlavorMask( uint *newValue = NULL );
  65. // make all these prototypes disappear in non GLMDEBUG
  66. #if GLMDEBUG
  67. // these are unconditional outputs, they don't interrogate the string
  68. void GLMStringOut( const char *string );
  69. void GLMStringOutIndented( const char *string, int indentColumns );
  70. #ifdef TOGL_DLL_EXPORT
  71. // these will look at the string to guess its flavor: <, >, ---, -M-, -S-
  72. DLL_EXPORT void GLMPrintfVA( const char *fmt, va_list vargs );
  73. DLL_EXPORT void GLMPrintf( const char *fmt, ... );
  74. #else
  75. DLL_IMPORT void GLMPrintfVA( const char *fmt, va_list vargs );
  76. DLL_IMPORT void GLMPrintf( const char *fmt, ... );
  77. #endif
  78. // these take an explicit flavor with a default value
  79. void GLMPrintStr( const char *str, EGLMDebugFlavor flavor = eDefaultFlavor );
  80. #define GLMPRINTTEXT_NUMBEREDLINES 0x80000000
  81. void GLMPrintText( const char *str, EGLMDebugFlavor flavor = eDefaultFlavor, uint options=0 ); // indent each newline
  82. int GLMIncIndent( int indentDelta );
  83. int GLMGetIndent( void );
  84. void GLMSetIndent( int indent );
  85. #endif
  86. // helpful macro if you are in a position to call GLM functions directly (i.e. you live in materialsystem / shaderapidx9)
  87. #if GLMDEBUG
  88. #define GLMPRINTF(args) GLMPrintf args
  89. #define GLMPRINTSTR(args) GLMPrintStr args
  90. #define GLMPRINTTEXT(args) GLMPrintText args
  91. #else
  92. #define GLMPRINTF(args)
  93. #define GLMPRINTSTR(args)
  94. #define GLMPRINTTEXT(args)
  95. #endif
  96. //===============================================================================
  97. // knob twiddling
  98. #ifdef TOGL_DLL_EXPORT
  99. DLL_EXPORT float GLMKnob( char *knobname, float *setvalue ); // Pass NULL to not-set the knob value
  100. DLL_EXPORT float GLMKnobToggle( char *knobname );
  101. #else
  102. DLL_IMPORT float GLMKnob( char *knobname, float *setvalue ); // Pass NULL to not-set the knob value
  103. DLL_IMPORT float GLMKnobToggle( char *knobname );
  104. #endif
  105. //===============================================================================
  106. // other stuff
  107. #if GLMDEBUG
  108. void GLMTriggerDebuggerBreak();
  109. inline void GLMDebugger( void )
  110. {
  111. if (GLMDebugChannelMask() & (1<<eDebugger))
  112. {
  113. DebuggerBreak();
  114. }
  115. if (GLMDebugChannelMask() & (1<<eGLProfiler))
  116. {
  117. GLMTriggerDebuggerBreak();
  118. }
  119. }
  120. #else
  121. #define GLMDebugger() do { } while(0)
  122. #endif
  123. // helpers for CGLSetOption - no op if no profiler
  124. void GLMProfilerClearTrace( void );
  125. void GLMProfilerEnableTrace( bool enable );
  126. // helpers for CGLSetParameter - no op if no profiler
  127. void GLMProfilerDumpState( void );
  128. void CheckGLError( int line );
  129. #endif // GLMDEBUG_H