3 * Copyright (C) 2006 Mathias Froehlich
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 #ifndef SG_SCENE_DEBUGDRAWCALLBACK_HXX
23 #define SG_SCENE_DEBUGDRAWCALLBACK_HXX
27 #include <osg/Drawable>
30 struct SGDebugDrawCallback : public osg::Drawable::DrawCallback {
31 virtual void drawImplementation(osg::State& state,
32 const osg::Drawable* drawable) const
34 // state.dirtyColorPointer();
35 printState(std::cout, drawable);
36 drawable->drawImplementation(state);
37 printState(std::cout, drawable);
38 // state.dirtyColorPointer();
41 void printState(std::ostream& stream, const osg::Drawable* drawable) const
43 stream << "Drawable \"" << drawable->getName() << "\"";
48 #define ERROR_CHECK(msg) \
50 GLenum errorNo = glGetError(); \
51 if (errorNo != GL_NO_ERROR) \
58 #define PRINT_STATE(flag) \
60 if (glIsEnabled(flag)) \
61 stream << " " #flag; \
62 ERROR_CHECK(" ERROR " #flag); \
65 PRINT_STATE(GL_COLOR_ARRAY);
66 PRINT_STATE(GL_EDGE_FLAG_ARRAY);
67 PRINT_STATE(GL_INDEX_ARRAY);
68 PRINT_STATE(GL_NORMAL_ARRAY);
69 PRINT_STATE(GL_TEXTURE_COORD_ARRAY);
70 PRINT_STATE(GL_VERTEX_ARRAY);
72 PRINT_STATE(GL_ALPHA_TEST);
73 PRINT_STATE(GL_AUTO_NORMAL);
74 PRINT_STATE(GL_BLEND);
75 PRINT_STATE(GL_CLIP_PLANE0);
76 PRINT_STATE(GL_CLIP_PLANE1);
77 PRINT_STATE(GL_CLIP_PLANE2);
78 PRINT_STATE(GL_CLIP_PLANE3);
79 PRINT_STATE(GL_CLIP_PLANE4);
80 PRINT_STATE(GL_CLIP_PLANE5);
81 PRINT_STATE(GL_COLOR_LOGIC_OP);
82 // PRINT_STATE(GL_COLOR_TABLE);
83 // PRINT_STATE(GL_CONVOLUTION_1D);
84 // PRINT_STATE(GL_CONVOLUTION_2D);
85 PRINT_STATE(GL_CULL_FACE);
86 PRINT_STATE(GL_DEPTH_TEST);
87 PRINT_STATE(GL_DITHER);
89 // PRINT_STATE(GL_HISTOGRAM);
90 PRINT_STATE(GL_INDEX_LOGIC_OP);
91 PRINT_STATE(GL_LIGHT0);
92 PRINT_STATE(GL_LIGHT1);
93 PRINT_STATE(GL_LIGHT2);
94 PRINT_STATE(GL_LIGHT3);
95 PRINT_STATE(GL_LIGHT4);
96 PRINT_STATE(GL_LIGHT5);
97 PRINT_STATE(GL_LIGHT6);
98 PRINT_STATE(GL_LIGHT7);
99 PRINT_STATE(GL_LIGHTING);
100 PRINT_STATE(GL_LINE_SMOOTH);
101 PRINT_STATE(GL_LINE_STIPPLE);
102 PRINT_STATE(GL_MAP1_COLOR_4);
103 PRINT_STATE(GL_MAP1_INDEX);
104 PRINT_STATE(GL_MAP1_NORMAL);
105 PRINT_STATE(GL_MAP1_TEXTURE_COORD_1);
106 PRINT_STATE(GL_MAP1_TEXTURE_COORD_2);
107 PRINT_STATE(GL_MAP1_TEXTURE_COORD_3);
108 PRINT_STATE(GL_MAP1_TEXTURE_COORD_4);
109 PRINT_STATE(GL_MAP2_COLOR_4);
110 PRINT_STATE(GL_MAP2_INDEX);
111 PRINT_STATE(GL_MAP2_NORMAL);
112 PRINT_STATE(GL_MAP2_TEXTURE_COORD_1);
113 PRINT_STATE(GL_MAP2_TEXTURE_COORD_2);
114 PRINT_STATE(GL_MAP2_TEXTURE_COORD_3);
115 PRINT_STATE(GL_MAP2_TEXTURE_COORD_4);
116 PRINT_STATE(GL_MAP2_VERTEX_3);
117 PRINT_STATE(GL_MAP2_VERTEX_4);
118 // PRINT_STATE(GL_MINMAX);
119 PRINT_STATE(GL_NORMALIZE);
120 PRINT_STATE(GL_POINT_SMOOTH);
121 PRINT_STATE(GL_POLYGON_SMOOTH);
122 PRINT_STATE(GL_POLYGON_OFFSET_FILL);
123 PRINT_STATE(GL_POLYGON_OFFSET_LINE);
124 PRINT_STATE(GL_POLYGON_OFFSET_POINT);
125 PRINT_STATE(GL_POLYGON_STIPPLE);
126 // PRINT_STATE(GL_POST_COLOR_MATRIX_COLOR_TABLE);
127 // PRINT_STATE(GL_POST_CONVOLUTION_COLOR_TABLE);
128 PRINT_STATE(GL_RESCALE_NORMAL);
129 PRINT_STATE(GL_SCISSOR_TEST);
130 // PRINT_STATE(GL_SEPARABLE_2D);
131 PRINT_STATE(GL_STENCIL_TEST);
132 PRINT_STATE(GL_TEXTURE_1D);
133 PRINT_STATE(GL_TEXTURE_2D);
135 PRINT_STATE(GL_TEXTURE_3D);
137 PRINT_STATE(GL_TEXTURE_GEN_Q);
138 PRINT_STATE(GL_TEXTURE_GEN_R);
139 PRINT_STATE(GL_TEXTURE_GEN_S);
140 PRINT_STATE(GL_TEXTURE_GEN_T);
148 #define PRINT_LIGHT(pname) \
151 glGetLightfv(GL_LIGHT0, pname, color.data());\
152 stream << " " #pname " " << color; \
154 PRINT_LIGHT(GL_AMBIENT);
155 PRINT_LIGHT(GL_DIFFUSE);
156 PRINT_LIGHT(GL_SPECULAR);
157 PRINT_LIGHT(GL_POSITION);
158 PRINT_LIGHT(GL_SPOT_DIRECTION);
162 if (glIsEnabled(GL_COLOR_MATERIAL)) {
163 stream << " GL_COLOR_MATERIAL(";
165 glGetIntegerv(GL_COLOR_MATERIAL_PARAMETER, &value);
166 if (value == GL_DIFFUSE)
167 stream << "GL_DIFFUSE";
168 if (value == GL_AMBIENT)
169 stream << "GL_AMBIENT";
170 if (value == GL_AMBIENT_AND_DIFFUSE)
171 stream << "GL_AMBIENT_AND_DIFFUSE";
172 if (value == GL_EMISSION)
173 stream << "GL_EMISSION";
174 if (value == GL_SPECULAR)
175 stream << "GL_SPECULAR";
177 #ifdef PRINT_MATERIAL
178 #undef PRINT_MATERIAL
180 #define PRINT_MATERIAL(pname) \
183 glGetMaterialfv(GL_FRONT, pname, color.data());\
184 stream << " " #pname " GL_FRONT " << color; \
185 glGetMaterialfv(GL_BACK, pname, color.data()); \
186 stream << " " #pname " GL_BACK " << color; \
189 PRINT_MATERIAL(GL_AMBIENT);
190 PRINT_MATERIAL(GL_DIFFUSE);
191 PRINT_MATERIAL(GL_EMISSION);
192 PRINT_MATERIAL(GL_SPECULAR);
193 #undef PRINT_MATERIAL