970020048dbdd665d884dc2a4756474c9993671b
7 * Mesa 3-D graphics library
10 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
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:
19 * The above copyright notice and this permission notice shall be included
20 * in all copies or substantial portions of the Software.
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 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #include "bufferobj.h"
42 * Specify whether to cull front- or back-facing facets.
44 * \param mode culling mode.
48 * Verifies the parameter and updates gl_polygon_attrib::CullFaceMode. On
49 * change, flushes the vertices and notifies the driver via
50 * the dd_function_table::CullFace callback.
53 _mesa_CullFace( GLenum mode
)
55 GET_CURRENT_CONTEXT(ctx
);
56 ASSERT_OUTSIDE_BEGIN_END(ctx
);
58 if (MESA_VERBOSE
&VERBOSE_API
)
59 _mesa_debug(ctx
, "glCullFace %s\n", _mesa_lookup_enum_by_nr(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
);
92 ASSERT_OUTSIDE_BEGIN_END(ctx
);
94 if (MESA_VERBOSE
&VERBOSE_API
)
95 _mesa_debug(ctx
, "glFrontFace %s\n", _mesa_lookup_enum_by_nr(mode
));
97 if (mode
!=GL_CW
&& mode
!=GL_CCW
) {
98 _mesa_error( ctx
, GL_INVALID_ENUM
, "glFrontFace" );
102 if (ctx
->Polygon
.FrontFace
== mode
)
105 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
106 ctx
->Polygon
.FrontFace
= mode
;
108 ctx
->Polygon
._FrontBit
= (GLboolean
) (mode
== GL_CW
);
110 if (ctx
->Driver
.FrontFace
)
111 ctx
->Driver
.FrontFace( ctx
, mode
);
116 * Set the polygon rasterization mode.
118 * \param face the polygons which \p mode applies to.
119 * \param mode how polygons should be rasterized.
121 * \sa glPolygonMode().
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.
128 _mesa_PolygonMode( GLenum face
, GLenum mode
)
130 GET_CURRENT_CONTEXT(ctx
);
131 ASSERT_OUTSIDE_BEGIN_END(ctx
);
133 if (MESA_VERBOSE
&VERBOSE_API
)
134 _mesa_debug(ctx
, "glPolygonMode %s %s\n",
135 _mesa_lookup_enum_by_nr(face
),
136 _mesa_lookup_enum_by_nr(mode
));
138 if (mode
!=GL_POINT
&& mode
!=GL_LINE
&& mode
!=GL_FILL
) {
139 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(mode)" );
145 if (ctx
->Polygon
.FrontMode
== mode
)
147 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
148 ctx
->Polygon
.FrontMode
= mode
;
150 case GL_FRONT_AND_BACK
:
151 if (ctx
->Polygon
.FrontMode
== mode
&&
152 ctx
->Polygon
.BackMode
== mode
)
154 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
155 ctx
->Polygon
.FrontMode
= mode
;
156 ctx
->Polygon
.BackMode
= mode
;
159 if (ctx
->Polygon
.BackMode
== mode
)
161 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
162 ctx
->Polygon
.BackMode
= mode
;
165 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(face)" );
169 if (ctx
->Polygon
.FrontMode
== GL_FILL
&& ctx
->Polygon
.BackMode
== GL_FILL
)
170 ctx
->_TriangleCaps
&= ~DD_TRI_UNFILLED
;
172 ctx
->_TriangleCaps
|= DD_TRI_UNFILLED
;
174 if (ctx
->Driver
.PolygonMode
)
175 ctx
->Driver
.PolygonMode(ctx
, face
, mode
);
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
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
193 _mesa_polygon_stipple(struct gl_context
*ctx
, const GLubyte
*pattern
)
195 pattern
= _mesa_map_validate_pbo_source(ctx
, 2,
196 &ctx
->Unpack
, 32, 32, 1,
197 GL_COLOR_INDEX
, GL_BITMAP
, pattern
,
202 _mesa_unpack_polygon_stipple(pattern
, ctx
->PolygonStipple
, &ctx
->Unpack
);
204 _mesa_unmap_pbo_source(ctx
, &ctx
->Unpack
);
209 * Called by glPolygonStipple.
212 _mesa_PolygonStipple( const GLubyte
*pattern
)
214 GET_CURRENT_CONTEXT(ctx
);
215 ASSERT_OUTSIDE_BEGIN_END(ctx
);
217 if (MESA_VERBOSE
&VERBOSE_API
)
218 _mesa_debug(ctx
, "glPolygonStipple\n");
220 FLUSH_VERTICES(ctx
, _NEW_POLYGONSTIPPLE
);
222 _mesa_polygon_stipple(ctx
, pattern
);
224 if (ctx
->Driver
.PolygonStipple
)
225 ctx
->Driver
.PolygonStipple(ctx
, pattern
);
230 * Called by glPolygonStipple.
233 _mesa_GetPolygonStipple( GLubyte
*dest
)
235 GET_CURRENT_CONTEXT(ctx
);
236 ASSERT_OUTSIDE_BEGIN_END(ctx
);
238 if (MESA_VERBOSE
&VERBOSE_API
)
239 _mesa_debug(ctx
, "glGetPolygonStipple\n");
241 dest
= _mesa_map_validate_pbo_dest(ctx
, 2,
242 &ctx
->Pack
, 32, 32, 1,
243 GL_COLOR_INDEX
, GL_BITMAP
, dest
,
244 "glGetPolygonStipple");
248 _mesa_pack_polygon_stipple(ctx
->PolygonStipple
, dest
, &ctx
->Pack
);
250 _mesa_unmap_pbo_dest(ctx
, &ctx
->Pack
);
255 _mesa_PolygonOffset( GLfloat factor
, GLfloat units
)
257 GET_CURRENT_CONTEXT(ctx
);
258 ASSERT_OUTSIDE_BEGIN_END(ctx
);
260 if (MESA_VERBOSE
&VERBOSE_API
)
261 _mesa_debug(ctx
, "glPolygonOffset %f %f\n", factor
, units
);
263 if (ctx
->Polygon
.OffsetFactor
== factor
&&
264 ctx
->Polygon
.OffsetUnits
== units
)
267 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
268 ctx
->Polygon
.OffsetFactor
= factor
;
269 ctx
->Polygon
.OffsetUnits
= units
;
271 if (ctx
->Driver
.PolygonOffset
)
272 ctx
->Driver
.PolygonOffset( ctx
, factor
, units
);
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
);
287 /**********************************************************************/
288 /** \name Initialization */
292 * Initialize the context polygon state.
294 * \param ctx GL context.
296 * Initializes __struct gl_contextRec::Polygon and __struct gl_contextRec::PolygonStipple
299 void _mesa_init_polygon( struct gl_context
* ctx
)
302 ctx
->Polygon
.CullFlag
= GL_FALSE
;
303 ctx
->Polygon
.CullFaceMode
= GL_BACK
;
304 ctx
->Polygon
.FrontFace
= GL_CCW
;
305 ctx
->Polygon
._FrontBit
= 0;
306 ctx
->Polygon
.FrontMode
= GL_FILL
;
307 ctx
->Polygon
.BackMode
= GL_FILL
;
308 ctx
->Polygon
.SmoothFlag
= GL_FALSE
;
309 ctx
->Polygon
.StippleFlag
= GL_FALSE
;
310 ctx
->Polygon
.OffsetFactor
= 0.0F
;
311 ctx
->Polygon
.OffsetUnits
= 0.0F
;
312 ctx
->Polygon
.OffsetPoint
= GL_FALSE
;
313 ctx
->Polygon
.OffsetLine
= GL_FALSE
;
314 ctx
->Polygon
.OffsetFill
= GL_FALSE
;
317 /* Polygon Stipple group */
318 memset( ctx
->PolygonStipple
, 0xff, 32*sizeof(GLuint
) );