16dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/**
26dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \file polygon.c
36dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Polygon operations.
46dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */
5afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
6afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/*
7afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Mesa 3-D graphics library
88dcfcad7a2598ba835930aac8f3fd6576e464c1cBrian * Version:  6.5.1
95e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen *
108dcfcad7a2598ba835930aac8f3fd6576e464c1cBrian * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
115e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen *
12afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Permission is hereby granted, free of charge, to any person obtaining a
13afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * copy of this software and associated documentation files (the "Software"),
14afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * to deal in the Software without restriction, including without limitation
15afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * and/or sell copies of the Software, and to permit persons to whom the
17afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Software is furnished to do so, subject to the following conditions:
185e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen *
19afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * The above copyright notice and this permission notice shall be included
20afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * in all copies or substantial portions of the Software.
215e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen *
22afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
25afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */
29afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
30afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
31fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul#include "glheader.h"
323c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul#include "imports.h"
33afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "context.h"
34afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "image.h"
35afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "enums.h"
361c131752c3e07ef91f49d4970dafca6d26585334Brian Paul#include "pack.h"
37b70610b9823fc7dc3672735c11be1a75fbb1a2a4Brian Paul#include "pbo.h"
38afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "polygon.h"
395e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen#include "mtypes.h"
40afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
41afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
426dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/**
436dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Specify whether to cull front- or back-facing facets.
446dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
456dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param mode culling mode.
466dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
476dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa glCullFace().
486dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
496dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies the parameter and updates gl_polygon_attrib::CullFaceMode. On
506dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * change, flushes the vertices and notifies the driver via
516dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * the dd_function_table::CullFace callback.
526dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */
53c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY
54fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_CullFace( GLenum mode )
55afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
56fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul   GET_CURRENT_CONTEXT(ctx);
57cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   ASSERT_OUTSIDE_BEGIN_END(ctx);
58afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
59afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (MESA_VERBOSE&VERBOSE_API)
604753d60dd070bb08d0116076bcc08025c86ce857Brian Paul      _mesa_debug(ctx, "glCullFace %s\n", _mesa_lookup_enum_by_nr(mode));
61afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
62afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (mode!=GL_FRONT && mode!=GL_BACK && mode!=GL_FRONT_AND_BACK) {
6308836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_error( ctx, GL_INVALID_ENUM, "glCullFace" );
64afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      return;
65afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
66afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
67cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (ctx->Polygon.CullFaceMode == mode)
68cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return;
69cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
70cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   FLUSH_VERTICES(ctx, _NEW_POLYGON);
71afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   ctx->Polygon.CullFaceMode = mode;
72afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
73afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (ctx->Driver.CullFace)
74afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      ctx->Driver.CullFace( ctx, mode );
75afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
76afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
77afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
786dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/**
796dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Define front- and back-facing
806dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
816dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param mode orientation of front-facing polygons.
826dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
836dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa glFrontFace().
846dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
856dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies the parameter and updates gl_polygon_attrib::FrontFace. On change
866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * flushes the vertices and notifies the driver via
876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * the dd_function_table::FrontFace callback.
886dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */
89c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY
90fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_FrontFace( GLenum mode )
91afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
92fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul   GET_CURRENT_CONTEXT(ctx);
93cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   ASSERT_OUTSIDE_BEGIN_END(ctx);
94afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
95afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (MESA_VERBOSE&VERBOSE_API)
964753d60dd070bb08d0116076bcc08025c86ce857Brian Paul      _mesa_debug(ctx, "glFrontFace %s\n", _mesa_lookup_enum_by_nr(mode));
97afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
98afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (mode!=GL_CW && mode!=GL_CCW) {
9908836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_error( ctx, GL_INVALID_ENUM, "glFrontFace" );
100afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      return;
101afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
10214f8b8b5c3316117651eef2c705da37e3047d472Keith Whitwell
103cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (ctx->Polygon.FrontFace == mode)
104cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return;
105cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
106cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   FLUSH_VERTICES(ctx, _NEW_POLYGON);
107afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   ctx->Polygon.FrontFace = mode;
108cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
109cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   ctx->Polygon._FrontBit = (GLboolean) (mode == GL_CW);
110afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
111afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (ctx->Driver.FrontFace)
112afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      ctx->Driver.FrontFace( ctx, mode );
113afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
114afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
115afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/**
1176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Set the polygon rasterization mode.
1186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
1196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param face the polygons which \p mode applies to.
1206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param mode how polygons should be rasterized.
1216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
1226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa glPolygonMode().
1236dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
1246dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Verifies the parameters and updates gl_polygon_attrib::FrontMode and
1256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * gl_polygon_attrib::BackMode. On change flushes the vertices and notifies the
1266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * driver via the dd_function_table::PolygonMode callback.
1276dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */
128c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY
129fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_PolygonMode( GLenum face, GLenum mode )
130afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
131fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul   GET_CURRENT_CONTEXT(ctx);
132cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   ASSERT_OUTSIDE_BEGIN_END(ctx);
133afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
134afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (MESA_VERBOSE&VERBOSE_API)
1354753d60dd070bb08d0116076bcc08025c86ce857Brian Paul      _mesa_debug(ctx, "glPolygonMode %s %s\n",
136d09a1d8b29ae5841ae39b5c24c3f4693dd750559Brian Paul                  _mesa_lookup_enum_by_nr(face),
137d09a1d8b29ae5841ae39b5c24c3f4693dd750559Brian Paul                  _mesa_lookup_enum_by_nr(mode));
138afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
139cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (mode!=GL_POINT && mode!=GL_LINE && mode!=GL_FILL) {
14008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_error( ctx, GL_INVALID_ENUM, "glPolygonMode(mode)" );
141afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      return;
142afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
143afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
144cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   switch (face) {
145cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   case GL_FRONT:
1467e1cab09a155a0f986342323624f460340de355fIan Romanick      if (ctx->API == API_OPENGL_CORE) {
1477e1cab09a155a0f986342323624f460340de355fIan Romanick         _mesa_error( ctx, GL_INVALID_ENUM, "glPolygonMode(face)" );
1487e1cab09a155a0f986342323624f460340de355fIan Romanick         return;
1497e1cab09a155a0f986342323624f460340de355fIan Romanick      }
150cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      if (ctx->Polygon.FrontMode == mode)
151cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell	 return;
152cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      FLUSH_VERTICES(ctx, _NEW_POLYGON);
153cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      ctx->Polygon.FrontMode = mode;
154cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      break;
155cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   case GL_FRONT_AND_BACK:
156cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      if (ctx->Polygon.FrontMode == mode &&
157cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell	  ctx->Polygon.BackMode == mode)
158cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell	 return;
159cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      FLUSH_VERTICES(ctx, _NEW_POLYGON);
160afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      ctx->Polygon.FrontMode = mode;
161afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg      ctx->Polygon.BackMode = mode;
162cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      break;
163cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   case GL_BACK:
1647e1cab09a155a0f986342323624f460340de355fIan Romanick      if (ctx->API == API_OPENGL_CORE) {
1657e1cab09a155a0f986342323624f460340de355fIan Romanick         _mesa_error( ctx, GL_INVALID_ENUM, "glPolygonMode(face)" );
1667e1cab09a155a0f986342323624f460340de355fIan Romanick         return;
1677e1cab09a155a0f986342323624f460340de355fIan Romanick      }
168cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      if (ctx->Polygon.BackMode == mode)
169cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell	 return;
170cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      FLUSH_VERTICES(ctx, _NEW_POLYGON);
171cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      ctx->Polygon.BackMode = mode;
172cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      break;
173cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   default:
17408836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul      _mesa_error( ctx, GL_INVALID_ENUM, "glPolygonMode(face)" );
175cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return;
176afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   }
17796c5db5f7ae2cb9d98f534285c34217ce9c2abf3Roland Scheidegger
178ed6d5ff6f8fdd34aaaa126119dbd8e1e321859d8Brian   if (ctx->Polygon.FrontMode == GL_FILL && ctx->Polygon.BackMode == GL_FILL)
179ed6d5ff6f8fdd34aaaa126119dbd8e1e321859d8Brian      ctx->_TriangleCaps &= ~DD_TRI_UNFILLED;
180ed6d5ff6f8fdd34aaaa126119dbd8e1e321859d8Brian   else
181ed6d5ff6f8fdd34aaaa126119dbd8e1e321859d8Brian      ctx->_TriangleCaps |= DD_TRI_UNFILLED;
182ed6d5ff6f8fdd34aaaa126119dbd8e1e321859d8Brian
18396c5db5f7ae2cb9d98f534285c34217ce9c2abf3Roland Scheidegger   if (ctx->Driver.PolygonMode)
18496c5db5f7ae2cb9d98f534285c34217ce9c2abf3Roland Scheidegger      ctx->Driver.PolygonMode(ctx, face, mode);
185afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
186afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
1876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell#if _HAVE_FULL_GL
188afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
189b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul
190b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul/**
191b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul * This routine updates the ctx->Polygon.Stipple state.
192b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul * If we're getting the stipple data from a PBO, we map the buffer
193b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul * in order to access the data.
194b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul * In any case, we obey the current pixel unpacking parameters when fetching
195b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul * the stipple data.
196b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul *
197b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul * In the future, this routine should be used as a fallback, called via
198b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul * ctx->Driver.PolygonStipple().  We'll have to update all the DRI drivers
199b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul * too.
200b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul */
201b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paulvoid
202f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_polygon_stipple(struct gl_context *ctx, const GLubyte *pattern)
203b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul{
20495027a00870bc1d12ea24dfb092a0cad6cbd5035Brian Paul   pattern = _mesa_map_validate_pbo_source(ctx, 2,
20595027a00870bc1d12ea24dfb092a0cad6cbd5035Brian Paul                                           &ctx->Unpack, 32, 32, 1,
2066b329b9274b18c50f4177eef7ee087d50ebc1525Brian Paul                                           GL_COLOR_INDEX, GL_BITMAP,
2076b329b9274b18c50f4177eef7ee087d50ebc1525Brian Paul                                           INT_MAX, pattern,
20895027a00870bc1d12ea24dfb092a0cad6cbd5035Brian Paul                                           "glPolygonStipple");
20995027a00870bc1d12ea24dfb092a0cad6cbd5035Brian Paul   if (!pattern)
210203f395aaf717a6faf21a76979cc24d544ae148bBrian Paul      return;
211203f395aaf717a6faf21a76979cc24d544ae148bBrian Paul
212203f395aaf717a6faf21a76979cc24d544ae148bBrian Paul   _mesa_unpack_polygon_stipple(pattern, ctx->PolygonStipple, &ctx->Unpack);
213203f395aaf717a6faf21a76979cc24d544ae148bBrian Paul
214203f395aaf717a6faf21a76979cc24d544ae148bBrian Paul   _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
215b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul}
216b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul
217b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul
218b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul/**
219b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul * Called by glPolygonStipple.
220b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul */
221c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY
2227c652d77220610ecc19aaefa20876216b035e961Brian Paul_mesa_PolygonStipple( const GLubyte *pattern )
223afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
224fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul   GET_CURRENT_CONTEXT(ctx);
225cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   ASSERT_OUTSIDE_BEGIN_END(ctx);
226afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
227afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (MESA_VERBOSE&VERBOSE_API)
2284753d60dd070bb08d0116076bcc08025c86ce857Brian Paul      _mesa_debug(ctx, "glPolygonStipple\n");
229afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
230cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   FLUSH_VERTICES(ctx, _NEW_POLYGONSTIPPLE);
231b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul
232b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul   _mesa_polygon_stipple(ctx, pattern);
233afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
234e5ed37fa4ed1cf2323b50d96eafb1dc00c1d6d42Keith Whitwell   if (ctx->Driver.PolygonStipple)
235b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul      ctx->Driver.PolygonStipple(ctx, pattern);
236afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
237afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
238afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
239b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul/**
240b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul * Called by glPolygonStipple.
241b6f97582dd0327eee1bdbef38d5e96d83d88b86fBrian Paul */
242c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY
2436b329b9274b18c50f4177eef7ee087d50ebc1525Brian Paul_mesa_GetnPolygonStippleARB( GLsizei bufSize, GLubyte *dest )
244afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
245fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul   GET_CURRENT_CONTEXT(ctx);
246cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   ASSERT_OUTSIDE_BEGIN_END(ctx);
247afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
248afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (MESA_VERBOSE&VERBOSE_API)
2494753d60dd070bb08d0116076bcc08025c86ce857Brian Paul      _mesa_debug(ctx, "glGetPolygonStipple\n");
250afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
25195027a00870bc1d12ea24dfb092a0cad6cbd5035Brian Paul   dest = _mesa_map_validate_pbo_dest(ctx, 2,
25295027a00870bc1d12ea24dfb092a0cad6cbd5035Brian Paul                                      &ctx->Pack, 32, 32, 1,
2536b329b9274b18c50f4177eef7ee087d50ebc1525Brian Paul                                      GL_COLOR_INDEX, GL_BITMAP,
2546b329b9274b18c50f4177eef7ee087d50ebc1525Brian Paul                                      bufSize, dest, "glGetPolygonStipple");
25595027a00870bc1d12ea24dfb092a0cad6cbd5035Brian Paul   if (!dest)
256203f395aaf717a6faf21a76979cc24d544ae148bBrian Paul      return;
257203f395aaf717a6faf21a76979cc24d544ae148bBrian Paul
258203f395aaf717a6faf21a76979cc24d544ae148bBrian Paul   _mesa_pack_polygon_stipple(ctx->PolygonStipple, dest, &ctx->Pack);
259203f395aaf717a6faf21a76979cc24d544ae148bBrian Paul
260203f395aaf717a6faf21a76979cc24d544ae148bBrian Paul   _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
261afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
262afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
263afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
264c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY
2656b329b9274b18c50f4177eef7ee087d50ebc1525Brian Paul_mesa_GetPolygonStipple( GLubyte *dest )
2666b329b9274b18c50f4177eef7ee087d50ebc1525Brian Paul{
2676b329b9274b18c50f4177eef7ee087d50ebc1525Brian Paul   _mesa_GetnPolygonStippleARB(INT_MAX, dest);
2686b329b9274b18c50f4177eef7ee087d50ebc1525Brian Paul}
2696b329b9274b18c50f4177eef7ee087d50ebc1525Brian Paul
2706b329b9274b18c50f4177eef7ee087d50ebc1525Brian Paul
2716b329b9274b18c50f4177eef7ee087d50ebc1525Brian Paulvoid GLAPIENTRY
272fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_PolygonOffset( GLfloat factor, GLfloat units )
273afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{
274fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul   GET_CURRENT_CONTEXT(ctx);
275cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   ASSERT_OUTSIDE_BEGIN_END(ctx);
276afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
277afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   if (MESA_VERBOSE&VERBOSE_API)
2784753d60dd070bb08d0116076bcc08025c86ce857Brian Paul      _mesa_debug(ctx, "glPolygonOffset %f %f\n", factor, units);
279afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
280cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   if (ctx->Polygon.OffsetFactor == factor &&
281cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell       ctx->Polygon.OffsetUnits == units)
282cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell      return;
283cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell
284cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell   FLUSH_VERTICES(ctx, _NEW_POLYGON);
285afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   ctx->Polygon.OffsetFactor = factor;
286afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg   ctx->Polygon.OffsetUnits = units;
287d2733fa1963ddaa6dd4bb41ef488a029964dd8f1Gareth Hughes
288d2733fa1963ddaa6dd4bb41ef488a029964dd8f1Gareth Hughes   if (ctx->Driver.PolygonOffset)
289d2733fa1963ddaa6dd4bb41ef488a029964dd8f1Gareth Hughes      ctx->Driver.PolygonOffset( ctx, factor, units );
290afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg}
291afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg
292fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul
293c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY
294fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_PolygonOffsetEXT( GLfloat factor, GLfloat bias )
295fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul{
296ed30dfa1264ec8875a3162c3c8778bc703bf11d5Brian Paul   GET_CURRENT_CONTEXT(ctx);
297e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul   /* XXX mult by DepthMaxF here??? */
298e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul   _mesa_PolygonOffset(factor, bias * ctx->DrawBuffer->_DepthMaxF );
299fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul}
3006dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell
3016dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell#endif
3026dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell
3036dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell
3046dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/**********************************************************************/
3056dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** \name Initialization */
3066dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/*@{*/
3076dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell
3086dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/**
3096dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Initialize the context polygon state.
3106dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
3116dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context.
3126dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell *
313f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg * Initializes __struct gl_contextRec::Polygon and __struct gl_contextRec::PolygonStipple
3146dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * attribute groups.
3156dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */
316f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergvoid _mesa_init_polygon( struct gl_context * ctx )
3176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell{
3186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell   /* Polygon group */
3196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell   ctx->Polygon.CullFlag = GL_FALSE;
3206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell   ctx->Polygon.CullFaceMode = GL_BACK;
3216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell   ctx->Polygon.FrontFace = GL_CCW;
3226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell   ctx->Polygon._FrontBit = 0;
3236dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell   ctx->Polygon.FrontMode = GL_FILL;
3246dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell   ctx->Polygon.BackMode = GL_FILL;
3256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell   ctx->Polygon.SmoothFlag = GL_FALSE;
3266dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell   ctx->Polygon.StippleFlag = GL_FALSE;
3276dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell   ctx->Polygon.OffsetFactor = 0.0F;
3286dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell   ctx->Polygon.OffsetUnits = 0.0F;
3296dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell   ctx->Polygon.OffsetPoint = GL_FALSE;
3306dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell   ctx->Polygon.OffsetLine = GL_FALSE;
3316dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell   ctx->Polygon.OffsetFill = GL_FALSE;
3326dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell
3336dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell
3346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell   /* Polygon Stipple group */
3352240ba10f30315410bcff77e372ee71664ac4453Brian Paul   memset( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );
3366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell}
3376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell
3386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/*@}*/
339