e509fe4d989b58041259036d4f5bc09222d0c9b8
7 * Mesa 3-D graphics library
9 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
43 * Specify whether to cull front- or back-facing facets.
45 * \param mode culling mode.
49 * Verifies the parameter and updates gl_polygon_attrib::CullFaceMode. On
50 * change, flushes the vertices and notifies the driver via
51 * the dd_function_table::CullFace callback.
54 _mesa_CullFace( GLenum mode
)
56 GET_CURRENT_CONTEXT(ctx
);
58 if (MESA_VERBOSE
&VERBOSE_API
)
59 _mesa_debug(ctx
, "glCullFace %s\n", _mesa_enum_to_string(mode
));
61 if (mode
!=GL_FRONT
&& mode
!=GL_BACK
&& mode
!=GL_FRONT_AND_BACK
) {
62 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCullFace" );
66 if (ctx
->Polygon
.CullFaceMode
== mode
)
69 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
70 ctx
->Polygon
.CullFaceMode
= mode
;
72 if (ctx
->Driver
.CullFace
)
73 ctx
->Driver
.CullFace( ctx
, mode
);
78 * Define front- and back-facing
80 * \param mode orientation of front-facing polygons.
84 * Verifies the parameter and updates gl_polygon_attrib::FrontFace. On change
85 * flushes the vertices and notifies the driver via
86 * the dd_function_table::FrontFace callback.
89 _mesa_FrontFace( GLenum mode
)
91 GET_CURRENT_CONTEXT(ctx
);
93 if (MESA_VERBOSE
&VERBOSE_API
)
94 _mesa_debug(ctx
, "glFrontFace %s\n", _mesa_enum_to_string(mode
));
96 if (ctx
->Polygon
.FrontFace
== mode
)
99 if (mode
!=GL_CW
&& mode
!=GL_CCW
) {
100 _mesa_error( ctx
, GL_INVALID_ENUM
, "glFrontFace" );
104 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
105 ctx
->Polygon
.FrontFace
= mode
;
107 if (ctx
->Driver
.FrontFace
)
108 ctx
->Driver
.FrontFace( ctx
, mode
);
113 * Set the polygon rasterization mode.
115 * \param face the polygons which \p mode applies to.
116 * \param mode how polygons should be rasterized.
118 * \sa glPolygonMode().
120 * Verifies the parameters and updates gl_polygon_attrib::FrontMode and
121 * gl_polygon_attrib::BackMode. On change flushes the vertices and notifies the
122 * driver via the dd_function_table::PolygonMode callback.
125 _mesa_PolygonMode( GLenum face
, GLenum mode
)
127 GET_CURRENT_CONTEXT(ctx
);
129 if (MESA_VERBOSE
&VERBOSE_API
)
130 _mesa_debug(ctx
, "glPolygonMode %s %s\n",
131 _mesa_enum_to_string(face
),
132 _mesa_enum_to_string(mode
));
139 case GL_FILL_RECTANGLE_NV
:
140 if (ctx
->Extensions
.NV_fill_rectangle
)
144 _mesa_error(ctx
, GL_INVALID_ENUM
, "glPolygonMode(mode)");
150 if (ctx
->API
== API_OPENGL_CORE
) {
151 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(face)" );
154 if (ctx
->Polygon
.FrontMode
== mode
)
156 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
157 ctx
->Polygon
.FrontMode
= mode
;
159 case GL_FRONT_AND_BACK
:
160 if (ctx
->Polygon
.FrontMode
== mode
&& ctx
->Polygon
.BackMode
== mode
)
162 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
163 ctx
->Polygon
.FrontMode
= mode
;
164 ctx
->Polygon
.BackMode
= mode
;
167 if (ctx
->API
== API_OPENGL_CORE
) {
168 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(face)" );
171 if (ctx
->Polygon
.BackMode
== mode
)
173 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
174 ctx
->Polygon
.BackMode
= mode
;
177 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(face)" );
181 if (ctx
->Driver
.PolygonMode
)
182 ctx
->Driver
.PolygonMode(ctx
, face
, mode
);
187 * Called by glPolygonStipple.
190 _mesa_PolygonStipple(const GLubyte
*pattern
)
192 GET_CURRENT_CONTEXT(ctx
);
194 if (MESA_VERBOSE
& VERBOSE_API
)
195 _mesa_debug(ctx
, "glPolygonStipple\n");
197 FLUSH_VERTICES(ctx
, _NEW_POLYGONSTIPPLE
);
199 pattern
= _mesa_map_validate_pbo_source(ctx
, 2,
200 &ctx
->Unpack
, 32, 32, 1,
201 GL_COLOR_INDEX
, GL_BITMAP
,
207 _mesa_unpack_polygon_stipple(pattern
, ctx
->PolygonStipple
, &ctx
->Unpack
);
209 _mesa_unmap_pbo_source(ctx
, &ctx
->Unpack
);
211 if (ctx
->Driver
.PolygonStipple
)
212 ctx
->Driver
.PolygonStipple(ctx
, pattern
);
217 * Called by glPolygonStipple.
220 _mesa_GetnPolygonStippleARB( GLsizei bufSize
, GLubyte
*dest
)
222 GET_CURRENT_CONTEXT(ctx
);
224 if (MESA_VERBOSE
&VERBOSE_API
)
225 _mesa_debug(ctx
, "glGetPolygonStipple\n");
227 dest
= _mesa_map_validate_pbo_dest(ctx
, 2,
228 &ctx
->Pack
, 32, 32, 1,
229 GL_COLOR_INDEX
, GL_BITMAP
,
230 bufSize
, dest
, "glGetPolygonStipple");
234 _mesa_pack_polygon_stipple(ctx
->PolygonStipple
, dest
, &ctx
->Pack
);
236 _mesa_unmap_pbo_dest(ctx
, &ctx
->Pack
);
241 _mesa_GetPolygonStipple( GLubyte
*dest
)
243 _mesa_GetnPolygonStippleARB(INT_MAX
, dest
);
247 _mesa_polygon_offset_clamp(struct gl_context
*ctx
,
248 GLfloat factor
, GLfloat units
, GLfloat clamp
)
250 if (ctx
->Polygon
.OffsetFactor
== factor
&&
251 ctx
->Polygon
.OffsetUnits
== units
&&
252 ctx
->Polygon
.OffsetClamp
== clamp
)
255 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
256 ctx
->Polygon
.OffsetFactor
= factor
;
257 ctx
->Polygon
.OffsetUnits
= units
;
258 ctx
->Polygon
.OffsetClamp
= clamp
;
260 if (ctx
->Driver
.PolygonOffset
)
261 ctx
->Driver
.PolygonOffset( ctx
, factor
, units
, clamp
);
265 _mesa_PolygonOffset( GLfloat factor
, GLfloat units
)
267 GET_CURRENT_CONTEXT(ctx
);
269 if (MESA_VERBOSE
&VERBOSE_API
)
270 _mesa_debug(ctx
, "glPolygonOffset %f %f\n", factor
, units
);
272 _mesa_polygon_offset_clamp(ctx
, factor
, units
, 0.0);
277 _mesa_PolygonOffsetEXT( GLfloat factor
, GLfloat bias
)
279 GET_CURRENT_CONTEXT(ctx
);
280 /* XXX mult by DepthMaxF here??? */
281 _mesa_PolygonOffset(factor
, bias
* ctx
->DrawBuffer
->_DepthMaxF
);
285 _mesa_PolygonOffsetClampEXT( GLfloat factor
, GLfloat units
, GLfloat clamp
)
287 GET_CURRENT_CONTEXT(ctx
);
289 if (!ctx
->Extensions
.EXT_polygon_offset_clamp
) {
290 _mesa_error(ctx
, GL_INVALID_OPERATION
,
291 "unsupported function (glPolygonOffsetClampEXT) called");
295 if (MESA_VERBOSE
&VERBOSE_API
)
296 _mesa_debug(ctx
, "glPolygonOffsetClampEXT %f %f %f\n", factor
, units
, clamp
);
298 _mesa_polygon_offset_clamp(ctx
, factor
, units
, clamp
);
303 /**********************************************************************/
304 /** \name Initialization */
308 * Initialize the context polygon state.
310 * \param ctx GL context.
312 * Initializes __struct gl_contextRec::Polygon and __struct gl_contextRec::PolygonStipple
315 void _mesa_init_polygon( struct gl_context
* ctx
)
318 ctx
->Polygon
.CullFlag
= GL_FALSE
;
319 ctx
->Polygon
.CullFaceMode
= GL_BACK
;
320 ctx
->Polygon
.FrontFace
= GL_CCW
;
321 ctx
->Polygon
.FrontMode
= GL_FILL
;
322 ctx
->Polygon
.BackMode
= GL_FILL
;
323 ctx
->Polygon
.SmoothFlag
= GL_FALSE
;
324 ctx
->Polygon
.StippleFlag
= GL_FALSE
;
325 ctx
->Polygon
.OffsetFactor
= 0.0F
;
326 ctx
->Polygon
.OffsetUnits
= 0.0F
;
327 ctx
->Polygon
.OffsetClamp
= 0.0F
;
328 ctx
->Polygon
.OffsetPoint
= GL_FALSE
;
329 ctx
->Polygon
.OffsetLine
= GL_FALSE
;
330 ctx
->Polygon
.OffsetFill
= GL_FALSE
;
333 /* Polygon Stipple group */
334 memset( ctx
->PolygonStipple
, 0xff, 32*sizeof(GLuint
) );