5ca3ffbc9450b9eea3678ae1400b4e6f5d9dae99
1 /* $Id: polygon.c,v 1.12 2000/09/26 20:53:53 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 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_AND_FLUSH(ctx
, "glCullFace");
49 if (MESA_VERBOSE
&VERBOSE_API
)
50 fprintf(stderr
, "glCullFace %s\n", gl_lookup_enum_by_nr(mode
));
52 if (mode
!=GL_FRONT
&& mode
!=GL_BACK
&& mode
!=GL_FRONT_AND_BACK
) {
53 gl_error( ctx
, GL_INVALID_ENUM
, "glCullFace" );
57 ctx
->Polygon
.CullFaceMode
= mode
;
58 ctx
->NewState
|= NEW_POLYGON
;
60 if (ctx
->Driver
.CullFace
)
61 ctx
->Driver
.CullFace( ctx
, mode
);
67 _mesa_FrontFace( GLenum mode
)
69 GET_CURRENT_CONTEXT(ctx
);
70 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glFrontFace");
72 if (MESA_VERBOSE
&VERBOSE_API
)
73 fprintf(stderr
, "glFrontFace %s\n", gl_lookup_enum_by_nr(mode
));
75 if (mode
!=GL_CW
&& mode
!=GL_CCW
) {
76 gl_error( ctx
, GL_INVALID_ENUM
, "glFrontFace" );
80 ctx
->Polygon
.FrontFace
= mode
;
81 ctx
->Polygon
.FrontBit
= (GLboolean
) (mode
== GL_CW
);
82 ctx
->NewState
|= NEW_POLYGON
;
84 if (ctx
->Driver
.FrontFace
)
85 ctx
->Driver
.FrontFace( ctx
, mode
);
91 _mesa_PolygonMode( GLenum face
, GLenum mode
)
93 GET_CURRENT_CONTEXT(ctx
);
94 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPolygonMode");
96 if (MESA_VERBOSE
&VERBOSE_API
)
97 fprintf(stderr
, "glPolygonMode %s %s\n",
98 gl_lookup_enum_by_nr(face
),
99 gl_lookup_enum_by_nr(mode
));
101 if (face
!=GL_FRONT
&& face
!=GL_BACK
&& face
!=GL_FRONT_AND_BACK
) {
102 gl_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(face)" );
105 else if (mode
!=GL_POINT
&& mode
!=GL_LINE
&& mode
!=GL_FILL
) {
106 gl_error( ctx
, GL_INVALID_ENUM
, "glPolygonMode(mode)" );
110 if (face
==GL_FRONT
|| face
==GL_FRONT_AND_BACK
) {
111 ctx
->Polygon
.FrontMode
= mode
;
113 if (face
==GL_BACK
|| face
==GL_FRONT_AND_BACK
) {
114 ctx
->Polygon
.BackMode
= mode
;
117 /* Compute a handy "shortcut" value: */
118 ctx
->TriangleCaps
&= ~DD_TRI_UNFILLED
;
119 ctx
->Polygon
.Unfilled
= GL_FALSE
;
121 if (ctx
->Polygon
.FrontMode
!=GL_FILL
|| ctx
->Polygon
.BackMode
!=GL_FILL
) {
122 ctx
->Polygon
.Unfilled
= GL_TRUE
;
123 ctx
->TriangleCaps
|= DD_TRI_UNFILLED
;
126 ctx
->NewState
|= (NEW_POLYGON
| NEW_RASTER_OPS
);
128 if (ctx
->Driver
.PolygonMode
) {
129 (*ctx
->Driver
.PolygonMode
)( ctx
, face
, mode
);
136 _mesa_PolygonStipple( const GLubyte
*pattern
)
138 GET_CURRENT_CONTEXT(ctx
);
139 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPolygonStipple");
141 if (MESA_VERBOSE
&VERBOSE_API
)
142 fprintf(stderr
, "glPolygonStipple\n");
144 _mesa_unpack_polygon_stipple(pattern
, ctx
->PolygonStipple
, &ctx
->Unpack
);
146 if (ctx
->Polygon
.StippleFlag
) {
147 ctx
->NewState
|= NEW_RASTER_OPS
;
150 if (ctx
->Driver
.PolygonStipple
)
151 ctx
->Driver
.PolygonStipple( ctx
, (const GLubyte
*) ctx
->PolygonStipple
);
157 _mesa_GetPolygonStipple( GLubyte
*dest
)
159 GET_CURRENT_CONTEXT(ctx
);
160 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPolygonOffset");
162 if (MESA_VERBOSE
&VERBOSE_API
)
163 fprintf(stderr
, "glGetPolygonStipple\n");
165 _mesa_pack_polygon_stipple(ctx
->PolygonStipple
, dest
, &ctx
->Pack
);
171 _mesa_PolygonOffset( GLfloat factor
, GLfloat units
)
173 GET_CURRENT_CONTEXT(ctx
);
174 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPolygonOffset");
176 if (MESA_VERBOSE
&VERBOSE_API
)
177 fprintf(stderr
, "glPolygonOffset %f %f\n", factor
, units
);
179 ctx
->Polygon
.OffsetFactor
= factor
;
180 ctx
->Polygon
.OffsetUnits
= units
;
186 _mesa_PolygonOffsetEXT( GLfloat factor
, GLfloat bias
)
188 GET_CURRENT_CONTEXT(ctx
);
189 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPolygonOffsetEXT");
190 _mesa_PolygonOffset(factor
, bias
* ctx
->Visual
.DepthMaxF
);