1*61046927SAndroid Build Coastguard Worker /*
2*61046927SAndroid Build Coastguard Worker * Mesa 3-D graphics library
3*61046927SAndroid Build Coastguard Worker *
4*61046927SAndroid Build Coastguard Worker * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
5*61046927SAndroid Build Coastguard Worker *
6*61046927SAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining a
7*61046927SAndroid Build Coastguard Worker * copy of this software and associated documentation files (the "Software"),
8*61046927SAndroid Build Coastguard Worker * to deal in the Software without restriction, including without limitation
9*61046927SAndroid Build Coastguard Worker * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10*61046927SAndroid Build Coastguard Worker * and/or sell copies of the Software, and to permit persons to whom the
11*61046927SAndroid Build Coastguard Worker * Software is furnished to do so, subject to the following conditions:
12*61046927SAndroid Build Coastguard Worker *
13*61046927SAndroid Build Coastguard Worker * The above copyright notice and this permission notice shall be included
14*61046927SAndroid Build Coastguard Worker * in all copies or substantial portions of the Software.
15*61046927SAndroid Build Coastguard Worker *
16*61046927SAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17*61046927SAndroid Build Coastguard Worker * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*61046927SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19*61046927SAndroid Build Coastguard Worker * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20*61046927SAndroid Build Coastguard Worker * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21*61046927SAndroid Build Coastguard Worker * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22*61046927SAndroid Build Coastguard Worker * OTHER DEALINGS IN THE SOFTWARE.
23*61046927SAndroid Build Coastguard Worker */
24*61046927SAndroid Build Coastguard Worker
25*61046927SAndroid Build Coastguard Worker
26*61046927SAndroid Build Coastguard Worker #include "util/glheader.h"
27*61046927SAndroid Build Coastguard Worker #include "context.h"
28*61046927SAndroid Build Coastguard Worker #include "lines.h"
29*61046927SAndroid Build Coastguard Worker #include "macros.h"
30*61046927SAndroid Build Coastguard Worker #include "mtypes.h"
31*61046927SAndroid Build Coastguard Worker #include "api_exec_decl.h"
32*61046927SAndroid Build Coastguard Worker
33*61046927SAndroid Build Coastguard Worker #include "state_tracker/st_context.h"
34*61046927SAndroid Build Coastguard Worker
35*61046927SAndroid Build Coastguard Worker /**
36*61046927SAndroid Build Coastguard Worker * Set the line width.
37*61046927SAndroid Build Coastguard Worker *
38*61046927SAndroid Build Coastguard Worker * \param width line width in pixels.
39*61046927SAndroid Build Coastguard Worker *
40*61046927SAndroid Build Coastguard Worker * \sa glLineWidth().
41*61046927SAndroid Build Coastguard Worker */
42*61046927SAndroid Build Coastguard Worker static ALWAYS_INLINE void
line_width(struct gl_context * ctx,GLfloat width,bool no_error)43*61046927SAndroid Build Coastguard Worker line_width(struct gl_context *ctx, GLfloat width, bool no_error)
44*61046927SAndroid Build Coastguard Worker {
45*61046927SAndroid Build Coastguard Worker /* If width is unchanged, there can't be an error */
46*61046927SAndroid Build Coastguard Worker if (ctx->Line.Width == width)
47*61046927SAndroid Build Coastguard Worker return;
48*61046927SAndroid Build Coastguard Worker
49*61046927SAndroid Build Coastguard Worker if (!no_error && width <= 0.0F) {
50*61046927SAndroid Build Coastguard Worker _mesa_error( ctx, GL_INVALID_VALUE, "glLineWidth" );
51*61046927SAndroid Build Coastguard Worker return;
52*61046927SAndroid Build Coastguard Worker }
53*61046927SAndroid Build Coastguard Worker
54*61046927SAndroid Build Coastguard Worker /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says (in the list
55*61046927SAndroid Build Coastguard Worker * of deprecated functionality):
56*61046927SAndroid Build Coastguard Worker *
57*61046927SAndroid Build Coastguard Worker * "Wide lines and line stipple - LineWidth is not deprecated, but
58*61046927SAndroid Build Coastguard Worker * values greater than 1.0 will generate an INVALID_VALUE error;"
59*61046927SAndroid Build Coastguard Worker *
60*61046927SAndroid Build Coastguard Worker * This is one of the very few cases where functionality was deprecated but
61*61046927SAndroid Build Coastguard Worker * *NOT* removed in a later spec. Therefore, we only disallow this in a
62*61046927SAndroid Build Coastguard Worker * forward compatible context.
63*61046927SAndroid Build Coastguard Worker */
64*61046927SAndroid Build Coastguard Worker if (!no_error && _mesa_is_desktop_gl_core(ctx)
65*61046927SAndroid Build Coastguard Worker && ((ctx->Const.ContextFlags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)
66*61046927SAndroid Build Coastguard Worker != 0)
67*61046927SAndroid Build Coastguard Worker && width > 1.0F) {
68*61046927SAndroid Build Coastguard Worker _mesa_error( ctx, GL_INVALID_VALUE, "glLineWidth" );
69*61046927SAndroid Build Coastguard Worker return;
70*61046927SAndroid Build Coastguard Worker }
71*61046927SAndroid Build Coastguard Worker
72*61046927SAndroid Build Coastguard Worker FLUSH_VERTICES(ctx, 0, GL_LINE_BIT);
73*61046927SAndroid Build Coastguard Worker ctx->NewDriverState |= ST_NEW_RASTERIZER;
74*61046927SAndroid Build Coastguard Worker ctx->Line.Width = width;
75*61046927SAndroid Build Coastguard Worker }
76*61046927SAndroid Build Coastguard Worker
77*61046927SAndroid Build Coastguard Worker
78*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_LineWidth_no_error(GLfloat width)79*61046927SAndroid Build Coastguard Worker _mesa_LineWidth_no_error(GLfloat width)
80*61046927SAndroid Build Coastguard Worker {
81*61046927SAndroid Build Coastguard Worker GET_CURRENT_CONTEXT(ctx);
82*61046927SAndroid Build Coastguard Worker line_width(ctx, width, true);
83*61046927SAndroid Build Coastguard Worker }
84*61046927SAndroid Build Coastguard Worker
85*61046927SAndroid Build Coastguard Worker
86*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_LineWidth(GLfloat width)87*61046927SAndroid Build Coastguard Worker _mesa_LineWidth(GLfloat width)
88*61046927SAndroid Build Coastguard Worker {
89*61046927SAndroid Build Coastguard Worker GET_CURRENT_CONTEXT(ctx);
90*61046927SAndroid Build Coastguard Worker
91*61046927SAndroid Build Coastguard Worker if (MESA_VERBOSE & VERBOSE_API)
92*61046927SAndroid Build Coastguard Worker _mesa_debug(ctx, "glLineWidth %f\n", width);
93*61046927SAndroid Build Coastguard Worker
94*61046927SAndroid Build Coastguard Worker line_width(ctx, width, false);
95*61046927SAndroid Build Coastguard Worker }
96*61046927SAndroid Build Coastguard Worker
97*61046927SAndroid Build Coastguard Worker
98*61046927SAndroid Build Coastguard Worker /**
99*61046927SAndroid Build Coastguard Worker * Set the line stipple pattern.
100*61046927SAndroid Build Coastguard Worker *
101*61046927SAndroid Build Coastguard Worker * \param factor pattern scale factor.
102*61046927SAndroid Build Coastguard Worker * \param pattern bit pattern.
103*61046927SAndroid Build Coastguard Worker *
104*61046927SAndroid Build Coastguard Worker * \sa glLineStipple().
105*61046927SAndroid Build Coastguard Worker *
106*61046927SAndroid Build Coastguard Worker * Updates gl_line_attrib::StippleFactor and gl_line_attrib::StipplePattern. On
107*61046927SAndroid Build Coastguard Worker * change flushes the vertices and notifies the driver via
108*61046927SAndroid Build Coastguard Worker * the dd_function_table::LineStipple callback.
109*61046927SAndroid Build Coastguard Worker */
110*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_LineStipple(GLint factor,GLushort pattern)111*61046927SAndroid Build Coastguard Worker _mesa_LineStipple( GLint factor, GLushort pattern )
112*61046927SAndroid Build Coastguard Worker {
113*61046927SAndroid Build Coastguard Worker GET_CURRENT_CONTEXT(ctx);
114*61046927SAndroid Build Coastguard Worker
115*61046927SAndroid Build Coastguard Worker if (MESA_VERBOSE & VERBOSE_API)
116*61046927SAndroid Build Coastguard Worker _mesa_debug(ctx, "glLineStipple %d %u\n", factor, pattern);
117*61046927SAndroid Build Coastguard Worker
118*61046927SAndroid Build Coastguard Worker factor = CLAMP( factor, 1, 256 );
119*61046927SAndroid Build Coastguard Worker
120*61046927SAndroid Build Coastguard Worker if (ctx->Line.StippleFactor == factor &&
121*61046927SAndroid Build Coastguard Worker ctx->Line.StipplePattern == pattern)
122*61046927SAndroid Build Coastguard Worker return;
123*61046927SAndroid Build Coastguard Worker
124*61046927SAndroid Build Coastguard Worker FLUSH_VERTICES(ctx, 0, GL_LINE_BIT);
125*61046927SAndroid Build Coastguard Worker ctx->NewDriverState |= ST_NEW_RASTERIZER;
126*61046927SAndroid Build Coastguard Worker ctx->Line.StippleFactor = factor;
127*61046927SAndroid Build Coastguard Worker ctx->Line.StipplePattern = pattern;
128*61046927SAndroid Build Coastguard Worker }
129*61046927SAndroid Build Coastguard Worker
130*61046927SAndroid Build Coastguard Worker
131*61046927SAndroid Build Coastguard Worker /**
132*61046927SAndroid Build Coastguard Worker * Initialize the context line state.
133*61046927SAndroid Build Coastguard Worker *
134*61046927SAndroid Build Coastguard Worker * \param ctx GL context.
135*61046927SAndroid Build Coastguard Worker *
136*61046927SAndroid Build Coastguard Worker * Initializes __struct gl_contextRec::Line and line related constants in
137*61046927SAndroid Build Coastguard Worker * __struct gl_contextRec::Const.
138*61046927SAndroid Build Coastguard Worker */
139*61046927SAndroid Build Coastguard Worker void
_mesa_init_line(struct gl_context * ctx)140*61046927SAndroid Build Coastguard Worker _mesa_init_line( struct gl_context * ctx )
141*61046927SAndroid Build Coastguard Worker {
142*61046927SAndroid Build Coastguard Worker ctx->Line.SmoothFlag = GL_FALSE;
143*61046927SAndroid Build Coastguard Worker ctx->Line.StippleFlag = GL_FALSE;
144*61046927SAndroid Build Coastguard Worker ctx->Line.Width = 1.0;
145*61046927SAndroid Build Coastguard Worker ctx->Line.StipplePattern = 0xffff;
146*61046927SAndroid Build Coastguard Worker ctx->Line.StippleFactor = 1;
147*61046927SAndroid Build Coastguard Worker }
148