3 * Print GL state information (for debugging)
4 * Copyright (C) 1998 Brian Paul
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Revision 1.1 1999/08/19 00:55:42 jtg
26 * Revision 1.4 1999/06/19 01:36:43 brianp
29 * Revision 1.3 1999/02/24 05:16:20 brianp
30 * added still more records to EnumTable
32 * Revision 1.2 1998/11/24 03:47:54 brianp
33 * added more records to EnumTable
35 * Revision 1.1 1998/11/24 03:41:16 brianp
59 GLenum enumerator
; /* GLenum constant */
60 const char *string
; /* string name */
61 int getType
; /* INT, FLOAT, DOUBLE, BOOLEAN, ENUM, or VOID */
62 int getCount
; /* number of values returned by the glGet*v() call */
66 /* XXX Lots more records to add here! Help, anyone? */
68 static struct EnumRecord EnumTable
[] = {
69 { GL_ACCUM_RED_BITS
, "GL_ACCUM_RED_BITS", INT
, 1 },
70 { GL_ACCUM_GREEN_BITS
, "GL_ACCUM_GREEN_BITS", INT
, 1 },
71 { GL_ACCUM_BLUE_BITS
, "GL_ACCUM_BLUE_BITS", INT
, 1 },
72 { GL_ACCUM_ALPHA_BITS
, "GL_ACCUM_ALPHA_BITS", INT
, 1 },
73 { GL_ACCUM_CLEAR_VALUE
, "GL_ACCUM_CLEAR_VALUE", FLOAT
, 4 },
74 { GL_ALPHA_BIAS
, "GL_ALPHA_BIAS", FLOAT
, 1 },
75 { GL_ALPHA_BITS
, "GL_ALPHA_BITS", INT
, 1 },
76 { GL_ALPHA_SCALE
, "GL_ALPHA_SCALE", FLOAT
, 1 },
77 { GL_ALPHA_TEST
, "GL_ALPHA_TEST", BOOLEAN
, 1 },
78 { GL_ALPHA_TEST_FUNC
, "GL_ALPHA_TEST_FUNC", ENUM
, 1 },
79 { GL_ALWAYS
, "GL_ALWAYS", ENUM
, 0 },
80 { GL_ALPHA_TEST_REF
, "GL_ALPHA_TEST_REF", FLOAT
, 1 },
81 { GL_ATTRIB_STACK_DEPTH
, "GL_ATTRIB_STACK_DEPTH", INT
, 1 },
82 { GL_AUTO_NORMAL
, "GL_AUTO_NORMAL", BOOLEAN
, 1 },
83 { GL_AUX_BUFFERS
, "GL_AUX_BUFFERS", INT
, 1 },
84 { GL_BLEND
, "GL_BLEND", BOOLEAN
, 1 },
85 { GL_BLEND_DST
, "GL_BLEND_DST", ENUM
, 1 },
86 { GL_BLEND_SRC
, "GL_BLEND_SRC", ENUM
, 1 },
87 { GL_BLUE_BIAS
, "GL_BLUE_BIAS", FLOAT
, 1 },
88 { GL_BLUE_BITS
, "GL_BLUE_BITS", INT
, 1 },
89 { GL_BLUE_SCALE
, "GL_BLUE_SCALE", FLOAT
, 1 },
91 { GL_CLAMP_TO_EDGE
, "GL_CLAMP_TO_EDGE", ENUM
, 0 },
92 { GL_CLEAR
, "GL_CLEAR", ENUM
, 0 },
93 { GL_CLIENT_ATTRIB_STACK_DEPTH
, "GL_CLIENT_ATTRIB_STACK_DEPTH", INT
, 1 },
94 { GL_CLIP_PLANE0
, "GL_CLIP_PLANE0", BOOLEAN
, 1 },
95 { GL_CLIP_PLANE1
, "GL_CLIP_PLANE1", BOOLEAN
, 1 },
96 { GL_CLIP_PLANE2
, "GL_CLIP_PLANE2", BOOLEAN
, 1 },
97 { GL_CLIP_PLANE3
, "GL_CLIP_PLANE3", BOOLEAN
, 1 },
98 { GL_CLIP_PLANE4
, "GL_CLIP_PLANE4", BOOLEAN
, 1 },
99 { GL_CLIP_PLANE5
, "GL_CLIP_PLANE5", BOOLEAN
, 1 },
100 { GL_COEFF
, "GL_COEEF", ENUM
, 0 },
101 { GL_COLOR
, "GL_COLOR", ENUM
, 0 },
102 { GL_COLOR_BUFFER_BIT
, "GL_COLOR_BUFFER_BIT", ENUM
, 0 },
103 { GL_COLOR_CLEAR_VALUE
, "GL_COLOR_CLEAR_VALUE", FLOAT
, 4 },
104 { GL_COLOR_INDEX
, "GL_COLOR_INDEX", ENUM
, 0 },
105 { GL_COLOR_MATERIAL
, "GL_COLOR_MATERIAL", BOOLEAN
, 1 },
106 { GL_COLOR_MATERIAL_FACE
, "GL_COLOR_MATERIAL_FACE", ENUM
, 1 },
107 { GL_COLOR_MATERIAL_PARAMETER
, "GL_COLOR_MATERIAL_PARAMETER", ENUM
, 1 },
108 { GL_COLOR_WRITEMASK
, "GL_COLOR_WRITEMASK", BOOLEAN
, 4 },
109 { GL_COMPILE
, "GL_COMPILE", ENUM
, 0 },
110 { GL_COMPILE_AND_EXECUTE
, "GL_COMPILE_AND_EXECUTE", ENUM
, 0 },
111 { GL_COPY
, "GL_COPY", ENUM
, 0 },
112 { GL_COPY_INVERTED
, "GL_COPY_INVERTED", ENUM
, 0 },
113 { GL_COPY_PIXEL_TOKEN
, "GL_COPY_PIXEL_TOKEN", ENUM
, 0 },
114 { GL_CULL_FACE
, "GL_CULL_FACE", BOOLEAN
, 1 },
115 { GL_CULL_FACE_MODE
, "GL_CULL_FACE_MODE", ENUM
, 1 },
116 { GL_CURRENT_BIT
, "GL_CURRENT_BIT", ENUM
, 0 },
117 { GL_CURRENT_COLOR
, "GL_CURRENT_COLOR", FLOAT
, 4 },
118 { GL_CURRENT_INDEX
, "GL_CURRENT_INDEX", INT
, 1 },
119 { GL_CURRENT_NORMAL
, "GL_CURRENT_NORMAL", FLOAT
, 3 },
120 { GL_CURRENT_RASTER_COLOR
, "GL_CURRENT_RASTER_COLOR", FLOAT
, 4 },
121 { GL_CURRENT_RASTER_DISTANCE
, "GL_CURRENT_RASTER_DISTANCE", FLOAT
, 1 },
122 { GL_CURRENT_RASTER_INDEX
, "GL_CURRENT_RASTER_INDEX", INT
, 1 },
123 { GL_CURRENT_RASTER_POSITION
, "GL_CURRENT_RASTER_POSITION", FLOAT
, 4 },
124 { GL_CURRENT_RASTER_TEXTURE_COORDS
, "GL_CURRENT_RASTER_TEXTURE_COORDS", FLOAT
, 4 },
125 { GL_CURRENT_RASTER_POSITION_VALID
, "GL_CURRENT_RASTER_POSITION_VALID", BOOLEAN
, 1 },
126 { GL_CURRENT_TEXTURE_COORDS
, "GL_CURRENT_TEXTURE_COORDS", FLOAT
, 4 },
127 { GL_CW
, "GL_CW", ENUM
, 0 },
128 { GL_CCW
, "GL_CCW", ENUM
, 0 },
130 { GL_DECAL
, "GL_DECAL", ENUM
, 0 },
131 { GL_DECR
, "GL_DECR", ENUM
, 0 },
132 { GL_DEPTH
, "GL_DEPTH", ENUM
, 0 },
133 { GL_DEPTH_BIAS
, "GL_DEPTH_BIAS", FLOAT
, 1 },
134 { GL_DEPTH_BITS
, "GL_DEPTH_BITS", INT
, 1 },
135 { GL_DEPTH_BUFFER_BIT
, "GL_DEPTH_BUFFER_BIT", ENUM
, 0 },
136 { GL_DEPTH_CLEAR_VALUE
, "GL_DEPTH_CLEAR_VALUE", FLOAT
, 1 },
137 { GL_DEPTH_COMPONENT
, "GL_DEPTH_COMPONENT", ENUM
, 0 },
138 { GL_DEPTH_FUNC
, "GL_DEPTH_FUNC", ENUM
, 1 },
139 { GL_DEPTH_RANGE
, "GL_DEPTH_RANGE", FLOAT
, 2 },
140 { GL_DEPTH_SCALE
, "GL_DEPTH_SCALE", FLOAT
, 1 },
141 { GL_DEPTH_TEST
, "GL_DEPTH_TEST", ENUM
, 1 },
142 { GL_DEPTH_WRITEMASK
, "GL_DEPTH_WRITEMASK", BOOLEAN
, 1 },
143 { GL_DIFFUSE
, "GL_DIFFUSE", ENUM
, 0 }, /*XXX*/
144 { GL_DITHER
, "GL_DITHER", BOOLEAN
, 1 },
145 { GL_DOMAIN
, "GL_DOMAIN", ENUM
, 0 },
146 { GL_DONT_CARE
, "GL_DONT_CARE", ENUM
, 0 },
147 { GL_DOUBLE
, "GL_DOUBLE", ENUM
, 0 },
148 { GL_DOUBLEBUFFER
, "GL_DOUBLEBUFFER", BOOLEAN
, 1},
149 { GL_DRAW_BUFFER
, "GL_DRAW_BUFFER", ENUM
, 1 },
150 { GL_DRAW_PIXEL_TOKEN
, "GL_DRAW_PIXEL_TOKEN", ENUM
, 0 },
151 { GL_DST_ALPHA
, "GL_DST_ALPHA", ENUM
, 0 },
152 { GL_DST_COLOR
, "GL_DST_COLOR", ENUM
, 0 },
154 { GL_EDGE_FLAG
, "GL_EDGE_FLAG", BOOLEAN
, 1 },
155 /* XXX GL_EDGE_FLAG_ARRAY_* */
156 { GL_EMISSION
, "GL_EMISSION", ENUM
, 0 }, /* XXX */
157 { GL_ENABLE_BIT
, "GL_ENABLE_BIT", ENUM
, 0 },
158 { GL_EQUAL
, "GL_EQUAL", ENUM
, 0 },
159 { GL_EQUIV
, "GL_EQUIV", ENUM
, 0 },
160 { GL_EVAL_BIT
, "GL_EVAL_BIT", ENUM
, 0 },
161 { GL_EXP
, "GL_EXP", ENUM
, 0 },
162 { GL_EXP2
, "GL_EXP2", ENUM
, 0 },
163 { GL_EXTENSIONS
, "GL_EXTENSIONS", ENUM
, 0 },
164 { GL_EYE_LINEAR
, "GL_EYE_LINEAR", ENUM
, 0 },
165 { GL_EYE_PLANE
, "GL_EYE_PLANE", ENUM
, 0 },
167 { GL_FALSE
, "GL_FALSE", ENUM
, 0 },
168 { GL_FASTEST
, "GL_FASTEST", ENUM
, 0 },
169 { GL_FEEDBACK
, "GL_FEEDBACK", ENUM
, 0 },
170 { GL_FEEDBACK_BUFFER_POINTER
, "GL_FEEDBACK_BUFFER_POINTER", VOID
, 0 },
171 { GL_FEEDBACK_BUFFER_SIZE
, "GL_FEEDBACK_BUFFER_SIZE", INT
, 1 },
172 { GL_FEEDBACK_BUFFER_TYPE
, "GL_FEEDBACK_BUFFER_TYPE", INT
, 1 },
173 { GL_FILL
, "GL_FILL", ENUM
, 0 },
174 { GL_FLAT
, "GL_FLAT", ENUM
, 0 },
175 { GL_FLOAT
, "GL_FLOAT", ENUM
, 0 },
176 { GL_FOG
, "GL_FOG", BOOLEAN
, 1 },
177 { GL_FOG_BIT
, "GL_FOG_BIT", ENUM
, 0 },
178 { GL_FOG_COLOR
, "GL_FOG_COLOR", FLOAT
, 4 },
179 { GL_FOG_DENSITY
, "GL_FOG_DENSITY", FLOAT
, 1 },
180 { GL_FOG_END
, "GL_FOG_END", FLOAT
, 1 },
181 { GL_FOG_HINT
, "GL_FOG_HINT", ENUM
, 1 },
182 { GL_FOG_INDEX
, "GL_FOG_INDEX", INT
, 1 },
183 { GL_FOG_MODE
, "GL_FOG_MODE", ENUM
, 1 },
184 { GL_FOG_START
, "GL_FOG_START", FLOAT
, 1 },
185 { GL_FRONT
, "GL_FRONT", ENUM
, 0 },
186 { GL_FRONT_AND_BACK
, "GL_FRONT_AND_BACK", ENUM
, 0 },
187 { GL_FRONT_FACE
, "GL_FRONT_FACE", ENUM
, 1 },
188 { GL_FRONT_LEFT
, "GL_FRONT_LEFT", ENUM
, 0 },
189 { GL_FRONT_RIGHT
, "GL_FRONT_RIGHT", ENUM
, 0 },
191 { GL_GEQUAL
, "GL_GEQUAL", ENUM
, 0 },
192 { GL_GREATER
, "GL_GREATER", ENUM
, 0 },
193 { GL_GREEN
, "GL_GREEN", ENUM
, 0 },
194 { GL_GREEN_BIAS
, "GL_GREEN_BIAS", FLOAT
, 1 },
195 { GL_GREEN_BITS
, "GL_GREEN_BITS", INT
, 1 },
196 { GL_GREEN_SCALE
, "GL_GREEN_SCALE", FLOAT
, 1 },
200 { GL_LESS
, "GL_LESS", ENUM
, 0 },
201 { GL_LEQUAL
, "GL_LEQUAL", ENUM
, 0 },
202 { GL_LIGHTING
, "GL_LIGHTING", BOOLEAN
, 1 },
203 { GL_LINE_SMOOTH
, "GL_LINE_SMOOTH", BOOLEAN
, 1 },
204 { GL_LINE_STIPPLE
, "GL_LINE_STIPPLE", BOOLEAN
, 1 },
205 { GL_LINE_STIPPLE_PATTERN
, "GL_LINE_STIPPLE_PATTERN", INT
, 1 },
206 { GL_LINE_STIPPLE_REPEAT
, "GL_LINE_STIPPLE_REPEAT", INT
, 1 },
207 { GL_LINE_WIDTH
, "GL_LINE_WIDTH", FLOAT
, 1 },
209 { GL_MODELVIEW_MATRIX
, "GL_MODELVIEW_MATRIX", DOUBLE
, 16 },
211 { GL_NEVER
, "GL_NEVER", ENUM
, 0 },
212 { GL_NOTEQUAL
, "GL_NOTEQUAL", ENUM
, 0 },
214 { GL_PROJECTION_MATRIX
, "GL_PROJECTION_MATRIX", FLOAT
, 16 },
216 { GL_PACK_SWAP_BYTES
, "GL_PACK_SWAP_BYTES", INT
, 1 },
217 { GL_PACK_LSB_FIRST
, "GL_PACK_LSB_FIRST", INT
, 1 },
218 { GL_PACK_ROW_LENGTH
, "GL_PACK_ROW_LENGTH", INT
, 1 },
219 { GL_PACK_SKIP_PIXELS
, "GL_PACK_SKIP_PIXELS", INT
, 1 },
220 { GL_PACK_SKIP_ROWS
, "GL_PACK_SKIP_ROWS", INT
, 1 },
221 { GL_PACK_ALIGNMENT
, "GL_PACK_ALIGNMENT", INT
, 1 },
223 { GL_TRUE
, "GL_TRUE", ENUM
, 0 },
225 { GL_UNPACK_SWAP_BYTES
, "GL_UNPACK_SWAP_BYTES", INT
, 1 },
226 { GL_UNPACK_LSB_FIRST
, "GL_UNPACK_LSB_FIRST", INT
, 1 },
227 { GL_UNPACK_ROW_LENGTH
, "GL_UNPACK_ROW_LENGTH", INT
, 1 },
228 { GL_UNPACK_SKIP_PIXELS
, "GL_UNPACK_SKIP_PIXELS", INT
, 1 },
229 { GL_UNPACK_SKIP_ROWS
, "GL_UNPACK_SKIP_ROWS", INT
, 1 },
230 { GL_UNPACK_ALIGNMENT
, "GL_UNPACK_ALIGNMENT", INT
, 1 },
232 { GL_VIEWPORT
, "GL_VIEWPORT", INT
, 4 },
239 #if defined(GL_EXT_blend_minmax)
240 { GL_BLEND_EQUATION_EXT
, "GL_BLEND_EQUATION_EXT", ENUM
, 1 },
242 #if defined(GL_EXT_blend_color)
243 { GL_BLEND_COLOR_EXT
, "GL_BLEND_COLOR_EXT", FLOAT
, 4 },
245 #if defined(GL_EXT_point_parameters)
246 { GL_DISTANCE_ATTENUATION_EXT
, "GL_DISTANCE_ATTENUATION_EXT", FLOAT
, 1 },
248 #if defined(GL_INGR_blend_func_separate)
249 { GL_BLEND_SRC_RGB_INGR
, "GL_BLEND_SRC_RGB_INGR", ENUM
, 1 },
250 { GL_BLEND_DST_RGB_INGR
, "GL_BLEND_DST_RGB_INGR", ENUM
, 1 },
251 { GL_BLEND_SRC_ALPHA_INGR
, "GL_BLEND_SRC_ALPHA_INGR", ENUM
, 1 },
252 { GL_BLEND_DST_ALPHA_INGR
, "GL_BLEND_DST_ALPHA_INGR", ENUM
, 1 },
256 { LAST_TOKEN
, "", 0, 0 }
260 static const struct EnumRecord
*FindRecord( GLenum var
)
263 for (i
= 0; EnumTable
[i
].enumerator
!= LAST_TOKEN
; i
++) {
264 if (EnumTable
[i
].enumerator
== var
) {
265 return &EnumTable
[i
];
274 * Return the string label for the given enum.
276 const char *GetEnumString( GLenum var
)
278 const struct EnumRecord
*rec
= FindRecord(var
);
288 * Print current value of the given state variable.
290 void PrintState( int indent
, GLenum var
)
292 const struct EnumRecord
*rec
= FindRecord(var
);
298 if (rec
->getCount
<= 0) {
299 assert(rec
->getType
== ENUM
);
300 printf("%s is not a state variable\n", rec
->string
);
303 switch (rec
->getType
) {
308 glGetIntegerv(rec
->enumerator
, values
);
309 printf("%s = ", rec
->string
);
310 for (i
= 0; i
< rec
->getCount
; i
++)
311 printf("%d ", values
[i
]);
319 glGetFloatv(rec
->enumerator
, values
);
320 printf("%s = ", rec
->string
);
321 for (i
= 0; i
< rec
->getCount
; i
++)
322 printf("%f ", values
[i
]);
328 GLdouble values
[100];
330 glGetDoublev(rec
->enumerator
, values
);
331 printf("%s = ", rec
->string
);
332 for (i
= 0; i
< rec
->getCount
; i
++)
333 printf("%f ", (float) values
[i
]);
339 GLboolean values
[100];
341 glGetBooleanv(rec
->enumerator
, values
);
342 printf("%s = ", rec
->string
);
343 for (i
= 0; i
< rec
->getCount
; i
++)
344 printf("%s ", values
[i
] ? "GL_TRUE" : "GL_FALSE");
352 glGetIntegerv(rec
->enumerator
, values
);
353 printf("%s = ", rec
->string
);
354 for (i
= 0; i
< rec
->getCount
; i
++) {
355 const char *str
= GetEnumString((GLenum
) values
[i
]);
368 glGetPointerv(rec
->enumerator
, values
);
369 printf("%s = ", rec
->string
);
370 for (i
= 0; i
< rec
->getCount
; i
++) {
371 printf("%p ", values
[i
]);
377 printf("fatal error in PrintState()\n");
383 printf("Unknown GLenum passed to PrintState()\n");
390 * Print all glPixelStore-related state.
391 * NOTE: Should write similar functions for lighting, texturing, etc.
393 void PrintPixelStoreState( void )
395 const GLenum enums
[] = {
402 GL_UNPACK_SWAP_BYTES
,
404 GL_UNPACK_ROW_LENGTH
,
405 GL_UNPACK_SKIP_PIXELS
,
411 printf("Pixel pack/unpack state:\n");
412 for (i
= 0; enums
[i
]; i
++) {
413 PrintState(3, enums
[i
]);
421 * Print all state for the given attribute group.
423 void PrintAttribState( GLbitfield attrib
)
425 static const GLenum depth_buffer_enums
[] = {
427 GL_DEPTH_CLEAR_VALUE
,
432 static const GLenum fog_enums
[] = {
442 static const GLenum line_enums
[] = {
445 GL_LINE_STIPPLE_PATTERN
,
446 GL_LINE_STIPPLE_REPEAT
,
451 const GLenum
*enumList
= NULL
;
454 case GL_DEPTH_BUFFER_BIT
:
455 enumList
= depth_buffer_enums
;
456 printf("GL_DEPTH_BUFFER_BIT state:\n");
459 enumList
= fog_enums
;
460 printf("GL_FOG_BIT state:\n");
463 enumList
= line_enums
;
464 printf("GL_LINE_BIT state:\n");
467 printf("Bad value in PrintAttribState()\n");
472 for (i
= 0; enumList
[i
]; i
++)
473 PrintState(3, enumList
[i
]);
481 #include "glut_wrap.h"
483 int main( int argc
, char *argv
[] )
485 glutInit( &argc
, argv
);
486 glutInitWindowPosition(0, 0);
487 glutInitWindowSize(400, 300);
488 glutInitDisplayMode(GLUT_RGB
);
489 glutCreateWindow(argv
[0]);
490 PrintAttribState(GL_DEPTH_BUFFER_BIT
);
491 PrintAttribState(GL_FOG_BIT
);
492 PrintAttribState(GL_LINE_BIT
);
493 PrintState(0, GL_ALPHA_BITS
);
494 PrintState(0, GL_VIEWPORT
);
495 PrintState(0, GL_ALPHA_TEST_FUNC
);
496 PrintState(0, GL_MODELVIEW_MATRIX
);
497 PrintState(0, GL_ALWAYS
);
498 PrintPixelStoreState();