2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * \file swrast/s_span.c
29 * \brief Span processing functions used by all rasterization functions.
30 * This is where all the per-fragment tests are performed
34 #include "main/glheader.h"
35 #include "main/colormac.h"
36 #include "main/format_pack.h"
37 #include "main/format_unpack.h"
38 #include "main/macros.h"
39 #include "main/imports.h"
40 #include "main/image.h"
44 #include "s_context.h"
48 #include "s_masking.h"
50 #include "s_stencil.h"
51 #include "s_texcombine.h"
54 * Set default fragment attributes for the span using the
55 * current raster values. Used prior to glDraw/CopyPixels
59 _swrast_span_default_attribs(struct gl_context
*ctx
, SWspan
*span
)
64 const GLfloat depthMax
= ctx
->DrawBuffer
->_DepthMaxF
;
65 if (ctx
->DrawBuffer
->Visual
.depthBits
<= 16)
66 span
->z
= FloatToFixed(ctx
->Current
.RasterPos
[2] * depthMax
+ 0.5F
);
68 GLfloat tmpf
= ctx
->Current
.RasterPos
[2] * depthMax
;
69 tmpf
= MIN2(tmpf
, depthMax
);
70 span
->z
= (GLint
)tmpf
;
73 span
->interpMask
|= SPAN_Z
;
76 /* W (for perspective correction) */
77 span
->attrStart
[FRAG_ATTRIB_WPOS
][3] = 1.0;
78 span
->attrStepX
[FRAG_ATTRIB_WPOS
][3] = 0.0;
79 span
->attrStepY
[FRAG_ATTRIB_WPOS
][3] = 0.0;
81 /* primary color, or color index */
82 UNCLAMPED_FLOAT_TO_CHAN(r
, ctx
->Current
.RasterColor
[0]);
83 UNCLAMPED_FLOAT_TO_CHAN(g
, ctx
->Current
.RasterColor
[1]);
84 UNCLAMPED_FLOAT_TO_CHAN(b
, ctx
->Current
.RasterColor
[2]);
85 UNCLAMPED_FLOAT_TO_CHAN(a
, ctx
->Current
.RasterColor
[3]);
86 #if CHAN_TYPE == GL_FLOAT
92 span
->red
= IntToFixed(r
);
93 span
->green
= IntToFixed(g
);
94 span
->blue
= IntToFixed(b
);
95 span
->alpha
= IntToFixed(a
);
101 span
->interpMask
|= SPAN_RGBA
;
103 COPY_4V(span
->attrStart
[FRAG_ATTRIB_COL0
], ctx
->Current
.RasterColor
);
104 ASSIGN_4V(span
->attrStepX
[FRAG_ATTRIB_COL0
], 0.0, 0.0, 0.0, 0.0);
105 ASSIGN_4V(span
->attrStepY
[FRAG_ATTRIB_COL0
], 0.0, 0.0, 0.0, 0.0);
107 /* Secondary color */
108 if (ctx
->Light
.Enabled
|| ctx
->Fog
.ColorSumEnabled
)
110 COPY_4V(span
->attrStart
[FRAG_ATTRIB_COL1
], ctx
->Current
.RasterSecondaryColor
);
111 ASSIGN_4V(span
->attrStepX
[FRAG_ATTRIB_COL1
], 0.0, 0.0, 0.0, 0.0);
112 ASSIGN_4V(span
->attrStepY
[FRAG_ATTRIB_COL1
], 0.0, 0.0, 0.0, 0.0);
117 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
118 GLfloat fogVal
; /* a coord or a blend factor */
119 if (swrast
->_PreferPixelFog
) {
120 /* fog blend factors will be computed from fog coordinates per pixel */
121 fogVal
= ctx
->Current
.RasterDistance
;
124 /* fog blend factor should be computed from fogcoord now */
125 fogVal
= _swrast_z_to_fogfactor(ctx
, ctx
->Current
.RasterDistance
);
127 span
->attrStart
[FRAG_ATTRIB_FOGC
][0] = fogVal
;
128 span
->attrStepX
[FRAG_ATTRIB_FOGC
][0] = 0.0;
129 span
->attrStepY
[FRAG_ATTRIB_FOGC
][0] = 0.0;
134 const GLuint attr
= FRAG_ATTRIB_TEX
;
135 const GLfloat
*tc
= ctx
->Current
.RasterTexCoords
;
137 /* use (s/q, t/q, r/q, 1) */
138 span
->attrStart
[attr
][0] = tc
[0] / tc
[3];
139 span
->attrStart
[attr
][1] = tc
[1] / tc
[3];
140 span
->attrStart
[attr
][2] = tc
[2] / tc
[3];
141 span
->attrStart
[attr
][3] = 1.0;
144 ASSIGN_4V(span
->attrStart
[attr
], 0.0F
, 0.0F
, 0.0F
, 1.0F
);
146 ASSIGN_4V(span
->attrStepX
[attr
], 0.0F
, 0.0F
, 0.0F
, 0.0F
);
147 ASSIGN_4V(span
->attrStepY
[attr
], 0.0F
, 0.0F
, 0.0F
, 0.0F
);
153 * Interpolate the active attributes (and'd with attrMask) to
154 * fill in span->array->attribs[].
155 * Perspective correction will be done. The point/line/triangle function
156 * should have computed attrStart/Step values for FRAG_ATTRIB_WPOS[3]!
159 interpolate_active_attribs(struct gl_context
*ctx
, SWspan
*span
,
160 GLbitfield64 attrMask
)
162 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
165 * Don't overwrite existing array values, such as colors that may have
166 * been produced by glDraw/CopyPixels.
168 attrMask
&= ~span
->arrayAttribs
;
171 if (attrMask
& BITFIELD64_BIT(attr
)) {
172 const GLfloat dwdx
= span
->attrStepX
[FRAG_ATTRIB_WPOS
][3];
173 GLfloat w
= span
->attrStart
[FRAG_ATTRIB_WPOS
][3];
174 const GLfloat dv0dx
= span
->attrStepX
[attr
][0];
175 const GLfloat dv1dx
= span
->attrStepX
[attr
][1];
176 const GLfloat dv2dx
= span
->attrStepX
[attr
][2];
177 const GLfloat dv3dx
= span
->attrStepX
[attr
][3];
178 GLfloat v0
= span
->attrStart
[attr
][0] + span
->leftClip
* dv0dx
;
179 GLfloat v1
= span
->attrStart
[attr
][1] + span
->leftClip
* dv1dx
;
180 GLfloat v2
= span
->attrStart
[attr
][2] + span
->leftClip
* dv2dx
;
181 GLfloat v3
= span
->attrStart
[attr
][3] + span
->leftClip
* dv3dx
;
183 for (k
= 0; k
< span
->end
; k
++) {
184 const GLfloat invW
= 1.0f
/ w
;
185 span
->array
->attribs
[attr
][k
][0] = v0
* invW
;
186 span
->array
->attribs
[attr
][k
][1] = v1
* invW
;
187 span
->array
->attribs
[attr
][k
][2] = v2
* invW
;
188 span
->array
->attribs
[attr
][k
][3] = v3
* invW
;
195 ASSERT((span
->arrayAttribs
& BITFIELD64_BIT(attr
)) == 0);
196 span
->arrayAttribs
|= BITFIELD64_BIT(attr
);
203 * Interpolate primary colors to fill in the span->array->rgba8 (or rgb16)
207 interpolate_int_colors(struct gl_context
*ctx
, SWspan
*span
)
210 const GLuint n
= span
->end
;
213 ASSERT(!(span
->arrayMask
& SPAN_RGBA
));
216 switch (span
->array
->ChanType
) {
218 case GL_UNSIGNED_BYTE
:
220 GLubyte (*rgba
)[4] = span
->array
->rgba8
;
221 if (span
->interpMask
& SPAN_FLAT
) {
223 color
[RCOMP
] = FixedToInt(span
->red
);
224 color
[GCOMP
] = FixedToInt(span
->green
);
225 color
[BCOMP
] = FixedToInt(span
->blue
);
226 color
[ACOMP
] = FixedToInt(span
->alpha
);
227 for (i
= 0; i
< n
; i
++) {
228 COPY_4UBV(rgba
[i
], color
);
232 GLfixed r
= span
->red
;
233 GLfixed g
= span
->green
;
234 GLfixed b
= span
->blue
;
235 GLfixed a
= span
->alpha
;
236 GLint dr
= span
->redStep
;
237 GLint dg
= span
->greenStep
;
238 GLint db
= span
->blueStep
;
239 GLint da
= span
->alphaStep
;
240 for (i
= 0; i
< n
; i
++) {
241 rgba
[i
][RCOMP
] = FixedToChan(r
);
242 rgba
[i
][GCOMP
] = FixedToChan(g
);
243 rgba
[i
][BCOMP
] = FixedToChan(b
);
244 rgba
[i
][ACOMP
] = FixedToChan(a
);
253 case GL_UNSIGNED_SHORT
:
255 GLushort (*rgba
)[4] = span
->array
->rgba16
;
256 if (span
->interpMask
& SPAN_FLAT
) {
258 color
[RCOMP
] = FixedToInt(span
->red
);
259 color
[GCOMP
] = FixedToInt(span
->green
);
260 color
[BCOMP
] = FixedToInt(span
->blue
);
261 color
[ACOMP
] = FixedToInt(span
->alpha
);
262 for (i
= 0; i
< n
; i
++) {
263 COPY_4V(rgba
[i
], color
);
267 GLushort (*rgba
)[4] = span
->array
->rgba16
;
269 GLint dr
, dg
, db
, da
;
275 dg
= span
->greenStep
;
277 da
= span
->alphaStep
;
278 for (i
= 0; i
< n
; i
++) {
279 rgba
[i
][RCOMP
] = FixedToChan(r
);
280 rgba
[i
][GCOMP
] = FixedToChan(g
);
281 rgba
[i
][BCOMP
] = FixedToChan(b
);
282 rgba
[i
][ACOMP
] = FixedToChan(a
);
293 interpolate_active_attribs(ctx
, span
, FRAG_BIT_COL0
);
296 _mesa_problem(ctx
, "bad datatype 0x%x in interpolate_int_colors",
297 span
->array
->ChanType
);
299 span
->arrayMask
|= SPAN_RGBA
;
304 * Populate the FRAG_ATTRIB_COL0 array.
307 interpolate_float_colors(SWspan
*span
)
309 GLfloat (*col0
)[4] = span
->array
->attribs
[FRAG_ATTRIB_COL0
];
310 const GLuint n
= span
->end
;
313 assert(!(span
->arrayAttribs
& FRAG_BIT_COL0
));
315 if (span
->arrayMask
& SPAN_RGBA
) {
316 /* convert array of int colors */
317 for (i
= 0; i
< n
; i
++) {
318 col0
[i
][0] = UBYTE_TO_FLOAT(span
->array
->rgba8
[i
][0]);
319 col0
[i
][1] = UBYTE_TO_FLOAT(span
->array
->rgba8
[i
][1]);
320 col0
[i
][2] = UBYTE_TO_FLOAT(span
->array
->rgba8
[i
][2]);
321 col0
[i
][3] = UBYTE_TO_FLOAT(span
->array
->rgba8
[i
][3]);
325 /* interpolate red/green/blue/alpha to get float colors */
326 ASSERT(span
->interpMask
& SPAN_RGBA
);
327 if (span
->interpMask
& SPAN_FLAT
) {
328 GLfloat r
= FixedToFloat(span
->red
);
329 GLfloat g
= FixedToFloat(span
->green
);
330 GLfloat b
= FixedToFloat(span
->blue
);
331 GLfloat a
= FixedToFloat(span
->alpha
);
332 for (i
= 0; i
< n
; i
++) {
333 ASSIGN_4V(col0
[i
], r
, g
, b
, a
);
337 GLfloat r
= FixedToFloat(span
->red
);
338 GLfloat g
= FixedToFloat(span
->green
);
339 GLfloat b
= FixedToFloat(span
->blue
);
340 GLfloat a
= FixedToFloat(span
->alpha
);
341 GLfloat dr
= FixedToFloat(span
->redStep
);
342 GLfloat dg
= FixedToFloat(span
->greenStep
);
343 GLfloat db
= FixedToFloat(span
->blueStep
);
344 GLfloat da
= FixedToFloat(span
->alphaStep
);
345 for (i
= 0; i
< n
; i
++) {
358 span
->arrayAttribs
|= FRAG_BIT_COL0
;
359 span
->array
->ChanType
= GL_FLOAT
;
365 * Fill in the span.zArray array from the span->z, zStep values.
368 _swrast_span_interpolate_z( const struct gl_context
*ctx
, SWspan
*span
)
370 const GLuint n
= span
->end
;
373 ASSERT(!(span
->arrayMask
& SPAN_Z
));
375 if (ctx
->DrawBuffer
->Visual
.depthBits
<= 16) {
376 GLfixed zval
= span
->z
;
377 GLuint
*z
= span
->array
->z
;
378 for (i
= 0; i
< n
; i
++) {
379 z
[i
] = FixedToInt(zval
);
384 /* Deep Z buffer, no fixed->int shift */
385 GLuint zval
= span
->z
;
386 GLuint
*z
= span
->array
->z
;
387 for (i
= 0; i
< n
; i
++) {
392 span
->interpMask
&= ~SPAN_Z
;
393 span
->arrayMask
|= SPAN_Z
;
398 * Compute mipmap LOD from partial derivatives.
399 * This the ideal solution, as given in the OpenGL spec.
402 _swrast_compute_lambda(GLfloat dsdx
, GLfloat dsdy
, GLfloat dtdx
, GLfloat dtdy
,
403 GLfloat dqdx
, GLfloat dqdy
, GLfloat texW
, GLfloat texH
,
404 GLfloat s
, GLfloat t
, GLfloat q
, GLfloat invQ
)
406 GLfloat dudx
= texW
* ((s
+ dsdx
) / (q
+ dqdx
) - s
* invQ
);
407 GLfloat dvdx
= texH
* ((t
+ dtdx
) / (q
+ dqdx
) - t
* invQ
);
408 GLfloat dudy
= texW
* ((s
+ dsdy
) / (q
+ dqdy
) - s
* invQ
);
409 GLfloat dvdy
= texH
* ((t
+ dtdy
) / (q
+ dqdy
) - t
* invQ
);
410 GLfloat x
= SQRTF(dudx
* dudx
+ dvdx
* dvdx
);
411 GLfloat y
= SQRTF(dudy
* dudy
+ dvdy
* dvdy
);
412 GLfloat rho
= MAX2(x
, y
);
413 GLfloat lambda
= LOG2(rho
);
419 * Compute mipmap LOD from partial derivatives.
420 * This is a faster approximation than above function.
424 _swrast_compute_lambda(GLfloat dsdx
, GLfloat dsdy
, GLfloat dtdx
, GLfloat dtdy
,
425 GLfloat dqdx
, GLfloat dqdy
, GLfloat texW
, GLfloat texH
,
426 GLfloat s
, GLfloat t
, GLfloat q
, GLfloat invQ
)
428 GLfloat dsdx2
= (s
+ dsdx
) / (q
+ dqdx
) - s
* invQ
;
429 GLfloat dtdx2
= (t
+ dtdx
) / (q
+ dqdx
) - t
* invQ
;
430 GLfloat dsdy2
= (s
+ dsdy
) / (q
+ dqdy
) - s
* invQ
;
431 GLfloat dtdy2
= (t
+ dtdy
) / (q
+ dqdy
) - t
* invQ
;
432 GLfloat maxU
, maxV
, rho
, lambda
;
433 dsdx2
= FABSF(dsdx2
);
434 dsdy2
= FABSF(dsdy2
);
435 dtdx2
= FABSF(dtdx2
);
436 dtdy2
= FABSF(dtdy2
);
437 maxU
= MAX2(dsdx2
, dsdy2
) * texW
;
438 maxV
= MAX2(dtdx2
, dtdy2
) * texH
;
439 rho
= MAX2(maxU
, maxV
);
447 * Fill in the span.array->attrib[FRAG_ATTRIB_TEXn] arrays from the
448 * using the attrStart/Step values.
450 * This function only used during fixed-function fragment processing.
452 * Note: in the places where we divide by Q (or mult by invQ) we're
453 * really doing two things: perspective correction and texcoord
454 * projection. Remember, for texcoord (s,t,r,q) we need to index
455 * texels with (s/q, t/q, r/q).
458 interpolate_texcoords(struct gl_context
*ctx
, SWspan
*span
)
460 if (ctx
->Texture
._EnabledCoord
) {
461 const GLuint attr
= FRAG_ATTRIB_TEX
;
462 const struct gl_texture_object
*obj
= ctx
->Texture
.Unit
._Current
;
464 GLboolean needLambda
;
465 GLfloat (*texcoord
)[4] = span
->array
->attribs
[attr
];
466 GLfloat
*lambda
= span
->array
->lambda
;
467 const GLfloat dsdx
= span
->attrStepX
[attr
][0];
468 const GLfloat dsdy
= span
->attrStepY
[attr
][0];
469 const GLfloat dtdx
= span
->attrStepX
[attr
][1];
470 const GLfloat dtdy
= span
->attrStepY
[attr
][1];
471 const GLfloat drdx
= span
->attrStepX
[attr
][2];
472 const GLfloat dqdx
= span
->attrStepX
[attr
][3];
473 const GLfloat dqdy
= span
->attrStepY
[attr
][3];
474 GLfloat s
= span
->attrStart
[attr
][0] + span
->leftClip
* dsdx
;
475 GLfloat t
= span
->attrStart
[attr
][1] + span
->leftClip
* dtdx
;
476 GLfloat r
= span
->attrStart
[attr
][2] + span
->leftClip
* drdx
;
477 GLfloat q
= span
->attrStart
[attr
][3] + span
->leftClip
* dqdx
;
480 const struct gl_texture_image
*img
= obj
->Image
[0][obj
->BaseLevel
];
481 const struct swrast_texture_image
*swImg
=
482 swrast_texture_image_const(img
);
484 needLambda
= (obj
->Sampler
.MinFilter
!= obj
->Sampler
.MagFilter
);
485 /* LOD is calculated directly in the ansiotropic filter, we can
486 * skip the normal lambda function as the result is ignored.
488 if (obj
->Sampler
.MaxAnisotropy
> 1.0 &&
489 obj
->Sampler
.MinFilter
== GL_LINEAR_MIPMAP_LINEAR
) {
490 needLambda
= GL_FALSE
;
492 texW
= swImg
->WidthScale
;
493 texH
= swImg
->HeightScale
;
496 /* using a fragment program */
499 needLambda
= GL_FALSE
;
504 for (i
= 0; i
< span
->end
; i
++) {
505 const GLfloat invQ
= (q
== 0.0F
) ? 1.0F
: (1.0F
/ q
);
506 texcoord
[i
][0] = s
* invQ
;
507 texcoord
[i
][1] = t
* invQ
;
508 texcoord
[i
][2] = r
* invQ
;
510 lambda
[i
] = _swrast_compute_lambda(dsdx
, dsdy
, dtdx
, dtdy
,
511 dqdx
, dqdy
, texW
, texH
,
518 span
->arrayMask
|= SPAN_LAMBDA
;
523 /* Ortho projection or polygon's parallel to window X axis */
524 const GLfloat invQ
= (q
== 0.0F
) ? 1.0F
: (1.0F
/ q
);
525 for (i
= 0; i
< span
->end
; i
++) {
526 texcoord
[i
][0] = s
* invQ
;
527 texcoord
[i
][1] = t
* invQ
;
528 texcoord
[i
][2] = r
* invQ
;
537 for (i
= 0; i
< span
->end
; i
++) {
538 const GLfloat invQ
= (q
== 0.0F
) ? 1.0F
: (1.0F
/ q
);
539 texcoord
[i
][0] = s
* invQ
;
540 texcoord
[i
][1] = t
* invQ
;
541 texcoord
[i
][2] = r
* invQ
;
556 * Fill in the arrays->attribs[FRAG_ATTRIB_WPOS] array.
559 interpolate_wpos(struct gl_context
*ctx
, SWspan
*span
)
561 GLfloat (*wpos
)[4] = span
->array
->attribs
[FRAG_ATTRIB_WPOS
];
563 const GLfloat zScale
= 1.0F
/ ctx
->DrawBuffer
->_DepthMaxF
;
566 if (span
->arrayMask
& SPAN_XY
) {
567 for (i
= 0; i
< span
->end
; i
++) {
568 wpos
[i
][0] = (GLfloat
) span
->array
->x
[i
];
569 wpos
[i
][1] = (GLfloat
) span
->array
->y
[i
];
573 for (i
= 0; i
< span
->end
; i
++) {
574 wpos
[i
][0] = (GLfloat
) span
->x
+ i
;
575 wpos
[i
][1] = (GLfloat
) span
->y
;
579 dw
= span
->attrStepX
[FRAG_ATTRIB_WPOS
][3];
580 w
= span
->attrStart
[FRAG_ATTRIB_WPOS
][3] + span
->leftClip
* dw
;
581 for (i
= 0; i
< span
->end
; i
++) {
582 wpos
[i
][2] = (GLfloat
) span
->array
->z
[i
] * zScale
;
590 * Apply the current polygon stipple pattern to a span of pixels.
593 stipple_polygon_span(struct gl_context
*ctx
, SWspan
*span
)
595 GLubyte
*mask
= span
->array
->mask
;
597 ASSERT(ctx
->Polygon
.StippleFlag
);
599 if (span
->arrayMask
& SPAN_XY
) {
600 /* arrays of x/y pixel coords */
602 for (i
= 0; i
< span
->end
; i
++) {
603 const GLint col
= span
->array
->x
[i
] % 32;
604 const GLint row
= span
->array
->y
[i
] % 32;
605 const GLuint stipple
= ctx
->PolygonStipple
[row
];
606 if (((1 << col
) & stipple
) == 0) {
612 /* horizontal span of pixels */
613 const GLuint highBit
= 1 << 31;
614 const GLuint stipple
= ctx
->PolygonStipple
[span
->y
% 32];
615 GLuint i
, m
= highBit
>> (GLuint
) (span
->x
% 32);
616 for (i
= 0; i
< span
->end
; i
++) {
617 if ((m
& stipple
) == 0) {
626 span
->writeAll
= GL_FALSE
;
631 * Clip a pixel span to the current buffer/window boundaries:
632 * DrawBuffer->_Xmin, _Xmax, _Ymin, _Ymax. This will accomplish
633 * window clipping and scissoring.
634 * Return: GL_TRUE some pixels still visible
635 * GL_FALSE nothing visible
638 clip_span( struct gl_context
*ctx
, SWspan
*span
)
640 const GLint xmin
= ctx
->DrawBuffer
->_Xmin
;
641 const GLint xmax
= ctx
->DrawBuffer
->_Xmax
;
642 const GLint ymin
= ctx
->DrawBuffer
->_Ymin
;
643 const GLint ymax
= ctx
->DrawBuffer
->_Ymax
;
647 if (span
->arrayMask
& SPAN_XY
) {
648 /* arrays of x/y pixel coords */
649 const GLint
*x
= span
->array
->x
;
650 const GLint
*y
= span
->array
->y
;
651 const GLint n
= span
->end
;
652 GLubyte
*mask
= span
->array
->mask
;
655 if (span
->arrayMask
& SPAN_MASK
) {
656 /* note: using & intead of && to reduce branches */
657 for (i
= 0; i
< n
; i
++) {
658 mask
[i
] &= (x
[i
] >= xmin
) & (x
[i
] < xmax
)
659 & (y
[i
] >= ymin
) & (y
[i
] < ymax
);
664 /* note: using & intead of && to reduce branches */
665 for (i
= 0; i
< n
; i
++) {
666 mask
[i
] = (x
[i
] >= xmin
) & (x
[i
] < xmax
)
667 & (y
[i
] >= ymin
) & (y
[i
] < ymax
);
674 /* horizontal span of pixels */
675 const GLint x
= span
->x
;
676 const GLint y
= span
->y
;
679 /* Trivial rejection tests */
680 if (y
< ymin
|| y
>= ymax
|| x
+ n
<= xmin
|| x
>= xmax
) {
682 return GL_FALSE
; /* all pixels clipped */
688 n
= span
->end
= xmax
- x
;
691 /* Clip to the left */
693 const GLint leftClip
= xmin
- x
;
696 ASSERT(leftClip
> 0);
697 ASSERT(x
+ n
> xmin
);
699 /* Clip 'leftClip' pixels from the left side.
700 * The span->leftClip field will be applied when we interpolate
701 * fragment attributes.
702 * For arrays of values, shift them left.
704 for (i
= 0; i
< FRAG_ATTRIB_MAX
; i
++) {
705 if (span
->interpMask
& (1 << i
)) {
707 for (j
= 0; j
< 4; j
++) {
708 span
->attrStart
[i
][j
] += leftClip
* span
->attrStepX
[i
][j
];
713 span
->red
+= leftClip
* span
->redStep
;
714 span
->green
+= leftClip
* span
->greenStep
;
715 span
->blue
+= leftClip
* span
->blueStep
;
716 span
->alpha
+= leftClip
* span
->alphaStep
;
717 span
->index
+= leftClip
* span
->indexStep
;
718 span
->z
+= leftClip
* span
->zStep
;
719 span
->intTex
[0] += leftClip
* span
->intTexStep
[0];
720 span
->intTex
[1] += leftClip
* span
->intTexStep
[1];
722 #define SHIFT_ARRAY(ARRAY, SHIFT, LEN) \
723 memmove(ARRAY, ARRAY + (SHIFT), (LEN) * sizeof(ARRAY[0]))
725 for (i
= 0; i
< FRAG_ATTRIB_MAX
; i
++) {
726 if (span
->arrayAttribs
& (1 << i
)) {
727 /* shift array elements left by 'leftClip' */
728 SHIFT_ARRAY(span
->array
->attribs
[i
], leftClip
, n
- leftClip
);
732 SHIFT_ARRAY(span
->array
->mask
, leftClip
, n
- leftClip
);
733 SHIFT_ARRAY(span
->array
->rgba8
, leftClip
, n
- leftClip
);
734 SHIFT_ARRAY(span
->array
->rgba16
, leftClip
, n
- leftClip
);
735 SHIFT_ARRAY(span
->array
->x
, leftClip
, n
- leftClip
);
736 SHIFT_ARRAY(span
->array
->y
, leftClip
, n
- leftClip
);
737 SHIFT_ARRAY(span
->array
->z
, leftClip
, n
- leftClip
);
738 SHIFT_ARRAY(span
->array
->index
, leftClip
, n
- leftClip
);
739 SHIFT_ARRAY(span
->array
->lambda
, leftClip
, n
- leftClip
);
740 SHIFT_ARRAY(span
->array
->coverage
, leftClip
, n
- leftClip
);
744 span
->leftClip
= leftClip
;
746 span
->end
-= leftClip
;
747 span
->writeAll
= GL_FALSE
;
750 ASSERT(span
->x
>= xmin
);
751 ASSERT(span
->x
+ span
->end
<= xmax
);
752 ASSERT(span
->y
>= ymin
);
753 ASSERT(span
->y
< ymax
);
755 return GL_TRUE
; /* some pixels visible */
761 * Add specular colors to primary colors.
762 * Only called during fixed-function operation.
763 * Result is float color array (FRAG_ATTRIB_COL0).
766 add_specular(struct gl_context
*ctx
, SWspan
*span
)
768 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
769 const GLubyte
*mask
= span
->array
->mask
;
770 GLfloat (*col0
)[4] = span
->array
->attribs
[FRAG_ATTRIB_COL0
];
771 GLfloat (*col1
)[4] = span
->array
->attribs
[FRAG_ATTRIB_COL1
];
774 ASSERT(!_swrast_use_fragment_program(ctx
));
775 ASSERT(span
->arrayMask
& SPAN_RGBA
);
776 ASSERT(swrast
->_ActiveAttribMask
& FRAG_BIT_COL1
);
777 (void) swrast
; /* silence warning */
779 if (span
->array
->ChanType
== GL_FLOAT
) {
780 if ((span
->arrayAttribs
& FRAG_BIT_COL0
) == 0) {
781 interpolate_active_attribs(ctx
, span
, FRAG_BIT_COL0
);
785 /* need float colors */
786 if ((span
->arrayAttribs
& FRAG_BIT_COL0
) == 0) {
787 interpolate_float_colors(span
);
791 if ((span
->arrayAttribs
& FRAG_BIT_COL1
) == 0) {
792 /* XXX could avoid this and interpolate COL1 in the loop below */
793 interpolate_active_attribs(ctx
, span
, FRAG_BIT_COL1
);
796 ASSERT(span
->arrayAttribs
& FRAG_BIT_COL0
);
797 ASSERT(span
->arrayAttribs
& FRAG_BIT_COL1
);
799 for (i
= 0; i
< span
->end
; i
++) {
801 col0
[i
][0] += col1
[i
][0];
802 col0
[i
][1] += col1
[i
][1];
803 col0
[i
][2] += col1
[i
][2];
807 span
->array
->ChanType
= GL_FLOAT
;
812 * Apply antialiasing coverage value to alpha values.
815 apply_aa_coverage(SWspan
*span
)
817 const GLfloat
*coverage
= span
->array
->coverage
;
819 if (span
->array
->ChanType
== GL_UNSIGNED_BYTE
) {
820 GLubyte (*rgba
)[4] = span
->array
->rgba8
;
821 for (i
= 0; i
< span
->end
; i
++) {
822 const GLfloat a
= rgba
[i
][ACOMP
] * coverage
[i
];
823 rgba
[i
][ACOMP
] = (GLubyte
) CLAMP(a
, 0.0, 255.0);
824 ASSERT(coverage
[i
] >= 0.0);
825 ASSERT(coverage
[i
] <= 1.0);
828 else if (span
->array
->ChanType
== GL_UNSIGNED_SHORT
) {
829 GLushort (*rgba
)[4] = span
->array
->rgba16
;
830 for (i
= 0; i
< span
->end
; i
++) {
831 const GLfloat a
= rgba
[i
][ACOMP
] * coverage
[i
];
832 rgba
[i
][ACOMP
] = (GLushort
) CLAMP(a
, 0.0, 65535.0);
836 GLfloat (*rgba
)[4] = span
->array
->attribs
[FRAG_ATTRIB_COL0
];
837 for (i
= 0; i
< span
->end
; i
++) {
838 rgba
[i
][ACOMP
] = rgba
[i
][ACOMP
] * coverage
[i
];
846 * Clamp span's float colors to [0,1]
849 clamp_colors(SWspan
*span
)
851 GLfloat (*rgba
)[4] = span
->array
->attribs
[FRAG_ATTRIB_COL0
];
853 ASSERT(span
->array
->ChanType
== GL_FLOAT
);
854 for (i
= 0; i
< span
->end
; i
++) {
855 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
856 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
857 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
858 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
864 * Convert the span's color arrays to the given type.
865 * The only way 'output' can be greater than zero is when we have a fragment
866 * program that writes to gl_FragData[1] or higher.
867 * \param output which fragment program color output is being processed
870 convert_color_type(SWspan
*span
, GLenum newType
, GLuint output
)
874 if (output
> 0 || span
->array
->ChanType
== GL_FLOAT
) {
875 src
= span
->array
->attribs
[FRAG_ATTRIB_COL0
+ output
];
876 span
->array
->ChanType
= GL_FLOAT
;
878 else if (span
->array
->ChanType
== GL_UNSIGNED_BYTE
) {
879 src
= span
->array
->rgba8
;
882 ASSERT(span
->array
->ChanType
== GL_UNSIGNED_SHORT
);
883 src
= span
->array
->rgba16
;
886 if (newType
== GL_UNSIGNED_BYTE
) {
887 dst
= span
->array
->rgba8
;
889 else if (newType
== GL_UNSIGNED_SHORT
) {
890 dst
= span
->array
->rgba16
;
893 dst
= span
->array
->attribs
[FRAG_ATTRIB_COL0
];
896 _mesa_convert_colors(span
->array
->ChanType
, src
,
898 span
->end
, span
->array
->mask
);
900 span
->array
->ChanType
= newType
;
901 span
->array
->rgba
= dst
;
907 * Apply fragment shader, fragment program or normal texturing to span.
910 shade_texture_span(struct gl_context
*ctx
, SWspan
*span
)
912 if (ctx
->Texture
._EnabledCoord
) {
913 /* conventional texturing */
916 if ((span
->arrayAttribs
& FRAG_BIT_COL0
) == 0) {
917 interpolate_int_colors(ctx
, span
);
920 if (!(span
->arrayMask
& SPAN_RGBA
))
921 interpolate_int_colors(ctx
, span
);
923 if (!(span
->arrayAttribs
& FRAG_BIT_TEX
))
924 interpolate_texcoords(ctx
, span
);
926 _swrast_texture_span(ctx
, span
);
931 /** Put colors at x/y locations into a renderbuffer */
933 put_values(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
935 GLuint count
, const GLint x
[], const GLint y
[],
936 const void *values
, const GLubyte
*mask
)
938 gl_pack_ubyte_rgba_func pack_ubyte
;
939 gl_pack_float_rgba_func pack_float
;
942 if (datatype
== GL_UNSIGNED_BYTE
)
943 pack_ubyte
= _mesa_get_pack_ubyte_rgba_function(rb
->Format
);
945 pack_float
= _mesa_get_pack_float_rgba_function(rb
->Format
);
947 for (i
= 0; i
< count
; i
++) {
949 GLubyte
*dst
= _swrast_pixel_address(rb
, x
[i
], y
[i
]);
951 if (datatype
== GL_UNSIGNED_BYTE
) {
952 pack_ubyte((const GLubyte
*) values
+ 4 * i
, dst
);
955 assert(datatype
== GL_FLOAT
);
956 pack_float((const GLfloat
*) values
+ 4 * i
, dst
);
963 /** Put row of colors into renderbuffer */
965 _swrast_put_row(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
967 GLuint count
, GLint x
, GLint y
,
968 const void *values
, const GLubyte
*mask
)
970 GLubyte
*dst
= _swrast_pixel_address(rb
, x
, y
);
973 if (datatype
== GL_UNSIGNED_BYTE
) {
974 _mesa_pack_ubyte_rgba_row(rb
->Format
, count
,
975 (const GLubyte (*)[4]) values
, dst
);
978 assert(datatype
== GL_FLOAT
);
979 _mesa_pack_float_rgba_row(rb
->Format
, count
,
980 (const GLfloat (*)[4]) values
, dst
);
984 const GLuint bpp
= _mesa_get_format_bytes(rb
->Format
);
985 GLuint i
, runLen
, runStart
;
986 /* We can't pass a 'mask' array to the _mesa_pack_rgba_row() functions
987 * so look for runs where mask=1...
989 runLen
= runStart
= 0;
990 for (i
= 0; i
< count
; i
++) {
997 if (!mask
[i
] || i
== count
- 1) {
998 /* might be the end of a run of pixels */
1000 if (datatype
== GL_UNSIGNED_BYTE
) {
1001 _mesa_pack_ubyte_rgba_row(rb
->Format
, runLen
,
1002 (const GLubyte (*)[4]) values
+ runStart
,
1003 dst
+ runStart
* bpp
);
1006 assert(datatype
== GL_FLOAT
);
1007 _mesa_pack_float_rgba_row(rb
->Format
, runLen
,
1008 (const GLfloat (*)[4]) values
+ runStart
,
1009 dst
+ runStart
* bpp
);
1021 * Apply all the per-fragment operations to a span.
1022 * This now includes texturing (_swrast_write_texture_span() is history).
1023 * This function may modify any of the array values in the span.
1024 * span->interpMask and span->arrayMask may be changed but will be restored
1025 * to their original values before returning.
1028 _swrast_write_rgba_span( struct gl_context
*ctx
, SWspan
*span
)
1030 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1031 const GLuint colorMask
= *((GLuint
*)ctx
->Color
.ColorMask
);
1032 const GLbitfield origInterpMask
= span
->interpMask
;
1033 const GLbitfield origArrayMask
= span
->arrayMask
;
1034 const GLbitfield64 origArrayAttribs
= span
->arrayAttribs
;
1035 const GLenum origChanType
= span
->array
->ChanType
;
1036 void * const origRgba
= span
->array
->rgba
;
1037 const GLboolean texture
= ctx
->Texture
._EnabledCoord
;
1038 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
1041 printf("%s() interp 0x%x array 0x%x\n", __FUNCTION__,
1042 span->interpMask, span->arrayMask);
1045 ASSERT(span
->primitive
== GL_POINT
||
1046 span
->primitive
== GL_LINE
||
1047 span
->primitive
== GL_POLYGON
||
1048 span
->primitive
== GL_BITMAP
);
1050 /* Fragment write masks */
1051 if (span
->arrayMask
& SPAN_MASK
) {
1052 /* mask was initialized by caller, probably glBitmap */
1053 span
->writeAll
= GL_FALSE
;
1056 memset(span
->array
->mask
, 1, span
->end
);
1057 span
->writeAll
= GL_TRUE
;
1060 /* Clip to window/scissor box */
1061 if (!clip_span(ctx
, span
)) {
1065 ASSERT(span
->end
<= MAX_WIDTH
);
1067 /* Depth bounds test */
1068 if (ctx
->Depth
.BoundsTest
&& fb
->Visual
.depthBits
> 0) {
1069 if (!_swrast_depth_bounds_test(ctx
, span
)) {
1075 /* Make sure all fragments are within window bounds */
1076 if (span
->arrayMask
& SPAN_XY
) {
1077 /* array of pixel locations */
1079 for (i
= 0; i
< span
->end
; i
++) {
1080 if (span
->array
->mask
[i
]) {
1081 assert(span
->array
->x
[i
] >= fb
->_Xmin
);
1082 assert(span
->array
->x
[i
] < fb
->_Xmax
);
1083 assert(span
->array
->y
[i
] >= fb
->_Ymin
);
1084 assert(span
->array
->y
[i
] < fb
->_Ymax
);
1090 /* Polygon Stippling */
1091 if (ctx
->Polygon
.StippleFlag
&& span
->primitive
== GL_POLYGON
) {
1092 stipple_polygon_span(ctx
, span
);
1095 /* This is the normal place to compute the fragment color/Z
1096 * from texturing or shading.
1098 if (texture
&& !swrast
->_DeferredTexture
) {
1099 shade_texture_span(ctx
, span
);
1102 /* Do the alpha test */
1103 if (ctx
->Color
.AlphaEnabled
) {
1104 if (!_swrast_alpha_test(ctx
, span
)) {
1105 /* all fragments failed test */
1110 /* Stencil and Z testing */
1111 if (ctx
->Stencil
._Enabled
|| ctx
->Depth
.Test
) {
1112 if (!(span
->arrayMask
& SPAN_Z
))
1113 _swrast_span_interpolate_z(ctx
, span
);
1115 if (ctx
->Stencil
._Enabled
) {
1116 /* Combined Z/stencil tests */
1117 if (!_swrast_stencil_and_ztest_span(ctx
, span
)) {
1118 /* all fragments failed test */
1122 else if (fb
->Visual
.depthBits
> 0) {
1123 /* Just regular depth testing */
1124 ASSERT(ctx
->Depth
.Test
);
1125 ASSERT(span
->arrayMask
& SPAN_Z
);
1126 if (!_swrast_depth_test_span(ctx
, span
)) {
1127 /* all fragments failed test */
1133 /* We had to wait until now to check for glColorMask(0,0,0,0) because of
1134 * the occlusion test.
1136 if (colorMask
== 0) {
1137 /* no colors to write */
1141 /* If we were able to defer fragment color computation to now, there's
1142 * a good chance that many fragments will have already been killed by
1143 * Z/stencil testing.
1145 if (texture
&& swrast
->_DeferredTexture
) {
1146 shade_texture_span(ctx
, span
);
1150 if ((span
->arrayAttribs
& FRAG_BIT_COL0
) == 0) {
1151 interpolate_active_attribs(ctx
, span
, FRAG_BIT_COL0
);
1154 if ((span
->arrayMask
& SPAN_RGBA
) == 0) {
1155 interpolate_int_colors(ctx
, span
);
1159 ASSERT(span
->arrayMask
& SPAN_RGBA
);
1161 if (span
->primitive
== GL_BITMAP
|| !swrast
->SpecularVertexAdd
) {
1162 /* Add primary and specular (diffuse + specular) colors */
1163 if (ctx
->Fog
.ColorSumEnabled
||
1164 (ctx
->Light
.Enabled
&&
1165 ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
)) {
1166 add_specular(ctx
, span
);
1171 if (swrast
->_FogEnabled
) {
1172 _swrast_fog_rgba_span(ctx
, span
);
1175 /* Antialias coverage application */
1176 if (span
->arrayMask
& SPAN_COVERAGE
) {
1177 apply_aa_coverage(span
);
1181 * Write to renderbuffers.
1182 * Depending on glDrawBuffer() state and the which color outputs are
1183 * written by the fragment shader, we may either replicate one color to
1184 * all renderbuffers or write a different color to each renderbuffer.
1185 * multiFragOutputs=TRUE for the later case.
1188 struct gl_renderbuffer
*rb
= fb
->_ColorDrawBuffer
;
1190 /* color[fragOutput] will be written to buffer */
1193 struct swrast_renderbuffer
*srb
= swrast_renderbuffer(rb
);
1194 GLenum colorType
= srb
->ColorType
;
1196 assert(colorType
== GL_UNSIGNED_BYTE
||
1197 colorType
== GL_FLOAT
);
1199 /* set span->array->rgba to colors for renderbuffer's datatype */
1200 if (span
->array
->ChanType
!= colorType
) {
1201 convert_color_type(span
, colorType
, 0);
1204 if (span
->array
->ChanType
== GL_UNSIGNED_BYTE
) {
1205 span
->array
->rgba
= span
->array
->rgba8
;
1208 span
->array
->rgba
= (void *)span
->array
->attribs
[FRAG_ATTRIB_COL0
];
1213 ASSERT(rb
->_BaseFormat
== GL_RGBA
||
1214 rb
->_BaseFormat
== GL_RGB
||
1215 rb
->_BaseFormat
== GL_RED
||
1216 rb
->_BaseFormat
== GL_RG
||
1217 rb
->_BaseFormat
== GL_ALPHA
);
1219 if (ctx
->Color
.ColorLogicOpEnabled
) {
1220 _swrast_logicop_rgba_span(ctx
, rb
, span
);
1222 else if (ctx
->Color
.BlendEnabled
) {
1223 _swrast_blend_span(ctx
, rb
, span
);
1226 if (colorMask
!= 0xffffffff) {
1227 _swrast_mask_rgba_span(ctx
, rb
, span
);
1230 if (span
->arrayMask
& SPAN_XY
) {
1231 /* array of pixel coords */
1233 span
->array
->ChanType
, span
->end
,
1234 span
->array
->x
, span
->array
->y
,
1235 span
->array
->rgba
, span
->array
->mask
);
1238 /* horizontal run of pixels */
1239 _swrast_put_row(ctx
, rb
,
1240 span
->array
->ChanType
,
1241 span
->end
, span
->x
, span
->y
,
1243 span
->writeAll
? NULL
: span
->array
->mask
);
1250 /* restore these values before returning */
1251 span
->interpMask
= origInterpMask
;
1252 span
->arrayMask
= origArrayMask
;
1253 span
->arrayAttribs
= origArrayAttribs
;
1254 span
->array
->ChanType
= origChanType
;
1255 span
->array
->rgba
= origRgba
;
1260 * Read float RGBA pixels from a renderbuffer. Clipping will be done to
1261 * prevent reading ouside the buffer's boundaries.
1262 * \param rgba the returned colors
1265 _swrast_read_rgba_span( struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1266 GLuint n
, GLint x
, GLint y
,
1269 struct swrast_renderbuffer
*srb
= swrast_renderbuffer(rb
);
1270 GLenum dstType
= GL_FLOAT
;
1271 const GLint bufWidth
= (GLint
) rb
->Width
;
1272 const GLint bufHeight
= (GLint
) rb
->Height
;
1274 if (y
< 0 || y
>= bufHeight
|| x
+ (GLint
) n
< 0 || x
>= bufWidth
) {
1275 /* completely above, below, or right */
1276 /* XXX maybe leave rgba values undefined? */
1277 memset(rgba
, 0, 4 * n
* sizeof(GLchan
));
1284 /* left edge clipping */
1286 length
= (GLint
) n
- skip
;
1288 /* completely left of window */
1291 if (length
> bufWidth
) {
1295 else if ((GLint
) (x
+ n
) > bufWidth
) {
1296 /* right edge clipping */
1298 length
= bufWidth
- x
;
1300 /* completely to right of window */
1311 ASSERT(rb
->_BaseFormat
== GL_RGBA
||
1312 rb
->_BaseFormat
== GL_RGB
||
1313 rb
->_BaseFormat
== GL_RG
||
1314 rb
->_BaseFormat
== GL_RED
||
1315 rb
->_BaseFormat
== GL_LUMINANCE
||
1316 rb
->_BaseFormat
== GL_INTENSITY
||
1317 rb
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
1318 rb
->_BaseFormat
== GL_ALPHA
);
1322 src
= _swrast_pixel_address(rb
, x
+ skip
, y
);
1324 if (dstType
== GL_UNSIGNED_BYTE
) {
1325 _mesa_unpack_ubyte_rgba_row(rb
->Format
, length
, src
,
1326 (GLubyte (*)[4]) rgba
+ skip
);
1328 else if (dstType
== GL_FLOAT
) {
1329 _mesa_unpack_rgba_row(rb
->Format
, length
, src
,
1330 (GLfloat (*)[4]) rgba
+ skip
);
1333 _mesa_problem(ctx
, "unexpected type in _swrast_read_rgba_span()");
1340 * Get colors at x/y positions with clipping.
1341 * \param type type of values to return
1344 get_values(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1345 GLuint count
, const GLint x
[], const GLint y
[],
1346 void *values
, GLenum type
)
1350 for (i
= 0; i
< count
; i
++) {
1351 if (x
[i
] >= 0 && y
[i
] >= 0 &&
1352 x
[i
] < (GLint
) rb
->Width
&& y
[i
] < (GLint
) rb
->Height
) {
1354 const GLubyte
*src
= _swrast_pixel_address(rb
, x
[i
], y
[i
]);
1356 if (type
== GL_UNSIGNED_BYTE
) {
1357 _mesa_unpack_ubyte_rgba_row(rb
->Format
, 1, src
,
1358 (GLubyte (*)[4]) values
+ i
);
1360 else if (type
== GL_FLOAT
) {
1361 _mesa_unpack_rgba_row(rb
->Format
, 1, src
,
1362 (GLfloat (*)[4]) values
+ i
);
1365 _mesa_problem(ctx
, "unexpected type in get_values()");
1373 * Get row of colors with clipping.
1374 * \param type type of values to return
1377 get_row(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1378 GLuint count
, GLint x
, GLint y
,
1379 GLvoid
*values
, GLenum type
)
1384 if (y
< 0 || y
>= (GLint
) rb
->Height
)
1385 return; /* above or below */
1387 if (x
+ (GLint
) count
<= 0 || x
>= (GLint
) rb
->Width
)
1388 return; /* entirely left or right */
1390 if (x
+ count
> rb
->Width
) {
1392 GLint clip
= x
+ count
- rb
->Width
;
1403 src
= _swrast_pixel_address(rb
, x
, y
);
1405 if (type
== GL_UNSIGNED_BYTE
) {
1406 _mesa_unpack_ubyte_rgba_row(rb
->Format
, count
, src
,
1407 (GLubyte (*)[4]) values
+ skip
);
1409 else if (type
== GL_FLOAT
) {
1410 _mesa_unpack_rgba_row(rb
->Format
, count
, src
,
1411 (GLfloat (*)[4]) values
+ skip
);
1414 _mesa_problem(ctx
, "unexpected type in get_row()");
1420 * Get RGBA pixels from the given renderbuffer.
1421 * Used by blending, logicop and masking functions.
1422 * \return pointer to the colors we read.
1425 _swrast_get_dest_rgba(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1430 /* Point rbPixels to a temporary space */
1431 rbPixels
= span
->array
->attribs
[FRAG_ATTRIB_MAX
- 1];
1433 /* Get destination values from renderbuffer */
1434 if (span
->arrayMask
& SPAN_XY
) {
1435 get_values(ctx
, rb
, span
->end
, span
->array
->x
, span
->array
->y
,
1436 rbPixels
, span
->array
->ChanType
);
1439 get_row(ctx
, rb
, span
->end
, span
->x
, span
->y
,
1440 rbPixels
, span
->array
->ChanType
);