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