PageRenderTime 54ms CodeModel.GetById 1ms app.highlight 47ms RepoModel.GetById 2ms 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
  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
 27// This file sets some global GL parameters, and implements some 
 28// useful functions for GL operations.
 29
 30#include "linden_common.h"
 31
 32#include "llgldbg.h"
 33
 34#include "llgl.h"
 35#include "llglheaders.h"
 36
 37
 38//------------------------------------------------------------------------
 39// cmstr()
 40//------------------------------------------------------------------------
 41const char *cmstr(int i)
 42{
 43	switch( i )
 44	{
 45	case GL_EMISSION: return "GL_EMISSION";
 46	case GL_AMBIENT: return "GL_AMBIENT";
 47	case GL_DIFFUSE: return "GL_DIFFUSE";
 48	case GL_SPECULAR: return "GL_SPECULAR";
 49	case GL_AMBIENT_AND_DIFFUSE: return "GL_AMBIENT_AND_DIFFUSE";
 50	}
 51	return "UNKNOWN";
 52}
 53
 54//------------------------------------------------------------------------
 55// facestr()
 56//------------------------------------------------------------------------
 57const char *facestr(int i)
 58{
 59	switch( i )
 60	{
 61	case GL_FRONT: return "GL_FRONT";
 62	case GL_BACK: return "GL_BACK";
 63	case GL_FRONT_AND_BACK: return "GL_FRONT_AND_BACK";
 64	}
 65	return "UNKNOWN";
 66}
 67
 68//------------------------------------------------------------------------
 69// boolstr()
 70//------------------------------------------------------------------------
 71const char *boolstr(int b)
 72{
 73	return b ? "GL_TRUE" : "GL_FALSE";
 74}
 75
 76//------------------------------------------------------------------------
 77// fv4()
 78//------------------------------------------------------------------------
 79const char *fv4(F32 *f)
 80{
 81	static char str[128];
 82	sprintf(str, "%8.3f %8.3f %8.3f %8.3f", f[0], f[1], f[2], f[3]);
 83	return str;
 84}
 85
 86//------------------------------------------------------------------------
 87// fv3()
 88//------------------------------------------------------------------------
 89const char *fv3(F32 *f)
 90{
 91	static char str[128];	/* Flawfinder: ignore */
 92	snprintf(str, sizeof(str), "%8.3f, %8.3f, %8.3f", f[0], f[1], f[2]);	/* Flawfinder: ignore */
 93	return str;
 94}
 95
 96//------------------------------------------------------------------------
 97// fv1()
 98//------------------------------------------------------------------------
 99const char *fv1(F32 *f)
