2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * \file swrast/s_span.c
28 * \brief Span processing functions used by all rasterization functions.
29 * This is where all the per-fragment tests are performed
40 #include "s_alphabuf.h"
42 #include "s_context.h"
46 #include "s_masking.h"
47 #include "s_nvfragprog.h"
49 #include "s_stencil.h"
50 #include "s_texture.h"
54 * Init span's Z interpolation values to the RasterPos Z.
55 * Used during setup for glDraw/CopyPixels.
58 _swrast_span_default_z( GLcontext
*ctx
, struct sw_span
*span
)
60 if (ctx
->Visual
.depthBits
<= 16)
61 span
->z
= FloatToFixed(ctx
->Current
.RasterPos
[2] * ctx
->DepthMax
+ 0.5F
);
63 span
->z
= (GLint
) (ctx
->Current
.RasterPos
[2] * ctx
->DepthMax
+ 0.5F
);
65 span
->interpMask
|= SPAN_Z
;
70 * Init span's fog interpolation values to the RasterPos fog.
71 * Used during setup for glDraw/CopyPixels.
74 _swrast_span_default_fog( GLcontext
*ctx
, struct sw_span
*span
)
76 span
->fog
= _swrast_z_to_fogfactor(ctx
, ctx
->Current
.RasterDistance
);
77 span
->fogStep
= span
->dfogdx
= span
->dfogdy
= 0.0F
;
78 span
->interpMask
|= SPAN_FOG
;
83 * Init span's color or index interpolation values to the RasterPos color.
84 * Used during setup for glDraw/CopyPixels.
87 _swrast_span_default_color( GLcontext
*ctx
, struct sw_span
*span
)
89 if (ctx
->Visual
.rgbMode
) {
91 UNCLAMPED_FLOAT_TO_CHAN(r
, ctx
->Current
.RasterColor
[0]);
92 UNCLAMPED_FLOAT_TO_CHAN(g
, ctx
->Current
.RasterColor
[1]);
93 UNCLAMPED_FLOAT_TO_CHAN(b
, ctx
->Current
.RasterColor
[2]);
94 UNCLAMPED_FLOAT_TO_CHAN(a
, ctx
->Current
.RasterColor
[3]);
95 #if CHAN_TYPE == GL_FLOAT
101 span
->red
= IntToFixed(r
);
102 span
->green
= IntToFixed(g
);
103 span
->blue
= IntToFixed(b
);
104 span
->alpha
= IntToFixed(a
);
110 span
->interpMask
|= SPAN_RGBA
;
113 span
->index
= IntToFixed(ctx
->Current
.RasterIndex
);
115 span
->interpMask
|= SPAN_INDEX
;
121 * Init span's texcoord interpolation values to the RasterPos texcoords.
122 * Used during setup for glDraw/CopyPixels.
125 _swrast_span_default_texcoords( GLcontext
*ctx
, struct sw_span
*span
)
128 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
129 COPY_4V(span
->tex
[i
], ctx
->Current
.RasterTexCoords
[i
]);
130 ASSIGN_4V(span
->texStepX
[i
], 0.0F
, 0.0F
, 0.0F
, 0.0F
);
131 ASSIGN_4V(span
->texStepY
[i
], 0.0F
, 0.0F
, 0.0F
, 0.0F
);
133 span
->interpMask
|= SPAN_TEXTURE
;
137 /* Fill in the span.color.rgba array from the interpolation values */
139 interpolate_colors(GLcontext
*ctx
, struct sw_span
*span
)
141 const GLuint n
= span
->end
;
142 GLchan (*rgba
)[4] = span
->array
->rgba
;
145 ASSERT((span
->interpMask
& SPAN_RGBA
) &&
146 !(span
->arrayMask
& SPAN_RGBA
));
148 if (span
->interpMask
& SPAN_FLAT
) {
151 color
[RCOMP
] = FixedToChan(span
->red
);
152 color
[GCOMP
] = FixedToChan(span
->green
);
153 color
[BCOMP
] = FixedToChan(span
->blue
);
154 color
[ACOMP
] = FixedToChan(span
->alpha
);
155 for (i
= 0; i
< n
; i
++) {
156 COPY_CHAN4(span
->array
->rgba
[i
], color
);
161 #if CHAN_TYPE == GL_FLOAT
162 GLfloat r
= span
->red
;
163 GLfloat g
= span
->green
;
164 GLfloat b
= span
->blue
;
165 GLfloat a
= span
->alpha
;
166 const GLfloat dr
= span
->redStep
;
167 const GLfloat dg
= span
->greenStep
;
168 const GLfloat db
= span
->blueStep
;
169 const GLfloat da
= span
->alphaStep
;
171 GLfixed r
= span
->red
;
172 GLfixed g
= span
->green
;
173 GLfixed b
= span
->blue
;
174 GLfixed a
= span
->alpha
;
175 const GLint dr
= span
->redStep
;
176 const GLint dg
= span
->greenStep
;
177 const GLint db
= span
->blueStep
;
178 const GLint da
= span
->alphaStep
;
180 for (i
= 0; i
< n
; i
++) {
181 rgba
[i
][RCOMP
] = FixedToChan(r
);
182 rgba
[i
][GCOMP
] = FixedToChan(g
);
183 rgba
[i
][BCOMP
] = FixedToChan(b
);
184 rgba
[i
][ACOMP
] = FixedToChan(a
);
191 span
->arrayMask
|= SPAN_RGBA
;
195 /* Fill in the span.color.index array from the interpolation values */
197 interpolate_indexes(GLcontext
*ctx
, struct sw_span
*span
)
199 GLfixed index
= span
->index
;
200 const GLint indexStep
= span
->indexStep
;
201 const GLuint n
= span
->end
;
202 GLuint
*indexes
= span
->array
->index
;
204 ASSERT((span
->interpMask
& SPAN_INDEX
) &&
205 !(span
->arrayMask
& SPAN_INDEX
));
207 if ((span
->interpMask
& SPAN_FLAT
) || (indexStep
== 0)) {
209 index
= FixedToInt(index
);
210 for (i
= 0; i
< n
; i
++) {
216 for (i
= 0; i
< n
; i
++) {
217 indexes
[i
] = FixedToInt(index
);
221 span
->arrayMask
|= SPAN_INDEX
;
225 /* Fill in the span.->array->spec array from the interpolation values */
227 interpolate_specular(GLcontext
*ctx
, struct sw_span
*span
)
229 if (span
->interpMask
& SPAN_FLAT
) {
231 const GLchan r
= FixedToChan(span
->specRed
);
232 const GLchan g
= FixedToChan(span
->specGreen
);
233 const GLchan b
= FixedToChan(span
->specBlue
);
235 for (i
= 0; i
< span
->end
; i
++) {
236 span
->array
->spec
[i
][RCOMP
] = r
;
237 span
->array
->spec
[i
][GCOMP
] = g
;
238 span
->array
->spec
[i
][BCOMP
] = b
;
243 #if CHAN_TYPE == GL_FLOAT
244 GLfloat r
= span
->specRed
;
245 GLfloat g
= span
->specGreen
;
246 GLfloat b
= span
->specBlue
;
248 GLfixed r
= span
->specRed
;
249 GLfixed g
= span
->specGreen
;
250 GLfixed b
= span
->specBlue
;
253 for (i
= 0; i
< span
->end
; i
++) {
254 span
->array
->spec
[i
][RCOMP
] = FixedToChan(r
);
255 span
->array
->spec
[i
][GCOMP
] = FixedToChan(g
);
256 span
->array
->spec
[i
][BCOMP
] = FixedToChan(b
);
257 r
+= span
->specRedStep
;
258 g
+= span
->specGreenStep
;
259 b
+= span
->specBlueStep
;
262 span
->arrayMask
|= SPAN_SPEC
;
266 /* Fill in the span.zArray array from the interpolation values */
268 _swrast_span_interpolate_z( const GLcontext
*ctx
, struct sw_span
*span
)
270 const GLuint n
= span
->end
;
273 ASSERT((span
->interpMask
& SPAN_Z
) &&
274 !(span
->arrayMask
& SPAN_Z
));
276 if (ctx
->Visual
.depthBits
<= 16) {
277 GLfixed zval
= span
->z
;
278 GLdepth
*z
= span
->array
->z
;
279 for (i
= 0; i
< n
; i
++) {
280 z
[i
] = FixedToInt(zval
);
285 /* Deep Z buffer, no fixed->int shift */
286 GLfixed zval
= span
->z
;
287 GLdepth
*z
= span
->array
->z
;
288 for (i
= 0; i
< n
; i
++) {
293 span
->arrayMask
|= SPAN_Z
;
298 * This the ideal solution, as given in the OpenGL spec.
302 compute_lambda(GLfloat dsdx
, GLfloat dsdy
, GLfloat dtdx
, GLfloat dtdy
,
303 GLfloat dqdx
, GLfloat dqdy
, GLfloat texW
, GLfloat texH
,
304 GLfloat s
, GLfloat t
, GLfloat q
, GLfloat invQ
)
306 GLfloat dudx
= texW
* ((s
+ dsdx
) / (q
+ dqdx
) - s
* invQ
);
307 GLfloat dvdx
= texH
* ((t
+ dtdx
) / (q
+ dqdx
) - t
* invQ
);
308 GLfloat dudy
= texW
* ((s
+ dsdy
) / (q
+ dqdy
) - s
* invQ
);
309 GLfloat dvdy
= texH
* ((t
+ dtdy
) / (q
+ dqdy
) - t
* invQ
);
310 GLfloat x
= SQRTF(dudx
* dudx
+ dvdx
* dvdx
);
311 GLfloat y
= SQRTF(dudy
* dudy
+ dvdy
* dvdy
);
312 GLfloat rho
= MAX2(x
, y
);
313 GLfloat lambda
= LOG2(rho
);
320 * This is a faster approximation
323 _swrast_compute_lambda(GLfloat dsdx
, GLfloat dsdy
, GLfloat dtdx
, GLfloat dtdy
,
324 GLfloat dqdx
, GLfloat dqdy
, GLfloat texW
, GLfloat texH
,
325 GLfloat s
, GLfloat t
, GLfloat q
, GLfloat invQ
)
327 GLfloat dsdx2
= (s
+ dsdx
) / (q
+ dqdx
) - s
* invQ
;
328 GLfloat dtdx2
= (t
+ dtdx
) / (q
+ dqdx
) - t
* invQ
;
329 GLfloat dsdy2
= (s
+ dsdy
) / (q
+ dqdy
) - s
* invQ
;
330 GLfloat dtdy2
= (t
+ dtdy
) / (q
+ dqdy
) - t
* invQ
;
331 GLfloat maxU
, maxV
, rho
, lambda
;
332 dsdx2
= FABSF(dsdx2
);
333 dsdy2
= FABSF(dsdy2
);
334 dtdx2
= FABSF(dtdx2
);
335 dtdy2
= FABSF(dtdy2
);
336 maxU
= MAX2(dsdx2
, dsdy2
) * texW
;
337 maxV
= MAX2(dtdx2
, dtdy2
) * texH
;
338 rho
= MAX2(maxU
, maxV
);
344 * Fill in the span.texcoords array from the interpolation values.
345 * XXX We could optimize here for the case when dq = 0. That would
346 * usually be the case when using an orthographic projection.
349 interpolate_texcoords(GLcontext
*ctx
, struct sw_span
*span
)
351 ASSERT(span
->interpMask
& SPAN_TEXTURE
);
352 ASSERT(!(span
->arrayMask
& SPAN_TEXTURE
));
354 if (ctx
->Texture
._EnabledCoordUnits
> 1) {
357 span
->arrayMask
|= SPAN_TEXTURE
;
358 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
359 if (ctx
->Texture
._EnabledCoordUnits
& (1 << u
)) {
360 const struct gl_texture_object
*obj
=ctx
->Texture
.Unit
[u
]._Current
;
362 GLboolean needLambda
;
364 const struct gl_texture_image
*img
= obj
->Image
[obj
->BaseLevel
];
365 needLambda
= (obj
->MinFilter
!= obj
->MagFilter
)
366 || ctx
->FragmentProgram
.Enabled
;
367 texW
= img
->WidthScale
;
368 texH
= img
->HeightScale
;
373 needLambda
= GL_FALSE
;
376 GLfloat (*texcoord
)[4] = span
->array
->texcoords
[u
];
377 GLfloat
*lambda
= span
->array
->lambda
[u
];
378 const GLfloat dsdx
= span
->texStepX
[u
][0];
379 const GLfloat dsdy
= span
->texStepY
[u
][0];
380 const GLfloat dtdx
= span
->texStepX
[u
][1];
381 const GLfloat dtdy
= span
->texStepY
[u
][1];
382 const GLfloat drdx
= span
->texStepX
[u
][2];
383 const GLfloat dqdx
= span
->texStepX
[u
][3];
384 const GLfloat dqdy
= span
->texStepY
[u
][3];
385 GLfloat s
= span
->tex
[u
][0];
386 GLfloat t
= span
->tex
[u
][1];
387 GLfloat r
= span
->tex
[u
][2];
388 GLfloat q
= span
->tex
[u
][3];
390 for (i
= 0; i
< span
->end
; i
++) {
391 const GLfloat invQ
= (q
== 0.0F
) ? 1.0F
: (1.0F
/ q
);
392 texcoord
[i
][0] = s
* invQ
;
393 texcoord
[i
][1] = t
* invQ
;
394 texcoord
[i
][2] = r
* invQ
;
396 lambda
[i
] = _swrast_compute_lambda(dsdx
, dsdy
, dtdx
, dtdy
,
397 dqdx
, dqdy
, texW
, texH
,
404 span
->arrayMask
|= SPAN_LAMBDA
;
407 GLfloat (*texcoord
)[4] = span
->array
->texcoords
[u
];
408 GLfloat
*lambda
= span
->array
->lambda
[u
];
409 const GLfloat dsdx
= span
->texStepX
[u
][0];
410 const GLfloat dtdx
= span
->texStepX
[u
][1];
411 const GLfloat drdx
= span
->texStepX
[u
][2];
412 const GLfloat dqdx
= span
->texStepX
[u
][3];
413 GLfloat s
= span
->tex
[u
][0];
414 GLfloat t
= span
->tex
[u
][1];
415 GLfloat r
= span
->tex
[u
][2];
416 GLfloat q
= span
->tex
[u
][3];
419 /* Ortho projection or polygon's parallel to window X axis */
420 const GLfloat invQ
= (q
== 0.0F
) ? 1.0F
: (1.0F
/ q
);
421 for (i
= 0; i
< span
->end
; i
++) {
422 texcoord
[i
][0] = s
* invQ
;
423 texcoord
[i
][1] = t
* invQ
;
424 texcoord
[i
][2] = r
* invQ
;
433 for (i
= 0; i
< span
->end
; i
++) {
434 const GLfloat invQ
= (q
== 0.0F
) ? 1.0F
: (1.0F
/ q
);
435 texcoord
[i
][0] = s
* invQ
;
436 texcoord
[i
][1] = t
* invQ
;
437 texcoord
[i
][2] = r
* invQ
;
452 const struct gl_texture_object
*obj
= ctx
->Texture
.Unit
[0]._Current
;
454 GLboolean needLambda
;
456 const struct gl_texture_image
*img
= obj
->Image
[obj
->BaseLevel
];
457 needLambda
= (obj
->MinFilter
!= obj
->MagFilter
)
458 || ctx
->FragmentProgram
.Enabled
;
459 texW
= (GLfloat
) img
->WidthScale
;
460 texH
= (GLfloat
) img
->HeightScale
;
463 needLambda
= GL_FALSE
;
466 span
->arrayMask
|= SPAN_TEXTURE
;
468 /* just texture unit 0, with lambda */
469 GLfloat (*texcoord
)[4] = span
->array
->texcoords
[0];
470 GLfloat
*lambda
= span
->array
->lambda
[0];
471 const GLfloat dsdx
= span
->texStepX
[0][0];
472 const GLfloat dsdy
= span
->texStepY
[0][0];
473 const GLfloat dtdx
= span
->texStepX
[0][1];
474 const GLfloat dtdy
= span
->texStepY
[0][1];
475 const GLfloat drdx
= span
->texStepX
[0][2];
476 const GLfloat dqdx
= span
->texStepX
[0][3];
477 const GLfloat dqdy
= span
->texStepY
[0][3];
478 GLfloat s
= span
->tex
[0][0];
479 GLfloat t
= span
->tex
[0][1];
480 GLfloat r
= span
->tex
[0][2];
481 GLfloat q
= span
->tex
[0][3];
483 for (i
= 0; i
< span
->end
; i
++) {
484 const GLfloat invQ
= (q
== 0.0F
) ? 1.0F
: (1.0F
/ q
);
485 lambda
[i
] = _swrast_compute_lambda(dsdx
, dsdy
, dtdx
, dtdy
,
486 dqdx
, dqdy
, texW
, texH
,
488 texcoord
[i
][0] = s
* invQ
;
489 texcoord
[i
][1] = t
* invQ
;
490 texcoord
[i
][2] = r
* invQ
;
497 span
->arrayMask
|= SPAN_LAMBDA
;
500 /* just texture 0, without lambda */
501 GLfloat (*texcoord
)[4] = span
->array
->texcoords
[0];
502 const GLfloat dsdx
= span
->texStepX
[0][0];
503 const GLfloat dtdx
= span
->texStepX
[0][1];
504 const GLfloat drdx
= span
->texStepX
[0][2];
505 const GLfloat dqdx
= span
->texStepX
[0][3];
506 GLfloat s
= span
->tex
[0][0];
507 GLfloat t
= span
->tex
[0][1];
508 GLfloat r
= span
->tex
[0][2];
509 GLfloat q
= span
->tex
[0][3];
512 /* Ortho projection or polygon's parallel to window X axis */
513 const GLfloat invQ
= (q
== 0.0F
) ? 1.0F
: (1.0F
/ q
);
514 for (i
= 0; i
< span
->end
; i
++) {
515 texcoord
[i
][0] = s
* invQ
;
516 texcoord
[i
][1] = t
* invQ
;
517 texcoord
[i
][2] = r
* invQ
;
524 for (i
= 0; i
< span
->end
; i
++) {
525 const GLfloat invQ
= (q
== 0.0F
) ? 1.0F
: (1.0F
/ q
);
526 texcoord
[i
][0] = s
* invQ
;
527 texcoord
[i
][1] = t
* invQ
;
528 texcoord
[i
][2] = r
* invQ
;
541 * Apply the current polygon stipple pattern to a span of pixels.
544 stipple_polygon_span( GLcontext
*ctx
, struct sw_span
*span
)
546 const GLuint highbit
= 0x80000000;
547 const GLuint stipple
= ctx
->PolygonStipple
[span
->y
% 32];
548 GLubyte
*mask
= span
->array
->mask
;
551 ASSERT(ctx
->Polygon
.StippleFlag
);
552 ASSERT((span
->arrayMask
& SPAN_XY
) == 0);
554 m
= highbit
>> (GLuint
) (span
->x
% 32);
556 for (i
= 0; i
< span
->end
; i
++) {
557 if ((m
& stipple
) == 0) {
565 span
->writeAll
= GL_FALSE
;
570 * Clip a pixel span to the current buffer/window boundaries:
571 * DrawBuffer->_Xmin, _Xmax, _Ymin, _Ymax. This will accomplish
572 * window clipping and scissoring.
573 * Return: GL_TRUE some pixels still visible
574 * GL_FALSE nothing visible
577 clip_span( GLcontext
*ctx
, struct sw_span
*span
)
579 const GLint xmin
= ctx
->DrawBuffer
->_Xmin
;
580 const GLint xmax
= ctx
->DrawBuffer
->_Xmax
;
581 const GLint ymin
= ctx
->DrawBuffer
->_Ymin
;
582 const GLint ymax
= ctx
->DrawBuffer
->_Ymax
;
584 if (span
->arrayMask
& SPAN_XY
) {
585 /* arrays of x/y pixel coords */
586 const GLint
*x
= span
->array
->x
;
587 const GLint
*y
= span
->array
->y
;
588 const GLint n
= span
->end
;
589 GLubyte
*mask
= span
->array
->mask
;
591 if (span
->arrayMask
& SPAN_MASK
) {
592 /* note: using & intead of && to reduce branches */
593 for (i
= 0; i
< n
; i
++) {
594 mask
[i
] &= (x
[i
] >= xmin
) & (x
[i
] < xmax
)
595 & (y
[i
] >= ymin
) & (y
[i
] < ymax
);
599 /* note: using & intead of && to reduce branches */
600 for (i
= 0; i
< n
; i
++) {
601 mask
[i
] = (x
[i
] >= xmin
) & (x
[i
] < xmax
)
602 & (y
[i
] >= ymin
) & (y
[i
] < ymax
);
605 return GL_TRUE
; /* some pixels visible */
608 /* horizontal span of pixels */
609 const GLint x
= span
->x
;
610 const GLint y
= span
->y
;
611 const GLint n
= span
->end
;
613 /* Trivial rejection tests */
614 if (y
< ymin
|| y
>= ymax
|| x
+ n
<= xmin
|| x
>= xmax
) {
616 return GL_FALSE
; /* all pixels clipped */
619 /* Clip to the left */
621 ASSERT(x
+ n
> xmin
);
622 span
->writeAll
= GL_FALSE
;
623 _mesa_bzero(span
->array
->mask
, (xmin
- x
) * sizeof(GLubyte
));
629 span
->end
= xmax
- x
;
632 return GL_TRUE
; /* some pixels visible */
639 * Draw to more than one color buffer (or none).
642 multi_write_index_span( GLcontext
*ctx
, struct sw_span
*span
)
644 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
647 /* loop over four possible dest color buffers */
648 for (bufferBit
= 1; bufferBit
<= 8; bufferBit
<<= 1) {
649 if (bufferBit
& ctx
->Color
._DrawDestMask
) {
650 GLuint indexTmp
[MAX_WIDTH
];
651 ASSERT(span
->end
< MAX_WIDTH
);
653 /* Set the current read/draw buffer */
654 swrast
->CurrentBuffer
= bufferBit
;
655 (*swrast
->Driver
.SetBuffer
)(ctx
, ctx
->DrawBuffer
, bufferBit
);
657 /* make copy of incoming indexes */
658 MEMCPY( indexTmp
, span
->array
->index
, span
->end
* sizeof(GLuint
) );
660 if (ctx
->Color
.IndexLogicOpEnabled
) {
661 _swrast_logicop_ci_span(ctx
, span
, indexTmp
);
664 if (ctx
->Color
.IndexMask
!= 0xffffffff) {
665 _swrast_mask_index_span(ctx
, span
, indexTmp
);
668 if (span
->arrayMask
& SPAN_XY
) {
669 /* array of pixel coords */
670 (*swrast
->Driver
.WriteCI32Pixels
)(ctx
, span
->end
,
671 span
->array
->x
, span
->array
->y
,
672 indexTmp
, span
->array
->mask
);
675 /* horizontal run of pixels */
676 (*swrast
->Driver
.WriteCI32Span
)(ctx
, span
->end
, span
->x
, span
->y
,
677 indexTmp
, span
->array
->mask
);
682 /* restore default dest buffer */
683 _swrast_use_draw_buffer(ctx
);
688 * Draw to more than one RGBA color buffer (or none).
689 * All fragment operations, up to (but not) blending/logicop should
690 * have been done first.
693 multi_write_rgba_span( GLcontext
*ctx
, struct sw_span
*span
)
695 const GLuint colorMask
= *((GLuint
*) ctx
->Color
.ColorMask
);
697 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
699 ASSERT(colorMask
!= 0x0);
701 if (ctx
->Color
.DrawBuffer
== GL_NONE
)
704 /* loop over four possible dest color buffers */
705 for (bufferBit
= 1; bufferBit
<= 8; bufferBit
<<= 1) {
706 if (bufferBit
& ctx
->Color
._DrawDestMask
) {
707 GLchan rgbaTmp
[MAX_WIDTH
][4];
708 ASSERT(span
->end
< MAX_WIDTH
);
710 /* Set the current read/draw buffer */
711 swrast
->CurrentBuffer
= bufferBit
;
712 (*swrast
->Driver
.SetBuffer
)(ctx
, ctx
->DrawBuffer
, bufferBit
);
714 /* make copy of incoming colors */
715 MEMCPY( rgbaTmp
, span
->array
->rgba
, 4 * span
->end
* sizeof(GLchan
) );
717 if (ctx
->Color
.ColorLogicOpEnabled
) {
718 _swrast_logicop_rgba_span(ctx
, span
, rgbaTmp
);
720 else if (ctx
->Color
.BlendEnabled
) {
721 _swrast_blend_span(ctx
, span
, rgbaTmp
);
724 if (colorMask
!= 0xffffffff) {
725 _swrast_mask_rgba_span(ctx
, span
, rgbaTmp
);
728 if (span
->arrayMask
& SPAN_XY
) {
729 /* array of pixel coords */
730 (*swrast
->Driver
.WriteRGBAPixels
)(ctx
, span
->end
,
731 span
->array
->x
, span
->array
->y
,
732 (const GLchan (*)[4]) rgbaTmp
,
734 if (SWRAST_CONTEXT(ctx
)->_RasterMask
& ALPHABUF_BIT
) {
735 _swrast_write_alpha_pixels(ctx
, span
->end
,
736 span
->array
->x
, span
->array
->y
,
737 (const GLchan (*)[4]) rgbaTmp
,
742 /* horizontal run of pixels */
743 (*swrast
->Driver
.WriteRGBASpan
)(ctx
, span
->end
, span
->x
, span
->y
,
744 (const GLchan (*)[4]) rgbaTmp
,
746 if (swrast
->_RasterMask
& ALPHABUF_BIT
) {
747 _swrast_write_alpha_span(ctx
, span
->end
, span
->x
, span
->y
,
748 (const GLchan (*)[4]) rgbaTmp
,
755 /* restore default dest buffer */
756 _swrast_use_draw_buffer(ctx
);
762 * This function may modify any of the array values in the span.
763 * span->interpMask and span->arrayMask may be changed but will be restored
764 * to their original values before returning.
767 _swrast_write_index_span( GLcontext
*ctx
, struct sw_span
*span
)
769 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
770 const GLuint origInterpMask
= span
->interpMask
;
771 const GLuint origArrayMask
= span
->arrayMask
;
773 ASSERT(span
->end
<= MAX_WIDTH
);
774 ASSERT(span
->primitive
== GL_POINT
|| span
->primitive
== GL_LINE
||
775 span
->primitive
== GL_POLYGON
|| span
->primitive
== GL_BITMAP
);
776 ASSERT((span
->interpMask
| span
->arrayMask
) & SPAN_INDEX
);
777 ASSERT((span
->interpMask
& span
->arrayMask
) == 0);
779 if (span
->arrayMask
& SPAN_MASK
) {
780 /* mask was initialized by caller, probably glBitmap */
781 span
->writeAll
= GL_FALSE
;
784 MEMSET(span
->array
->mask
, 1, span
->end
);
785 span
->writeAll
= GL_TRUE
;
789 if ((swrast
->_RasterMask
& CLIP_BIT
) || (span
->primitive
!= GL_POLYGON
)) {
790 if (!clip_span(ctx
, span
)) {
796 if (span
->arrayMask
& SPAN_XY
) {
798 for (i
= 0; i
< span
->end
; i
++) {
799 if (span
->array
->mask
[i
]) {
800 assert(span
->array
->x
[i
] >= ctx
->DrawBuffer
->_Xmin
);
801 assert(span
->array
->x
[i
] < ctx
->DrawBuffer
->_Xmax
);
802 assert(span
->array
->y
[i
] >= ctx
->DrawBuffer
->_Ymin
);
803 assert(span
->array
->y
[i
] < ctx
->DrawBuffer
->_Ymax
);
809 /* Polygon Stippling */
810 if (ctx
->Polygon
.StippleFlag
&& span
->primitive
== GL_POLYGON
) {
811 stipple_polygon_span(ctx
, span
);
814 /* Depth test and stencil */
815 if (ctx
->Depth
.Test
|| ctx
->Stencil
.Enabled
) {
816 if (span
->interpMask
& SPAN_Z
)
817 _swrast_span_interpolate_z(ctx
, span
);
819 if (ctx
->Stencil
.Enabled
) {
820 if (!_swrast_stencil_and_ztest_span(ctx
, span
)) {
821 span
->arrayMask
= origArrayMask
;
826 ASSERT(ctx
->Depth
.Test
);
827 if (!_swrast_depth_test_span(ctx
, span
)) {
828 span
->arrayMask
= origArrayMask
;
834 /* if we get here, something passed the depth test */
835 ctx
->OcclusionResult
= GL_TRUE
;
837 /* we have to wait until after occlusion to do this test */
838 if (ctx
->Color
.DrawBuffer
== GL_NONE
|| ctx
->Color
.IndexMask
== 0) {
839 /* write no pixels */
840 span
->arrayMask
= origArrayMask
;
844 /* Interpolate the color indexes if needed */
845 if (span
->interpMask
& SPAN_INDEX
) {
846 interpolate_indexes(ctx
, span
);
847 /* clear the bit - this allows the WriteMonoCISpan optimization below */
848 span
->interpMask
&= ~SPAN_INDEX
;
852 if (ctx
->Fog
.Enabled
) {
853 _swrast_fog_ci_span(ctx
, span
);
856 /* Antialias coverage application */
857 if (span
->arrayMask
& SPAN_COVERAGE
) {
859 GLuint
*index
= span
->array
->index
;
860 GLfloat
*coverage
= span
->array
->coverage
;
861 for (i
= 0; i
< span
->end
; i
++) {
862 ASSERT(coverage
[i
] < 16);
863 index
[i
] = (index
[i
] & ~0xf) | ((GLuint
) coverage
[i
]);
867 if (swrast
->_RasterMask
& MULTI_DRAW_BIT
) {
868 /* draw to zero or two or more buffers */
869 multi_write_index_span(ctx
, span
);
872 /* normal situation: draw to exactly one buffer */
873 if (ctx
->Color
.IndexLogicOpEnabled
) {
874 _swrast_logicop_ci_span(ctx
, span
, span
->array
->index
);
877 if (ctx
->Color
.IndexMask
!= 0xffffffff) {
878 _swrast_mask_index_span(ctx
, span
, span
->array
->index
);
882 if (span
->arrayMask
& SPAN_XY
) {
883 /* array of pixel coords */
884 if ((span
->interpMask
& SPAN_INDEX
) && span
->indexStep
== 0) {
885 /* all pixels have same color index */
886 (*swrast
->Driver
.WriteMonoCIPixels
)(ctx
, span
->end
,
887 span
->array
->x
, span
->array
->y
,
888 FixedToInt(span
->index
),
892 (*swrast
->Driver
.WriteCI32Pixels
)(ctx
, span
->end
, span
->array
->x
,
893 span
->array
->y
, span
->array
->index
,
898 /* horizontal run of pixels */
899 if ((span
->interpMask
& SPAN_INDEX
) && span
->indexStep
== 0) {
900 /* all pixels have same color index */
901 (*swrast
->Driver
.WriteMonoCISpan
)(ctx
, span
->end
, span
->x
, span
->y
,
902 FixedToInt(span
->index
),
906 (*swrast
->Driver
.WriteCI32Span
)(ctx
, span
->end
, span
->x
, span
->y
,
913 span
->interpMask
= origInterpMask
;
914 span
->arrayMask
= origArrayMask
;
919 * This function may modify any of the array values in the span.
920 * span->interpMask and span->arrayMask may be changed but will be restored
921 * to their original values before returning.
924 _swrast_write_rgba_span( GLcontext
*ctx
, struct sw_span
*span
)
926 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
927 const GLuint colorMask
= *((GLuint
*) ctx
->Color
.ColorMask
);
928 const GLuint origInterpMask
= span
->interpMask
;
929 const GLuint origArrayMask
= span
->arrayMask
;
932 ASSERT(span
->end
<= MAX_WIDTH
);
933 ASSERT(span
->primitive
== GL_POINT
|| span
->primitive
== GL_LINE
||
934 span
->primitive
== GL_POLYGON
|| span
->primitive
== GL_BITMAP
);
935 ASSERT((span
->interpMask
& span
->arrayMask
) == 0);
936 ASSERT((span
->interpMask
| span
->arrayMask
) & SPAN_RGBA
);
938 if (ctx
->Fog
.Enabled
)
939 ASSERT((span
->interpMask
| span
->arrayMask
) & SPAN_FOG
);
941 ASSERT((span
->interpMask
| span
->arrayMask
) & SPAN_Z
);
944 if (span
->arrayMask
& SPAN_MASK
) {
945 /* mask was initialized by caller, probably glBitmap */
946 span
->writeAll
= GL_FALSE
;
949 MEMSET(span
->array
->mask
, 1, span
->end
);
950 span
->writeAll
= GL_TRUE
;
953 /* Determine if we have mono-chromatic colors */
954 monoColor
= (span
->interpMask
& SPAN_RGBA
) &&
955 span
->redStep
== 0 && span
->greenStep
== 0 &&
956 span
->blueStep
== 0 && span
->alphaStep
== 0;
959 if ((swrast
->_RasterMask
& CLIP_BIT
) || (span
->primitive
!= GL_POLYGON
)) {
960 if (!clip_span(ctx
, span
)) {
966 if (span
->arrayMask
& SPAN_XY
) {
968 for (i
= 0; i
< span
->end
; i
++) {
969 if (span
->array
->mask
[i
]) {
970 assert(span
->array
->x
[i
] >= ctx
->DrawBuffer
->_Xmin
);
971 assert(span
->array
->x
[i
] < ctx
->DrawBuffer
->_Xmax
);
972 assert(span
->array
->y
[i
] >= ctx
->DrawBuffer
->_Ymin
);
973 assert(span
->array
->y
[i
] < ctx
->DrawBuffer
->_Ymax
);
979 /* Polygon Stippling */
980 if (ctx
->Polygon
.StippleFlag
&& span
->primitive
== GL_POLYGON
) {
981 stipple_polygon_span(ctx
, span
);
984 /* Fragment program */
985 if (ctx
->FragmentProgram
.Enabled
) {
986 /* Now we may need to interpolate the colors */
987 if ((span
->interpMask
& SPAN_RGBA
) &&
988 (span
->arrayMask
& SPAN_RGBA
) == 0) {
989 interpolate_colors(ctx
, span
);
990 span
->interpMask
&= ~SPAN_RGBA
;
992 if (span
->interpMask
& SPAN_SPEC
) {
993 interpolate_specular(ctx
, span
);
995 _swrast_exec_nv_fragment_program(ctx
, span
);
996 monoColor
= GL_FALSE
;
999 /* Do the alpha test */
1000 if (ctx
->Color
.AlphaEnabled
) {
1001 if (!_swrast_alpha_test(ctx
, span
)) {
1002 span
->interpMask
= origInterpMask
;
1003 span
->arrayMask
= origArrayMask
;
1008 /* Stencil and Z testing */
1009 if (ctx
->Stencil
.Enabled
|| ctx
->Depth
.Test
) {
1010 if (span
->interpMask
& SPAN_Z
)
1011 _swrast_span_interpolate_z(ctx
, span
);
1013 if (ctx
->Stencil
.Enabled
) {
1014 if (!_swrast_stencil_and_ztest_span(ctx
, span
)) {
1015 span
->interpMask
= origInterpMask
;
1016 span
->arrayMask
= origArrayMask
;
1021 ASSERT(ctx
->Depth
.Test
);
1022 ASSERT(span
->arrayMask
& SPAN_Z
);
1023 /* regular depth testing */
1024 if (!_swrast_depth_test_span(ctx
, span
)) {
1025 span
->interpMask
= origInterpMask
;
1026 span
->arrayMask
= origArrayMask
;
1032 /* if we get here, something passed the depth test */
1033 ctx
->OcclusionResult
= GL_TRUE
;
1035 /* can't abort span-writing until after occlusion testing */
1036 if (colorMask
== 0x0) {
1037 span
->interpMask
= origInterpMask
;
1038 span
->arrayMask
= origArrayMask
;
1042 /* Now we may need to interpolate the colors */
1043 if ((span
->interpMask
& SPAN_RGBA
) && (span
->arrayMask
& SPAN_RGBA
) == 0) {
1044 interpolate_colors(ctx
, span
);
1045 /* clear the bit - this allows the WriteMonoCISpan optimization below */
1046 span
->interpMask
&= ~SPAN_RGBA
;
1050 if (ctx
->Fog
.Enabled
) {
1051 _swrast_fog_rgba_span(ctx
, span
);
1052 monoColor
= GL_FALSE
;
1055 /* Antialias coverage application */
1056 if (span
->arrayMask
& SPAN_COVERAGE
) {
1057 GLchan (*rgba
)[4] = span
->array
->rgba
;
1058 GLfloat
*coverage
= span
->array
->coverage
;
1060 for (i
= 0; i
< span
->end
; i
++) {
1061 rgba
[i
][ACOMP
] = (GLchan
) (rgba
[i
][ACOMP
] * coverage
[i
]);
1063 monoColor
= GL_FALSE
;
1066 if (swrast
->_RasterMask
& MULTI_DRAW_BIT
) {
1067 multi_write_rgba_span(ctx
, span
);
1070 /* normal: write to exactly one buffer */
1071 if (ctx
->Color
.ColorLogicOpEnabled
) {
1072 _swrast_logicop_rgba_span(ctx
, span
, span
->array
->rgba
);
1073 monoColor
= GL_FALSE
;
1075 else if (ctx
->Color
.BlendEnabled
) {
1076 _swrast_blend_span(ctx
, span
, span
->array
->rgba
);
1077 monoColor
= GL_FALSE
;
1080 /* Color component masking */
1081 if (colorMask
!= 0xffffffff) {
1082 _swrast_mask_rgba_span(ctx
, span
, span
->array
->rgba
);
1083 monoColor
= GL_FALSE
;
1087 if (span
->arrayMask
& SPAN_XY
) {
1088 /* array of pixel coords */
1089 /* XXX test for mono color */
1090 (*swrast
->Driver
.WriteRGBAPixels
)(ctx
, span
->end
, span
->array
->x
,
1091 span
->array
->y
, (const GLchan (*)[4]) span
->array
->rgba
, span
->array
->mask
);
1092 if (SWRAST_CONTEXT(ctx
)->_RasterMask
& ALPHABUF_BIT
) {
1093 _swrast_write_alpha_pixels(ctx
, span
->end
,
1094 span
->array
->x
, span
->array
->y
,
1095 (const GLchan (*)[4]) span
->array
->rgba
,
1100 /* horizontal run of pixels */
1102 /* all pixels have same color */
1104 color
[RCOMP
] = FixedToChan(span
->red
);
1105 color
[GCOMP
] = FixedToChan(span
->green
);
1106 color
[BCOMP
] = FixedToChan(span
->blue
);
1107 color
[ACOMP
] = FixedToChan(span
->alpha
);
1108 (*swrast
->Driver
.WriteMonoRGBASpan
)(ctx
, span
->end
, span
->x
,
1109 span
->y
, color
, span
->array
->mask
);
1110 if (swrast
->_RasterMask
& ALPHABUF_BIT
) {
1111 _swrast_write_mono_alpha_span(ctx
, span
->end
, span
->x
, span
->y
,
1113 span
->writeAll
? ((const GLubyte
*) NULL
) : span
->array
->mask
);
1117 /* each pixel is a different color */
1118 (*swrast
->Driver
.WriteRGBASpan
)(ctx
, span
->end
, span
->x
, span
->y
,
1119 (const GLchan (*)[4]) span
->array
->rgba
,
1120 span
->writeAll
? ((const GLubyte
*) NULL
) : span
->array
->mask
);
1121 if (swrast
->_RasterMask
& ALPHABUF_BIT
) {
1122 _swrast_write_alpha_span(ctx
, span
->end
, span
->x
, span
->y
,
1123 (const GLchan (*)[4]) span
->array
->rgba
,
1124 span
->writeAll
? ((const GLubyte
*) NULL
) : span
->array
->mask
);
1130 span
->interpMask
= origInterpMask
;
1131 span
->arrayMask
= origArrayMask
;
1136 * Add specular color to base color. This is used only when
1137 * GL_LIGHT_MODEL_COLOR_CONTROL = GL_SEPARATE_SPECULAR_COLOR.
1140 add_colors(GLuint n
, GLchan rgba
[][4], GLchan specular
[][4] )
1143 for (i
= 0; i
< n
; i
++) {
1144 #if CHAN_TYPE == GL_FLOAT
1146 rgba
[i
][RCOMP
] += specular
[i
][RCOMP
];
1147 rgba
[i
][GCOMP
] += specular
[i
][GCOMP
];
1148 rgba
[i
][BCOMP
] += specular
[i
][BCOMP
];
1150 GLint r
= rgba
[i
][RCOMP
] + specular
[i
][RCOMP
];
1151 GLint g
= rgba
[i
][GCOMP
] + specular
[i
][GCOMP
];
1152 GLint b
= rgba
[i
][BCOMP
] + specular
[i
][BCOMP
];
1153 rgba
[i
][RCOMP
] = (GLchan
) MIN2(r
, CHAN_MAX
);
1154 rgba
[i
][GCOMP
] = (GLchan
) MIN2(g
, CHAN_MAX
);
1155 rgba
[i
][BCOMP
] = (GLchan
) MIN2(b
, CHAN_MAX
);
1162 * This function may modify any of the array values in the span.
1163 * span->interpMask and span->arrayMask may be changed but will be restored
1164 * to their original values before returning.
1167 _swrast_write_texture_span( GLcontext
*ctx
, struct sw_span
*span
)
1169 const GLuint colorMask
= *((GLuint
*) ctx
->Color
.ColorMask
);
1170 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1171 const GLuint origArrayMask
= span
->arrayMask
;
1173 ASSERT(span
->primitive
== GL_POINT
|| span
->primitive
== GL_LINE
||
1174 span
->primitive
== GL_POLYGON
|| span
->primitive
== GL_BITMAP
);
1175 ASSERT(span
->end
<= MAX_WIDTH
);
1176 ASSERT((span
->interpMask
& span
->arrayMask
) == 0);
1177 ASSERT(ctx
->Texture
._EnabledCoordUnits
);
1180 printf("%s() interp 0x%x array 0x%x\n", __FUNCTION__, span->interpMask, span->arrayMask);
1183 if (span
->arrayMask
& SPAN_MASK
) {
1184 /* mask was initialized by caller, probably glBitmap */
1185 span
->writeAll
= GL_FALSE
;
1188 MEMSET(span
->array
->mask
, 1, span
->end
);
1189 span
->writeAll
= GL_TRUE
;
1193 if ((swrast
->_RasterMask
& CLIP_BIT
) || (span
->primitive
!= GL_POLYGON
)) {
1194 if (!clip_span(ctx
, span
)) {
1200 if (span
->arrayMask
& SPAN_XY
) {
1202 for (i
= 0; i
< span
->end
; i
++) {
1203 if (span
->array
->mask
[i
]) {
1204 assert(span
->array
->x
[i
] >= ctx
->DrawBuffer
->_Xmin
);
1205 assert(span
->array
->x
[i
] < ctx
->DrawBuffer
->_Xmax
);
1206 assert(span
->array
->y
[i
] >= ctx
->DrawBuffer
->_Ymin
);
1207 assert(span
->array
->y
[i
] < ctx
->DrawBuffer
->_Ymax
);
1213 /* Polygon Stippling */
1214 if (ctx
->Polygon
.StippleFlag
&& span
->primitive
== GL_POLYGON
) {
1215 stipple_polygon_span(ctx
, span
);
1218 /* Need texture coordinates now */
1219 if ((span
->interpMask
& SPAN_TEXTURE
)
1220 && (span
->arrayMask
& SPAN_TEXTURE
) == 0)
1221 interpolate_texcoords(ctx
, span
);
1223 /* Texture with alpha test */
1224 if (ctx
->Color
.AlphaEnabled
) {
1226 /* Now we need the rgba array, fill it in if needed */
1227 if ((span
->interpMask
& SPAN_RGBA
) && (span
->arrayMask
& SPAN_RGBA
) == 0)
1228 interpolate_colors(ctx
, span
);
1230 if (span
->interpMask
& SPAN_SPEC
) {
1231 interpolate_specular(ctx
, span
);
1234 /* Texturing without alpha is done after depth-testing which
1235 * gives a potential speed-up.
1237 if (ctx
->FragmentProgram
.Enabled
)
1238 _swrast_exec_nv_fragment_program( ctx
, span
);
1240 _swrast_texture_span( ctx
, span
);
1242 /* Do the alpha test */
1243 if (!_swrast_alpha_test(ctx
, span
)) {
1244 span
->arrayMask
= origArrayMask
;
1249 /* Stencil and Z testing */
1250 if (ctx
->Stencil
.Enabled
|| ctx
->Depth
.Test
) {
1251 if (span
->interpMask
& SPAN_Z
)
1252 _swrast_span_interpolate_z(ctx
, span
);
1254 if (ctx
->Stencil
.Enabled
) {
1255 if (!_swrast_stencil_and_ztest_span(ctx
, span
)) {
1256 span
->arrayMask
= origArrayMask
;
1261 ASSERT(ctx
->Depth
.Test
);
1262 ASSERT(span
->arrayMask
& SPAN_Z
);
1263 /* regular depth testing */
1264 if (!_swrast_depth_test_span(ctx
, span
)) {
1265 span
->arrayMask
= origArrayMask
;
1271 /* if we get here, some fragments passed the depth test */
1272 ctx
->OcclusionResult
= GL_TRUE
;
1274 /* We had to wait until now to check for glColorMask(F,F,F,F) because of
1275 * the occlusion test.
1277 if (colorMask
== 0x0) {
1278 span
->arrayMask
= origArrayMask
;
1282 /* Texture without alpha test */
1283 if (!ctx
->Color
.AlphaEnabled
) {
1285 /* Now we need the rgba array, fill it in if needed */
1286 if ((span
->interpMask
& SPAN_RGBA
) && (span
->arrayMask
& SPAN_RGBA
) == 0)
1287 interpolate_colors(ctx
, span
);
1289 if (span
->interpMask
& SPAN_SPEC
) {
1290 interpolate_specular(ctx
, span
);
1293 if (ctx
->FragmentProgram
.Enabled
)
1294 _swrast_exec_nv_fragment_program( ctx
, span
);
1296 _swrast_texture_span( ctx
, span
);
1299 ASSERT(span
->arrayMask
& SPAN_RGBA
);
1301 /* Add base and specular colors */
1302 if (ctx
->Fog
.ColorSumEnabled
||
1303 (ctx
->Light
.Enabled
&&
1304 ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
)) {
1305 if (span
->interpMask
& SPAN_SPEC
) {
1306 interpolate_specular(ctx
, span
);
1308 ASSERT(span
->arrayMask
& SPAN_SPEC
);
1309 add_colors( span
->end
, span
->array
->rgba
, span
->array
->spec
);
1313 if (ctx
->Fog
.Enabled
) {
1314 _swrast_fog_rgba_span(ctx
, span
);
1317 /* Antialias coverage application */
1318 if (span
->arrayMask
& SPAN_COVERAGE
) {
1319 GLchan (*rgba
)[4] = span
->array
->rgba
;
1320 GLfloat
*coverage
= span
->array
->coverage
;
1322 for (i
= 0; i
< span
->end
; i
++) {
1323 rgba
[i
][ACOMP
] = (GLchan
) (rgba
[i
][ACOMP
] * coverage
[i
]);
1327 if (swrast
->_RasterMask
& MULTI_DRAW_BIT
) {
1328 multi_write_rgba_span(ctx
, span
);
1331 /* normal: write to exactly one buffer */
1332 if (ctx
->Color
.ColorLogicOpEnabled
) {
1333 _swrast_logicop_rgba_span(ctx
, span
, span
->array
->rgba
);
1335 else if (ctx
->Color
.BlendEnabled
) {
1336 _swrast_blend_span(ctx
, span
, span
->array
->rgba
);
1339 if (colorMask
!= 0xffffffff) {
1340 _swrast_mask_rgba_span(ctx
, span
, span
->array
->rgba
);
1344 if (span
->arrayMask
& SPAN_XY
) {
1345 /* array of pixel coords */
1346 (*swrast
->Driver
.WriteRGBAPixels
)(ctx
, span
->end
, span
->array
->x
,
1347 span
->array
->y
, (const GLchan (*)[4]) span
->array
->rgba
, span
->array
->mask
);
1348 if (SWRAST_CONTEXT(ctx
)->_RasterMask
& ALPHABUF_BIT
) {
1349 _swrast_write_alpha_pixels(ctx
, span
->end
,
1350 span
->array
->x
, span
->array
->y
,
1351 (const GLchan (*)[4]) span
->array
->rgba
,
1356 /* horizontal run of pixels */
1357 (*swrast
->Driver
.WriteRGBASpan
)(ctx
, span
->end
, span
->x
, span
->y
,
1358 (const GLchan (*)[4]) span
->array
->rgba
,
1359 span
->writeAll
? NULL
: span
->array
->mask
);
1360 if (swrast
->_RasterMask
& ALPHABUF_BIT
) {
1361 _swrast_write_alpha_span(ctx
, span
->end
, span
->x
, span
->y
,
1362 (const GLchan (*)[4]) span
->array
->rgba
,
1363 span
->writeAll
? NULL
: span
->array
->mask
);
1368 span
->arrayMask
= origArrayMask
;
1374 * Read RGBA pixels from frame buffer. Clipping will be done to prevent
1375 * reading ouside the buffer's boundaries.
1378 _swrast_read_rgba_span( GLcontext
*ctx
, GLframebuffer
*buffer
,
1379 GLuint n
, GLint x
, GLint y
, GLchan rgba
[][4] )
1381 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1382 const GLint bufWidth
= (GLint
) buffer
->Width
;
1383 const GLint bufHeight
= (GLint
) buffer
->Height
;
1385 if (y
< 0 || y
>= bufHeight
|| x
+ (GLint
) n
< 0 || x
>= bufWidth
) {
1386 /* completely above, below, or right */
1387 /* XXX maybe leave undefined? */
1388 _mesa_bzero(rgba
, 4 * n
* sizeof(GLchan
));
1393 /* left edge clippping */
1395 length
= (GLint
) n
- skip
;
1397 /* completely left of window */
1400 if (length
> bufWidth
) {
1404 else if ((GLint
) (x
+ n
) > bufWidth
) {
1405 /* right edge clipping */
1407 length
= bufWidth
- x
;
1409 /* completely to right of window */
1419 (*swrast
->Driver
.ReadRGBASpan
)( ctx
, length
, x
+ skip
, y
, rgba
+ skip
);
1420 if (buffer
->UseSoftwareAlphaBuffers
) {
1421 _swrast_read_alpha_span(ctx
, length
, x
+ skip
, y
, rgba
+ skip
);
1428 * Read CI pixels from frame buffer. Clipping will be done to prevent
1429 * reading ouside the buffer's boundaries.
1432 _swrast_read_index_span( GLcontext
*ctx
, GLframebuffer
*buffer
,
1433 GLuint n
, GLint x
, GLint y
, GLuint indx
[] )
1435 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1436 const GLint bufWidth
= (GLint
) buffer
->Width
;
1437 const GLint bufHeight
= (GLint
) buffer
->Height
;
1439 if (y
< 0 || y
>= bufHeight
|| x
+ (GLint
) n
< 0 || x
>= bufWidth
) {
1440 /* completely above, below, or right */
1441 _mesa_bzero(indx
, n
* sizeof(GLuint
));
1446 /* left edge clippping */
1448 length
= (GLint
) n
- skip
;
1450 /* completely left of window */
1453 if (length
> bufWidth
) {
1457 else if ((GLint
) (x
+ n
) > bufWidth
) {
1458 /* right edge clipping */
1460 length
= bufWidth
- x
;
1462 /* completely to right of window */
1472 (*swrast
->Driver
.ReadCI32Span
)( ctx
, length
, skip
+ x
, y
, indx
+ skip
);