09399da8ea0fea12a0176053f60b7cfeaef584cd
[mesa.git] / src / mesa / main / polygon.c
1 /* $Id: polygon.c,v 1.2 1999/08/26 14:50:49 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.1
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 <assert.h>
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include "context.h"
36 #include "image.h"
37 #include "enums.h"
38 #include "macros.h"
39 #include "polygon.h"
40 #include "types.h"
41 #ifdef XFree86Server
42 #include "GL/xf86glx.h"
43 #endif
44 #endif
45
46
47
48 void gl_CullFace( GLcontext *ctx, GLenum mode )
49 {
50 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glCullFace");
51
52 if (MESA_VERBOSE&VERBOSE_API)
53 fprintf(stderr, "glCullFace %s\n", gl_lookup_enum_by_nr(mode));
54
55 if (mode!=GL_FRONT && mode!=GL_BACK && mode!=GL_FRONT_AND_BACK) {
56 gl_error( ctx, GL_INVALID_ENUM, "glCullFace" );
57 return;
58 }
59
60 ctx->Polygon.CullFaceMode = mode;
61 ctx->NewState |= NEW_POLYGON;
62
63 if (ctx->Driver.CullFace)
64 ctx->Driver.CullFace( ctx, mode );
65 }
66
67
68
69 void gl_FrontFace( GLcontext *ctx, GLenum mode )
70 {
71 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glFrontFace");
72
73 if (MESA_VERBOSE&VERBOSE_API)
74 fprintf(stderr, "glFrontFace %s\n", gl_lookup_enum_by_nr(mode));
75
76 if (mode!=GL_CW && mode!=GL_CCW) {
77 gl_error( ctx, GL_INVALID_ENUM, "glFrontFace" );
78 return;
79 }
80 ctx->Polygon.FrontFace = mode;
81 ctx->Polygon.FrontBit = (mode == GL_CW);
82
83 if (ctx->Driver.FrontFace)
84 ctx->Driver.FrontFace( ctx, mode );
85 }
86
87
88
89 void gl_PolygonMode( GLcontext *ctx, GLenum face, GLenum mode )
90 {
91 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonMode");
92
93 if (MESA_VERBOSE&VERBOSE_API)
94 fprintf(stderr, "glPolygonMode %s %s\n",
95 gl_lookup_enum_by_nr(face),
96 gl_lookup_enum_by_nr(mode));
97
98 if (face!=GL_FRONT && face!=GL_BACK && face!=GL_FRONT_AND_BACK) {
99 gl_error( ctx, GL_INVALID_ENUM, "glPolygonMode(face)" );
100 return;
101 }
102 else if (mode!=GL_POINT && mode!=GL_LINE && mode!=GL_FILL) {
103 gl_error( ctx, GL_INVALID_ENUM, "glPolygonMode(mode)" );
104 return;
105 }
106
107 if (face==GL_FRONT || face==GL_FRONT_AND_BACK) {
108 ctx->Polygon.FrontMode = mode;
109 }
110 if (face==GL_BACK || face==GL_FRONT_AND_BACK) {
111 ctx->Polygon.BackMode = mode;
112 }
113
114 /* Compute a handy "shortcut" value: */
115 ctx->TriangleCaps &= ~DD_TRI_UNFILLED;
116 ctx->Polygon.Unfilled = GL_FALSE;
117
118 if (ctx->Polygon.FrontMode!=GL_FILL || ctx->Polygon.BackMode!=GL_FILL) {
119 ctx->Polygon.Unfilled = GL_TRUE;
120 ctx->TriangleCaps |= DD_TRI_UNFILLED;
121 }
122
123 ctx->NewState |= (NEW_POLYGON | NEW_RASTER_OPS);
124
125 if (ctx->Driver.PolygonMode) {
126 (*ctx->Driver.PolygonMode)( ctx, face, mode );
127 }
128 }
129
130
131
132 /*
133 * NOTE: stipple pattern has already been unpacked.
134 */
135 void gl_PolygonStipple( GLcontext *ctx, const GLuint pattern[32] )
136 {
137 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonStipple");
138
139 if (MESA_VERBOSE&VERBOSE_API)
140 fprintf(stderr, "glPolygonStipple\n");
141
142 MEMCPY( ctx->PolygonStipple, pattern, 32 * 4 );
143
144 if (ctx->Polygon.StippleFlag) {
145 ctx->NewState |= NEW_RASTER_OPS;
146 }
147 }
148
149
150
151 void gl_GetPolygonStipple( GLcontext *ctx, GLubyte *dest )
152 {
153 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonOffset");
154
155 if (MESA_VERBOSE&VERBOSE_API)
156 fprintf(stderr, "glGetPolygonStipple\n");
157
158 gl_pack_polygon_stipple( ctx, ctx->PolygonStipple, dest );
159 }
160
161
162
163 void gl_PolygonOffset( GLcontext *ctx,
164 GLfloat factor, GLfloat units )
165 {
166 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPolygonOffset");
167
168 if (MESA_VERBOSE&VERBOSE_API)
169 fprintf(stderr, "glPolygonOffset %f %f\n", factor, units);
170
171 ctx->Polygon.OffsetFactor = factor;
172 ctx->Polygon.OffsetUnits = units;
173 }
174