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 cull_face(struct gl_context
*ctx
, GLenum mode
)
56 if (ctx
->Polygon
.CullFaceMode
== mode
)
59 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonState
? 0 : _NEW_POLYGON
);
60 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonState
;
61 ctx
->Polygon
.CullFaceMode
= mode
;
63 if (ctx
->Driver
.CullFace
)
64 ctx
->Driver
.CullFace(ctx
, mode
);
69 _mesa_CullFace_no_error(GLenum mode
)
71 GET_CURRENT_CONTEXT(ctx
);
77 _mesa_CullFace(GLenum mode
)
79 GET_CURRENT_CONTEXT(ctx
);
81 if (MESA_VERBOSE
& VERBOSE_API
)
82 _mesa_debug(ctx
, "glCullFace %s\n", _mesa_enum_to_string(mode
));
84 if (mode
!= GL_FRONT
&& mode
!= GL_BACK
&& mode
!= GL_FRONT_AND_BACK
) {
85 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCullFace");
94 * Define front- and back-facing
96 * \param mode orientation of front-facing polygons.
100 * Verifies the parameter and updates gl_polygon_attrib::FrontFace. On change
101 * flushes the vertices and notifies the driver via
102 * the dd_function_table::FrontFace callback.
104 static ALWAYS_INLINE
void
105 front_face(struct gl_context
*ctx
, GLenum mode
, bool no_error
)
107 if (ctx
->Polygon
.FrontFace
== mode
)
110 if (!no_error
&& mode
!= GL_CW
&& mode
!= GL_CCW
) {
111 _mesa_error(ctx
, GL_INVALID_ENUM
, "glFrontFace");
115 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonState
? 0 : _NEW_POLYGON
);
116 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonState
;
117 ctx
->Polygon
.FrontFace
= mode
;
119 if (ctx
->Driver
.FrontFace
)
120 ctx
->Driver
.FrontFace(ctx
, mode
);
125 _mesa_FrontFace_no_error(GLenum mode
)
127 GET_CURRENT_CONTEXT(ctx
);
128 front_face(ctx
, mode
, true);
133 _mesa_FrontFace(GLenum mode
)
135 GET_CURRENT_CONTEXT(ctx
);
137 if (MESA_VERBOSE
& VERBOSE_API
)
138 _mesa_debug(ctx
, "glFrontFace %s\n", _mesa_enum_to_string(mode
));
140 front_face(ctx
, mode
, false);
145 * Set the polygon rasterization mode.
147 * \param face the polygons which \p mode applies to.
148 * \param mode how polygons should be rasterized.
150 * \sa glPolygonMode().
152 * Verifies the parameters and updates gl_polygon_attrib::FrontMode and
153 * gl_polygon_attrib::BackMode. On change flushes the vertices and notifies the
154 * driver via the dd_function_table::PolygonMode callback.
157 _mesa_PolygonMode( GLenum face
, GLenum mode
)
159 GET_CURRENT_CONTEXT(ctx
);
161 if (MESA_VERBOSE
&VERBOSE_API
)
162 _mesa_debug(ctx
, "glPolygonMode %s %s\n",
163 _mesa_enum_to_string(face
),
164 _mesa_enum_to_string(mode
));
171 case GL_FILL_RECTANGLE_NV
:
172 if (ctx
->Extensions
.NV_fill_rectangle
)
176 _mesa_error(ctx
, GL_INVALID_ENUM
, "glPolygonMode(mode)");
182 if (ctx
->API
== API_OPENGL_CORE
) {
183 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(face)" );
186 if (ctx
->Polygon
.FrontMode
== mode
)
188 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonState
? 0 : _NEW_POLYGON
);
189 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonState
;
190 ctx
->Polygon
.FrontMode
= mode
;
192 case GL_FRONT_AND_BACK
:
193 if (ctx
->Polygon
.FrontMode
== mode
&& ctx
->Polygon
.BackMode
== mode
)
195 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonState
? 0 : _NEW_POLYGON
);
196 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonState
;
197 ctx
->Polygon
.FrontMode
= mode
;
198 ctx
->Polygon
.BackMode
= mode
;
201 if (ctx
->API
== API_OPENGL_CORE
) {
202 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(face)" );
205 if (ctx
->Polygon
.BackMode
== mode
)
207 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonState
? 0 : _NEW_POLYGON
);
208 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonState
;
209 ctx
->Polygon
.BackMode
= mode
;
212 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(face)" );
216 if (ctx
->Driver
.PolygonMode
)
217 ctx
->Driver
.PolygonMode(ctx
, face
, mode
);
222 * Called by glPolygonStipple.
225 _mesa_PolygonStipple(const GLubyte
*pattern
)
227 GET_CURRENT_CONTEXT(ctx
);
229 if (MESA_VERBOSE
& VERBOSE_API
)
230 _mesa_debug(ctx
, "glPolygonStipple\n");
232 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonStipple
? 0 :
233 _NEW_POLYGONSTIPPLE
);
234 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonStipple
;
236 pattern
= _mesa_map_validate_pbo_source(ctx
, 2,
237 &ctx
->Unpack
, 32, 32, 1,
238 GL_COLOR_INDEX
, GL_BITMAP
,
244 _mesa_unpack_polygon_stipple(pattern
, ctx
->PolygonStipple
, &ctx
->Unpack
);
246 _mesa_unmap_pbo_source(ctx
, &ctx
->Unpack
);
248 if (ctx
->Driver
.PolygonStipple
)
249 ctx
->Driver
.PolygonStipple(ctx
, pattern
);
254 * Called by glPolygonStipple.
257 _mesa_GetnPolygonStippleARB( GLsizei bufSize
, GLubyte
*dest
)
259 GET_CURRENT_CONTEXT(ctx
);
261 if (MESA_VERBOSE
&VERBOSE_API
)
262 _mesa_debug(ctx
, "glGetPolygonStipple\n");
264 dest
= _mesa_map_validate_pbo_dest(ctx
, 2,
265 &ctx
->Pack
, 32, 32, 1,
266 GL_COLOR_INDEX
, GL_BITMAP
,
267 bufSize
, dest
, "glGetPolygonStipple");
271 _mesa_pack_polygon_stipple(ctx
->PolygonStipple
, dest
, &ctx
->Pack
);
273 _mesa_unmap_pbo_dest(ctx
, &ctx
->Pack
);
278 _mesa_GetPolygonStipple( GLubyte
*dest
)
280 _mesa_GetnPolygonStippleARB(INT_MAX
, dest
);
284 _mesa_polygon_offset_clamp(struct gl_context
*ctx
,
285 GLfloat factor
, GLfloat units
, GLfloat clamp
)
287 if (ctx
->Polygon
.OffsetFactor
== factor
&&
288 ctx
->Polygon
.OffsetUnits
== units
&&
289 ctx
->Polygon
.OffsetClamp
== clamp
)
292 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonState
? 0 : _NEW_POLYGON
);
293 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonState
;
294 ctx
->Polygon
.OffsetFactor
= factor
;
295 ctx
->Polygon
.OffsetUnits
= units
;
296 ctx
->Polygon
.OffsetClamp
= clamp
;
298 if (ctx
->Driver
.PolygonOffset
)
299 ctx
->Driver
.PolygonOffset( ctx
, factor
, units
, clamp
);
303 _mesa_PolygonOffset( GLfloat factor
, GLfloat units
)
305 GET_CURRENT_CONTEXT(ctx
);
307 if (MESA_VERBOSE
&VERBOSE_API
)
308 _mesa_debug(ctx
, "glPolygonOffset %f %f\n", factor
, units
);
310 _mesa_polygon_offset_clamp(ctx
, factor
, units
, 0.0);
315 _mesa_PolygonOffsetEXT( GLfloat factor
, GLfloat bias
)
317 GET_CURRENT_CONTEXT(ctx
);
318 /* XXX mult by DepthMaxF here??? */
319 _mesa_PolygonOffset(factor
, bias
* ctx
->DrawBuffer
->_DepthMaxF
);
323 _mesa_PolygonOffsetClampEXT( GLfloat factor
, GLfloat units
, GLfloat clamp
)
325 GET_CURRENT_CONTEXT(ctx
);
327 if (!ctx
->Extensions
.EXT_polygon_offset_clamp
) {
328 _mesa_error(ctx
, GL_INVALID_OPERATION
,
329 "unsupported function (glPolygonOffsetClampEXT) called");
333 if (MESA_VERBOSE
&VERBOSE_API
)
334 _mesa_debug(ctx
, "glPolygonOffsetClampEXT %f %f %f\n", factor
, units
, clamp
);
336 _mesa_polygon_offset_clamp(ctx
, factor
, units
, clamp
);
341 /**********************************************************************/
342 /** \name Initialization */
346 * Initialize the context polygon state.
348 * \param ctx GL context.
350 * Initializes __struct gl_contextRec::Polygon and __struct gl_contextRec::PolygonStipple
353 void _mesa_init_polygon( struct gl_context
* ctx
)
356 ctx
->Polygon
.CullFlag
= GL_FALSE
;
357 ctx
->Polygon
.CullFaceMode
= GL_BACK
;
358 ctx
->Polygon
.FrontFace
= GL_CCW
;
359 ctx
->Polygon
.FrontMode
= GL_FILL
;
360 ctx
->Polygon
.BackMode
= GL_FILL
;
361 ctx
->Polygon
.SmoothFlag
= GL_FALSE
;
362 ctx
->Polygon
.StippleFlag
= GL_FALSE
;
363 ctx
->Polygon
.OffsetFactor
= 0.0F
;
364 ctx
->Polygon
.OffsetUnits
= 0.0F
;
365 ctx
->Polygon
.OffsetClamp
= 0.0F
;
366 ctx
->Polygon
.OffsetPoint
= GL_FALSE
;
367 ctx
->Polygon
.OffsetLine
= GL_FALSE
;
368 ctx
->Polygon
.OffsetFill
= GL_FALSE
;
371 /* Polygon Stipple group */
372 memset( ctx
->PolygonStipple
, 0xff, 32*sizeof(GLuint
) );