lines.c revision 27558a160a9fe91745728d7626995cd88f8fe339
1/* $Id: lines.c,v 1.31 2003/03/01 01:50:21 brianp Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version:  5.1
6 *
7 * Copyright (C) 1999-2003  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#include "glheader.h"
29#include "context.h"
30#include "depth.h"
31#include "lines.h"
32#include "macros.h"
33#include "texstate.h"
34#include "mtypes.h"
35
36
37void
38_mesa_LineWidth( GLfloat width )
39{
40   GET_CURRENT_CONTEXT(ctx);
41   ASSERT_OUTSIDE_BEGIN_END(ctx);
42
43   if (width<=0.0) {
44      _mesa_error( ctx, GL_INVALID_VALUE, "glLineWidth" );
45      return;
46   }
47
48   if (ctx->Line.Width == width)
49      return;
50
51   FLUSH_VERTICES(ctx, _NEW_LINE);
52   ctx->Line.Width = width;
53   ctx->Line._Width = CLAMP(width,
54			    ctx->Const.MinLineWidth,
55			    ctx->Const.MaxLineWidth);
56
57
58   if (width != 1.0)
59      ctx->_TriangleCaps |= DD_LINE_WIDTH;
60   else
61      ctx->_TriangleCaps &= ~DD_LINE_WIDTH;
62
63   if (ctx->Driver.LineWidth)
64      (*ctx->Driver.LineWidth)(ctx, width);
65}
66
67
68
69void
70_mesa_LineStipple( GLint factor, GLushort pattern )
71{
72   GET_CURRENT_CONTEXT(ctx);
73   ASSERT_OUTSIDE_BEGIN_END(ctx);
74
75   factor = CLAMP( factor, 1, 256 );
76
77   if (ctx->Line.StippleFactor == factor &&
78       ctx->Line.StipplePattern == pattern)
79      return;
80
81   FLUSH_VERTICES(ctx, _NEW_LINE);
82   ctx->Line.StippleFactor = factor;
83   ctx->Line.StipplePattern = pattern;
84
85   if (ctx->Driver.LineStipple)
86      ctx->Driver.LineStipple( ctx, factor, pattern );
87}
88