49a60e8e533002d37297d2f179fc9d65e7f25612
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.
105 _mesa_FrontFace( GLenum mode
)
107 GET_CURRENT_CONTEXT(ctx
);
109 if (MESA_VERBOSE
&VERBOSE_API
)
110 _mesa_debug(ctx
, "glFrontFace %s\n", _mesa_enum_to_string(mode
));
112 if (ctx
->Polygon
.FrontFace
== mode
)
115 if (mode
!=GL_CW
&& mode
!=GL_CCW
) {
116 _mesa_error( ctx
, GL_INVALID_ENUM
, "glFrontFace" );
120 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonState
? 0 : _NEW_POLYGON
);
121 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonState
;
122 ctx
->Polygon
.FrontFace
= mode
;
124 if (ctx
->Driver
.FrontFace
)
125 ctx
->Driver
.FrontFace( ctx
, mode
);
130 * Set the polygon rasterization mode.
132 * \param face the polygons which \p mode applies to.
133 * \param mode how polygons should be rasterized.
135 * \sa glPolygonMode().
137 * Verifies the parameters and updates gl_polygon_attrib::FrontMode and
138 * gl_polygon_attrib::BackMode. On change flushes the vertices and notifies the
139 * driver via the dd_function_table::PolygonMode callback.
142 _mesa_PolygonMode( GLenum face
, GLenum mode
)
144 GET_CURRENT_CONTEXT(ctx
);
146 if (MESA_VERBOSE
&VERBOSE_API
)
147 _mesa_debug(ctx
, "glPolygonMode %s %s\n",
148 _mesa_enum_to_string(face
),
149 _mesa_enum_to_string(mode
));
156 case GL_FILL_RECTANGLE_NV
:
157 if (ctx
->Extensions
.NV_fill_rectangle
)
161 _mesa_error(ctx
, GL_INVALID_ENUM
, "glPolygonMode(mode)");
167 if (ctx
->API
== API_OPENGL_CORE
) {
168 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(face)" );
171 if (ctx
->Polygon
.FrontMode
== mode
)
173 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonState
? 0 : _NEW_POLYGON
);
174 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonState
;
175 ctx
->Polygon
.FrontMode
= mode
;
177 case GL_FRONT_AND_BACK
:
178 if (ctx
->Polygon
.FrontMode
== mode
&& ctx
->Polygon
.BackMode
== mode
)
180 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonState
? 0 : _NEW_POLYGON
);
181 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonState
;
182 ctx
->Polygon
.FrontMode
= mode
;
183 ctx
->Polygon
.BackMode
= mode
;
186 if (ctx
->API
== API_OPENGL_CORE
) {
187 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(face)" );
190 if (ctx
->Polygon
.BackMode
== mode
)
192 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonState
? 0 : _NEW_POLYGON
);
193 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonState
;
194 ctx
->Polygon
.BackMode
= mode
;
197 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(face)" );
201 if (ctx
->Driver
.PolygonMode
)
202 ctx
->Driver
.PolygonMode(ctx
, face
, mode
);
207 * Called by glPolygonStipple.
210 _mesa_PolygonStipple(const GLubyte
*pattern
)
212 GET_CURRENT_CONTEXT(ctx
);
214 if (MESA_VERBOSE
& VERBOSE_API
)
215 _mesa_debug(ctx
, "glPolygonStipple\n");
217 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonStipple
? 0 :
218 _NEW_POLYGONSTIPPLE
);
219 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonStipple
;
221 pattern
= _mesa_map_validate_pbo_source(ctx
, 2,
222 &ctx
->Unpack
, 32, 32, 1,
223 GL_COLOR_INDEX
, GL_BITMAP
,
229 _mesa_unpack_polygon_stipple(pattern
, ctx
->PolygonStipple
, &ctx
->Unpack
);
231 _mesa_unmap_pbo_source(ctx
, &ctx
->Unpack
);
233 if (ctx
->Driver
.PolygonStipple
)
234 ctx
->Driver
.PolygonStipple(ctx
, pattern
);
239 * Called by glPolygonStipple.
242 _mesa_GetnPolygonStippleARB( GLsizei bufSize
, GLubyte
*dest
)
244 GET_CURRENT_CONTEXT(ctx
);
246 if (MESA_VERBOSE
&VERBOSE_API
)
247 _mesa_debug(ctx
, "glGetPolygonStipple\n");
249 dest
= _mesa_map_validate_pbo_dest(ctx
, 2,
250 &ctx
->Pack
, 32, 32, 1,
251 GL_COLOR_INDEX
, GL_BITMAP
,
252 bufSize
, dest
, "glGetPolygonStipple");
256 _mesa_pack_polygon_stipple(ctx
->PolygonStipple
, dest
, &ctx
->Pack
);
258 _mesa_unmap_pbo_dest(ctx
, &ctx
->Pack
);
263 _mesa_GetPolygonStipple( GLubyte
*dest
)
265 _mesa_GetnPolygonStippleARB(INT_MAX
, dest
);
269 _mesa_polygon_offset_clamp(struct gl_context
*ctx
,
270 GLfloat factor
, GLfloat units
, GLfloat clamp
)
272 if (ctx
->Polygon
.OffsetFactor
== factor
&&
273 ctx
->Polygon
.OffsetUnits
== units
&&
274 ctx
->Polygon
.OffsetClamp
== clamp
)
277 FLUSH_VERTICES(ctx
, ctx
->DriverFlags
.NewPolygonState
? 0 : _NEW_POLYGON
);
278 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewPolygonState
;
279 ctx
->Polygon
.OffsetFactor
= factor
;
280 ctx
->Polygon
.OffsetUnits
= units
;
281 ctx
->Polygon
.OffsetClamp
= clamp
;
283 if (ctx
->Driver
.PolygonOffset
)
284 ctx
->Driver
.PolygonOffset( ctx
, factor
, units
, clamp
);
288 _mesa_PolygonOffset( GLfloat factor
, GLfloat units
)
290 GET_CURRENT_CONTEXT(ctx
);
292 if (MESA_VERBOSE
&VERBOSE_API
)
293 _mesa_debug(ctx
, "glPolygonOffset %f %f\n", factor
, units
);
295 _mesa_polygon_offset_clamp(ctx
, factor
, units
, 0.0);
300 _mesa_PolygonOffsetEXT( GLfloat factor
, GLfloat bias
)
302 GET_CURRENT_CONTEXT(ctx
);
303 /* XXX mult by DepthMaxF here??? */
304 _mesa_PolygonOffset(factor
, bias
* ctx
->DrawBuffer
->_DepthMaxF
);
308 _mesa_PolygonOffsetClampEXT( GLfloat factor
, GLfloat units
, GLfloat clamp
)
310 GET_CURRENT_CONTEXT(ctx
);
312 if (!ctx
->Extensions
.EXT_polygon_offset_clamp
) {
313 _mesa_error(ctx
, GL_INVALID_OPERATION
,
314 "unsupported function (glPolygonOffsetClampEXT) called");
318 if (MESA_VERBOSE
&VERBOSE_API
)
319 _mesa_debug(ctx
, "glPolygonOffsetClampEXT %f %f %f\n", factor
, units
, clamp
);
321 _mesa_polygon_offset_clamp(ctx
, factor
, units
, clamp
);
326 /**********************************************************************/
327 /** \name Initialization */
331 * Initialize the context polygon state.
333 * \param ctx GL context.
335 * Initializes __struct gl_contextRec::Polygon and __struct gl_contextRec::PolygonStipple
338 void _mesa_init_polygon( struct gl_context
* ctx
)
341 ctx
->Polygon
.CullFlag
= GL_FALSE
;
342 ctx
->Polygon
.CullFaceMode
= GL_BACK
;
343 ctx
->Polygon
.FrontFace
= GL_CCW
;
344 ctx
->Polygon
.FrontMode
= GL_FILL
;
345 ctx
->Polygon
.BackMode
= GL_FILL
;
346 ctx
->Polygon
.SmoothFlag
= GL_FALSE
;
347 ctx
->Polygon
.StippleFlag
= GL_FALSE
;
348 ctx
->Polygon
.OffsetFactor
= 0.0F
;
349 ctx
->Polygon
.OffsetUnits
= 0.0F
;
350 ctx
->Polygon
.OffsetClamp
= 0.0F
;
351 ctx
->Polygon
.OffsetPoint
= GL_FALSE
;
352 ctx
->Polygon
.OffsetLine
= GL_FALSE
;
353 ctx
->Polygon
.OffsetFill
= GL_FALSE
;
356 /* Polygon Stipple group */
357 memset( ctx
->PolygonStipple
, 0xff, 32*sizeof(GLuint
) );