Merge branch 'master' of git+ssh://joukj@git.freedesktop.org/git/mesa/mesa
[mesa.git] / src / mesa / main / lines.c
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 */
42 void 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
59 if (width != 1.0F)
60 ctx->_TriangleCaps |= DD_LINE_WIDTH;
61 else
62 ctx->_TriangleCaps &= ~DD_LINE_WIDTH;
63
64 if (ctx->Driver.LineWidth)
65 ctx->Driver.LineWidth(ctx, width);
66 }
67
68
69 /**
70 * Set the line stipple pattern.
71 *
72 * \param factor pattern scale factor.
73 * \param pattern bit pattern.
74 *
75 * \sa glLineStipple().
76 *
77 * Updates gl_line_attrib::StippleFactor and gl_line_attrib::StipplePattern. On
78 * change flushes the vertices and notifies the driver via
79 * the dd_function_table::LineStipple callback.
80 */
81 void GLAPIENTRY
82 _mesa_LineStipple( GLint factor, GLushort pattern )
83 {
84 GET_CURRENT_CONTEXT(ctx);
85 ASSERT_OUTSIDE_BEGIN_END(ctx);
86
87 factor = CLAMP( factor, 1, 256 );
88
89 if (ctx->Line.StippleFactor == factor &&
90 ctx->Line.StipplePattern == pattern)
91 return;
92
93 FLUSH_VERTICES(ctx, _NEW_LINE);
94 ctx->Line.StippleFactor = factor;
95 ctx->Line.StipplePattern = pattern;
96
97 if (ctx->Driver.LineStipple)
98 ctx->Driver.LineStipple( ctx, factor, pattern );
99 }
100
101
102 /**
103 * Initialize the context line state.
104 *
105 * \param ctx GL context.
106 *
107 * Initializes __GLcontextRec::Line and line related constants in
108 * __GLcontextRec::Const.
109 */
110 void GLAPIENTRY
111 _mesa_init_line( GLcontext * ctx )
112 {
113 ctx->Line.SmoothFlag = GL_FALSE;
114 ctx->Line.StippleFlag = GL_FALSE;
115 ctx->Line.Width = 1.0;
116 ctx->Line.StipplePattern = 0xffff;
117 ctx->Line.StippleFactor = 1;
118 }