winGLSpecial_ScriptBinding.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. /*! @addtogroup WindowsPlatform Windows Platform
  23. @ingroup TorqueScriptFunctions
  24. @{
  25. */
  26. #if defined (TORQUE_DEBUG) || defined(INTERNAL_RELEASE)
  27. /*! Use the GLEnableLogging function to enable/disable the gathering of OpenGL metrics.
  28. For this to work, the engine must have been compiled with either TORQUE_DEBUG or INTERNAL_RELEASE defined. Always be sure to do a disable after an enable to flush the last log data to the log file.
  29. @param enable A boolean value. If set to true, the engine will gather various OpenGL metrics and dump them to a file named gl_log.txt. If set to false, logging is stopped, the last writes to the log are flushed, and the file is closed.
  30. @return No return value.
  31. @sa GLEnableMetrics, metrics
  32. */
  33. ConsoleFunctionWithDocs(GLEnableLogging, ConsoleVoid, 2, 2, ( enable ))
  34. {
  35. argc;
  36. bool enable = dAtob(argv[1]);
  37. if(loggingEnabled == enable)
  38. return;
  39. if(enable && (outlineEnabled || perfEnabled))
  40. return;
  41. loggingEnabled = enable;
  42. if ( enable )
  43. {
  44. if ( !winState.log_fp )
  45. {
  46. struct tm *newtime;
  47. time_t aclock;
  48. time( &aclock );
  49. newtime = localtime( &aclock );
  50. asctime( newtime );
  51. winState.log_fp = fopen( "gl_log.txt", "wt" );
  52. fprintf( winState.log_fp, "%s\n", asctime( newtime ) );
  53. fflush(winState.log_fp);
  54. }
  55. #define GL_FUNCTION(fn_type, fn_name, fn_args, fn_body) fn_name = log##fn_name;
  56. #include "platform/GLCoreFunc.h"
  57. #include "platform/GLExtFunc.h"
  58. #include "platform/GLUFunc.h"
  59. #undef GL_FUNCTION
  60. }
  61. else
  62. {
  63. if ( winState.log_fp )
  64. {
  65. fprintf( winState.log_fp, "*** CLOSING LOG ***\n" );
  66. fflush(winState.log_fp);
  67. fclose( winState.log_fp );
  68. winState.log_fp = NULL;
  69. }
  70. #define GL_FUNCTION(fn_type, fn_name, fn_args, fn_body) fn_name = dll##fn_name;
  71. #include "platform/GLCoreFunc.h"
  72. #include "platform/GLExtFunc.h"
  73. #include "platform/GLUFunc.h"
  74. #undef GL_FUNCTION
  75. }
  76. }
  77. #endif
  78. /*! Enables outlines with OpenGL
  79. @param enable Boolean value representing whether or not outlines should be enabled.
  80. @return No Return Value.
  81. */
  82. ConsoleFunctionWithDocs(GLEnableOutline, ConsoleVoid, 2, 2, (bool))
  83. {
  84. argc;
  85. bool enable = dAtob(argv[1]);
  86. if(outlineEnabled == enable)
  87. return;
  88. if(enable && (loggingEnabled || perfEnabled))
  89. return;
  90. outlineEnabled = enable;
  91. if ( enable )
  92. {
  93. glDrawElements = outlineDrawElements;
  94. glDrawArrays = outlineDrawArrays;
  95. dwglSwapBuffers = outlineSwapBuffers;
  96. }
  97. else
  98. {
  99. glDrawElements = dllglDrawElements;
  100. glDrawArrays = dllglDrawArrays;
  101. dwglSwapBuffers = dlldwglSwapBuffers;
  102. }
  103. }
  104. /*! Use the GLEnableMetrics function to enable or disable logging of OpenGL texture and video metrics.
  105. For this to work, the engine must have been compiled with either TORQUE_DEBUG or INTERNAL_RELEASE defined. Use the metrics function to get at this information. Also, once this feature is enabled, the following globals will be available for inspection/examination: <OpenGL::triCount0 ? Terrain triangles, OpenGL::triCount1? DIF triangles, OpenGL::triCount2 ? DTS triangles, OpenGL::triCount3 ? Uncategorized triangles, OpenGL::primCount0 - Terrain primitives, OpenGL::primCount1 ? DIF primitives, OpenGL::primCount2 ? DTS primitives, OpenGL::primCount3 ? Uncategorized primitives>
  106. @param enable A boolean value. When this is set to true, texture and video (triangles and primitives) logging is enabled and dumped as part of calls to certain metrics.
  107. @return No return value.
  108. @sa GLEnableLogging, metrics
  109. */
  110. ConsoleFunctionWithDocs(GLEnableMetrics, ConsoleVoid, 2, 2, ( enable ))
  111. {
  112. argc;
  113. static bool varsAdded = false;
  114. if(!varsAdded)
  115. {
  116. Con::addVariable("OpenGL::triCount0", TypeS32, &gGLState.triCount[0]);
  117. Con::addVariable("OpenGL::triCount1", TypeS32, &gGLState.triCount[1]);
  118. Con::addVariable("OpenGL::triCount2", TypeS32, &gGLState.triCount[2]);
  119. Con::addVariable("OpenGL::triCount3", TypeS32, &gGLState.triCount[3]);
  120. Con::addVariable("OpenGL::primCount0", TypeS32, &gGLState.primCount[0]);
  121. Con::addVariable("OpenGL::primCount1", TypeS32, &gGLState.primCount[1]);
  122. Con::addVariable("OpenGL::primCount2", TypeS32, &gGLState.primCount[2]);
  123. Con::addVariable("OpenGL::primCount3", TypeS32, &gGLState.primCount[3]);
  124. varsAdded = true;
  125. }
  126. bool enable = dAtob(argv[1]);
  127. if(perfEnabled == enable)
  128. return;
  129. if(enable && (loggingEnabled || outlineEnabled))
  130. return;
  131. perfEnabled = enable;
  132. if ( enable )
  133. {
  134. glDrawElements = perfDrawElements;
  135. glDrawArrays = perfDrawArrays;
  136. }
  137. else
  138. {
  139. glDrawElements = dllglDrawElements;
  140. glDrawArrays = dllglDrawArrays;
  141. }
  142. }
  143. /*! @} */ // end group WindowsPlatform