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