polygon.c revision 08836341788a9f9d638d9dc8328510ccd18ddeb5
1/* $Id: polygon.c,v 1.19 2001/03/03 20:33:27 brianp Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version:  3.5
6 *
7 * Copyright (C) 1999-2001  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 "mtypes.h"
39#endif
40
41
42
43void
44_mesa_CullFace( GLenum mode )
45{
46   GET_CURRENT_CONTEXT(ctx);
47   ASSERT_OUTSIDE_BEGIN_END(ctx);
48
49   if (MESA_VERBOSE&VERBOSE_API)
50      fprintf(stderr, "glCullFace %s\n", _mesa_lookup_enum_by_nr(mode));
51
52   if (mode!=GL_FRONT && mode!=GL_BACK && mode!=GL_FRONT_AND_BACK) {
53      _mesa_error( ctx, GL_INVALID_ENUM, "glCullFace" );
54      return;
55   }
56
57   if (ctx->Polygon.CullFaceMode == mode)
58      return;
59
60   FLUSH_VERTICES(ctx, _NEW_POLYGON);
61   ctx->Polygon.CullFaceMode = mode;
62
63   if (ctx->Driver.CullFace)
64      ctx->Driver.CullFace( ctx, mode );
65}
66
67
68
69void
70_mesa_FrontFace( GLenum mode )
71{
72   GET_CURRENT_CONTEXT(ctx);
73   ASSERT_OUTSIDE_BEGIN_END(ctx);
74
75   if (MESA_VERBOSE&VERBOSE_API)
76      fprintf(stderr, "glFrontFace %s\n", _mesa_lookup_enum_by_nr(mode));
77
78   if (mode!=GL_CW && mode!=GL_CCW) {
79      _mesa_error( ctx, GL_INVALID_ENUM, "glFrontFace" );
80      return;
81   }
82
83   if (ctx->Polygon.FrontFace == mode)
84      return;
85
86   FLUSH_VERTICES(ctx, _NEW_POLYGON);
87   ctx->Polygon.FrontFace = mode;
88
89   ctx->Polygon._FrontBit = (GLboolean) (mode == GL_CW);
90
91   if (ctx->Driver.FrontFace)
92      ctx->Driver.FrontFace( ctx, mode );
93}
94
95
96
97void
98_mesa_PolygonMode( GLenum face, GLenum mode )
99{
100   GET_CURRENT_CONTEXT(ctx);
101   ASSERT_OUTSIDE_BEGIN_END(ctx);
102
103   if (MESA_VERBOSE&VERBOSE_API)
104      fprintf(stderr, "glPolygonMode %s %s\n",
105	      _mesa_lookup_enum_by_nr(face),
106	      _mesa_lookup_enum_by_nr(mode));
107
108   if (mode!=GL_POINT && mode!=GL_LINE && mode!=GL_FILL) {
109      _mesa_error( ctx, GL_INVALID_ENUM, "glPolygonMode(mode)" );
110      return;
111   }
112
113   switch (face) {
114   case GL_FRONT:
115      if (ctx->Polygon.FrontMode == mode)
116	 return;
117      FLUSH_VERTICES(ctx, _NEW_POLYGON);
118      ctx->Polygon.FrontMode = mode;
119      break;
120   case GL_FRONT_AND_BACK:
121      if (ctx->Polygon.FrontMode == mode &&
122	  ctx->Polygon.BackMode == mode)
123	 return;
124      FLUSH_VERTICES(ctx, _NEW_POLYGON);
125      ctx->Polygon.FrontMode = mode;
126      ctx->Polygon.BackMode = mode;
127      break;
128   case GL_BACK:
129      if (ctx->Polygon.BackMode == mode)
130	 return;
131      FLUSH_VERTICES(ctx, _NEW_POLYGON);
132      ctx->Polygon.BackMode = mode;
133      break;
134   default:
135      _mesa_error( ctx, GL_INVALID_ENUM, "glPolygonMode(face)" );
136      return;
137   }
138
139   ctx->_TriangleCaps &= ~DD_TRI_UNFILLED;
140   if (ctx->Polygon.FrontMode!=GL_FILL || ctx->Polygon.BackMode!=GL_FILL)
141      ctx->_TriangleCaps |= DD_TRI_UNFILLED;
142
143   if (ctx->Driver.PolygonMode) {
144      (*ctx->Driver.PolygonMode)( ctx, face, mode );
145   }
146}
147
148
149
150void
151_mesa_PolygonStipple( const GLubyte *pattern )
152{
153   GET_CURRENT_CONTEXT(ctx);
154   ASSERT_OUTSIDE_BEGIN_END(ctx);
155
156   if (MESA_VERBOSE&VERBOSE_API)
157      fprintf(stderr, "glPolygonStipple\n");
158
159   FLUSH_VERTICES(ctx, _NEW_POLYGONSTIPPLE);
160   _mesa_unpack_polygon_stipple(pattern, ctx->PolygonStipple, &ctx->Unpack);
161
162   if (ctx->Driver.PolygonStipple)
163      ctx->Driver.PolygonStipple( ctx, (const GLubyte *) ctx->PolygonStipple );
164}
165
166
167
168void
169_mesa_GetPolygonStipple( GLubyte *dest )
170{
171   GET_CURRENT_CONTEXT(ctx);
172   ASSERT_OUTSIDE_BEGIN_END(ctx);
173
174   if (MESA_VERBOSE&VERBOSE_API)
175      fprintf(stderr, "glGetPolygonStipple\n");
176
177   _mesa_pack_polygon_stipple(ctx->PolygonStipple, dest, &ctx->Pack);
178}
179
180
181
182void
183_mesa_PolygonOffset( GLfloat factor, GLfloat units )
184{
185   GET_CURRENT_CONTEXT(ctx);
186   ASSERT_OUTSIDE_BEGIN_END(ctx);
187
188   if (MESA_VERBOSE&VERBOSE_API)
189      fprintf(stderr, "glPolygonOffset %f %f\n", factor, units);
190
191   if (ctx->Polygon.OffsetFactor == factor &&
192       ctx->Polygon.OffsetUnits == units)
193      return;
194
195   FLUSH_VERTICES(ctx, _NEW_POLYGON);
196   ctx->Polygon.OffsetFactor = factor;
197   ctx->Polygon.OffsetUnits = units;
198   ctx->Polygon.OffsetMRD = units * ctx->MRD;
199}
200
201
202
203void
204_mesa_PolygonOffsetEXT( GLfloat factor, GLfloat bias )
205{
206   GET_CURRENT_CONTEXT(ctx);
207   _mesa_PolygonOffset(factor, bias * ctx->DepthMaxF );
208}
209