winGLSpecial_ScriptBinding.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. winState.log_fp = fopen( "gl_log.txt", "wt" );
  51. fprintf( winState.log_fp, "%s\n", asctime( newtime ) );
  52. fflush(winState.log_fp);
  53. }
  54. #define GL_FUNCTION(fn_type, fn_name, fn_args, fn_body) fn_name = log##fn_name;
  55. #include "platform/GLCoreFunc.h"
  56. #include "platform/GLExtFunc.h"
  57. #include "platform/GLUFunc.h"
  58. #undef GL_FUNCTION
  59. }
  60. else
  61. {
  62. if ( winState.log_fp )
  63. {
  64. fprintf( winState.log_fp, "*** CLOSING LOG ***\n" );
  65. fflush(winState.log_fp);
  66. fclose( winState.log_fp );
  67. winState.log_fp = NULL;
  68. }
  69. #define GL_FUNCTION(fn_type, fn_name, fn_args, fn_body) fn_name = dll##fn_name;
  70. #include "platform/GLCoreFunc.h"
  71. #include "platform/GLExtFunc.h"
  72. #include "platform/GLUFunc.h"
  73. #undef GL_FUNCTION
  74. }
  75. }
  76. #endif
  77. /*! Enables outlines with OpenGL
  78. @param enable Boolean value representing whether or not outlines should be enabled.
  79. @return No Return Value.
  80. */
  81. ConsoleFunctionWithDocs(GLEnableOutline, ConsoleVoid, 2, 2, (bool))
  82. {
  83. argc;
  84. bool enable = dAtob(argv[1]);
  85. if(outlineEnabled == enable)
  86. return;
  87. if(enable && (loggingEnabled || perfEnabled))
  88. return;
  89. outlineEnabled = enable;
  90. if ( enable )
  91. {
  92. glDrawElements = outlineDrawElements;
  93. glDrawArrays = outlineDrawArrays;
  94. dwglSwapBuffers = outlineSwapBuffers;
  95. }
  96. else
  97. {
  98. glDrawElements = dllglDrawElements;
  99. glDrawArrays = dllglDrawArrays;
  100. dwglSwapBuffers = dlldwglSwapBuffers;
  101. }
  102. }
  103. /*! Use the GLEnableMetrics function to enable or disable logging of OpenGL texture and video metrics.
  104. 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>
  105. @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.
  106. @return No return value.
  107. @sa GLEnableLogging, metrics
  108. */
  109. ConsoleFunctionWithDocs(GLEnableMetrics, ConsoleVoid, 2, 2, ( enable ))
  110. {
  111. argc;
  112. static bool varsAdded = false;
  113. if(!varsAdded)
  114. {
  115. Con::addVariable("OpenGL::triCount0", TypeS32, &gGLState.triCount[0]);
  116. Con::addVariable("OpenGL::triCount1", TypeS32, &gGLState.triCount[1]);
  117. Con::addVariable("OpenGL::triCount2", TypeS32, &gGLState.triCount[2]);
  118. Con::addVariable("OpenGL::triCount3", TypeS32, &gGLState.triCount[3]);
  119. Con::addVariable("OpenGL::primCount0", TypeS32, &gGLState.primCount[0]);
  120. Con::addVariable("OpenGL::primCount1", TypeS32, &gGLState.primCount[1]);
  121. Con::addVariable("OpenGL::primCount2", TypeS32, &gGLState.primCount[2]);
  122. Con::addVariable("OpenGL::primCount3", TypeS32, &gGLState.primCount[3]);
  123. varsAdded = true;
  124. }
  125. bool enable = dAtob(argv[1]);
  126. if(perfEnabled == enable)
  127. return;
  128. if(enable && (loggingEnabled || outlineEnabled))
  129. return;
  130. perfEnabled = enable;
  131. if ( enable )
  132. {
  133. glDrawElements = perfDrawElements;
  134. glDrawArrays = perfDrawArrays;
  135. }
  136. else
  137. {
  138. glDrawElements = dllglDrawElements;
  139. glDrawArrays = dllglDrawArrays;
  140. }
  141. }
  142. /*! @} */ // end group WindowsPlatform