42 const GLubyte *errString = NULL;
43 BOOL errorOccurred = NO;
45 static BOOL noReenter;
47 if (noReenter)
return NO;
57 errCode = glGetError();
59 if (errCode == GL_NO_ERROR)
break;
62 errString = gluErrorString(errCode);
63 if (format ==
nil) format =
@"<unknown>";
65 va_start(args, format);
66 format = [[[NSString alloc] initWithFormat:format arguments:args] autorelease];
78 while (glGetError() != 0) {}
99 OOGL(glPolygonMode(GL_FRONT_AND_BACK, GL_LINE));
106 OOGL(glPolygonMode(GL_FRONT_AND_BACK, GL_FILL));
113 if (
EXPECT_NOT((radius <= 0)||(step < 1)))
return;
122 r = radius * z_distance / sqrt(z_distance * z_distance - radius * radius);
123 delta = step *
M_PI / 180.0f;
126 for (i = 0; i < (
M_PI * 2.0); i += delta)
130 glVertex3f(s, c, 0.0);
132 glVertex3f(0.0, r, 0.0);
138 GLfloat ww = 0.5 * siz.width;
139 GLfloat hh = 0.5 * siz.height;
145 delta = step *
M_PI / 180.0f;
147 for (theta = 0.0f; theta < (2.0f *
M_PI); theta += delta)
149 glVertex3f(
x + ww * sin(theta),
y + hh * cos(theta), z);
151 glVertex3f(
x,
y + hh, z);
155void GLDrawOval(GLfloat
x, GLfloat
y, GLfloat z, NSSize siz, GLfloat step)
179 for (i = 0; i < n; i++)
181 glVertex3f(points->
x, points->
y, points->
z);
193 for (i = 0; i < n; i++)
195 glVertex3f(points->
x, points->
y, points->
z);
208 for (i = 0; i < n; i++)
210 glVertex3f(points->
x, points->
y, points->
z );
240 NSCParameterAssert(factor >= 0.0f && isfinite(factor));
269 if (glIsEnabled(GL_LIGHTING))
272 for (i = 0; i != 8; ++i)
293 #define COLOR_EQUAL(color, r, g, b, a) (color[0] == (r) && color[1] == (g) && color[2] == (b) && color[3] == (a))
294 #define COLOR_CASE(r, g, b, a, str) do { if (COLOR_EQUAL(color, (r), (g), (b), (a))) return (str); } while (0)
306 return [NSString stringWithFormat:@"(%.2ff, %.2ff, %.2ff, %.2ff)", color[0], color[1], color[2], color[3]];
313 GLenum lightID = GL_LIGHT0 + lightIdx;
318 OOGL(enabled = glIsEnabled(lightID));
325 OOGL(glGetLightfv(GL_LIGHT1, GL_AMBIENT, color));
327 OOGL(glGetLightfv(GL_LIGHT1, GL_DIFFUSE, color));
329 OOGL(glGetLightfv(GL_LIGHT1, GL_SPECULAR, color));
352 OOGL(glGetMaterialfv(GL_FRONT, GL_AMBIENT, color));
355 OOGL(glGetMaterialfv(GL_FRONT, GL_DIFFUSE, color));
358 OOGL(glGetMaterialfv(GL_FRONT, GL_EMISSION, color));
361 OOGL(glGetMaterialfv(GL_FRONT, GL_SPECULAR, color));
364 OOGL(glGetMaterialfv(GL_FRONT, GL_SHININESS, &shininess));
369 OOGL(glGetFloatv(GL_CURRENT_COLOR, color));
372 OOGL(glGetIntegerv(GL_SHADE_MODEL, &shadeModel));
375 OOGL(blending = glIsEnabled(GL_BLEND));
379 OOGL(glGetIntegerv(GL_BLEND_SRC, &blendSrc));
380 OOGL(glGetIntegerv(GL_BLEND_DST, &blendDst));
384 OOGL(glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &texMode));
391 OOGL(glGetIntegerv(GL_ACTIVE_TEXTURE_ARB, &textureUnit));
394 OOGL(glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE_ARB, &textureUnit));
408 OOGL(enabled = glIsEnabled(GL_CULL_FACE));
416 OOGL(glGetIntegerv(GL_CULL_FACE_MODE, &value));
419 OOGL(glGetIntegerv(GL_FRONT_FACE, &value));
439 OOGL(enabled = glIsEnabled(GL_FOG));
445 OOGL(glGetIntegerv(GL_FOG_MODE, &value));
448 OOGL(glGetFloatv(GL_FOG_COLOR, color));
451 OOGL(glGetFloatv(GL_FOG_START, &start));
452 OOGL(glGetFloatv(GL_FOG_END, &end));
455 OOGL(glGetFloatv(GL_FOG_DENSITY, &density));
458 OOGL(glGetFloatv(GL_FOG_DENSITY, &index));
470#define DUMP_STATE_FLAG(x) OOLog(kOOLogOpenGLStateDump, @ #x ": %@", OOGLFlagToString(glIsEnabled(x)))
471#define DUMP_GET_FLAG(x) do { GLboolean flag; glGetBooleanv(x, &flag); OOLog(kOOLogOpenGLStateDump, @ #x ": %@", OOGLFlagToString(flag)); } while (0)
486#undef DUMP_STATE_FLAG
490#define CASE(x) case x: return @#x
505 CASE(GL_ONE_MINUS_DST_COLOR);
506 CASE(GL_ONE_MINUS_SRC_COLOR);
509 CASE(GL_ONE_MINUS_SRC_ALPHA);
510 CASE(GL_ONE_MINUS_DST_ALPHA);
511 CASE(GL_SRC_ALPHA_SATURATE);
526 CASE(GL_FRONT_AND_BACK);
538#define TEXCASE(x) CASE(x##_ARB)
540 TEXCASE(GL_TEXTURE0);
541 TEXCASE(GL_TEXTURE1);
542 TEXCASE(GL_TEXTURE2);
543 TEXCASE(GL_TEXTURE3);
544 TEXCASE(GL_TEXTURE4);
545 TEXCASE(GL_TEXTURE5);
546 TEXCASE(GL_TEXTURE6);
547 TEXCASE(GL_TEXTURE7);
548 TEXCASE(GL_TEXTURE8);
549 TEXCASE(GL_TEXTURE9);
550 TEXCASE(GL_TEXTURE10);
551 TEXCASE(GL_TEXTURE11);
552 TEXCASE(GL_TEXTURE12);
553 TEXCASE(GL_TEXTURE13);
554 TEXCASE(GL_TEXTURE14);
555 TEXCASE(GL_TEXTURE15);
558 default:
return [NSString stringWithFormat:@"unknown: %u", value];
565 return value ?
@"ENABLED" :
@"disabled";
NSString *const kOOLogOpenGLError
BOOL OOLogWillDisplayMessagesInClass(NSString *inMessageClass)
#define OOLog(class, format,...)
#define OO_ENTER_OPENGL()
NSString * OOGLEnumToString(GLenum value)
void OOGLWireframeModeOn(void)
static void GLDumpMaterialState(void)
static void GLDumpStateFlags(void)
static void GLDrawOvalPoints(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat step)
void GLDrawFilledOval(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat step)
static void GLDumpCullingState(void)
void OOGLWireframeModeOff(void)
NSString * OOGLColorToString(GLfloat color[4])
static GLfloat sDisplayScaleFactor
void GLDrawPoints(OOGLVector *points, int n)
static void GLDumpLightState(unsigned lightIdx)
void GLDrawQuadStrip(OOGLVector *points, int n)
BOOL OOCheckOpenGLErrors(NSString *format,...)
void GLScaledLineWidth(GLfloat width)
static NSString *const kOOLogOpenGLStateDump
void GLDrawOval(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat step)
void GLSetDisplayScaleFactor(GLfloat factor)
void GLDrawBallBillboard(GLfloat radius, GLfloat step, GLfloat z_distance)
static void GLDumpFogState(void)
void LogOpenGLState(void)
void GLScaledPointSize(GLfloat size)
#define COLOR_CASE(r, g, b, a, str)
void GLDrawFilledPoints(OOGLVector *points, int n)
NSString * OOGLFlagToString(bool value)
#define DUMP_STATE_FLAG(x)
GLfloat GLGetDisplayScaleFactor(void)