Replace the flags Mesa was using for ctx->NewState with a new set
[mesa.git] / src / mesa / main / polygon.c
1 /* $Id: polygon.c,v 1.14 2000/10/30 13:32:01 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2000 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;
127
128 if (ctx->Driver.PolygonMode) {
129 (*ctx->Driver.PolygonMode)( ctx, face, mode );
130 }
131 }
132
133
134
135 void
136 _mesa_PolygonStipple( const GLubyte *pattern )
137 {
138 GET_CURRENT_CONTEXT(ctx);
139 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonStipple");
140
141 if (MESA_VERBOSE&VERBOSE_API)
142 fprintf(stderr, "glPolygonStipple\n");
143
144 _mesa_unpack_polygon_stipple(pattern, ctx->PolygonStipple, &ctx->Unpack);
145
146 ctx->NewState |= _NEW_POLYGONSTIPPLE;
147
148 if (ctx->Driver.PolygonStipple)
149 ctx->Driver.PolygonStipple( ctx, (const GLubyte *) ctx->PolygonStipple );
150 }
151
152
153
154 void
155 _mesa_GetPolygonStipple( GLubyte *dest )
156 {
157 GET_CURRENT_CONTEXT(ctx);
158 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonOffset");
159
160 if (MESA_VERBOSE&VERBOSE_API)
161 fprintf(stderr, "glGetPolygonStipple\n");
162
163 _mesa_pack_polygon_stipple(ctx->PolygonStipple, dest, &ctx->Pack);
164 }
165
166
167
168 void
169 _mesa_PolygonOffset( GLfloat factor, GLfloat units )
170 {
171 GET_CURRENT_CONTEXT(ctx);
172 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonOffset");
173
174 if (MESA_VERBOSE&VERBOSE_API)
175 fprintf(stderr, "glPolygonOffset %f %f\n", factor, units);
176
177 ctx->Polygon.OffsetFactor = factor;
178 ctx->Polygon.OffsetUnits = units;
179 ctx->Polygon.OffsetMRD = units * ctx->Visual.MRD;
180 ctx->NewState |= _NEW_POLYGON;
181 }
182
183
184
185 void
186 _mesa_PolygonOffsetEXT( GLfloat factor, GLfloat bias )
187 {
188 GET_CURRENT_CONTEXT(ctx);
189 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonOffsetEXT");
190 _mesa_PolygonOffset(factor, bias * ctx->Visual.DepthMaxF );
191 }