| 1 |
/** |
| 2 |
* \file lines.c |
| 3 |
* Line operations. |
| 4 |
*/ |
| 5 |
|
| 6 |
/* |
| 7 |
* Mesa 3-D graphics library |
| 8 |
* Version: 5.1 |
| 9 |
* |
| 10 |
* Copyright (C) 1999-2003 Brian Paul All Rights Reserved. |
| 11 |
* |
| 12 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 13 |
* copy of this software and associated documentation files (the "Software"), |
| 14 |
* to deal in the Software without restriction, including without limitation |
| 15 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 16 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 17 |
* Software is furnished to do so, subject to the following conditions: |
| 18 |
* |
| 19 |
* The above copyright notice and this permission notice shall be included |
| 20 |
* in all copies or substantial portions of the Software. |
| 21 |
* |
| 22 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 23 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 24 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 25 |
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 26 |
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 27 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 28 |
*/ |
| 29 |
|
| 30 |
|
| 31 |
#include "glheader.h" |
| 32 |
#include "context.h" |
| 33 |
#include "depth.h" |
| 34 |
#include "lines.h" |
| 35 |
#include "macros.h" |
| 36 |
#include "texstate.h" |
| 37 |
#include "mtypes.h" |
| 38 |
|
| 39 |
|
| 40 |
/** |
| 41 |
* Set the line width. |
| 42 |
* |
| 43 |
* \param width line width in pixels. |
| 44 |
* |
| 45 |
* \sa glLineWidth(). |
| 46 |
* |
| 47 |
* Verifies the parameter and updates gl_line_attrib::Width. On a change, |
| 48 |
* flushes the vertices, updates the clamped line width and marks the |
| 49 |
* DD_LINE_WIDTH flag in __GLcontextRec::_TriangleCaps for the drivers if the |
| 50 |
* width is different from one. Notifies the driver via the |
| 51 |
* dd_function_table::LineWidth callback. |
| 52 |
*/ |
| 53 |
void GLAPIENTRY |
| 54 |
_mesa_LineWidth( GLfloat width ) |
| 55 |
{ |
| 56 |
GET_CURRENT_CONTEXT(ctx); |
| 57 |
ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 58 |
|
| 59 |
if (width<=0.0) { |
| 60 |
_mesa_error( ctx, GL_INVALID_VALUE, "glLineWidth" ); |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
if (ctx->Line.Width == width) |
| 65 |
return; |
| 66 |
|
| 67 |
FLUSH_VERTICES(ctx, _NEW_LINE); |
| 68 |
ctx->Line.Width = width; |
| 69 |
ctx->Line._Width = CLAMP(width, |
| 70 |
ctx->Const.MinLineWidth, |
| 71 |
ctx->Const.MaxLineWidth); |
| 72 |
|
| 73 |
|
| 74 |
if (width != 1.0) |
| 75 |
ctx->_TriangleCaps |= DD_LINE_WIDTH; |
| 76 |
else |
| 77 |
ctx->_TriangleCaps &= ~DD_LINE_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 |
ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 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 __GLcontextRec::Line and line related constants in |
| 123 |
* __GLcontextRec::Const. |
| 124 |
*/ |
| 125 |
void GLAPIENTRY _mesa_init_line( GLcontext * ctx ) |
| 126 |
{ |
| 127 |
/* Line group */ |
| 128 |
ctx->Line.SmoothFlag = GL_FALSE; |
| 129 |
ctx->Line.StippleFlag = GL_FALSE; |
| 130 |
ctx->Line.Width = 1.0; |
| 131 |
ctx->Line._Width = 1.0; |
| 132 |
ctx->Line.StipplePattern = 0xffff; |
| 133 |
ctx->Line.StippleFactor = 1; |
| 134 |
} |