lines.c revision 7117f1b4
1/*
2 * Mesa 3-D graphics library
3 * Version:  6.5.3
4 *
5 * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26#include "glheader.h"
27#include "context.h"
28#include "depth.h"
29#include "lines.h"
30#include "macros.h"
31#include "texstate.h"
32#include "mtypes.h"
33
34
35/**
36 * Set the line width.
37 *
38 * \param width line width in pixels.
39 *
40 * \sa glLineWidth().
41 */
42void GLAPIENTRY
43_mesa_LineWidth( GLfloat width )
44{
45   GET_CURRENT_CONTEXT(ctx);
46   ASSERT_OUTSIDE_BEGIN_END(ctx);
47
48   if (width<=0.0) {
49      _mesa_error( ctx, GL_INVALID_VALUE, "glLineWidth" );
50      return;
51   }
52
53   if (ctx->Line.Width == width)
54      return;
55
56   FLUSH_VERTICES(ctx, _NEW_LINE);
57   ctx->Line.Width = width;
58   ctx->Line._Width = CLAMP(width,
59			    ctx->Const.MinLineWidth,
60			    ctx->Const.MaxLineWidth);
61
62   if (width != 1.0F)
63      ctx->_TriangleCaps |= DD_LINE_WIDTH;
64   else
65      ctx->_TriangleCaps &= ~DD_LINE_WIDTH;
66
67   if (ctx->Driver.LineWidth)
68      ctx->Driver.LineWidth(ctx, width);
69}
70
71
72/**
73 * Set the line stipple pattern.
74 *
75 * \param factor pattern scale factor.
76 * \param pattern bit pattern.
77 *
78 * \sa glLineStipple().
79 *
80 * Updates gl_line_attrib::StippleFactor and gl_line_attrib::StipplePattern. On
81 * change flushes the vertices and notifies the driver via
82 * the dd_function_table::LineStipple callback.
83 */
84void GLAPIENTRY
85_mesa_LineStipple( GLint factor, GLushort pattern )
86{
87   GET_CURRENT_CONTEXT(ctx);
88   ASSERT_OUTSIDE_BEGIN_END(ctx);
89
90   factor = CLAMP( factor, 1, 256 );
91
92   if (ctx->Line.StippleFactor == factor &&
93       ctx->Line.StipplePattern == pattern)
94      return;
95
96   FLUSH_VERTICES(ctx, _NEW_LINE);
97   ctx->Line.StippleFactor = factor;
98   ctx->Line.StipplePattern = pattern;
99
100   if (ctx->Driver.LineStipple)
101      ctx->Driver.LineStipple( ctx, factor, pattern );
102}
103
104
105/**
106 * Initialize the context line state.
107 *
108 * \param ctx GL context.
109 *
110 * Initializes __GLcontextRec::Line and line related constants in
111 * __GLcontextRec::Const.
112 */
113void GLAPIENTRY _mesa_init_line( GLcontext * ctx )
114{
115   /* Line group */
116   ctx->Line.SmoothFlag = GL_FALSE;
117   ctx->Line.StippleFlag = GL_FALSE;
118   ctx->Line.Width = 1.0;
119   ctx->Line._Width = 1.0;
120   ctx->Line.StipplePattern = 0xffff;
121   ctx->Line.StippleFactor = 1;
122}
123