1 /* $Id: t_eval_api.c,v 1.6 2001/05/01 13:18:03 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
94 GLboolean compiling
= ctx
->CompileFlag
;
95 struct immediate
*im
= TNL_CURRENT_IM(ctx
);
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
;
104 _tnl_hard_begin( ctx
, prim
);
105 for (i
=i1
;i
<=i2
;i
++,u
+=du
) {
106 _tnl_eval_coord1f( ctx
, u
);
110 /* Need this for replay *and* compile:
112 FLUSH_VERTICES( ctx
, 0 );
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
;
127 _tnl_exec_EvalMesh2( GLenum mode
, GLint i1
, GLint i2
, GLint j1
, GLint j2
)
129 GET_CURRENT_CONTEXT(ctx
);
131 GLfloat u
, du
, v
, dv
, v1
, u1
;
132 ASSERT_OUTSIDE_BEGIN_END(ctx
);
134 /* fprintf(stderr, "%s\n", __FUNCTION__); */
136 /* No effect if vertex maps disabled.
138 if (!ctx
->Eval
.Map2Vertex4
&& !ctx
->Eval
.Map2Vertex3
)
142 du
= ctx
->Eval
.MapGrid2du
;
143 dv
= ctx
->Eval
.MapGrid2dv
;
144 v1
= ctx
->Eval
.MapGrid2v1
+ j1
* dv
;
145 u1
= ctx
->Eval
.MapGrid2u1
+ i1
* du
;
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.
152 GLboolean compiling
= ctx
->CompileFlag
;
153 struct immediate
*im
= TNL_CURRENT_IM(ctx
);
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
;
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
);
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
);
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
);
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
);
199 _mesa_error( ctx
, GL_INVALID_ENUM
, "glEvalMesh2(mode)" );
203 /* Need this for replay *and* compile:
205 FLUSH_VERTICES( ctx
, 0 );
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
;
218 void _tnl_eval_init( GLcontext
*ctx
)
220 GLvertexformat
*vfmt
= &(TNL_CONTEXT(ctx
)->vtxfmt
);
221 vfmt
->EvalMesh1
= _tnl_exec_EvalMesh1
;
222 vfmt
->EvalMesh2
= _tnl_exec_EvalMesh2
;