jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame^] | 1 | /* $Id: glstate.c,v 1.1 1999/08/19 00:55:42 jtg Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Print GL state information (for debugging) |
| 5 | * Copyright (C) 1998 Brian Paul |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Library General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Library General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Library General Public |
| 18 | * License along with this library; if not, write to the Free |
| 19 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
| 22 | |
| 23 | /* |
| 24 | * $Log: glstate.c,v $ |
| 25 | * Revision 1.1 1999/08/19 00:55:42 jtg |
| 26 | * Initial revision |
| 27 | * |
| 28 | * Revision 1.4 1999/06/19 01:36:43 brianp |
| 29 | * more features added |
| 30 | * |
| 31 | * Revision 1.3 1999/02/24 05:16:20 brianp |
| 32 | * added still more records to EnumTable |
| 33 | * |
| 34 | * Revision 1.2 1998/11/24 03:47:54 brianp |
| 35 | * added more records to EnumTable |
| 36 | * |
| 37 | * Revision 1.1 1998/11/24 03:41:16 brianp |
| 38 | * Initial revision |
| 39 | * |
| 40 | */ |
| 41 | |
| 42 | |
| 43 | |
| 44 | #include <assert.h> |
| 45 | #include <GL/gl.h> |
| 46 | #include <stdio.h> |
| 47 | #include <stdlib.h> |
| 48 | #include "glstate.h" |
| 49 | |
| 50 | |
| 51 | #define FLOAT 1 |
| 52 | #define INT 2 |
| 53 | #define DOUBLE 3 |
| 54 | #define BOOLEAN 4 |
| 55 | #define ENUM 5 |
| 56 | #define VOID 6 |
| 57 | #define LAST_TOKEN ~0 |
| 58 | |
| 59 | |
| 60 | struct EnumRecord { |
| 61 | GLenum enumerator; /* GLenum constant */ |
| 62 | const char *string; /* string name */ |
| 63 | int getType; /* INT, FLOAT, DOUBLE, BOOLEAN, ENUM, or VOID */ |
| 64 | int getCount; /* number of values returned by the glGet*v() call */ |
| 65 | }; |
| 66 | |
| 67 | |
| 68 | /* XXX Lots more records to add here! Help, anyone? */ |
| 69 | |
| 70 | static struct EnumRecord EnumTable[] = { |
| 71 | { GL_ACCUM_RED_BITS, "GL_ACCUM_RED_BITS", INT, 1 }, |
| 72 | { GL_ACCUM_GREEN_BITS, "GL_ACCUM_GREEN_BITS", INT, 1 }, |
| 73 | { GL_ACCUM_BLUE_BITS, "GL_ACCUM_BLUE_BITS", INT, 1 }, |
| 74 | { GL_ACCUM_ALPHA_BITS, "GL_ACCUM_ALPHA_BITS", INT, 1 }, |
| 75 | { GL_ACCUM_CLEAR_VALUE, "GL_ACCUM_CLEAR_VALUE", FLOAT, 4 }, |
| 76 | { GL_ALPHA_BIAS, "GL_ALPHA_BIAS", FLOAT, 1 }, |
| 77 | { GL_ALPHA_BITS, "GL_ALPHA_BITS", INT, 1 }, |
| 78 | { GL_ALPHA_SCALE, "GL_ALPHA_SCALE", FLOAT, 1 }, |
| 79 | { GL_ALPHA_TEST, "GL_ALPHA_TEST", BOOLEAN, 1 }, |
| 80 | { GL_ALPHA_TEST_FUNC, "GL_ALPHA_TEST_FUNC", ENUM, 1 }, |
| 81 | { GL_ALWAYS, "GL_ALWAYS", ENUM, 0 }, |
| 82 | { GL_ALPHA_TEST_REF, "GL_ALPHA_TEST_REF", FLOAT, 1 }, |
| 83 | { GL_ATTRIB_STACK_DEPTH, "GL_ATTRIB_STACK_DEPTH", INT, 1 }, |
| 84 | { GL_AUTO_NORMAL, "GL_AUTO_NORMAL", BOOLEAN, 1 }, |
| 85 | { GL_AUX_BUFFERS, "GL_AUX_BUFFERS", INT, 1 }, |
| 86 | { GL_BLEND, "GL_BLEND", BOOLEAN, 1 }, |
| 87 | { GL_BLEND_DST, "GL_BLEND_DST", ENUM, 1 }, |
| 88 | { GL_BLEND_SRC, "GL_BLEND_SRC", ENUM, 1 }, |
| 89 | { GL_BLUE_BIAS, "GL_BLUE_BIAS", FLOAT, 1 }, |
| 90 | { GL_BLUE_BITS, "GL_BLUE_BITS", INT, 1 }, |
| 91 | { GL_BLUE_SCALE, "GL_BLUE_SCALE", FLOAT, 1 }, |
| 92 | |
| 93 | { GL_CLAMP_TO_EDGE, "GL_CLAMP_TO_EDGE", ENUM, 0 }, |
| 94 | { GL_CLEAR, "GL_CLEAR", ENUM, 0 }, |
| 95 | { GL_CLIENT_ATTRIB_STACK_DEPTH, "GL_CLIENT_ATTRIB_STACK_DEPTH", INT, 1 }, |
| 96 | { GL_CLIP_PLANE0, "GL_CLIP_PLANE0", BOOLEAN, 1 }, |
| 97 | { GL_CLIP_PLANE1, "GL_CLIP_PLANE1", BOOLEAN, 1 }, |
| 98 | { GL_CLIP_PLANE2, "GL_CLIP_PLANE2", BOOLEAN, 1 }, |
| 99 | { GL_CLIP_PLANE3, "GL_CLIP_PLANE3", BOOLEAN, 1 }, |
| 100 | { GL_CLIP_PLANE4, "GL_CLIP_PLANE4", BOOLEAN, 1 }, |
| 101 | { GL_CLIP_PLANE5, "GL_CLIP_PLANE5", BOOLEAN, 1 }, |
| 102 | { GL_COEFF, "GL_COEEF", ENUM, 0 }, |
| 103 | { GL_COLOR, "GL_COLOR", ENUM, 0 }, |
| 104 | { GL_COLOR_BUFFER_BIT, "GL_COLOR_BUFFER_BIT", ENUM, 0 }, |
| 105 | { GL_COLOR_CLEAR_VALUE, "GL_COLOR_CLEAR_VALUE", FLOAT, 4 }, |
| 106 | { GL_COLOR_INDEX, "GL_COLOR_INDEX", ENUM, 0 }, |
| 107 | { GL_COLOR_MATERIAL, "GL_COLOR_MATERIAL", BOOLEAN, 1 }, |
| 108 | { GL_COLOR_MATERIAL_FACE, "GL_COLOR_MATERIAL_FACE", ENUM, 1 }, |
| 109 | { GL_COLOR_MATERIAL_PARAMETER, "GL_COLOR_MATERIAL_PARAMETER", ENUM, 1 }, |
| 110 | { GL_COLOR_WRITEMASK, "GL_COLOR_WRITEMASK", BOOLEAN, 4 }, |
| 111 | { GL_COMPILE, "GL_COMPILE", ENUM, 0 }, |
| 112 | { GL_COMPILE_AND_EXECUTE, "GL_COMPILE_AND_EXECUTE", ENUM, 0 }, |
| 113 | { GL_COPY, "GL_COPY", ENUM, 0 }, |
| 114 | { GL_COPY_INVERTED, "GL_COPY_INVERTED", ENUM, 0 }, |
| 115 | { GL_COPY_PIXEL_TOKEN, "GL_COPY_PIXEL_TOKEN", ENUM, 0 }, |
| 116 | { GL_CULL_FACE, "GL_CULL_FACE", BOOLEAN, 1 }, |
| 117 | { GL_CULL_FACE_MODE, "GL_CULL_FACE_MODE", ENUM, 1 }, |
| 118 | { GL_CURRENT_BIT, "GL_CURRENT_BIT", ENUM, 0 }, |
| 119 | { GL_CURRENT_COLOR, "GL_CURRENT_COLOR", FLOAT, 4 }, |
| 120 | { GL_CURRENT_INDEX, "GL_CURRENT_INDEX", INT, 1 }, |
| 121 | { GL_CURRENT_NORMAL, "GL_CURRENT_NORMAL", FLOAT, 3 }, |
| 122 | { GL_CURRENT_RASTER_COLOR, "GL_CURRENT_RASTER_COLOR", FLOAT, 4 }, |
| 123 | { GL_CURRENT_RASTER_DISTANCE, "GL_CURRENT_RASTER_DISTANCE", FLOAT, 1 }, |
| 124 | { GL_CURRENT_RASTER_INDEX, "GL_CURRENT_RASTER_INDEX", INT, 1 }, |
| 125 | { GL_CURRENT_RASTER_POSITION, "GL_CURRENT_RASTER_POSITION", FLOAT, 4 }, |
| 126 | { GL_CURRENT_RASTER_TEXTURE_COORDS, "GL_CURRENT_RASTER_TEXTURE_COORDS", FLOAT, 4 }, |
| 127 | { GL_CURRENT_RASTER_POSITION_VALID, "GL_CURRENT_RASTER_POSITION_VALID", BOOLEAN, 1 }, |
| 128 | { GL_CURRENT_TEXTURE_COORDS, "GL_CURRENT_TEXTURE_COORDS", FLOAT, 4 }, |
| 129 | { GL_CW, "GL_CW", ENUM, 0 }, |
| 130 | { GL_CCW, "GL_CCW", ENUM, 0 }, |
| 131 | |
| 132 | { GL_DECAL, "GL_DECAL", ENUM, 0 }, |
| 133 | { GL_DECR, "GL_DECR", ENUM, 0 }, |
| 134 | { GL_DEPTH, "GL_DEPTH", ENUM, 0 }, |
| 135 | { GL_DEPTH_BIAS, "GL_DEPTH_BIAS", FLOAT, 1 }, |
| 136 | { GL_DEPTH_BITS, "GL_DEPTH_BITS", INT, 1 }, |
| 137 | { GL_DEPTH_BUFFER_BIT, "GL_DEPTH_BUFFER_BIT", ENUM, 0 }, |
| 138 | { GL_DEPTH_CLEAR_VALUE, "GL_DEPTH_CLEAR_VALUE", FLOAT, 1 }, |
| 139 | { GL_DEPTH_COMPONENT, "GL_DEPTH_COMPONENT", ENUM, 0 }, |
| 140 | { GL_DEPTH_FUNC, "GL_DEPTH_FUNC", ENUM, 1 }, |
| 141 | { GL_DEPTH_RANGE, "GL_DEPTH_RANGE", FLOAT, 2 }, |
| 142 | { GL_DEPTH_SCALE, "GL_DEPTH_SCALE", FLOAT, 1 }, |
| 143 | { GL_DEPTH_TEST, "GL_DEPTH_TEST", ENUM, 1 }, |
| 144 | { GL_DEPTH_WRITEMASK, "GL_DEPTH_WRITEMASK", BOOLEAN, 1 }, |
| 145 | { GL_DIFFUSE, "GL_DIFFUSE", ENUM, 0 }, /*XXX*/ |
| 146 | { GL_DITHER, "GL_DITHER", BOOLEAN, 1 }, |
| 147 | { GL_DOMAIN, "GL_DOMAIN", ENUM, 0 }, |
| 148 | { GL_DONT_CARE, "GL_DONT_CARE", ENUM, 0 }, |
| 149 | { GL_DOUBLE, "GL_DOUBLE", ENUM, 0 }, |
| 150 | { GL_DOUBLEBUFFER, "GL_DOUBLEBUFFER", BOOLEAN, 1}, |
| 151 | { GL_DRAW_BUFFER, "GL_DRAW_BUFFER", ENUM, 1 }, |
| 152 | { GL_DRAW_PIXEL_TOKEN, "GL_DRAW_PIXEL_TOKEN", ENUM, 0 }, |
| 153 | { GL_DST_ALPHA, "GL_DST_ALPHA", ENUM, 0 }, |
| 154 | { GL_DST_COLOR, "GL_DST_COLOR", ENUM, 0 }, |
| 155 | |
| 156 | { GL_EDGE_FLAG, "GL_EDGE_FLAG", BOOLEAN, 1 }, |
| 157 | /* XXX GL_EDGE_FLAG_ARRAY_* */ |
| 158 | { GL_EMISSION, "GL_EMISSION", ENUM, 0 }, /* XXX */ |
| 159 | { GL_ENABLE_BIT, "GL_ENABLE_BIT", ENUM, 0 }, |
| 160 | { GL_EQUAL, "GL_EQUAL", ENUM, 0 }, |
| 161 | { GL_EQUIV, "GL_EQUIV", ENUM, 0 }, |
| 162 | { GL_EVAL_BIT, "GL_EVAL_BIT", ENUM, 0 }, |
| 163 | { GL_EXP, "GL_EXP", ENUM, 0 }, |
| 164 | { GL_EXP2, "GL_EXP2", ENUM, 0 }, |
| 165 | { GL_EXTENSIONS, "GL_EXTENSIONS", ENUM, 0 }, |
| 166 | { GL_EYE_LINEAR, "GL_EYE_LINEAR", ENUM, 0 }, |
| 167 | { GL_EYE_PLANE, "GL_EYE_PLANE", ENUM, 0 }, |
| 168 | |
| 169 | { GL_FALSE, "GL_FALSE", ENUM, 0 }, |
| 170 | { GL_FASTEST, "GL_FASTEST", ENUM, 0 }, |
| 171 | { GL_FEEDBACK, "GL_FEEDBACK", ENUM, 0 }, |
| 172 | { GL_FEEDBACK_BUFFER_POINTER, "GL_FEEDBACK_BUFFER_POINTER", VOID, 0 }, |
| 173 | { GL_FEEDBACK_BUFFER_SIZE, "GL_FEEDBACK_BUFFER_SIZE", INT, 1 }, |
| 174 | { GL_FEEDBACK_BUFFER_TYPE, "GL_FEEDBACK_BUFFER_TYPE", INT, 1 }, |
| 175 | { GL_FILL, "GL_FILL", ENUM, 0 }, |
| 176 | { GL_FLAT, "GL_FLAT", ENUM, 0 }, |
| 177 | { GL_FLOAT, "GL_FLOAT", ENUM, 0 }, |
| 178 | { GL_FOG, "GL_FOG", BOOLEAN, 1 }, |
| 179 | { GL_FOG_BIT, "GL_FOG_BIT", ENUM, 0 }, |
| 180 | { GL_FOG_COLOR, "GL_FOG_COLOR", FLOAT, 4 }, |
| 181 | { GL_FOG_DENSITY, "GL_FOG_DENSITY", FLOAT, 1 }, |
| 182 | { GL_FOG_END, "GL_FOG_END", FLOAT, 1 }, |
| 183 | { GL_FOG_HINT, "GL_FOG_HINT", ENUM, 1 }, |
| 184 | { GL_FOG_INDEX, "GL_FOG_INDEX", INT, 1 }, |
| 185 | { GL_FOG_MODE, "GL_FOG_MODE", ENUM, 1 }, |
| 186 | { GL_FOG_START, "GL_FOG_START", FLOAT, 1 }, |
| 187 | { GL_FRONT, "GL_FRONT", ENUM, 0 }, |
| 188 | { GL_FRONT_AND_BACK, "GL_FRONT_AND_BACK", ENUM, 0 }, |
| 189 | { GL_FRONT_FACE, "GL_FRONT_FACE", ENUM, 1 }, |
| 190 | { GL_FRONT_LEFT, "GL_FRONT_LEFT", ENUM, 0 }, |
| 191 | { GL_FRONT_RIGHT, "GL_FRONT_RIGHT", ENUM, 0 }, |
| 192 | |
| 193 | { GL_GEQUAL, "GL_GEQUAL", ENUM, 0 }, |
| 194 | { GL_GREATER, "GL_GREATER", ENUM, 0 }, |
| 195 | { GL_GREEN, "GL_GREEN", ENUM, 0 }, |
| 196 | { GL_GREEN_BIAS, "GL_GREEN_BIAS", FLOAT, 1 }, |
| 197 | { GL_GREEN_BITS, "GL_GREEN_BITS", INT, 1 }, |
| 198 | { GL_GREEN_SCALE, "GL_GREEN_SCALE", FLOAT, 1 }, |
| 199 | |
| 200 | |
| 201 | |
| 202 | { GL_LESS, "GL_LESS", ENUM, 0 }, |
| 203 | { GL_LEQUAL, "GL_LEQUAL", ENUM, 0 }, |
| 204 | { GL_LIGHTING, "GL_LIGHTING", BOOLEAN, 1 }, |
| 205 | { GL_LINE_SMOOTH, "GL_LINE_SMOOTH", BOOLEAN, 1 }, |
| 206 | { GL_LINE_STIPPLE, "GL_LINE_STIPPLE", BOOLEAN, 1 }, |
| 207 | { GL_LINE_STIPPLE_PATTERN, "GL_LINE_STIPPLE_PATTERN", INT, 1 }, |
| 208 | { GL_LINE_STIPPLE_REPEAT, "GL_LINE_STIPPLE_REPEAT", INT, 1 }, |
| 209 | { GL_LINE_WIDTH, "GL_LINE_WIDTH", FLOAT, 1 }, |
| 210 | |
| 211 | { GL_MODELVIEW_MATRIX, "GL_MODELVIEW_MATRIX", DOUBLE, 16 }, |
| 212 | |
| 213 | { GL_NEVER, "GL_NEVER", ENUM, 0 }, |
| 214 | { GL_NOTEQUAL, "GL_NOTEQUAL", ENUM, 0 }, |
| 215 | |
| 216 | { GL_PROJECTION_MATRIX, "GL_PROJECTION_MATRIX", FLOAT, 16 }, |
| 217 | |
| 218 | { GL_PACK_SWAP_BYTES, "GL_PACK_SWAP_BYTES", INT, 1 }, |
| 219 | { GL_PACK_LSB_FIRST, "GL_PACK_LSB_FIRST", INT, 1 }, |
| 220 | { GL_PACK_ROW_LENGTH, "GL_PACK_ROW_LENGTH", INT, 1 }, |
| 221 | { GL_PACK_SKIP_PIXELS, "GL_PACK_SKIP_PIXELS", INT, 1 }, |
| 222 | { GL_PACK_SKIP_ROWS, "GL_PACK_SKIP_ROWS", INT, 1 }, |
| 223 | { GL_PACK_ALIGNMENT, "GL_PACK_ALIGNMENT", INT, 1 }, |
| 224 | |
| 225 | { GL_TRUE, "GL_TRUE", ENUM, 0 }, |
| 226 | |
| 227 | { GL_UNPACK_SWAP_BYTES, "GL_UNPACK_SWAP_BYTES", INT, 1 }, |
| 228 | { GL_UNPACK_LSB_FIRST, "GL_UNPACK_LSB_FIRST", INT, 1 }, |
| 229 | { GL_UNPACK_ROW_LENGTH, "GL_UNPACK_ROW_LENGTH", INT, 1 }, |
| 230 | { GL_UNPACK_SKIP_PIXELS, "GL_UNPACK_SKIP_PIXELS", INT, 1 }, |
| 231 | { GL_UNPACK_SKIP_ROWS, "GL_UNPACK_SKIP_ROWS", INT, 1 }, |
| 232 | { GL_UNPACK_ALIGNMENT, "GL_UNPACK_ALIGNMENT", INT, 1 }, |
| 233 | |
| 234 | { GL_VIEWPORT, "GL_VIEWPORT", INT, 4 }, |
| 235 | |
| 236 | |
| 237 | /* |
| 238 | * Extensions |
| 239 | */ |
| 240 | |
| 241 | #if defined(GL_EXT_blend_minmax) |
| 242 | { GL_BLEND_EQUATION_EXT, "GL_BLEND_EQUATION_EXT", ENUM, 1 }, |
| 243 | #endif |
| 244 | #if defined(GL_EXT_blend_color) |
| 245 | { GL_BLEND_COLOR_EXT, "GL_BLEND_COLOR_EXT", FLOAT, 4 }, |
| 246 | #endif |
| 247 | #if defined(GL_EXT_point_parameters) |
| 248 | { GL_DISTANCE_ATTENUATION_EXT, "GL_DISTANCE_ATTENUATION_EXT", FLOAT, 1 }, |
| 249 | #endif |
| 250 | #if defined(GL_INGR_blend_func_separate) |
| 251 | { GL_BLEND_SRC_RGB_INGR, "GL_BLEND_SRC_RGB_INGR", ENUM, 1 }, |
| 252 | { GL_BLEND_DST_RGB_INGR, "GL_BLEND_DST_RGB_INGR", ENUM, 1 }, |
| 253 | { GL_BLEND_SRC_ALPHA_INGR, "GL_BLEND_SRC_ALPHA_INGR", ENUM, 1 }, |
| 254 | { GL_BLEND_DST_ALPHA_INGR, "GL_BLEND_DST_ALPHA_INGR", ENUM, 1 }, |
| 255 | #endif |
| 256 | |
| 257 | |
| 258 | { LAST_TOKEN, "", 0, 0 } |
| 259 | }; |
| 260 | |
| 261 | |
| 262 | static const struct EnumRecord *FindRecord( GLenum var ) |
| 263 | { |
| 264 | int i; |
| 265 | for (i = 0; EnumTable[i].enumerator != LAST_TOKEN; i++) { |
| 266 | if (EnumTable[i].enumerator == var) { |
| 267 | return &EnumTable[i]; |
| 268 | } |
| 269 | } |
| 270 | return NULL; |
| 271 | } |
| 272 | |
| 273 | |
| 274 | |
| 275 | /* |
| 276 | * Return the string label for the given enum. |
| 277 | */ |
| 278 | const char *GetEnumString( GLenum var ) |
| 279 | { |
| 280 | const struct EnumRecord *rec = FindRecord(var); |
| 281 | if (rec) |
| 282 | return rec->string; |
| 283 | else |
| 284 | return NULL; |
| 285 | } |
| 286 | |
| 287 | |
| 288 | |
| 289 | /* |
| 290 | * Print current value of the given state variable. |
| 291 | */ |
| 292 | void PrintState( int indent, GLenum var ) |
| 293 | { |
| 294 | const struct EnumRecord *rec = FindRecord(var); |
| 295 | |
| 296 | while (indent-- > 0) |
| 297 | putchar(' '); |
| 298 | |
| 299 | if (rec) { |
| 300 | if (rec->getCount <= 0) { |
| 301 | assert(rec->getType == ENUM); |
| 302 | printf("%s is not a state variable\n", rec->string); |
| 303 | } |
| 304 | else { |
| 305 | switch (rec->getType) { |
| 306 | case INT: |
| 307 | { |
| 308 | GLint values[100]; |
| 309 | int i; |
| 310 | glGetIntegerv(rec->enumerator, values); |
| 311 | printf("%s = ", rec->string); |
| 312 | for (i = 0; i < rec->getCount; i++) |
| 313 | printf("%d ", values[i]); |
| 314 | printf("\n"); |
| 315 | } |
| 316 | break; |
| 317 | case FLOAT: |
| 318 | { |
| 319 | GLfloat values[100]; |
| 320 | int i; |
| 321 | glGetFloatv(rec->enumerator, values); |
| 322 | printf("%s = ", rec->string); |
| 323 | for (i = 0; i < rec->getCount; i++) |
| 324 | printf("%f ", values[i]); |
| 325 | printf("\n"); |
| 326 | } |
| 327 | break; |
| 328 | case DOUBLE: |
| 329 | { |
| 330 | GLdouble values[100]; |
| 331 | int i; |
| 332 | glGetDoublev(rec->enumerator, values); |
| 333 | printf("%s = ", rec->string); |
| 334 | for (i = 0; i < rec->getCount; i++) |
| 335 | printf("%f ", (float) values[i]); |
| 336 | printf("\n"); |
| 337 | } |
| 338 | break; |
| 339 | case BOOLEAN: |
| 340 | { |
| 341 | GLboolean values[100]; |
| 342 | int i; |
| 343 | glGetBooleanv(rec->enumerator, values); |
| 344 | printf("%s = ", rec->string); |
| 345 | for (i = 0; i < rec->getCount; i++) |
| 346 | printf("%s ", values[i] ? "GL_TRUE" : "GL_FALSE"); |
| 347 | printf("\n"); |
| 348 | } |
| 349 | break; |
| 350 | case ENUM: |
| 351 | { |
| 352 | GLint values[100]; |
| 353 | int i; |
| 354 | glGetIntegerv(rec->enumerator, values); |
| 355 | printf("%s = ", rec->string); |
| 356 | for (i = 0; i < rec->getCount; i++) { |
| 357 | const char *str = GetEnumString((GLenum) values[i]); |
| 358 | if (str) |
| 359 | printf("%s ", str); |
| 360 | else |
| 361 | printf("??? "); |
| 362 | } |
| 363 | printf("\n"); |
| 364 | } |
| 365 | break; |
| 366 | case VOID: |
| 367 | { |
| 368 | GLvoid *values[100]; |
| 369 | int i; |
| 370 | glGetPointerv(rec->enumerator, values); |
| 371 | printf("%s = ", rec->string); |
| 372 | for (i = 0; i < rec->getCount; i++) { |
| 373 | printf("%p ", values[i]); |
| 374 | } |
| 375 | printf("\n"); |
| 376 | } |
| 377 | break; |
| 378 | default: |
| 379 | printf("fatal error in PrintState()\n"); |
| 380 | abort(); |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | else { |
| 385 | printf("Unknown GLenum passed to PrintState()\n"); |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | |
| 390 | |
| 391 | /* |
| 392 | * Print all glPixelStore-related state. |
| 393 | * NOTE: Should write similar functions for lighting, texturing, etc. |
| 394 | */ |
| 395 | void PrintPixelStoreState( void ) |
| 396 | { |
| 397 | const GLenum enums[] = { |
| 398 | GL_PACK_SWAP_BYTES, |
| 399 | GL_PACK_LSB_FIRST, |
| 400 | GL_PACK_ROW_LENGTH, |
| 401 | GL_PACK_SKIP_PIXELS, |
| 402 | GL_PACK_SKIP_ROWS, |
| 403 | GL_PACK_ALIGNMENT, |
| 404 | GL_UNPACK_SWAP_BYTES, |
| 405 | GL_UNPACK_LSB_FIRST, |
| 406 | GL_UNPACK_ROW_LENGTH, |
| 407 | GL_UNPACK_SKIP_PIXELS, |
| 408 | GL_UNPACK_SKIP_ROWS, |
| 409 | GL_UNPACK_ALIGNMENT, |
| 410 | 0 |
| 411 | }; |
| 412 | int i; |
| 413 | printf("Pixel pack/unpack state:\n"); |
| 414 | for (i = 0; enums[i]; i++) { |
| 415 | PrintState(3, enums[i]); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 | /* |
| 423 | * Print all state for the given attribute group. |
| 424 | */ |
| 425 | void PrintAttribState( GLbitfield attrib ) |
| 426 | { |
| 427 | static const GLenum depth_buffer_enums[] = { |
| 428 | GL_DEPTH_FUNC, |
| 429 | GL_DEPTH_CLEAR_VALUE, |
| 430 | GL_DEPTH_TEST, |
| 431 | GL_DEPTH_WRITEMASK, |
| 432 | 0 |
| 433 | }; |
| 434 | static const GLenum fog_enums[] = { |
| 435 | GL_FOG, |
| 436 | GL_FOG_COLOR, |
| 437 | GL_FOG_DENSITY, |
| 438 | GL_FOG_START, |
| 439 | GL_FOG_END, |
| 440 | GL_FOG_INDEX, |
| 441 | GL_FOG_MODE, |
| 442 | 0 |
| 443 | }; |
| 444 | static const GLenum line_enums[] = { |
| 445 | GL_LINE_SMOOTH, |
| 446 | GL_LINE_STIPPLE, |
| 447 | GL_LINE_STIPPLE_PATTERN, |
| 448 | GL_LINE_STIPPLE_REPEAT, |
| 449 | GL_LINE_WIDTH, |
| 450 | 0 |
| 451 | }; |
| 452 | |
| 453 | const GLenum *enumList = NULL; |
| 454 | |
| 455 | switch (attrib) { |
| 456 | case GL_DEPTH_BUFFER_BIT: |
| 457 | enumList = depth_buffer_enums; |
| 458 | printf("GL_DEPTH_BUFFER_BIT state:\n"); |
| 459 | break; |
| 460 | case GL_FOG_BIT: |
| 461 | enumList = fog_enums; |
| 462 | printf("GL_FOG_BIT state:\n"); |
| 463 | break; |
| 464 | case GL_LINE_BIT: |
| 465 | enumList = line_enums; |
| 466 | printf("GL_LINE_BIT state:\n"); |
| 467 | break; |
| 468 | default: |
| 469 | printf("Bad value in PrintAttribState()\n"); |
| 470 | } |
| 471 | |
| 472 | if (enumList) { |
| 473 | int i; |
| 474 | for (i = 0; enumList[i]; i++) |
| 475 | PrintState(3, enumList[i]); |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | |
| 480 | /*#define TEST*/ |
| 481 | #ifdef TEST |
| 482 | |
| 483 | #include <GL/glut.h> |
| 484 | |
| 485 | int main( int argc, char *argv[] ) |
| 486 | { |
| 487 | glutInit( &argc, argv ); |
| 488 | glutInitWindowPosition(0, 0); |
| 489 | glutInitWindowSize(400, 300); |
| 490 | glutInitDisplayMode(GLUT_RGB); |
| 491 | glutCreateWindow(argv[0]); |
| 492 | PrintAttribState(GL_DEPTH_BUFFER_BIT); |
| 493 | PrintAttribState(GL_FOG_BIT); |
| 494 | PrintAttribState(GL_LINE_BIT); |
| 495 | PrintState(0, GL_ALPHA_BITS); |
| 496 | PrintState(0, GL_VIEWPORT); |
| 497 | PrintState(0, GL_ALPHA_TEST_FUNC); |
| 498 | PrintState(0, GL_MODELVIEW_MATRIX); |
| 499 | PrintState(0, GL_ALWAYS); |
| 500 | PrintPixelStoreState(); |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | #endif |