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