llgldbg.cpp

Go to the documentation of this file.
00001 
00032 // This file sets some global GL parameters, and implements some 
00033 // useful functions for GL operations.
00034 
00035 #include "linden_common.h"
00036 
00037 #include "llgldbg.h"
00038 
00039 #include "llgl.h"
00040 #include "llglheaders.h"
00041 
00042 
00043 //------------------------------------------------------------------------
00044 // cmstr()
00045 //------------------------------------------------------------------------
00046 char *cmstr(int i)
00047 {
00048         switch( i )
00049         {
00050         case GL_EMISSION: return "GL_EMISSION";
00051         case GL_AMBIENT: return "GL_AMBIENT";
00052         case GL_DIFFUSE: return "GL_DIFFUSE";
00053         case GL_SPECULAR: return "GL_SPECULAR";
00054         case GL_AMBIENT_AND_DIFFUSE: return "GL_AMBIENT_AND_DIFFUSE";
00055         }
00056         return "UNKNOWN";
00057 }
00058 
00059 //------------------------------------------------------------------------
00060 // facestr()
00061 //------------------------------------------------------------------------
00062 char *facestr(int i)
00063 {
00064         switch( i )
00065         {
00066         case GL_FRONT: return "GL_FRONT";
00067         case GL_BACK: return "GL_BACK";
00068         case GL_FRONT_AND_BACK: return "GL_FRONT_AND_BACK";
00069         }
00070         return "UNKNOWN";
00071 }
00072 
00073 //------------------------------------------------------------------------
00074 // boolstr()
00075 //------------------------------------------------------------------------
00076 const char *boolstr(int b)
00077 {
00078         return b ? "GL_TRUE" : "GL_FALSE";
00079 }
00080 
00081 //------------------------------------------------------------------------
00082 // fv4()
00083 //------------------------------------------------------------------------
00084 char *fv4(F32 *f)
00085 {
00086         static char str[128];
00087         sprintf(str, "%8.3f %8.3f %8.3f %8.3f", f[0], f[1], f[2], f[3]);
00088         return str;
00089 }
00090 
00091 //------------------------------------------------------------------------
00092 // fv3()
00093 //------------------------------------------------------------------------
00094 char *fv3(F32 *f)
00095 {
00096         static char str[128];   /* Flawfinder: ignore */
00097         snprintf(str, sizeof(str), "%8.3f, %8.3f, %8.3f", f[0], f[1], f[2]);    /* Flawfinder: ignore */
00098         return str;
00099 }
00100 
00101 //------------------------------------------------------------------------
00102 // fv1()
00103 //------------------------------------------------------------------------
00104 char *fv1(F32 *f)
00105 {
00106         static char str[128];   /* Flawfinder: ignore */
00107         snprintf(str, sizeof(str), "%8.3f", f[0]);              /* Flawfinder: ignore */
00108         return str;
00109 }
00110 
00111 //------------------------------------------------------------------------
00112 // llgl_dump()
00113 //------------------------------------------------------------------------
00114 void llgl_dump()
00115 {
00116         int i;
00117         F32 fv[16];
00118         GLboolean b;
00119 
00120         llinfos << "==========================" << llendl;
00121         llinfos << "OpenGL State" << llendl;
00122         llinfos << "==========================" << llendl;
00123 
00124         llinfos << "-----------------------------------" << llendl;
00125         llinfos << "Current Values" << llendl;
00126         llinfos << "-----------------------------------" << llendl;
00127 
00128         glGetFloatv(GL_CURRENT_COLOR, fv);
00129         llinfos << "GL_CURRENT_COLOR          : " << fv4(fv) << llendl;
00130 
00131         glGetFloatv(GL_CURRENT_NORMAL, fv);
00132         llinfos << "GL_CURRENT_NORMAL          : " << fv3(fv) << llendl;
00133 
00134         llinfos << "-----------------------------------" << llendl;
00135         llinfos << "Lighting" << llendl;
00136         llinfos << "-----------------------------------" << llendl;
00137 
00138         llinfos << "GL_LIGHTING                : " << boolstr(glIsEnabled(GL_LIGHTING)) << llendl;
00139 
00140         llinfos << "GL_COLOR_MATERIAL          : " << boolstr(glIsEnabled(GL_COLOR_MATERIAL)) << llendl;
00141 
00142         glGetIntegerv(GL_COLOR_MATERIAL_PARAMETER, (GLint*)&i);
00143         llinfos << "GL_COLOR_MATERIAL_PARAMETER: " << cmstr(i) << llendl;
00144 
00145         glGetIntegerv(GL_COLOR_MATERIAL_FACE, (GLint*)&i);
00146         llinfos << "GL_COLOR_MATERIAL_FACE     : " << facestr(i) << llendl;
00147 
00148         fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
00149         glGetMaterialfv(GL_FRONT, GL_AMBIENT, fv);
00150         llinfos << "GL_AMBIENT material        : " << fv4(fv) << llendl;
00151 
00152         fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
00153         glGetMaterialfv(GL_FRONT, GL_DIFFUSE, fv);
00154         llinfos << "GL_DIFFUSE material        : " << fv4(fv) << llendl;
00155 
00156         fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
00157         glGetMaterialfv(GL_FRONT, GL_SPECULAR, fv);
00158         llinfos << "GL_SPECULAR material       : " << fv4(fv) << llendl;
00159 
00160         fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
00161         glGetMaterialfv(GL_FRONT, GL_EMISSION, fv);
00162         llinfos << "GL_EMISSION material       : " << fv4(fv) << llendl;
00163 
00164         fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
00165         glGetMaterialfv(GL_FRONT, GL_SHININESS, fv);
00166         llinfos << "GL_SHININESS material      : " << fv1(fv) << llendl;
00167 
00168         fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
00169         glGetFloatv(GL_LIGHT_MODEL_AMBIENT, fv);
00170         llinfos << "GL_LIGHT_MODEL_AMBIENT     : " << fv4(fv) << llendl;
00171 
00172         glGetBooleanv(GL_LIGHT_MODEL_LOCAL_VIEWER, &b);
00173         llinfos << "GL_LIGHT_MODEL_LOCAL_VIEWER: " << boolstr(b) << llendl;
00174 
00175         glGetBooleanv(GL_LIGHT_MODEL_TWO_SIDE, &b);
00176         llinfos << "GL_LIGHT_MODEL_TWO_SIDE    : " << boolstr(b) << llendl;
00177 
00178         for (int l=0; l<8; l++)
00179         {
00180         b = glIsEnabled(GL_LIGHT0+l);
00181         llinfos << "GL_LIGHT" << l << "                  : " << boolstr(b) << llendl;
00182 
00183         if (!b)
00184                 continue;
00185 
00186         glGetLightfv(GL_LIGHT0+l, GL_AMBIENT, fv);
00187         llinfos << "  GL_AMBIENT light         : " << fv4(fv) << llendl;
00188 
00189         glGetLightfv(GL_LIGHT0+l, GL_DIFFUSE, fv);
00190         llinfos << "  GL_DIFFUSE light         : " << fv4(fv) << llendl;
00191 
00192         glGetLightfv(GL_LIGHT0+l, GL_SPECULAR, fv);
00193         llinfos << "  GL_SPECULAR light        : " << fv4(fv) << llendl;
00194 
00195         glGetLightfv(GL_LIGHT0+l, GL_POSITION, fv);
00196         llinfos << "  GL_POSITION light        : " << fv4(fv) << llendl;
00197 
00198         glGetLightfv(GL_LIGHT0+l, GL_CONSTANT_ATTENUATION, fv);
00199         llinfos << "  GL_CONSTANT_ATTENUATION  : " << fv1(fv) << llendl;
00200 
00201         glGetLightfv(GL_LIGHT0+l, GL_QUADRATIC_ATTENUATION, fv);
00202         llinfos << "  GL_QUADRATIC_ATTENUATION : " << fv1(fv) << llendl;
00203 
00204         glGetLightfv(GL_LIGHT0+l, GL_SPOT_DIRECTION, fv);
00205         llinfos << "  GL_SPOT_DIRECTION        : " << fv4(fv) << llendl;
00206 
00207         glGetLightfv(GL_LIGHT0+l, GL_SPOT_EXPONENT, fv);
00208         llinfos << "  GL_SPOT_EXPONENT         : " << fv1(fv) << llendl;
00209 
00210         glGetLightfv(GL_LIGHT0+l, GL_SPOT_CUTOFF, fv);
00211         llinfos << "  GL_SPOT_CUTOFF           : " << fv1(fv) << llendl;
00212         }
00213 
00214         llinfos << "-----------------------------------" << llendl;
00215         llinfos << "Pixel Operations" << llendl;
00216         llinfos << "-----------------------------------" << llendl;
00217 
00218         llinfos << "GL_ALPHA_TEST              : " << boolstr(glIsEnabled(GL_ALPHA_TEST)) << llendl;
00219         llinfos << "GL_DEPTH_TEST              : " << boolstr(glIsEnabled(GL_DEPTH_TEST)) << llendl;
00220 
00221         glGetBooleanv(GL_DEPTH_WRITEMASK, &b);
00222         llinfos << "GL_DEPTH_WRITEMASK         : " << boolstr(b) << llendl;
00223         
00224         llinfos << "GL_BLEND                   : " << boolstr(glIsEnabled(GL_BLEND)) << llendl;
00225         llinfos << "GL_DITHER                  : " << boolstr(glIsEnabled(GL_DITHER)) << llendl;
00226 }
00227 
00228 // End

Generated on Thu Jul 1 06:08:39 2010 for Second Life Viewer by  doxygen 1.4.7