Team Fortress 2 Source Code as on 22/4/2020
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.

181 lines
5.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. // TOGL CODE LICENSE
  3. //
  4. // Copyright 2011-2014 Valve Corporation
  5. // All Rights Reserved.
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. #ifndef GLMDEBUG_H
  25. #define GLMDEBUG_H
  26. #include "tier0/platform.h"
  27. #if defined( OSX )
  28. #include <stdarg.h>
  29. #endif
  30. // include this anywhere you need to be able to compile-out code related specifically to GLM debugging.
  31. // we expect DEBUG to be driven by the build system so you can include this header anywhere.
  32. // when we come out, GLMDEBUG will be defined to a value - 0, 1, or 2
  33. // 0 means no GLM debugging is possible
  34. // 1 means it's possible and resulted from being a debug build
  35. // 2 means it's possible and resulted from being manually forced on for a release build
  36. #ifdef POSIX
  37. #ifndef GLMDEBUG
  38. #ifdef DEBUG
  39. #define GLMDEBUG 1 // normally 1 here, testing
  40. #else
  41. // #define GLMDEBUG 2 // don't check this in enabled..
  42. #endif
  43. #ifndef GLMDEBUG
  44. #define GLMDEBUG 0
  45. #endif
  46. #endif
  47. #else
  48. #ifndef GLMDEBUG
  49. #define GLMDEBUG 0
  50. #endif
  51. #endif
  52. //===============================================================================
  53. // debug channels
  54. enum EGLMDebugChannel
  55. {
  56. ePrintf,
  57. eDebugger,
  58. eGLProfiler
  59. };
  60. #if GLMDEBUG
  61. // make all these prototypes disappear in non GLMDEBUG
  62. void GLMDebugInitialize( bool forceReinit=false );
  63. bool GLMDetectOGLP( void );
  64. bool GLMDetectGDB( void );
  65. uint GLMDetectAvailableChannels( void );
  66. uint GLMDebugChannelMask( uint *newValue = NULL );
  67. // note that GDB and OGLP can both come and go during run - forceCheck will allow that to be detected.
  68. // mask returned is in form of 1<<n, n from EGLMDebugChannel
  69. #endif
  70. //===============================================================================
  71. // debug message flavors
  72. enum EGLMDebugFlavor
  73. {
  74. eAllFlavors, // 0
  75. eDebugDump, // 1 debug dump flavor -D-
  76. eTenure, // 2 code tenures > <
  77. eComment, // 3 one off messages ---
  78. eMatrixData, // 4 matrix data -M-
  79. eShaderData, // 5 shader data (params) -S-
  80. eFrameBufData, // 6 FBO data (attachments) -F-
  81. eDXStuff, // 7 dxabstract spew -X-
  82. eAllocations, // 8 tracking allocs and frees -A-
  83. eSlowness, // 9 slow things happening (srgb flips..) -Z-
  84. eDefaultFlavor, // not specified (no marker)
  85. eFlavorCount
  86. };
  87. uint GLMDebugFlavorMask( uint *newValue = NULL );
  88. // make all these prototypes disappear in non GLMDEBUG
  89. #if GLMDEBUG
  90. // these are unconditional outputs, they don't interrogate the string
  91. void GLMStringOut( const char *string );
  92. void GLMStringOutIndented( const char *string, int indentColumns );
  93. #ifdef TOGL_DLL_EXPORT
  94. // these will look at the string to guess its flavor: <, >, ---, -M-, -S-
  95. DLL_EXPORT void GLMPrintfVA( const char *fmt, va_list vargs );
  96. DLL_EXPORT void GLMPrintf( const char *fmt, ... );
  97. #else
  98. DLL_IMPORT void GLMPrintfVA( const char *fmt, va_list vargs );
  99. DLL_IMPORT void GLMPrintf( const char *fmt, ... );
  100. #endif
  101. // these take an explicit flavor with a default value
  102. void GLMPrintStr( const char *str, EGLMDebugFlavor flavor = eDefaultFlavor );
  103. #define GLMPRINTTEXT_NUMBEREDLINES 0x80000000
  104. void GLMPrintText( const char *str, EGLMDebugFlavor flavor = eDefaultFlavor, uint options=0 ); // indent each newline
  105. int GLMIncIndent( int indentDelta );
  106. int GLMGetIndent( void );
  107. void GLMSetIndent( int indent );
  108. #endif
  109. // helpful macro if you are in a position to call GLM functions directly (i.e. you live in materialsystem / shaderapidx9)
  110. #if GLMDEBUG
  111. #define GLMPRINTF(args) GLMPrintf args
  112. #define GLMPRINTSTR(args) GLMPrintStr args
  113. #define GLMPRINTTEXT(args) GLMPrintText args
  114. #else
  115. #define GLMPRINTF(args)
  116. #define GLMPRINTSTR(args)
  117. #define GLMPRINTTEXT(args)
  118. #endif
  119. //===============================================================================
  120. // knob twiddling
  121. #ifdef TOGL_DLL_EXPORT
  122. DLL_EXPORT float GLMKnob( char *knobname, float *setvalue ); // Pass NULL to not-set the knob value
  123. DLL_EXPORT float GLMKnobToggle( char *knobname );
  124. #else
  125. DLL_IMPORT float GLMKnob( char *knobname, float *setvalue ); // Pass NULL to not-set the knob value
  126. DLL_IMPORT float GLMKnobToggle( char *knobname );
  127. #endif
  128. //===============================================================================
  129. // other stuff
  130. #if GLMDEBUG
  131. void GLMTriggerDebuggerBreak();
  132. inline void GLMDebugger( void )
  133. {
  134. if (GLMDebugChannelMask() & (1<<eDebugger))
  135. {
  136. DebuggerBreak();
  137. }
  138. if (GLMDebugChannelMask() & (1<<eGLProfiler))
  139. {
  140. GLMTriggerDebuggerBreak();
  141. }
  142. }
  143. #else
  144. #define GLMDebugger() do { } while(0)
  145. #endif
  146. // helpers for CGLSetOption - no op if no profiler
  147. void GLMProfilerClearTrace( void );
  148. void GLMProfilerEnableTrace( bool enable );
  149. // helpers for CGLSetParameter - no op if no profiler
  150. void GLMProfilerDumpState( void );
  151. void CheckGLError( int line );
  152. #endif // GLMDEBUG_H