1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
/*
* Mesa 3-D graphics library
* Version: 7.1
*
* Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "main/glheader.h"
#include "main/context.h"
#include "main/colormac.h"
#include "main/macros.h"
#include "s_aaline.h"
#include "s_context.h"
#include "s_feedback.h"
#include "s_lines.h"
#include "s_span.h"
/*
* Init the mask[] array to implement a line stipple.
*/
static void
compute_stipple_mask( GLcontext *ctx, GLuint len, GLubyte mask[] )
{
SWcontext *swrast = SWRAST_CONTEXT(ctx);
GLuint i;
for (i = 0; i < len; i++) {
GLuint bit = (swrast->StippleCounter / ctx->Line.StippleFactor) & 0xf;
if ((1 << bit) & ctx->Line.StipplePattern) {
mask[i] = GL_TRUE;
}
else {
mask[i] = GL_FALSE;
}
swrast->StippleCounter++;
}
}
/*
* To draw a wide line we can simply redraw the span N times, side by side.
*/
static void
draw_wide_line( GLcontext *ctx, SWspan *span, GLboolean xMajor )
{
const GLint width = (GLint) CLAMP(ctx->Line.Width,
ctx->Const.MinLineWidth,
ctx->Const.MaxLineWidth);
GLint start;
ASSERT(span->end < MAX_WIDTH);
if (width & 1)
start = width / 2;
else
start = width / 2 - 1;
if (xMajor) {
GLint *y = span->array->y;
GLuint i;
GLint w;
for (w = 0; w < width; w++) {
if (w == 0) {
for (i = 0; i < span->end; i++)
y[i] -= start;
}
else {
for (i = 0; i < span->end; i++)
y[i]++;
}
if (ctx->Visual.rgbMode)
_swrast_write_rgba_span(ctx, span);
else
_swrast_write_index_span(ctx, span);
}
}
else {
GLint *x = span->array->x;
GLuint i;
GLint w;
for (w = 0; w < width; w++) {
if (w == 0) {
for (i = 0; i < span->end; i++)
x[i] -= start;
}
else {
for (i = 0; i < span->end; i++)
x[i]++;
}
if (ctx->Visual.rgbMode)
_swrast_write_rgba_span(ctx, span);
else
_swrast_write_index_span(ctx, span);
}
}
}
/**********************************************************************/
/***** Rasterization *****/
/**********************************************************************/
/* Simple color index line (no stipple, width=1, no Z, no fog, no tex)*/
#define NAME simple_no_z_ci_line
#define INTERP_INDEX
#define RENDER_SPAN(span) _swrast_write_index_span(ctx, &span)
#include "s_linetemp.h"
/* Simple RGBA index line (no stipple, width=1, no Z, no fog, no tex)*/
#define NAME simple_no_z_rgba_line
#define INTERP_RGBA
#define RENDER_SPAN(span) _swrast_write_rgba_span(ctx, &span);
#include "s_linetemp.h"
/* Z, fog, wide, stipple color index line */
#define NAME ci_line
#define INTERP_INDEX
#define INTERP_Z
#define INTERP_ATTRIBS /* for fog */
#define RENDER_SPAN(span) \
if (ctx->Line.StippleFlag) { \
span.arrayMask |= SPAN_MASK; \
compute_stipple_mask(ctx, span.end, span.array->mask); \
} \
if (ctx->Line.Width > 1.0) { \
draw_wide_line(ctx, &span, (GLboolean)(dx > dy)); \
} \
else { \
_swrast_write_index_span(ctx, &span); \
}
#include "s_linetemp.h"
/* Z, fog, wide, stipple RGBA line */
#define NAME rgba_line
#define INTERP_RGBA
#define INTERP_Z
#define RENDER_SPAN(span) \
if (ctx->Line.StippleFlag) { \
span.arrayMask |= SPAN_MASK; \
compute_stipple_mask(ctx, span.end, span.array->mask); \
} \
if (ctx->Line.Width > 1.0) { \
draw_wide_line(ctx, &span, (GLboolean)(dx > dy)); \
} \
else { \
_swrast_write_rgba_span(ctx, &span); \
}
#include "s_linetemp.h"
/* General-purpose line (any/all features). */
#define NAME general_line
#define INTERP_RGBA
#define INTERP_Z
#define INTERP_ATTRIBS
#define RENDER_SPAN(span) \
if (ctx->Line.StippleFlag) { \
span.arrayMask |= SPAN_MASK; \
compute_stipple_mask(ctx, span.end, span.array->mask); \
} \
if (ctx->Line.Width > 1.0) { \
draw_wide_line(ctx, &span, (GLboolean)(dx > dy)); \
} \
else { \
_swrast_write_rgba_span(ctx, &span); \
}
#include "s_linetemp.h"
void
_swrast_add_spec_terms_line(GLcontext *ctx,
const SWvertex *v0, const SWvertex *v1)
{
SWvertex *ncv0 = (SWvertex *)v0;
SWvertex *ncv1 = (SWvertex *)v1;
GLfloat rSum, gSum, bSum;
GLchan cSave[2][4];
/* save original colors */
COPY_CHAN4(cSave[0], ncv0->color);
COPY_CHAN4(cSave[1], ncv1->color);
/* sum v0 */
rSum = CHAN_TO_FLOAT(ncv0->color[0]) + ncv0->attrib[FRAG_ATTRIB_COL1][0];
gSum = CHAN_TO_FLOAT(ncv0->color[1]) + ncv0->attrib[FRAG_ATTRIB_COL1][1];
bSum = CHAN_TO_FLOAT(ncv0->color[2]) + ncv0->attrib[FRAG_ATTRIB_COL1][2];
UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[0], rSum);
UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[1], gSum);
UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[2], bSum);
/* sum v1 */
rSum = CHAN_TO_FLOAT(ncv1->color[0]) + ncv1->attrib[FRAG_ATTRIB_COL1][0];
gSum = CHAN_TO_FLOAT(ncv1->color[1]) + ncv1->attrib[FRAG_ATTRIB_COL1][1];
bSum = CHAN_TO_FLOAT(ncv1->color[2]) + ncv1->attrib[FRAG_ATTRIB_COL1][2];
UNCLAMPED_FLOAT_TO_CHAN(ncv1->color[0], rSum);
UNCLAMPED_FLOAT_TO_CHAN(ncv1->color[1], gSum);
UNCLAMPED_FLOAT_TO_CHAN(ncv1->color[2], bSum);
/* draw */
SWRAST_CONTEXT(ctx)->SpecLine( ctx, ncv0, ncv1 );
/* restore original colors */
COPY_CHAN4( ncv0->attrib[FRAG_ATTRIB_COL0], cSave[0] );
COPY_CHAN4( ncv1->attrib[FRAG_ATTRIB_COL0], cSave[1] );
}
#ifdef DEBUG
/* record the current line function name */
static const char *lineFuncName = NULL;
#define USE(lineFunc) \
do { \
lineFuncName = #lineFunc; \
/*printf("%s\n", lineFuncName);*/ \
swrast->Line = lineFunc; \
} while (0)
#else
#define USE(lineFunc) swrast->Line = lineFunc
#endif
/**
* Determine which line drawing function to use given the current
* rendering context.
*
* Please update the summary flag _SWRAST_NEW_LINE if you add or remove
* tests to this code.
*/
void
_swrast_choose_line( GLcontext *ctx )
{
SWcontext *swrast = SWRAST_CONTEXT(ctx);
const GLboolean rgbmode = ctx->Visual.rgbMode;
GLboolean specular = (ctx->Fog.ColorSumEnabled ||
(ctx->Light.Enabled &&
ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR));
if (ctx->RenderMode == GL_RENDER) {
if (ctx->Line.SmoothFlag) {
/* antialiased lines */
_swrast_choose_aa_line_function(ctx);
ASSERT(swrast->Line);
}
else if (ctx->Texture._EnabledCoordUnits
|| ctx->FragmentProgram._Current
|| swrast->_FogEnabled
|| specular) {
USE(general_line);
}
else if (ctx->Depth.Test
|| ctx->Line.Width != 1.0
|| ctx->Line.StippleFlag) {
/* no texture, but Z, fog, width>1, stipple, etc. */
if (rgbmode)
#if CHAN_BITS == 32
USE(general_line);
#else
USE(rgba_line);
#endif
else
USE(ci_line);
}
else {
ASSERT(!ctx->Depth.Test);
ASSERT(ctx->Line.Width == 1.0);
/* simple lines */
if (rgbmode)
USE(simple_no_z_rgba_line);
else
USE(simple_no_z_ci_line);
}
}
else if (ctx->RenderMode == GL_FEEDBACK) {
USE(_swrast_feedback_line);
}
else {
ASSERT(ctx->RenderMode == GL_SELECT);
USE(_swrast_select_line);
}
}
|