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#include "api_exec_decl.h" 32 33#include "state_tracker/st_context.h" 34 35/** 36 * Set the line width. 37 * 38 * \param width line width in pixels. 39 * 40 * \sa glLineWidth(). 41 */ 42static ALWAYS_INLINE void 43line_width(struct gl_context *ctx, GLfloat width, bool no_error) 44{ 45 /* If width is unchanged, there can't be an error */ 46 if (ctx->Line.Width == width) 47 return; 48 49 if (!no_error && width <= 0.0F) { 50 _mesa_error( ctx, GL_INVALID_VALUE, "glLineWidth" ); 51 return; 52 } 53 54 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says (in the list 55 * of deprecated functionality): 56 * 57 * "Wide lines and line stipple - LineWidth is not deprecated, but 58 * values greater than 1.0 will generate an INVALID_VALUE error;" 59 * 60 * This is one of the very few cases where functionality was deprecated but 61 * *NOT* removed in a later spec. Therefore, we only disallow this in a 62 * forward compatible context. 63 */ 64 if (!no_error && ctx->API == API_OPENGL_CORE 65 && ((ctx->Const.ContextFlags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) 66 != 0) 67 && width > 1.0F) { 68 _mesa_error( ctx, GL_INVALID_VALUE, "glLineWidth" ); 69 return; 70 } 71 72 FLUSH_VERTICES(ctx, 0, GL_LINE_BIT); 73 ctx->NewDriverState |= ST_NEW_RASTERIZER; 74 ctx->Line.Width = width; 75} 76 77 78void GLAPIENTRY 79_mesa_LineWidth_no_error(GLfloat width) 80{ 81 GET_CURRENT_CONTEXT(ctx); 82 line_width(ctx, width, true); 83} 84 85 86void GLAPIENTRY 87_mesa_LineWidth(GLfloat width) 88{ 89 GET_CURRENT_CONTEXT(ctx); 90 91 if (MESA_VERBOSE & VERBOSE_API) 92 _mesa_debug(ctx, "glLineWidth %f\n", width); 93 94 line_width(ctx, width, false); 95} 96 97 98/** 99 * Set the line stipple pattern. 100 * 101 * \param factor pattern scale factor. 102 * \param pattern bit pattern. 103 * 104 * \sa glLineStipple(). 105 * 106 * Updates gl_line_attrib::StippleFactor and gl_line_attrib::StipplePattern. On 107 * change flushes the vertices and notifies the driver via 108 * the dd_function_table::LineStipple callback. 109 */ 110void GLAPIENTRY 111_mesa_LineStipple( GLint factor, GLushort pattern ) 112{ 113 GET_CURRENT_CONTEXT(ctx); 114 115 if (MESA_VERBOSE & VERBOSE_API) 116 _mesa_debug(ctx, "glLineStipple %d %u\n", factor, pattern); 117 118 factor = CLAMP( factor, 1, 256 ); 119 120 if (ctx->Line.StippleFactor == factor && 121 ctx->Line.StipplePattern == pattern) 122 return; 123 124 FLUSH_VERTICES(ctx, 0, GL_LINE_BIT); 125 ctx->NewDriverState |= ST_NEW_RASTERIZER; 126 ctx->Line.StippleFactor = factor; 127 ctx->Line.StipplePattern = pattern; 128} 129 130 131/** 132 * Initialize the context line state. 133 * 134 * \param ctx GL context. 135 * 136 * Initializes __struct gl_contextRec::Line and line related constants in 137 * __struct gl_contextRec::Const. 138 */ 139void 140_mesa_init_line( struct gl_context * ctx ) 141{ 142 ctx->Line.SmoothFlag = GL_FALSE; 143 ctx->Line.StippleFlag = GL_FALSE; 144 ctx->Line.Width = 1.0; 145 ctx->Line.StipplePattern = 0xffff; 146 ctx->Line.StippleFactor = 1; 147} 148