1 /* $Id: polygon.c,v 1.25 2002/10/24 23:57:21 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 _mesa_CullFace( GLenum mode
)
41 GET_CURRENT_CONTEXT(ctx
);
42 ASSERT_OUTSIDE_BEGIN_END(ctx
);
44 if (MESA_VERBOSE
&VERBOSE_API
)
45 _mesa_debug(ctx
, "glCullFace %s\n", _mesa_lookup_enum_by_nr(mode
));
47 if (mode
!=GL_FRONT
&& mode
!=GL_BACK
&& mode
!=GL_FRONT_AND_BACK
) {
48 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCullFace" );
52 if (ctx
->Polygon
.CullFaceMode
== mode
)
55 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
56 ctx
->Polygon
.CullFaceMode
= mode
;
58 if (ctx
->Driver
.CullFace
)
59 ctx
->Driver
.CullFace( ctx
, mode
);
65 _mesa_FrontFace( GLenum mode
)
67 GET_CURRENT_CONTEXT(ctx
);
68 ASSERT_OUTSIDE_BEGIN_END(ctx
);
70 if (MESA_VERBOSE
&VERBOSE_API
)
71 _mesa_debug(ctx
, "glFrontFace %s\n", _mesa_lookup_enum_by_nr(mode
));
73 if (mode
!=GL_CW
&& mode
!=GL_CCW
) {
74 _mesa_error( ctx
, GL_INVALID_ENUM
, "glFrontFace" );
78 if (ctx
->Polygon
.FrontFace
== mode
)
81 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
82 ctx
->Polygon
.FrontFace
= mode
;
84 ctx
->Polygon
._FrontBit
= (GLboolean
) (mode
== GL_CW
);
86 if (ctx
->Driver
.FrontFace
)
87 ctx
->Driver
.FrontFace( ctx
, mode
);
93 _mesa_PolygonMode( GLenum face
, GLenum mode
)
95 GET_CURRENT_CONTEXT(ctx
);
96 ASSERT_OUTSIDE_BEGIN_END(ctx
);
98 if (MESA_VERBOSE
&VERBOSE_API
)
99 _mesa_debug(ctx
, "glPolygonMode %s %s\n",
100 _mesa_lookup_enum_by_nr(face
),
101 _mesa_lookup_enum_by_nr(mode
));
103 if (mode
!=GL_POINT
&& mode
!=GL_LINE
&& mode
!=GL_FILL
) {
104 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(mode)" );
110 if (ctx
->Polygon
.FrontMode
== mode
)
112 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
113 ctx
->Polygon
.FrontMode
= mode
;
115 case GL_FRONT_AND_BACK
:
116 if (ctx
->Polygon
.FrontMode
== mode
&&
117 ctx
->Polygon
.BackMode
== mode
)
119 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
120 ctx
->Polygon
.FrontMode
= mode
;
121 ctx
->Polygon
.BackMode
= mode
;
124 if (ctx
->Polygon
.BackMode
== mode
)
126 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
127 ctx
->Polygon
.BackMode
= mode
;
130 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(face)" );
134 ctx
->_TriangleCaps
&= ~DD_TRI_UNFILLED
;
135 if (ctx
->Polygon
.FrontMode
!=GL_FILL
|| ctx
->Polygon
.BackMode
!=GL_FILL
)
136 ctx
->_TriangleCaps
|= DD_TRI_UNFILLED
;
138 if (ctx
->Driver
.PolygonMode
) {
139 (*ctx
->Driver
.PolygonMode
)( ctx
, face
, mode
);
146 _mesa_PolygonStipple( const GLubyte
*pattern
)
148 GET_CURRENT_CONTEXT(ctx
);
149 ASSERT_OUTSIDE_BEGIN_END(ctx
);
151 if (MESA_VERBOSE
&VERBOSE_API
)
152 _mesa_debug(ctx
, "glPolygonStipple\n");
154 FLUSH_VERTICES(ctx
, _NEW_POLYGONSTIPPLE
);
155 _mesa_unpack_polygon_stipple(pattern
, ctx
->PolygonStipple
, &ctx
->Unpack
);
157 if (ctx
->Driver
.PolygonStipple
)
158 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) ctx
->PolygonStipple
);
164 _mesa_GetPolygonStipple( GLubyte
*dest
)
166 GET_CURRENT_CONTEXT(ctx
);
167 ASSERT_OUTSIDE_BEGIN_END(ctx
);
169 if (MESA_VERBOSE
&VERBOSE_API
)
170 _mesa_debug(ctx
, "glGetPolygonStipple\n");
172 _mesa_pack_polygon_stipple(ctx
->PolygonStipple
, dest
, &ctx
->Pack
);
178 _mesa_PolygonOffset( GLfloat factor
, GLfloat units
)
180 GET_CURRENT_CONTEXT(ctx
);
181 ASSERT_OUTSIDE_BEGIN_END(ctx
);
183 if (MESA_VERBOSE
&VERBOSE_API
)
184 _mesa_debug(ctx
, "glPolygonOffset %f %f\n", factor
, units
);
186 if (ctx
->Polygon
.OffsetFactor
== factor
&&
187 ctx
->Polygon
.OffsetUnits
== units
)
190 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
191 ctx
->Polygon
.OffsetFactor
= factor
;
192 ctx
->Polygon
.OffsetUnits
= units
;
194 if (ctx
->Driver
.PolygonOffset
)
195 ctx
->Driver
.PolygonOffset( ctx
, factor
, units
);
201 _mesa_PolygonOffsetEXT( GLfloat factor
, GLfloat bias
)
203 GET_CURRENT_CONTEXT(ctx
);
204 _mesa_PolygonOffset(factor
, bias
* ctx
->DepthMaxF
);