Allow different max texture sizes for 1/2D, 3D and cube maps.
[mesa.git] / src / mesa / tnl / t_eval_api.c
1 /* $Id: t_eval_api.c,v 1.7 2001/05/14 09:00:51 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 * State to watch:
94 * - enabled maps
95 * - map state for each enabled map, including control points
96 * - grid state
97 *
98 * Could alternatively cache individual maps in arrays, rather than
99 * building immediates.
100 */
101 {
102 GLboolean compiling = ctx->CompileFlag;
103 struct immediate *im = TNL_CURRENT_IM(ctx);
104
105 if (compiling) {
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;
110 }
111
112 _tnl_hard_begin( ctx, prim );
113 for (i=i1;i<=i2;i++,u+=du) {
114 _tnl_eval_coord1f( ctx, u );
115 }
116 _tnl_end(ctx);
117
118 /* Need this for replay *and* compile:
119 */
120 FLUSH_VERTICES( ctx, 0 );
121
122 if (compiling) {
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;
128 }
129 }
130 }
131
132
133
134 void
135 _tnl_exec_EvalMesh2( GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2 )
136 {
137 GET_CURRENT_CONTEXT(ctx);
138 GLint i, j;
139 GLfloat u, du, v, dv, v1, u1;
140 ASSERT_OUTSIDE_BEGIN_END(ctx);
141
142 /* fprintf(stderr, "%s\n", __FUNCTION__); */
143
144 /* No effect if vertex maps disabled.
145 */
146 if (!ctx->Eval.Map2Vertex4 && !ctx->Eval.Map2Vertex3)
147 return;
148
149
150 du = ctx->Eval.MapGrid2du;
151 dv = ctx->Eval.MapGrid2dv;
152 v1 = ctx->Eval.MapGrid2v1 + j1 * dv;
153 u1 = ctx->Eval.MapGrid2u1 + i1 * du;
154
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.
158 */
159 {
160 GLboolean compiling = ctx->CompileFlag;
161 struct immediate *im = TNL_CURRENT_IM(ctx);
162
163 if (compiling) {
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;
168 }
169
170 switch (mode) {
171 case GL_POINT:
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 );
176 }
177 }
178 _tnl_end(ctx);
179 break;
180 case GL_LINE:
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 );
185 }
186 _tnl_end(ctx);
187 }
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 );
192 }
193 _tnl_end(ctx);
194 }
195 break;
196 case GL_FILL:
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 );
202 }
203 _tnl_end(ctx);
204 }
205 break;
206 default:
207 _mesa_error( ctx, GL_INVALID_ENUM, "glEvalMesh2(mode)" );
208 return;
209 }
210
211 /* Need this for replay *and* compile:
212 */
213 FLUSH_VERTICES( ctx, 0 );
214
215 if (compiling) {
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;
220 }
221 }
222 }
223
224
225
226 void _tnl_eval_init( GLcontext *ctx )
227 {
228 GLvertexformat *vfmt = &(TNL_CONTEXT(ctx)->vtxfmt);
229 vfmt->EvalMesh1 = _tnl_exec_EvalMesh1;
230 vfmt->EvalMesh2 = _tnl_exec_EvalMesh2;
231 }