Initial work for bounds checking of vertex arrays and vertex buffer objects.
[mesa.git] / src / mesa / tnl / t_imm_debug.c
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 5.1
5 *
6 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #include "mtypes.h"
27 #include "context.h"
28 #include "imports.h"
29 #include "t_context.h"
30 #include "t_imm_debug.h"
31
32
33 void _tnl_print_vert_flags( const char *name, GLuint flags )
34 {
35 _mesa_debug(NULL,
36 "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
37 name,
38 flags,
39 (flags & VERT_BIT_CLIP) ? "clip/proj-clip/glend, " : "",
40 (flags & VERT_BIT_EDGEFLAG) ? "edgeflag, " : "",
41 (flags & VERT_BIT_ELT) ? "array-elt, " : "",
42 (flags & VERT_BIT_END_VB) ? "end-vb, " : "",
43 (flags & VERT_BITS_EVAL_ANY) ? "eval-coord, " : "",
44 (flags & VERT_BIT_EYE) ? "eye/glbegin, " : "",
45 (flags & VERT_BIT_FOG) ? "fog-coord, " : "",
46 (flags & VERT_BIT_INDEX) ? "index, " : "",
47 (flags & VERT_BIT_MATERIAL) ? "material, " : "",
48 (flags & VERT_BIT_NORMAL) ? "normals, " : "",
49 (flags & VERT_BIT_POS) ? "obj, " : "",
50 (flags & VERT_BIT_OBJ_3) ? "obj-3, " : "",
51 (flags & VERT_BIT_OBJ_4) ? "obj-4, " : "",
52 (flags & VERT_BIT_POINT_SIZE) ? "point-size, " : "",
53 (flags & VERT_BIT_COLOR0) ? "colors, " : "",
54 (flags & VERT_BIT_COLOR1) ? "specular, " : "",
55 (flags & VERT_BIT_TEX0) ? "texcoord0, " : "",
56 (flags & VERT_BIT_TEX1) ? "texcoord1, " : "",
57 (flags & VERT_BIT_TEX2) ? "texcoord2, " : "",
58 (flags & VERT_BIT_TEX3) ? "texcoord3, " : "",
59 (flags & VERT_BIT_TEX4) ? "texcoord4, " : "",
60 (flags & VERT_BIT_TEX5) ? "texcoord5, " : "",
61 (flags & VERT_BIT_TEX6) ? "texcoord6, " : "",
62 (flags & VERT_BIT_TEX7) ? "texcoord7, " : ""
63 );
64 }
65
66 void _tnl_print_cassette( struct immediate *IM )
67 {
68 GLuint i;
69 GLuint *flags = IM->Flag;
70 GLuint andflag = IM->CopyAndFlag;
71 GLuint orflag = (IM->CopyOrFlag|IM->Evaluated);
72 GLuint state = IM->BeginState;
73 GLuint req = ~0;
74
75 _mesa_debug(NULL, "Cassette id %d, %u rows.\n", IM->id,
76 IM->Count - IM->CopyStart);
77
78 _tnl_print_vert_flags("Contains at least one", orflag);
79
80 if (IM->Count != IM->CopyStart)
81 {
82 _tnl_print_vert_flags("Contains a full complement of", andflag);
83
84 _mesa_debug(NULL, "Final begin/end state %s/%s, errors %s/%s\n",
85 (state & VERT_BEGIN_0) ? "in" : "out",
86 (state & VERT_BEGIN_1) ? "in" : "out",
87 (state & VERT_ERROR_0) ? "y" : "n",
88 (state & VERT_ERROR_1) ? "y" : "n");
89
90 }
91
92 for (i = IM->CopyStart ; i <= IM->Count ; i++) {
93 _mesa_debug(NULL, "%u: ", i);
94 if (req & VERT_BITS_OBJ_234) {
95 if (flags[i] & VERT_BIT_EVAL_C1)
96 _mesa_debug(NULL, "EvalCoord %f ",
97 IM->Attrib[VERT_ATTRIB_POS][i][0]);
98 else if (flags[i] & VERT_BIT_EVAL_P1)
99 _mesa_debug(NULL, "EvalPoint %.0f ",
100 IM->Attrib[VERT_ATTRIB_POS][i][0]);
101 else if (flags[i] & VERT_BIT_EVAL_C2)
102 _mesa_debug(NULL, "EvalCoord %f %f ",
103 IM->Attrib[VERT_ATTRIB_POS][i][0],
104 IM->Attrib[VERT_ATTRIB_POS][i][1]);
105 else if (flags[i] & VERT_BIT_EVAL_P2)
106 _mesa_debug(NULL, "EvalPoint %.0f %.0f ",
107 IM->Attrib[VERT_ATTRIB_POS][i][0],
108 IM->Attrib[VERT_ATTRIB_POS][i][1]);
109 else if (i < IM->Count && (flags[i] & VERT_BITS_OBJ_234)) {
110 _mesa_debug(NULL, "Obj %f %f %f %f",
111 IM->Attrib[VERT_ATTRIB_POS][i][0],
112 IM->Attrib[VERT_ATTRIB_POS][i][1],
113 IM->Attrib[VERT_ATTRIB_POS][i][2],
114 IM->Attrib[VERT_ATTRIB_POS][i][3]);
115 }
116 }
117
118 if (req & flags[i] & VERT_BIT_ELT)
119 _mesa_debug(NULL, " Elt %u\t", IM->Elt[i]);
120
121 if (req & flags[i] & VERT_BIT_NORMAL)
122 _mesa_debug(NULL, " Norm %f %f %f ",
123 IM->Attrib[VERT_ATTRIB_NORMAL][i][0],
124 IM->Attrib[VERT_ATTRIB_NORMAL][i][1],
125 IM->Attrib[VERT_ATTRIB_NORMAL][i][2]);
126
127 if (req & flags[i] & VERT_BITS_TEX_ANY) {
128 GLuint j;
129 for (j = 0 ; j < MAX_TEXTURE_COORD_UNITS ; j++) {
130 if (req & flags[i] & VERT_BIT_TEX(j)) {
131 _mesa_debug(NULL, "TC%d %f %f %f %f", j,
132 IM->Attrib[VERT_ATTRIB_TEX0 + j][i][0],
133 IM->Attrib[VERT_ATTRIB_TEX0 + j][i][1],
134 IM->Attrib[VERT_ATTRIB_TEX0 + j][i][2],
135 IM->Attrib[VERT_ATTRIB_TEX0 + j][i][3]);
136 }
137 }
138 }
139
140 if (req & flags[i] & VERT_BIT_COLOR0)
141 _mesa_debug(NULL, " Rgba %f %f %f %f ",
142 IM->Attrib[VERT_ATTRIB_COLOR0][i][0],
143 IM->Attrib[VERT_ATTRIB_COLOR0][i][1],
144 IM->Attrib[VERT_ATTRIB_COLOR0][i][2],
145 IM->Attrib[VERT_ATTRIB_COLOR0][i][3]);
146
147 if (req & flags[i] & VERT_BIT_COLOR1)
148 _mesa_debug(NULL, " Spec %f %f %f ",
149 IM->Attrib[VERT_ATTRIB_COLOR1][i][0],
150 IM->Attrib[VERT_ATTRIB_COLOR1][i][1],
151 IM->Attrib[VERT_ATTRIB_COLOR1][i][2]);
152
153 if (req & flags[i] & VERT_BIT_FOG)
154 _mesa_debug(NULL, " Fog %f ", IM->Attrib[VERT_ATTRIB_FOG][i][0]);
155
156 if (req & flags[i] & VERT_BIT_INDEX)
157 _mesa_debug(NULL, " Index %u ", IM->Index[i]);
158
159 if (req & flags[i] & VERT_BIT_EDGEFLAG)
160 _mesa_debug(NULL, " Edgeflag %d ", IM->EdgeFlag[i]);
161
162 if (req & flags[i] & VERT_BIT_MATERIAL)
163 _mesa_debug(NULL, " Material ");
164
165
166 /* The order of these two is not easily knowable, but this is
167 * the usually correct way to look at them.
168 */
169 if (req & flags[i] & VERT_BIT_END)
170 _mesa_debug(NULL, " END ");
171
172 if (req & flags[i] & VERT_BIT_BEGIN)
173 _mesa_debug(NULL, " BEGIN(%s) (%s%s%s%s)",
174 _mesa_prim_name[IM->Primitive[i] & PRIM_MODE_MASK],
175 (IM->Primitive[i] & PRIM_LAST) ? "LAST," : "",
176 (IM->Primitive[i] & PRIM_BEGIN) ? "BEGIN," : "",
177 (IM->Primitive[i] & PRIM_END) ? "END," : "",
178 (IM->Primitive[i] & PRIM_PARITY) ? "PARITY," : "");
179
180 _mesa_debug(NULL, "\n");
181 }
182 }