f93ab1956656f9252d6911a4a2998068584f115b
[mesa.git] / src / mesa / main / polygon.c
1 /* $Id: polygon.c,v 1.7 1999/11/11 01:22:27 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.3
6 *
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 */
26
27
28 #ifdef PC_HEADER
29 #include "all.h"
30 #else
31 #include "glheader.h"
32 #include "context.h"
33 #include "image.h"
34 #include "enums.h"
35 #include "macros.h"
36 #include "mem.h"
37 #include "polygon.h"
38 #include "types.h"
39 #endif
40
41
42
43 void
44 _mesa_CullFace( GLenum mode )
45 {
46 GET_CURRENT_CONTEXT(ctx);
47 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCullFace");
48
49 if (MESA_VERBOSE&VERBOSE_API)
50 fprintf(stderr, "glCullFace %s\n", gl_lookup_enum_by_nr(mode));
51
52 if (mode!=GL_FRONT && mode!=GL_BACK && mode!=GL_FRONT_AND_BACK) {
53 gl_error( ctx, GL_INVALID_ENUM, "glCullFace" );
54 return;
55 }
56
57 ctx->Polygon.CullFaceMode = mode;
58 ctx->NewState |= NEW_POLYGON;
59
60 if (ctx->Driver.CullFace)
61 ctx->Driver.CullFace( ctx, mode );
62 }
63
64
65
66 void
67 _mesa_FrontFace( GLenum mode )
68 {
69 GET_CURRENT_CONTEXT(ctx);
70 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFrontFace");
71
72 if (MESA_VERBOSE&VERBOSE_API)
73 fprintf(stderr, "glFrontFace %s\n", gl_lookup_enum_by_nr(mode));
74
75 if (mode!=GL_CW && mode!=GL_CCW) {
76 gl_error( ctx, GL_INVALID_ENUM, "glFrontFace" );
77 return;
78 }
79
80 ctx->Polygon.FrontFace = mode;
81 ctx->Polygon.FrontBit = (GLboolean) (mode == GL_CW);
82 ctx->NewState |= NEW_POLYGON;
83
84 if (ctx->Driver.FrontFace)
85 ctx->Driver.FrontFace( ctx, mode );
86 }
87
88
89
90 void
91 _mesa_PolygonMode( GLenum face, GLenum mode )
92 {
93 GET_CURRENT_CONTEXT(ctx);
94 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonMode");
95
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));
100
101 if (face!=GL_FRONT && face!=GL_BACK && face!=GL_FRONT_AND_BACK) {
102 gl_error( ctx, GL_INVALID_ENUM, "glPolygonMode(face)" );
103 return;
104 }
105 else if (mode!=GL_POINT && mode!=GL_LINE && mode!=GL_FILL) {
106 gl_error( ctx, GL_INVALID_ENUM, "glPolygonMode(mode)" );
107 return;
108 }
109
110 if (face==GL_FRONT || face==GL_FRONT_AND_BACK) {
111 ctx->Polygon.FrontMode = mode;
112 }
113 if (face==GL_BACK || face==GL_FRONT_AND_BACK) {
114 ctx->Polygon.BackMode = mode;
115 }
116
117 /* Compute a handy "shortcut" value: */
118 ctx->TriangleCaps &= ~DD_TRI_UNFILLED;
119 ctx->Polygon.Unfilled = GL_FALSE;
120
121 if (ctx->Polygon.FrontMode!=GL_FILL || ctx->Polygon.BackMode!=GL_FILL) {
122 ctx->Polygon.Unfilled = GL_TRUE;
123 ctx->TriangleCaps |= DD_TRI_UNFILLED;
124 }
125
126 ctx->NewState |= (NEW_POLYGON | NEW_RASTER_OPS);
127
128 if (ctx->Driver.PolygonMode) {
129 (*ctx->Driver.PolygonMode)( ctx, face, mode );
130 }
131 }
132
133
134
135 /*
136 * NOTE: stipple pattern has already been unpacked.
137 */
138 void
139 _mesa_PolygonStipple( const GLubyte *mask )
140 {
141 GET_CURRENT_CONTEXT(ctx);
142 GLuint *pattern = (GLuint *) mask; /* XXX verify */
143 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonStipple");
144
145 if (MESA_VERBOSE&VERBOSE_API)
146 fprintf(stderr, "glPolygonStipple\n");
147
148 MEMCPY( ctx->PolygonStipple, pattern, 32 * 4 );
149
150 if (ctx->Polygon.StippleFlag) {
151 ctx->NewState |= NEW_RASTER_OPS;
152 }
153 }
154
155
156
157 void
158 _mesa_GetPolygonStipple( GLubyte *dest )
159 {
160 GET_CURRENT_CONTEXT(ctx);
161 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonOffset");
162
163 if (MESA_VERBOSE&VERBOSE_API)
164 fprintf(stderr, "glGetPolygonStipple\n");
165
166 gl_pack_polygon_stipple( ctx, ctx->PolygonStipple, dest );
167 }
168
169
170
171 void
172 _mesa_PolygonOffset( GLfloat factor, GLfloat units )
173 {
174 GET_CURRENT_CONTEXT(ctx);
175 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonOffset");
176
177 if (MESA_VERBOSE&VERBOSE_API)
178 fprintf(stderr, "glPolygonOffset %f %f\n", factor, units);
179
180 ctx->Polygon.OffsetFactor = factor;
181 ctx->Polygon.OffsetUnits = units;
182 }
183
184
185 void
186 _mesa_PolygonOffsetEXT( GLfloat factor, GLfloat bias )
187 {
188 _mesa_PolygonOffset(factor, bias * DEPTH_SCALE );
189 }
190