1afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg/* 2afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Mesa 3-D graphics library 38dcfcad7a2598ba835930aac8f3fd6576e464c1cBrian * Version: 6.5.3 45e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 58dcfcad7a2598ba835930aac8f3fd6576e464c1cBrian * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. 65e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 7afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Permission is hereby granted, free of charge, to any person obtaining a 8afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * copy of this software and associated documentation files (the "Software"), 9afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * to deal in the Software without restriction, including without limitation 10afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * and/or sell copies of the Software, and to permit persons to whom the 12afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * Software is furnished to do so, subject to the following conditions: 135e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 14afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * The above copyright notice and this permission notice shall be included 15afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * in all copies or substantial portions of the Software. 165e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 17afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg */ 24afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 25afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 26fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul#include "glheader.h" 27afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "context.h" 28afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "lines.h" 29afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg#include "macros.h" 305e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen#include "mtypes.h" 31afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 32afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 336dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Set the line width. 356dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 366dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param width line width in pixels. 376dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 386dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa glLineWidth(). 396dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */ 40c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 41fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_LineWidth( GLfloat width ) 42afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 43fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 44cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END(ctx); 45cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 462634e92dc0cecc364984bef9169a91bb96bafdcdBrian Paul if (MESA_VERBOSE & VERBOSE_API) 472634e92dc0cecc364984bef9169a91bb96bafdcdBrian Paul _mesa_debug(ctx, "glLineWidth %f\n", width); 482634e92dc0cecc364984bef9169a91bb96bafdcdBrian Paul 49afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg if (width<=0.0) { 5008836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul _mesa_error( ctx, GL_INVALID_VALUE, "glLineWidth" ); 51afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg return; 52afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg } 535e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen 5429512df6355706cc678d3994185c20c4d66b57c4Ian Romanick /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says (in the list 5529512df6355706cc678d3994185c20c4d66b57c4Ian Romanick * of deprecated functionality): 5629512df6355706cc678d3994185c20c4d66b57c4Ian Romanick * 5729512df6355706cc678d3994185c20c4d66b57c4Ian Romanick * "Wide lines and line stipple - LineWidth is not deprecated, but 5829512df6355706cc678d3994185c20c4d66b57c4Ian Romanick * values greater than 1.0 will generate an INVALID_VALUE error;" 5929512df6355706cc678d3994185c20c4d66b57c4Ian Romanick * 6029512df6355706cc678d3994185c20c4d66b57c4Ian Romanick * This is one of the very few cases where functionality was deprecated but 6129512df6355706cc678d3994185c20c4d66b57c4Ian Romanick * *NOT* removed in a later spec. Therefore, we only disallow this in a 6229512df6355706cc678d3994185c20c4d66b57c4Ian Romanick * forward compatible context. 6329512df6355706cc678d3994185c20c4d66b57c4Ian Romanick */ 6429512df6355706cc678d3994185c20c4d66b57c4Ian Romanick if (ctx->API == API_OPENGL_CORE 6529512df6355706cc678d3994185c20c4d66b57c4Ian Romanick && ((ctx->Const.ContextFlags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) 6629512df6355706cc678d3994185c20c4d66b57c4Ian Romanick != 0)) { 6729512df6355706cc678d3994185c20c4d66b57c4Ian Romanick _mesa_error( ctx, GL_INVALID_VALUE, "glLineWidth" ); 6829512df6355706cc678d3994185c20c4d66b57c4Ian Romanick return; 6929512df6355706cc678d3994185c20c4d66b57c4Ian Romanick } 7029512df6355706cc678d3994185c20c4d66b57c4Ian Romanick 7122144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes if (ctx->Line.Width == width) 72cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return; 73a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell 74cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell FLUSH_VERTICES(ctx, _NEW_LINE); 75cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ctx->Line.Width = width; 76b980b2eeb62dc48101a7481d02d196c80b9da397Keith Whitwell 77cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell if (ctx->Driver.LineWidth) 788dcfcad7a2598ba835930aac8f3fd6576e464c1cBrian ctx->Driver.LineWidth(ctx, width); 79afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 80afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 81afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg 826dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 836dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Set the line stipple pattern. 846dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 856dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param factor pattern scale factor. 866dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param pattern bit pattern. 876dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 886dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \sa glLineStipple(). 896dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 906dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Updates gl_line_attrib::StippleFactor and gl_line_attrib::StipplePattern. On 916dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * change flushes the vertices and notifies the driver via 926dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * the dd_function_table::LineStipple callback. 936dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */ 94c40d1dd62dd9bcbb97128e37a75d991a8d3b2d8cKendall Bennettvoid GLAPIENTRY 95fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul_mesa_LineStipple( GLint factor, GLushort pattern ) 96afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg{ 97fbd8f212c3866ec98c1d8c9d3db3ddb7e7c479a5Brian Paul GET_CURRENT_CONTEXT(ctx); 98cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ASSERT_OUTSIDE_BEGIN_END(ctx); 99cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 1002634e92dc0cecc364984bef9169a91bb96bafdcdBrian Paul if (MESA_VERBOSE & VERBOSE_API) 1012634e92dc0cecc364984bef9169a91bb96bafdcdBrian Paul _mesa_debug(ctx, "glLineStipple %d %u\n", factor, pattern); 1022634e92dc0cecc364984bef9169a91bb96bafdcdBrian Paul 103321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell factor = CLAMP( factor, 1, 256 ); 104321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell 105321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell if (ctx->Line.StippleFactor == factor && 106cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell ctx->Line.StipplePattern == pattern) 107cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell return; 108cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell 109cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell FLUSH_VERTICES(ctx, _NEW_LINE); 110321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell ctx->Line.StippleFactor = factor; 111afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg ctx->Line.StipplePattern = pattern; 112a96308c37db0bc0086a017d318bc3504aa5f0b1aKeith Whitwell 113e5ed37fa4ed1cf2323b50d96eafb1dc00c1d6d42Keith Whitwell if (ctx->Driver.LineStipple) 114e5ed37fa4ed1cf2323b50d96eafb1dc00c1d6d42Keith Whitwell ctx->Driver.LineStipple( ctx, factor, pattern ); 115afb833d4e89c312460a4ab9ed6a7a8ca4ebbfe1cjtg} 1166dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell 1176dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell 1186dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell/** 1196dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * Initialize the context line state. 1206dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 1216dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * \param ctx GL context. 1226dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 123f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg * Initializes __struct gl_contextRec::Line and line related constants in 124f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg * __struct gl_contextRec::Const. 1256dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell */ 126af2aa8e9cf88a9ee3ec338eddc9a47bf2f142cb7Brianvoid GLAPIENTRY 127f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg_mesa_init_line( struct gl_context * ctx ) 1286dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell{ 1296dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell ctx->Line.SmoothFlag = GL_FALSE; 1306dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell ctx->Line.StippleFlag = GL_FALSE; 1316dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell ctx->Line.Width = 1.0; 1326dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell ctx->Line.StipplePattern = 0xffff; 1336dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell ctx->Line.StippleFactor = 1; 1346dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell} 135