mesa: remove GLvertexformat::EvalMesh1(), EvalMesh2()
[mesa.git] / src / mesa / main / polygon.c
1 /**
2 * \file polygon.c
3 * Polygon operations.
4 */
5
6 /*
7 * Mesa 3-D graphics library
8 * Version: 6.5.1
9 *
10 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included
20 * in all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31
32 #include "glheader.h"
33 #include "imports.h"
34 #include "context.h"
35 #include "image.h"
36 #include "enums.h"
37 #include "pack.h"
38 #include "pbo.h"
39 #include "polygon.h"
40 #include "mtypes.h"
41
42
43 /**
44 * Specify whether to cull front- or back-facing facets.
45 *
46 * \param mode culling mode.
47 *
48 * \sa glCullFace().
49 *
50 * Verifies the parameter and updates gl_polygon_attrib::CullFaceMode. On
51 * change, flushes the vertices and notifies the driver via
52 * the dd_function_table::CullFace callback.
53 */
54 void GLAPIENTRY
55 _mesa_CullFace( GLenum mode )
56 {
57 GET_CURRENT_CONTEXT(ctx);
58
59 if (MESA_VERBOSE&VERBOSE_API)
60 _mesa_debug(ctx, "glCullFace %s\n", _mesa_lookup_enum_by_nr(mode));
61
62 if (mode!=GL_FRONT && mode!=GL_BACK && mode!=GL_FRONT_AND_BACK) {
63 _mesa_error( ctx, GL_INVALID_ENUM, "glCullFace" );
64 return;
65 }
66
67 if (ctx->Polygon.CullFaceMode == mode)
68 return;
69
70 FLUSH_VERTICES(ctx, _NEW_POLYGON);
71 ctx->Polygon.CullFaceMode = mode;
72
73 if (ctx->Driver.CullFace)
74 ctx->Driver.CullFace( ctx, mode );
75 }
76
77
78 /**
79 * Define front- and back-facing
80 *
81 * \param mode orientation of front-facing polygons.
82 *
83 * \sa glFrontFace().
84 *
85 * Verifies the parameter and updates gl_polygon_attrib::FrontFace. On change
86 * flushes the vertices and notifies the driver via
87 * the dd_function_table::FrontFace callback.
88 */
89 void GLAPIENTRY
90 _mesa_FrontFace( GLenum mode )
91 {
92 GET_CURRENT_CONTEXT(ctx);
93
94 if (MESA_VERBOSE&VERBOSE_API)
95 _mesa_debug(ctx, "glFrontFace %s\n", _mesa_lookup_enum_by_nr(mode));
96
97 if (mode!=GL_CW && mode!=GL_CCW) {
98 _mesa_error( ctx, GL_INVALID_ENUM, "glFrontFace" );
99 return;
100 }
101
102 if (ctx->Polygon.FrontFace == mode)
103 return;
104
105 FLUSH_VERTICES(ctx, _NEW_POLYGON);
106 ctx->Polygon.FrontFace = mode;
107
108 ctx->Polygon._FrontBit = (GLboolean) (mode == GL_CW);
109
110 if (ctx->Driver.FrontFace)
111 ctx->Driver.FrontFace( ctx, mode );
112 }
113
114
115 /**
116 * Set the polygon rasterization mode.
117 *
118 * \param face the polygons which \p mode applies to.
119 * \param mode how polygons should be rasterized.
120 *
121 * \sa glPolygonMode().
122 *
123 * Verifies the parameters and updates gl_polygon_attrib::FrontMode and
124 * gl_polygon_attrib::BackMode. On change flushes the vertices and notifies the
125 * driver via the dd_function_table::PolygonMode callback.
126 */
127 void GLAPIENTRY
128 _mesa_PolygonMode( GLenum face, GLenum mode )
129 {
130 GET_CURRENT_CONTEXT(ctx);
131
132 if (MESA_VERBOSE&VERBOSE_API)
133 _mesa_debug(ctx, "glPolygonMode %s %s\n",
134 _mesa_lookup_enum_by_nr(face),
135 _mesa_lookup_enum_by_nr(mode));
136
137 if (mode!=GL_POINT && mode!=GL_LINE && mode!=GL_FILL) {
138 _mesa_error( ctx, GL_INVALID_ENUM, "glPolygonMode(mode)" );
139 return;
140 }
141
142 switch (face) {
143 case GL_FRONT:
144 if (ctx->API == API_OPENGL_CORE) {
145 _mesa_error( ctx, GL_INVALID_ENUM, "glPolygonMode(face)" );
146 return;
147 }
148 if (ctx->Polygon.FrontMode == mode)
149 return;
150 FLUSH_VERTICES(ctx, _NEW_POLYGON);
151 ctx->Polygon.FrontMode = mode;
152 break;
153 case GL_FRONT_AND_BACK:
154 if (ctx->Polygon.FrontMode == mode &&
155 ctx->Polygon.BackMode == mode)
156 return;
157 FLUSH_VERTICES(ctx, _NEW_POLYGON);
158 ctx->Polygon.FrontMode = mode;
159 ctx->Polygon.BackMode = mode;
160 break;
161 case GL_BACK:
162 if (ctx->API == API_OPENGL_CORE) {
163 _mesa_error( ctx, GL_INVALID_ENUM, "glPolygonMode(face)" );
164 return;
165 }
166 if (ctx->Polygon.BackMode == mode)
167 return;
168 FLUSH_VERTICES(ctx, _NEW_POLYGON);
169 ctx->Polygon.BackMode = mode;
170 break;
171 default:
172 _mesa_error( ctx, GL_INVALID_ENUM, "glPolygonMode(face)" );
173 return;
174 }
175
176 if (ctx->Driver.PolygonMode)
177 ctx->Driver.PolygonMode(ctx, face, mode);
178 }
179
180
181 /**
182 * This routine updates the ctx->Polygon.Stipple state.
183 * If we're getting the stipple data from a PBO, we map the buffer
184 * in order to access the data.
185 * In any case, we obey the current pixel unpacking parameters when fetching
186 * the stipple data.
187 *
188 * In the future, this routine should be used as a fallback, called via
189 * ctx->Driver.PolygonStipple(). We'll have to update all the DRI drivers
190 * too.
191 */
192 void
193 _mesa_polygon_stipple(struct gl_context *ctx, const GLubyte *pattern)
194 {
195 pattern = _mesa_map_validate_pbo_source(ctx, 2,
196 &ctx->Unpack, 32, 32, 1,
197 GL_COLOR_INDEX, GL_BITMAP,
198 INT_MAX, pattern,
199 "glPolygonStipple");
200 if (!pattern)
201 return;
202
203 _mesa_unpack_polygon_stipple(pattern, ctx->PolygonStipple, &ctx->Unpack);
204
205 _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
206 }
207
208
209 /**
210 * Called by glPolygonStipple.
211 */
212 void GLAPIENTRY
213 _mesa_PolygonStipple( const GLubyte *pattern )
214 {
215 GET_CURRENT_CONTEXT(ctx);
216
217 if (MESA_VERBOSE&VERBOSE_API)
218 _mesa_debug(ctx, "glPolygonStipple\n");
219
220 FLUSH_VERTICES(ctx, _NEW_POLYGONSTIPPLE);
221
222 _mesa_polygon_stipple(ctx, pattern);
223
224 if (ctx->Driver.PolygonStipple)
225 ctx->Driver.PolygonStipple(ctx, pattern);
226 }
227
228
229 /**
230 * Called by glPolygonStipple.
231 */
232 void GLAPIENTRY
233 _mesa_GetnPolygonStippleARB( GLsizei bufSize, GLubyte *dest )
234 {
235 GET_CURRENT_CONTEXT(ctx);
236
237 if (MESA_VERBOSE&VERBOSE_API)
238 _mesa_debug(ctx, "glGetPolygonStipple\n");
239
240 dest = _mesa_map_validate_pbo_dest(ctx, 2,
241 &ctx->Pack, 32, 32, 1,
242 GL_COLOR_INDEX, GL_BITMAP,
243 bufSize, dest, "glGetPolygonStipple");
244 if (!dest)
245 return;
246
247 _mesa_pack_polygon_stipple(ctx->PolygonStipple, dest, &ctx->Pack);
248
249 _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
250 }
251
252
253 void GLAPIENTRY
254 _mesa_GetPolygonStipple( GLubyte *dest )
255 {
256 _mesa_GetnPolygonStippleARB(INT_MAX, dest);
257 }
258
259
260 void GLAPIENTRY
261 _mesa_PolygonOffset( GLfloat factor, GLfloat units )
262 {
263 GET_CURRENT_CONTEXT(ctx);
264
265 if (MESA_VERBOSE&VERBOSE_API)
266 _mesa_debug(ctx, "glPolygonOffset %f %f\n", factor, units);
267
268 if (ctx->Polygon.OffsetFactor == factor &&
269 ctx->Polygon.OffsetUnits == units)
270 return;
271
272 FLUSH_VERTICES(ctx, _NEW_POLYGON);
273 ctx->Polygon.OffsetFactor = factor;
274 ctx->Polygon.OffsetUnits = units;
275
276 if (ctx->Driver.PolygonOffset)
277 ctx->Driver.PolygonOffset( ctx, factor, units );
278 }
279
280
281 void GLAPIENTRY
282 _mesa_PolygonOffsetEXT( GLfloat factor, GLfloat bias )
283 {
284 GET_CURRENT_CONTEXT(ctx);
285 /* XXX mult by DepthMaxF here??? */
286 _mesa_PolygonOffset(factor, bias * ctx->DrawBuffer->_DepthMaxF );
287 }
288
289
290
291 /**********************************************************************/
292 /** \name Initialization */
293 /*@{*/
294
295 /**
296 * Initialize the context polygon state.
297 *
298 * \param ctx GL context.
299 *
300 * Initializes __struct gl_contextRec::Polygon and __struct gl_contextRec::PolygonStipple
301 * attribute groups.
302 */
303 void _mesa_init_polygon( struct gl_context * ctx )
304 {
305 /* Polygon group */
306 ctx->Polygon.CullFlag = GL_FALSE;
307 ctx->Polygon.CullFaceMode = GL_BACK;
308 ctx->Polygon.FrontFace = GL_CCW;
309 ctx->Polygon._FrontBit = 0;
310 ctx->Polygon.FrontMode = GL_FILL;
311 ctx->Polygon.BackMode = GL_FILL;
312 ctx->Polygon.SmoothFlag = GL_FALSE;
313 ctx->Polygon.StippleFlag = GL_FALSE;
314 ctx->Polygon.OffsetFactor = 0.0F;
315 ctx->Polygon.OffsetUnits = 0.0F;
316 ctx->Polygon.OffsetPoint = GL_FALSE;
317 ctx->Polygon.OffsetLine = GL_FALSE;
318 ctx->Polygon.OffsetFill = GL_FALSE;
319
320
321 /* Polygon Stipple group */
322 memset( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
323 }
324
325 /*@}*/