1 /* $Id: polygon.c,v 1.23 2002/06/15 02:38:16 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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.
44 _mesa_CullFace( GLenum mode
)
46 GET_CURRENT_CONTEXT(ctx
);
47 ASSERT_OUTSIDE_BEGIN_END(ctx
);
49 if (MESA_VERBOSE
&VERBOSE_API
)
50 _mesa_debug(ctx
, "glCullFace %s\n", _mesa_lookup_enum_by_nr(mode
));
52 if (mode
!=GL_FRONT
&& mode
!=GL_BACK
&& mode
!=GL_FRONT_AND_BACK
) {
53 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCullFace" );
57 if (ctx
->Polygon
.CullFaceMode
== mode
)
60 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
61 ctx
->Polygon
.CullFaceMode
= mode
;
63 if (ctx
->Driver
.CullFace
)
64 ctx
->Driver
.CullFace( ctx
, mode
);
70 _mesa_FrontFace( GLenum mode
)
72 GET_CURRENT_CONTEXT(ctx
);
73 ASSERT_OUTSIDE_BEGIN_END(ctx
);
75 if (MESA_VERBOSE
&VERBOSE_API
)
76 _mesa_debug(ctx
, "glFrontFace %s\n", _mesa_lookup_enum_by_nr(mode
));
78 if (mode
!=GL_CW
&& mode
!=GL_CCW
) {
79 _mesa_error( ctx
, GL_INVALID_ENUM
, "glFrontFace" );
83 if (ctx
->Polygon
.FrontFace
== mode
)
86 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
87 ctx
->Polygon
.FrontFace
= mode
;
89 ctx
->Polygon
._FrontBit
= (GLboolean
) (mode
== GL_CW
);
91 if (ctx
->Driver
.FrontFace
)
92 ctx
->Driver
.FrontFace( ctx
, mode
);
98 _mesa_PolygonMode( GLenum face
, GLenum mode
)
100 GET_CURRENT_CONTEXT(ctx
);
101 ASSERT_OUTSIDE_BEGIN_END(ctx
);
103 if (MESA_VERBOSE
&VERBOSE_API
)
104 _mesa_debug(ctx
, "glPolygonMode %s %s\n",
105 _mesa_lookup_enum_by_nr(face
),
106 _mesa_lookup_enum_by_nr(mode
));
108 if (mode
!=GL_POINT
&& mode
!=GL_LINE
&& mode
!=GL_FILL
) {
109 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(mode)" );
115 if (ctx
->Polygon
.FrontMode
== mode
)
117 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
118 ctx
->Polygon
.FrontMode
= mode
;
120 case GL_FRONT_AND_BACK
:
121 if (ctx
->Polygon
.FrontMode
== mode
&&
122 ctx
->Polygon
.BackMode
== mode
)
124 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
125 ctx
->Polygon
.FrontMode
= mode
;
126 ctx
->Polygon
.BackMode
= mode
;
129 if (ctx
->Polygon
.BackMode
== mode
)
131 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
132 ctx
->Polygon
.BackMode
= mode
;
135 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(face)" );
139 ctx
->_TriangleCaps
&= ~DD_TRI_UNFILLED
;
140 if (ctx
->Polygon
.FrontMode
!=GL_FILL
|| ctx
->Polygon
.BackMode
!=GL_FILL
)
141 ctx
->_TriangleCaps
|= DD_TRI_UNFILLED
;
143 if (ctx
->Driver
.PolygonMode
) {
144 (*ctx
->Driver
.PolygonMode
)( ctx
, face
, mode
);
151 _mesa_PolygonStipple( const GLubyte
*pattern
)
153 GET_CURRENT_CONTEXT(ctx
);
154 ASSERT_OUTSIDE_BEGIN_END(ctx
);
156 if (MESA_VERBOSE
&VERBOSE_API
)
157 _mesa_debug(ctx
, "glPolygonStipple\n");
159 FLUSH_VERTICES(ctx
, _NEW_POLYGONSTIPPLE
);
160 _mesa_unpack_polygon_stipple(pattern
, ctx
->PolygonStipple
, &ctx
->Unpack
);
162 if (ctx
->Driver
.PolygonStipple
)
163 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) ctx
->PolygonStipple
);
169 _mesa_GetPolygonStipple( GLubyte
*dest
)
171 GET_CURRENT_CONTEXT(ctx
);
172 ASSERT_OUTSIDE_BEGIN_END(ctx
);
174 if (MESA_VERBOSE
&VERBOSE_API
)
175 _mesa_debug(ctx
, "glGetPolygonStipple\n");
177 _mesa_pack_polygon_stipple(ctx
->PolygonStipple
, dest
, &ctx
->Pack
);
183 _mesa_PolygonOffset( GLfloat factor
, GLfloat units
)
185 GET_CURRENT_CONTEXT(ctx
);
186 ASSERT_OUTSIDE_BEGIN_END(ctx
);
188 if (MESA_VERBOSE
&VERBOSE_API
)
189 _mesa_debug(ctx
, "glPolygonOffset %f %f\n", factor
, units
);
191 if (ctx
->Polygon
.OffsetFactor
== factor
&&
192 ctx
->Polygon
.OffsetUnits
== units
)
195 FLUSH_VERTICES(ctx
, _NEW_POLYGON
);
196 ctx
->Polygon
.OffsetFactor
= factor
;
197 ctx
->Polygon
.OffsetUnits
= units
;
198 ctx
->Polygon
.OffsetMRD
= units
* ctx
->MRD
;
200 if (ctx
->Driver
.PolygonOffset
)
201 ctx
->Driver
.PolygonOffset( ctx
, factor
, units
);
207 _mesa_PolygonOffsetEXT( GLfloat factor
, GLfloat bias
)
209 GET_CURRENT_CONTEXT(ctx
);
210 _mesa_PolygonOffset(factor
, bias
* ctx
->DepthMaxF
);