PageRenderTime 81ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llrender/llgldbg.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 223 lines | 129 code | 45 blank | 49 comment | 2 complexity | 0d7946c808cbe0d3f164909cfd2ef613 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llgldbg.cpp
  3. * @brief Definitions for OpenGL debugging support
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. // This file sets some global GL parameters, and implements some
  27. // useful functions for GL operations.
  28. #include "linden_common.h"
  29. #include "llgldbg.h"
  30. #include "llgl.h"
  31. #include "llglheaders.h"
  32. //------------------------------------------------------------------------
  33. // cmstr()
  34. //------------------------------------------------------------------------
  35. const char *cmstr(int i)
  36. {
  37. switch( i )
  38. {
  39. case GL_EMISSION: return "GL_EMISSION";
  40. case GL_AMBIENT: return "GL_AMBIENT";
  41. case GL_DIFFUSE: return "GL_DIFFUSE";
  42. case GL_SPECULAR: return "GL_SPECULAR";
  43. case GL_AMBIENT_AND_DIFFUSE: return "GL_AMBIENT_AND_DIFFUSE";
  44. }
  45. return "UNKNOWN";
  46. }
  47. //------------------------------------------------------------------------
  48. // facestr()
  49. //------------------------------------------------------------------------
  50. const char *facestr(int i)
  51. {
  52. switch( i )
  53. {
  54. case GL_FRONT: return "GL_FRONT";
  55. case GL_BACK: return "GL_BACK";
  56. case GL_FRONT_AND_BACK: return "GL_FRONT_AND_BACK";
  57. }
  58. return "UNKNOWN";
  59. }
  60. //------------------------------------------------------------------------
  61. // boolstr()
  62. //------------------------------------------------------------------------
  63. const char *boolstr(int b)
  64. {
  65. return b ? "GL_TRUE" : "GL_FALSE";
  66. }
  67. //------------------------------------------------------------------------
  68. // fv4()
  69. //------------------------------------------------------------------------
  70. const char *fv4(F32 *f)
  71. {
  72. static char str[128];
  73. sprintf(str, "%8.3f %8.3f %8.3f %8.3f", f[0], f[1], f[2], f[3]);
  74. return str;
  75. }
  76. //------------------------------------------------------------------------
  77. // fv3()
  78. //------------------------------------------------------------------------
  79. const char *fv3(F32 *f)
  80. {
  81. static char str[128]; /* Flawfinder: ignore */
  82. snprintf(str, sizeof(str), "%8.3f, %8.3f, %8.3f", f[0], f[1], f[2]); /* Flawfinder: ignore */
  83. return str;
  84. }
  85. //------------------------------------------------------------------------
  86. // fv1()
  87. //------------------------------------------------------------------------
  88. const char *fv1(F32 *f)
  89. {
  90. static char str[128]; /* Flawfinder: ignore */
  91. snprintf(str, sizeof(str), "%8.3f", f[0]); /* Flawfinder: ignore */
  92. return str;
  93. }
  94. //------------------------------------------------------------------------
  95. // llgl_dump()
  96. //------------------------------------------------------------------------
  97. void llgl_dump()
  98. {
  99. int i;
  100. F32 fv[16];
  101. GLboolean b;
  102. llinfos << "==========================" << llendl;
  103. llinfos << "OpenGL State" << llendl;
  104. llinfos << "==========================" << llendl;
  105. llinfos << "-----------------------------------" << llendl;
  106. llinfos << "Current Values" << llendl;
  107. llinfos << "-----------------------------------" << llendl;
  108. glGetFloatv(GL_CURRENT_COLOR, fv);
  109. llinfos << "GL_CURRENT_COLOR : " << fv4(fv) << llendl;
  110. glGetFloatv(GL_CURRENT_NORMAL, fv);
  111. llinfos << "GL_CURRENT_NORMAL : " << fv3(fv) << llendl;
  112. llinfos << "-----------------------------------" << llendl;
  113. llinfos << "Lighting" << llendl;
  114. llinfos << "-----------------------------------" << llendl;
  115. llinfos << "GL_LIGHTING : " << boolstr(glIsEnabled(GL_LIGHTING)) << llendl;
  116. llinfos << "GL_COLOR_MATERIAL : " << boolstr(glIsEnabled(GL_COLOR_MATERIAL)) << llendl;
  117. glGetIntegerv(GL_COLOR_MATERIAL_PARAMETER, (GLint*)&i);
  118. llinfos << "GL_COLOR_MATERIAL_PARAMETER: " << cmstr(i) << llendl;
  119. glGetIntegerv(GL_COLOR_MATERIAL_FACE, (GLint*)&i);
  120. llinfos << "GL_COLOR_MATERIAL_FACE : " << facestr(i) << llendl;
  121. fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
  122. glGetMaterialfv(GL_FRONT, GL_AMBIENT, fv);
  123. llinfos << "GL_AMBIENT material : " << fv4(fv) << llendl;
  124. fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
  125. glGetMaterialfv(GL_FRONT, GL_DIFFUSE, fv);
  126. llinfos << "GL_DIFFUSE material : " << fv4(fv) << llendl;
  127. fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
  128. glGetMaterialfv(GL_FRONT, GL_SPECULAR, fv);
  129. llinfos << "GL_SPECULAR material : " << fv4(fv) << llendl;
  130. fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
  131. glGetMaterialfv(GL_FRONT, GL_EMISSION, fv);
  132. llinfos << "GL_EMISSION material : " << fv4(fv) << llendl;
  133. fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
  134. glGetMaterialfv(GL_FRONT, GL_SHININESS, fv);
  135. llinfos << "GL_SHININESS material : " << fv1(fv) << llendl;
  136. fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
  137. glGetFloatv(GL_LIGHT_MODEL_AMBIENT, fv);
  138. llinfos << "GL_LIGHT_MODEL_AMBIENT : " << fv4(fv) << llendl;
  139. glGetBooleanv(GL_LIGHT_MODEL_LOCAL_VIEWER, &b);
  140. llinfos << "GL_LIGHT_MODEL_LOCAL_VIEWER: " << boolstr(b) << llendl;
  141. glGetBooleanv(GL_LIGHT_MODEL_TWO_SIDE, &b);
  142. llinfos << "GL_LIGHT_MODEL_TWO_SIDE : " << boolstr(b) << llendl;
  143. for (int l=0; l<8; l++)
  144. {
  145. b = glIsEnabled(GL_LIGHT0+l);
  146. llinfos << "GL_LIGHT" << l << " : " << boolstr(b) << llendl;
  147. if (!b)
  148. continue;
  149. glGetLightfv(GL_LIGHT0+l, GL_AMBIENT, fv);
  150. llinfos << " GL_AMBIENT light : " << fv4(fv) << llendl;
  151. glGetLightfv(GL_LIGHT0+l, GL_DIFFUSE, fv);
  152. llinfos << " GL_DIFFUSE light : " << fv4(fv) << llendl;
  153. glGetLightfv(GL_LIGHT0+l, GL_SPECULAR, fv);
  154. llinfos << " GL_SPECULAR light : " << fv4(fv) << llendl;
  155. glGetLightfv(GL_LIGHT0+l, GL_POSITION, fv);
  156. llinfos << " GL_POSITION light : " << fv4(fv) << llendl;
  157. glGetLightfv(GL_LIGHT0+l, GL_CONSTANT_ATTENUATION, fv);
  158. llinfos << " GL_CONSTANT_ATTENUATION : " << fv1(fv) << llendl;
  159. glGetLightfv(GL_LIGHT0+l, GL_QUADRATIC_ATTENUATION, fv);
  160. llinfos << " GL_QUADRATIC_ATTENUATION : " << fv1(fv) << llendl;
  161. glGetLightfv(GL_LIGHT0+l, GL_SPOT_DIRECTION, fv);
  162. llinfos << " GL_SPOT_DIRECTION : " << fv4(fv) << llendl;
  163. glGetLightfv(GL_LIGHT0+l, GL_SPOT_EXPONENT, fv);
  164. llinfos << " GL_SPOT_EXPONENT : " << fv1(fv) << llendl;
  165. glGetLightfv(GL_LIGHT0+l, GL_SPOT_CUTOFF, fv);
  166. llinfos << " GL_SPOT_CUTOFF : " << fv1(fv) << llendl;
  167. }
  168. llinfos << "-----------------------------------" << llendl;
  169. llinfos << "Pixel Operations" << llendl;
  170. llinfos << "-----------------------------------" << llendl;
  171. llinfos << "GL_ALPHA_TEST : " << boolstr(glIsEnabled(GL_ALPHA_TEST)) << llendl;
  172. llinfos << "GL_DEPTH_TEST : " << boolstr(glIsEnabled(GL_DEPTH_TEST)) << llendl;
  173. glGetBooleanv(GL_DEPTH_WRITEMASK, &b);
  174. llinfos << "GL_DEPTH_WRITEMASK : " << boolstr(b) << llendl;
  175. llinfos << "GL_BLEND : " << boolstr(glIsEnabled(GL_BLEND)) << llendl;
  176. llinfos << "GL_DITHER : " << boolstr(glIsEnabled(GL_DITHER)) << llendl;
  177. }
  178. // End