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.
53 static ALWAYS_INLINE
void
54 cull_face(struct gl_context
*ctx
, GLenum mode
, bool no_error
)
56 if (ctx
->Polygon
.CullFaceMode
== mode
)
60 mode
!= GL_FRONT
&& mode
!= GL_BACK
&& mode
!= GL_FRONT_AND_BACK
) {
61 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCullFace");
65 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonState
? 0 : _NEW_POLYGON
);
66 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonState
;
67 ctx
->Polygon
.CullFaceMode
= mode
;
69 if (ctx
->Driver
.CullFace
)
70 ctx
->Driver
.CullFace(ctx
, mode
);
75 _mesa_CullFace_no_error(GLenum mode
)
77 GET_CURRENT_CONTEXT(ctx
);
78 cull_face(ctx
, mode
, true);
83 _mesa_CullFace(GLenum mode
)
85 GET_CURRENT_CONTEXT(ctx
);
87 if (MESA_VERBOSE
& VERBOSE_API
)
88 _mesa_debug(ctx
, "glCullFace %s\n", _mesa_enum_to_string(mode
));
90 cull_face(ctx
, mode
, false);
95 * Define front- and back-facing
97 * \param mode orientation of front-facing polygons.
101 * Verifies the parameter and updates gl_polygon_attrib::FrontFace. On change
102 * flushes the vertices and notifies the driver via
103 * the dd_function_table::FrontFace callback.
105 static ALWAYS_INLINE
void
106 front_face(struct gl_context
*ctx
, GLenum mode
, bool no_error
)
108 if (ctx
->Polygon
.FrontFace
== mode
)
111 if (!no_error
&& mode
!= GL_CW
&& mode
!= GL_CCW
) {
112 _mesa_error(ctx
, GL_INVALID_ENUM
, "glFrontFace");
116 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonState
? 0 : _NEW_POLYGON
);
117 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonState
;
118 ctx
->Polygon
.FrontFace
= mode
;
120 if (ctx
->Driver
.FrontFace
)
121 ctx
->Driver
.FrontFace(ctx
, mode
);
126 _mesa_FrontFace_no_error(GLenum mode
)
128 GET_CURRENT_CONTEXT(ctx
);
129 front_face(ctx
, mode
, true);
134 _mesa_FrontFace(GLenum mode
)
136 GET_CURRENT_CONTEXT(ctx
);
138 if (MESA_VERBOSE
& VERBOSE_API
)
139 _mesa_debug(ctx
, "glFrontFace %s\n", _mesa_enum_to_string(mode
));
141 front_face(ctx
, mode
, false);
146 * Set the polygon rasterization mode.
148 * \param face the polygons which \p mode applies to.
149 * \param mode how polygons should be rasterized.
151 * \sa glPolygonMode().
153 * Verifies the parameters and updates gl_polygon_attrib::FrontMode and
154 * gl_polygon_attrib::BackMode. On change flushes the vertices and notifies the
155 * driver via the dd_function_table::PolygonMode callback.
157 static ALWAYS_INLINE
void
158 polygon_mode(struct gl_context
*ctx
, GLenum face
, GLenum mode
, bool no_error
)
160 if (MESA_VERBOSE
& VERBOSE_API
)
161 _mesa_debug(ctx
, "glPolygonMode %s %s\n",
162 _mesa_enum_to_string(face
),
163 _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)");
183 if (!no_error
&& ctx
->API
== API_OPENGL_CORE
) {
184 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(face)" );
187 if (ctx
->Polygon
.FrontMode
== mode
)
189 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonState
? 0 : _NEW_POLYGON
);
190 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonState
;
191 ctx
->Polygon
.FrontMode
= mode
;
193 case GL_FRONT_AND_BACK
:
194 if (ctx
->Polygon
.FrontMode
== mode
&& ctx
->Polygon
.BackMode
== mode
)
196 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonState
? 0 : _NEW_POLYGON
);
197 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonState
;
198 ctx
->Polygon
.FrontMode
= mode
;
199 ctx
->Polygon
.BackMode
= mode
;
202 if (!no_error
&& ctx
->API
== API_OPENGL_CORE
) {
203 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(face)" );
206 if (ctx
->Polygon
.BackMode
== mode
)
208 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonState
? 0 : _NEW_POLYGON
);
209 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonState
;
210 ctx
->Polygon
.BackMode
= mode
;
214 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(face)" );
218 if (ctx
->Driver
.PolygonMode
)
219 ctx
->Driver
.PolygonMode(ctx
, face
, mode
);
224 _mesa_PolygonMode_no_error(GLenum face
, GLenum mode
)
226 GET_CURRENT_CONTEXT(ctx
);
227 polygon_mode(ctx
, face
, mode
, true);
232 _mesa_PolygonMode(GLenum face
, GLenum mode
)
234 GET_CURRENT_CONTEXT(ctx
);
235 polygon_mode(ctx
, face
, mode
, false);
240 * Called by glPolygonStipple.
243 _mesa_PolygonStipple(const GLubyte
*pattern
)
245 GET_CURRENT_CONTEXT(ctx
);
247 if (MESA_VERBOSE
& VERBOSE_API
)
248 _mesa_debug(ctx
, "glPolygonStipple\n");
250 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonStipple
? 0 :
251 _NEW_POLYGONSTIPPLE
);
252 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonStipple
;
254 pattern
= _mesa_map_validate_pbo_source(ctx
, 2,
255 &ctx
->Unpack
, 32, 32, 1,
256 GL_COLOR_INDEX
, GL_BITMAP
,
262 _mesa_unpack_polygon_stipple(pattern
, ctx
->PolygonStipple
, &ctx
->Unpack
);
264 _mesa_unmap_pbo_source(ctx
, &ctx
->Unpack
);
266 if (ctx
->Driver
.PolygonStipple
)
267 ctx
->Driver
.PolygonStipple(ctx
, pattern
);
272 * Called by glPolygonStipple.
275 _mesa_GetnPolygonStippleARB( GLsizei bufSize
, GLubyte
*dest
)
277 GET_CURRENT_CONTEXT(ctx
);
279 if (MESA_VERBOSE
&VERBOSE_API
)
280 _mesa_debug(ctx
, "glGetPolygonStipple\n");
282 dest
= _mesa_map_validate_pbo_dest(ctx
, 2,
283 &ctx
->Pack
, 32, 32, 1,
284 GL_COLOR_INDEX
, GL_BITMAP
,
285 bufSize
, dest
, "glGetPolygonStipple");
289 _mesa_pack_polygon_stipple(ctx
->PolygonStipple
, dest
, &ctx
->Pack
);
291 _mesa_unmap_pbo_dest(ctx
, &ctx
->Pack
);
296 _mesa_GetPolygonStipple( GLubyte
*dest
)
298 _mesa_GetnPolygonStippleARB(INT_MAX
, dest
);
302 _mesa_polygon_offset_clamp(struct gl_context
*ctx
,
303 GLfloat factor
, GLfloat units
, GLfloat clamp
)
305 if (ctx
->Polygon
.OffsetFactor
== factor
&&
306 ctx
->Polygon
.OffsetUnits
== units
&&
307 ctx
->Polygon
.OffsetClamp
== clamp
)
310 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonState
? 0 : _NEW_POLYGON
);
311 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonState
;
312 ctx
->Polygon
.OffsetFactor
= factor
;
313 ctx
->Polygon
.OffsetUnits
= units
;
314 ctx
->Polygon
.OffsetClamp
= clamp
;
316 if (ctx
->Driver
.PolygonOffset
)
317 ctx
->Driver
.PolygonOffset( ctx
, factor
, units
, clamp
);
321 _mesa_PolygonOffset( GLfloat factor
, GLfloat units
)
323 GET_CURRENT_CONTEXT(ctx
);
325 if (MESA_VERBOSE
&VERBOSE_API
)
326 _mesa_debug(ctx
, "glPolygonOffset %f %f\n", factor
, units
);
328 _mesa_polygon_offset_clamp(ctx
, factor
, units
, 0.0);
332 _mesa_PolygonOffsetEXT( GLfloat factor
, GLfloat bias
)
334 GET_CURRENT_CONTEXT(ctx
);
335 /* XXX mult by DepthMaxF here??? */
336 _mesa_PolygonOffset(factor
, bias
* ctx
->DrawBuffer
->_DepthMaxF
);
340 _mesa_PolygonOffsetClampEXT( GLfloat factor
, GLfloat units
, GLfloat clamp
)
342 GET_CURRENT_CONTEXT(ctx
);
344 if (!ctx
->Extensions
.ARB_polygon_offset_clamp
) {
345 _mesa_error(ctx
, GL_INVALID_OPERATION
,
346 "unsupported function (%s) called", "glPolygonOffsetClamp");
350 if (MESA_VERBOSE
&VERBOSE_API
)
351 _mesa_debug(ctx
, "glPolygonOffsetClamp %f %f %f\n", factor
, units
, clamp
);
353 _mesa_polygon_offset_clamp(ctx
, factor
, units
, clamp
);
356 /**********************************************************************/
357 /** \name Initialization */
361 * Initialize the context polygon state.
363 * \param ctx GL context.
365 * Initializes __struct gl_contextRec::Polygon and __struct gl_contextRec::PolygonStipple
368 void _mesa_init_polygon( struct gl_context
* ctx
)
371 ctx
->Polygon
.CullFlag
= GL_FALSE
;
372 ctx
->Polygon
.CullFaceMode
= GL_BACK
;
373 ctx
->Polygon
.FrontFace
= GL_CCW
;
374 ctx
->Polygon
.FrontMode
= GL_FILL
;
375 ctx
->Polygon
.BackMode
= GL_FILL
;
376 ctx
->Polygon
.SmoothFlag
= GL_FALSE
;
377 ctx
->Polygon
.StippleFlag
= GL_FALSE
;
378 ctx
->Polygon
.OffsetFactor
= 0.0F
;
379 ctx
->Polygon
.OffsetUnits
= 0.0F
;
380 ctx
->Polygon
.OffsetClamp
= 0.0F
;
381 ctx
->Polygon
.OffsetPoint
= GL_FALSE
;
382 ctx
->Polygon
.OffsetLine
= GL_FALSE
;
383 ctx
->Polygon
.OffsetFill
= GL_FALSE
;
386 /* Polygon Stipple group */
387 memset( ctx
->PolygonStipple
, 0xff, 32*sizeof(GLuint
) );