removed debug
[mesa.git] / src / mesa / tnl / t_eval_api.c
1 /* $Id: t_eval_api.c,v 1.6 2001/05/01 13:18:03 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28 #include "glheader.h"
29 #include "colormac.h"
30 #include "context.h"
31 #include "macros.h"
32 #include "mem.h"
33 #include "mmath.h"
34 #include "mtypes.h"
35 #include "math/m_eval.h"
36
37 #include "t_eval_api.h"
38 #include "t_imm_api.h"
39 #include "t_imm_alloc.h"
40 #include "t_imm_exec.h"
41
42
43
44
45
46 /* KW: If are compiling, we don't know whether eval will produce a
47 * vertex when it is run in the future. If this is pure immediate
48 * mode, eval is a noop if neither vertex map is enabled.
49 *
50 * Thus we need to have a check in the display list code or
51 * elsewhere for eval(1,2) vertices in the case where
52 * map(1,2)_vertex is disabled, and to purge those vertices from
53 * the vb.
54 */
55 void
56 _tnl_exec_EvalMesh1( GLenum mode, GLint i1, GLint i2 )
57 {
58 GET_CURRENT_CONTEXT(ctx);
59 GLint i;
60 GLfloat u, du;
61 GLenum prim;
62 ASSERT_OUTSIDE_BEGIN_END(ctx);
63
64 /* fprintf(stderr, "%s\n", __FUNCTION__); */
65
66 switch (mode) {
67 case GL_POINT:
68 prim = GL_POINTS;
69 break;
70 case GL_LINE:
71 prim = GL_LINE_STRIP;
72 break;
73 default:
74 _mesa_error( ctx, GL_INVALID_ENUM, "glEvalMesh1(mode)" );
75 return;
76 }
77
78 /* No effect if vertex maps disabled.
79 */
80 if (!ctx->Eval.Map1Vertex4 && !ctx->Eval.Map1Vertex3)
81 return;
82
83 du = ctx->Eval.MapGrid1du;
84 u = ctx->Eval.MapGrid1u1 + i1 * du;
85
86 /* Need to turn off compilation -- this is already saved, and the
87 * coordinates generated and the test above depend on state that
88 * may change before the list is executed.
89 *
90 * TODO: Anaylse display lists to determine if this state is
91 * constant.
92 */
93 {
94 GLboolean compiling = ctx->CompileFlag;
95 struct immediate *im = TNL_CURRENT_IM(ctx);
96
97 if (compiling) {
98 FLUSH_VERTICES( ctx, 0 );
99 SET_IMMEDIATE( ctx, _tnl_alloc_immediate( ctx ) );
100 TNL_CURRENT_IM(ctx)->ref_count++;
101 ctx->CompileFlag = GL_FALSE;
102 }
103
104 _tnl_hard_begin( ctx, prim );
105 for (i=i1;i<=i2;i++,u+=du) {
106 _tnl_eval_coord1f( ctx, u );
107 }
108 _tnl_end(ctx);
109
110 /* Need this for replay *and* compile:
111 */
112 FLUSH_VERTICES( ctx, 0 );
113
114 if (compiling) {
115 TNL_CURRENT_IM(ctx)->ref_count--;
116 ASSERT( TNL_CURRENT_IM(ctx)->ref_count == 0 );
117 _tnl_free_immediate( TNL_CURRENT_IM(ctx) );
118 SET_IMMEDIATE( ctx, im );
119 ctx->CompileFlag = GL_TRUE;
120 }
121 }
122 }
123
124
125
126 void
127 _tnl_exec_EvalMesh2( GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2 )
128 {
129 GET_CURRENT_CONTEXT(ctx);
130 GLint i, j;
131 GLfloat u, du, v, dv, v1, u1;
132 ASSERT_OUTSIDE_BEGIN_END(ctx);
133
134 /* fprintf(stderr, "%s\n", __FUNCTION__); */
135
136 /* No effect if vertex maps disabled.
137 */
138 if (!ctx->Eval.Map2Vertex4 && !ctx->Eval.Map2Vertex3)
139 return;
140
141
142 du = ctx->Eval.MapGrid2du;
143 dv = ctx->Eval.MapGrid2dv;
144 v1 = ctx->Eval.MapGrid2v1 + j1 * dv;
145 u1 = ctx->Eval.MapGrid2u1 + i1 * du;
146
147 /* Need to turn off compilation -- this is already saved, and the
148 * coordinates generated and the test above depend on state that
149 * may change before the list is executed.
150 */
151 {
152 GLboolean compiling = ctx->CompileFlag;
153 struct immediate *im = TNL_CURRENT_IM(ctx);
154
155 if (compiling) {
156 FLUSH_VERTICES( ctx, 0 );
157 SET_IMMEDIATE( ctx, _tnl_alloc_immediate( ctx ) );
158 TNL_CURRENT_IM(ctx)->ref_count++;
159 ctx->CompileFlag = GL_FALSE;
160 }
161
162 switch (mode) {
163 case GL_POINT:
164 _tnl_hard_begin( ctx, GL_POINTS );
165 for (v=v1,j=j1;j<=j2;j++,v+=dv) {
166 for (u=u1,i=i1;i<=i2;i++,u+=du) {
167 _tnl_eval_coord2f( ctx, u, v );
168 }
169 }
170 _tnl_end(ctx);
171 break;
172 case GL_LINE:
173 for (v=v1,j=j1;j<=j2;j++,v+=dv) {
174 _tnl_hard_begin( ctx, GL_LINE_STRIP );
175 for (u=u1,i=i1;i<=i2;i++,u+=du) {
176 _tnl_eval_coord2f( ctx, u, v );
177 }
178 _tnl_end(ctx);
179 }
180 for (u=u1,i=i1;i<=i2;i++,u+=du) {
181 _tnl_hard_begin( ctx, GL_LINE_STRIP );
182 for (v=v1,j=j1;j<=j2;j++,v+=dv) {
183 _tnl_eval_coord2f( ctx, u, v );
184 }
185 _tnl_end(ctx);
186 }
187 break;
188 case GL_FILL:
189 for (v=v1,j=j1;j<j2;j++,v+=dv) {
190 _tnl_hard_begin( ctx, GL_TRIANGLE_STRIP );
191 for (u=u1,i=i1;i<=i2;i++,u+=du) {
192 _tnl_eval_coord2f( ctx, u, v );
193 _tnl_eval_coord2f( ctx, u, v+dv );
194 }
195 _tnl_end(ctx);
196 }
197 break;
198 default:
199 _mesa_error( ctx, GL_INVALID_ENUM, "glEvalMesh2(mode)" );
200 return;
201 }
202
203 /* Need this for replay *and* compile:
204 */
205 FLUSH_VERTICES( ctx, 0 );
206
207 if (compiling) {
208 TNL_CURRENT_IM(ctx)->ref_count--;
209 _tnl_free_immediate( TNL_CURRENT_IM( ctx ) );
210 SET_IMMEDIATE( ctx, im );
211 ctx->CompileFlag = GL_TRUE;
212 }
213 }
214 }
215
216
217
218 void _tnl_eval_init( GLcontext *ctx )
219 {
220 GLvertexformat *vfmt = &(TNL_CONTEXT(ctx)->vtxfmt);
221 vfmt->EvalMesh1 = _tnl_exec_EvalMesh1;
222 vfmt->EvalMesh2 = _tnl_exec_EvalMesh2;
223 }