1 /* $Id: t_eval_api.c,v 1.7 2001/05/14 09:00:51 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
35 #include "math/m_eval.h"
37 #include "t_eval_api.h"
38 #include "t_imm_api.h"
39 #include "t_imm_alloc.h"
40 #include "t_imm_exec.h"
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.
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
56 _tnl_exec_EvalMesh1( GLenum mode
, GLint i1
, GLint i2
)
58 GET_CURRENT_CONTEXT(ctx
);
62 ASSERT_OUTSIDE_BEGIN_END(ctx
);
64 /* fprintf(stderr, "%s\n", __FUNCTION__); */
74 _mesa_error( ctx
, GL_INVALID_ENUM
, "glEvalMesh1(mode)" );
78 /* No effect if vertex maps disabled.
80 if (!ctx
->Eval
.Map1Vertex4
&& !ctx
->Eval
.Map1Vertex3
)
83 du
= ctx
->Eval
.MapGrid1du
;
84 u
= ctx
->Eval
.MapGrid1u1
+ i1
* du
;
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.
90 * TODO: Anaylse display lists to determine if this state is
95 * - map state for each enabled map, including control points
98 * Could alternatively cache individual maps in arrays, rather than
99 * building immediates.
102 GLboolean compiling
= ctx
->CompileFlag
;
103 struct immediate
*im
= TNL_CURRENT_IM(ctx
);
106 FLUSH_VERTICES( ctx
, 0 );
107 SET_IMMEDIATE( ctx
, _tnl_alloc_immediate( ctx
) );
108 TNL_CURRENT_IM(ctx
)->ref_count
++;
109 ctx
->CompileFlag
= GL_FALSE
;
112 _tnl_hard_begin( ctx
, prim
);
113 for (i
=i1
;i
<=i2
;i
++,u
+=du
) {
114 _tnl_eval_coord1f( ctx
, u
);
118 /* Need this for replay *and* compile:
120 FLUSH_VERTICES( ctx
, 0 );
123 TNL_CURRENT_IM(ctx
)->ref_count
--;
124 ASSERT( TNL_CURRENT_IM(ctx
)->ref_count
== 0 );
125 _tnl_free_immediate( TNL_CURRENT_IM(ctx
) );
126 SET_IMMEDIATE( ctx
, im
);
127 ctx
->CompileFlag
= GL_TRUE
;
135 _tnl_exec_EvalMesh2( GLenum mode
, GLint i1
, GLint i2
, GLint j1
, GLint j2
)
137 GET_CURRENT_CONTEXT(ctx
);
139 GLfloat u
, du
, v
, dv
, v1
, u1
;
140 ASSERT_OUTSIDE_BEGIN_END(ctx
);
142 /* fprintf(stderr, "%s\n", __FUNCTION__); */
144 /* No effect if vertex maps disabled.
146 if (!ctx
->Eval
.Map2Vertex4
&& !ctx
->Eval
.Map2Vertex3
)
150 du
= ctx
->Eval
.MapGrid2du
;
151 dv
= ctx
->Eval
.MapGrid2dv
;
152 v1
= ctx
->Eval
.MapGrid2v1
+ j1
* dv
;
153 u1
= ctx
->Eval
.MapGrid2u1
+ i1
* du
;
155 /* Need to turn off compilation -- this is already saved, and the
156 * coordinates generated and the test above depend on state that
157 * may change before the list is executed.
160 GLboolean compiling
= ctx
->CompileFlag
;
161 struct immediate
*im
= TNL_CURRENT_IM(ctx
);
164 FLUSH_VERTICES( ctx
, 0 );
165 SET_IMMEDIATE( ctx
, _tnl_alloc_immediate( ctx
) );
166 TNL_CURRENT_IM(ctx
)->ref_count
++;
167 ctx
->CompileFlag
= GL_FALSE
;
172 _tnl_hard_begin( ctx
, GL_POINTS
);
173 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
174 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
175 _tnl_eval_coord2f( ctx
, u
, v
);
181 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
182 _tnl_hard_begin( ctx
, GL_LINE_STRIP
);
183 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
184 _tnl_eval_coord2f( ctx
, u
, v
);
188 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
189 _tnl_hard_begin( ctx
, GL_LINE_STRIP
);
190 for (v
=v1
,j
=j1
;j
<=j2
;j
++,v
+=dv
) {
191 _tnl_eval_coord2f( ctx
, u
, v
);
197 for (v
=v1
,j
=j1
;j
<j2
;j
++,v
+=dv
) {
198 _tnl_hard_begin( ctx
, GL_TRIANGLE_STRIP
);
199 for (u
=u1
,i
=i1
;i
<=i2
;i
++,u
+=du
) {
200 _tnl_eval_coord2f( ctx
, u
, v
);
201 _tnl_eval_coord2f( ctx
, u
, v
+dv
);
207 _mesa_error( ctx
, GL_INVALID_ENUM
, "glEvalMesh2(mode)" );
211 /* Need this for replay *and* compile:
213 FLUSH_VERTICES( ctx
, 0 );
216 TNL_CURRENT_IM(ctx
)->ref_count
--;
217 _tnl_free_immediate( TNL_CURRENT_IM( ctx
) );
218 SET_IMMEDIATE( ctx
, im
);
219 ctx
->CompileFlag
= GL_TRUE
;
226 void _tnl_eval_init( GLcontext
*ctx
)
228 GLvertexformat
*vfmt
= &(TNL_CONTEXT(ctx
)->vtxfmt
);
229 vfmt
->EvalMesh1
= _tnl_exec_EvalMesh1
;
230 vfmt
->EvalMesh2
= _tnl_exec_EvalMesh2
;