100{
101	static char str[128];	/* Flawfinder: ignore */
102	snprintf(str, sizeof(str), "%8.3f", f[0]);		/* Flawfinder: ignore */
103	return str;
104}
105
106//------------------------------------------------------------------------
107// llgl_dump()
108//------------------------------------------------------------------------
109void llgl_dump()
110{
111	int i;
112	F32 fv[16];
113	GLboolean b;
114
115	llinfos << "==========================" << llendl;
116	llinfos << "OpenGL State" << llendl;
117	llinfos << "==========================" << llendl;
118
119	llinfos << "-----------------------------------" << llendl;
120	llinfos << "Current Values" << llendl;
121	llinfos << "-----------------------------------" << llendl;
122
123	glGetFloatv(GL_CURRENT_COLOR, fv);
124	llinfos << "GL_CURRENT_COLOR          : " << fv4(fv) << llendl;
125
126	glGetFloatv(GL_CURRENT_NORMAL, fv);
127	llinfos << "GL_CURRENT_NORMAL          : " << fv3(fv) << llendl;
128
129	llinfos << "-----------------------------------" << llendl;
130	llinfos << "Lighting" << llendl;
131	llinfos << "-----------------------------------" << llendl;
132
133	llinfos << "GL_LIGHTING                : " << boolstr(glIsEnabled(GL_LIGHTING)) << llendl;
134
135	llinfos << "GL_COLOR_MATERIAL          : " << boolstr(glIsEnabled(GL_COLOR_MATERIAL)) << llendl;
136
137	glGetIntegerv(GL_COLOR_MATERIAL_PARAMETER, (GLint*)&i);
138	llinfos << "GL_COLOR_MATERIAL_PARAMETER: " << cmstr(i) << llendl;
139
140	glGetIntegerv(GL_COLOR_MATERIAL_FACE, (GLint*)&i);
141	llinfos << "GL_COLOR_MATERIAL_FACE     : " << facestr(i) << llendl;
142
143	fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
144	glGetMaterialfv(GL_FRONT, GL_AMBIENT, fv);
145	llinfos << "GL_AMBIENT material        : " << fv4(fv) << llendl;
146
147	fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
148	glGetMaterialfv(GL_FRONT, GL_DIFFUSE, fv);
149	llinfos << "GL_DIFFUSE material        : " << fv4(fv) << llendl;
150
151	fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
152	glGetMaterialfv(GL_FRONT, GL_SPECULAR, fv);
153	llinfos << "GL_SPECULAR material       : " << fv4(fv) << llendl;
154
155	fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
156	glGetMaterialfv(GL_FRONT, GL_EMISSION, fv);
157	llinfos << "GL_EMISSION material       : " << fv4(fv) << llendl;
158
159	fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
160	glGetMaterialfv(GL_FRONT, GL_SHININESS, fv);
161	llinfos << "GL_SHININESS material      : " << fv1(fv) << llendl;
162
163	fv[0] = fv[1] = fv[2] = fv[3] = 12345.6789f;
164	glGetFloatv(GL_LIGHT_MODEL_AMBIENT, fv);
165	llinfos << "GL_LIGHT_MODEL_AMBIENT     : " << fv4(fv) << llendl;
166
167	glGetBooleanv(GL_LIGHT_MODEL_LOCAL_VIEWER, &b);
168	llinfos << "GL_LIGHT_MODEL_LOCAL_VIEWER: " << boolstr(b) << llendl;
169
170	glGetBooleanv(GL_LIGHT_MODEL_TWO_SIDE, &b);
171	llinfos << "GL_LIGHT_MODEL_TWO_SIDE    : " << boolstr(b) << llendl;
172
173	for (int l=0; l<8; l++)
174	{
175	b = glIsEnabled(GL_LIGHT0+l);
176	llinfos << "GL_LIGHT" << l << "                  : " << boolstr(b) << llendl;
177
178	if (!b)
179		continue;
180
181	glGetLightfv(GL_LIGHT0+l, GL_AMBIENT, fv);
182	llinfos << "  GL_AMBIENT light         : " << fv4(fv) << llendl;
183
184	glGetLightfv(GL_LIGHT0+l, GL_DIFFUSE, fv);
185	llinfos << "  GL_DIFFUSE light         : " << fv4(fv) << llendl;
186
187	glGetLightfv(GL_LIGHT0+l, GL_SPECULAR, fv);
188	llinfos << "  GL_SPECULAR light        : " << fv4(fv) << llendl;
189
190	glGetLightfv(GL_LIGHT0+l, GL_POSITION, fv);
191	llinfos << "  GL_POSITION light        : " << fv4(fv) << llendl;
192
193	glGetLightfv(GL_LIGHT0+l, GL_CONSTANT_ATTENUATION, fv);
194	llinfos << "  GL_CONSTANT_ATTENUATION  : " << fv1(fv) << llendl;
195
196	glGetLightfv(GL_LIGHT0+l, GL_QUADRATIC_ATTENUATION, fv);
197	llinfos << "  GL_QUADRATIC_ATTENUATION : " << fv1(fv) << llendl;
198
199	glGetLightfv(GL_LIGHT0+l, GL_SPOT_DIRECTION, fv);
200	llinfos << "  GL_SPOT_DIRECTION        : " << fv4(fv) << llendl;
201
202	glGetLightfv(GL_LIGHT0+l, GL_SPOT_EXPONENT, fv);
203	llinfos << "  GL_SPOT_EXPONENT         : " << fv1(fv) << llendl;
204
205	glGetLightfv(GL_LIGHT0+l, GL_SPOT_CUTOFF, fv);
206	llinfos << "  GL_SPOT_CUTOFF           : " << fv1(fv) << llendl;
207	}
208
209	llinfos << "-----------------------------------" << llendl;
210	llinfos << "Pixel Operations" << llendl;
211	llinfos << "-----------------------------------" << llendl;
212
213	llinfos << "GL_ALPHA_TEST              : " << boolstr(glIsEnabled(GL_ALPHA_TEST)) << llendl;
214	llinfos << "GL_DEPTH_TEST              : " << boolstr(glIsEnabled(GL_DEPTH_TEST)) << llendl;
215
216	glGetBooleanv(GL_DEPTH_WRITEMASK, &b);
217	llinfos << "GL_DEPTH_WRITEMASK         : " << boolstr(b) << llendl;
218	
219	llinfos << "GL_BLEND                   : " << boolstr(glIsEnabled(GL_BLEND)) << llendl;
220	llinfos << "GL_DITHER                  : " << boolstr(glIsEnabled(GL_DITHER)) << llendl;
221}
222
223// End