1 /* $Id: polygon.c,v 1.7 1999/11/11 01:22:27 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 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 * NOTE: stipple pattern has already been unpacked.
139 _mesa_PolygonStipple( const GLubyte
*mask
)
141 GET_CURRENT_CONTEXT(ctx
);
142 GLuint
*pattern
= (GLuint
*) mask
; /* XXX verify */
143 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPolygonStipple");
145 if (MESA_VERBOSE
&VERBOSE_API
)
146 fprintf(stderr
, "glPolygonStipple\n");
148 MEMCPY( ctx
->PolygonStipple
, pattern
, 32 * 4 );
150 if (ctx
->Polygon
.StippleFlag
) {
151 ctx
->NewState
|= NEW_RASTER_OPS
;
158 _mesa_GetPolygonStipple( GLubyte
*dest
)
160 GET_CURRENT_CONTEXT(ctx
);
161 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPolygonOffset");
163 if (MESA_VERBOSE
&VERBOSE_API
)
164 fprintf(stderr
, "glGetPolygonStipple\n");
166 gl_pack_polygon_stipple( ctx
, ctx
->PolygonStipple
, dest
);
172 _mesa_PolygonOffset( GLfloat factor
, GLfloat units
)
174 GET_CURRENT_CONTEXT(ctx
);
175 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPolygonOffset");
177 if (MESA_VERBOSE
&VERBOSE_API
)
178 fprintf(stderr
, "glPolygonOffset %f %f\n", factor
, units
);
180 ctx
->Polygon
.OffsetFactor
= factor
;
181 ctx
->Polygon
.OffsetUnits
= units
;
186 _mesa_PolygonOffsetEXT( GLfloat factor
, GLfloat bias
)
188 _mesa_PolygonOffset(factor
, bias
* DEPTH_SCALE
);