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"
56 * Set default fragment attributes for the span using the
57 * current raster values. Used prior to glDraw/CopyPixels
61 _swrast_span_default_attribs(struct gl_context
*ctx
, SWspan
*span
)
66 const GLfloat depthMax
= ctx
->DrawBuffer
->_DepthMaxF
;
67 if (ctx
->DrawBuffer
->Visual
.depthBits
<= 16)
68 span
->z
= FloatToFixed(ctx
->Current
.RasterPos
[2] * depthMax
+ 0.5F
);
70 GLfloat tmpf
= ctx
->Current
.RasterPos
[2] * depthMax
;
71 tmpf
= MIN2(tmpf
, depthMax
);
72 span
->z
= (GLint
)tmpf
;
75 span
->interpMask
|= SPAN_Z
;
78 /* W (for perspective correction) */
79 span
->attrStart
[FRAG_ATTRIB_WPOS
][3] = 1.0;
80 span
->attrStepX
[FRAG_ATTRIB_WPOS
][3] = 0.0;
81 span
->attrStepY
[FRAG_ATTRIB_WPOS
][3] = 0.0;
83 /* primary color, or color index */
84 UNCLAMPED_FLOAT_TO_CHAN(r
, ctx
->Current
.RasterColor
[0]);
85 UNCLAMPED_FLOAT_TO_CHAN(g
, ctx
->Current
.RasterColor
[1]);
86 UNCLAMPED_FLOAT_TO_CHAN(b
, ctx
->Current
.RasterColor
[2]);
87 UNCLAMPED_FLOAT_TO_CHAN(a
, ctx
->Current
.RasterColor
[3]);
88 #if CHAN_TYPE == GL_FLOAT
94 span
->red
= IntToFixed(r
);
95 span
->green
= IntToFixed(g
);
96 span
->blue
= IntToFixed(b
);
97 span
->alpha
= IntToFixed(a
);
103 span
->interpMask
|= SPAN_RGBA
;
105 COPY_4V(span
->attrStart
[FRAG_ATTRIB_COL0
], ctx
->Current
.RasterColor
);
106 ASSIGN_4V(span
->attrStepX
[FRAG_ATTRIB_COL0
], 0.0, 0.0, 0.0, 0.0);
107 ASSIGN_4V(span
->attrStepY
[FRAG_ATTRIB_COL0
], 0.0, 0.0, 0.0, 0.0);
109 /* Secondary color */
110 if (ctx
->Light
.Enabled
|| ctx
->Fog
.ColorSumEnabled
)
112 COPY_4V(span
->attrStart
[FRAG_ATTRIB_COL1
], ctx
->Current
.RasterSecondaryColor
);
113 ASSIGN_4V(span
->attrStepX
[FRAG_ATTRIB_COL1
], 0.0, 0.0, 0.0, 0.0);
114 ASSIGN_4V(span
->attrStepY
[FRAG_ATTRIB_COL1
], 0.0, 0.0, 0.0, 0.0);
119 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
120 GLfloat fogVal
; /* a coord or a blend factor */
121 if (swrast
->_PreferPixelFog
) {
122 /* fog blend factors will be computed from fog coordinates per pixel */
123 fogVal
= ctx
->Current
.RasterDistance
;
126 /* fog blend factor should be computed from fogcoord now */
127 fogVal
= _swrast_z_to_fogfactor(ctx
, ctx
->Current
.RasterDistance
);
129 span
->attrStart
[FRAG_ATTRIB_FOGC
][0] = fogVal
;
130 span
->attrStepX
[FRAG_ATTRIB_FOGC
][0] = 0.0;
131 span
->attrStepY
[FRAG_ATTRIB_FOGC
][0] = 0.0;
137 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++) {
138 const GLuint attr
= FRAG_ATTRIB_TEX0
+ i
;
139 const GLfloat
*tc
= ctx
->Current
.RasterTexCoords
[i
];
141 /* use (s/q, t/q, r/q, 1) */
142 span
->attrStart
[attr
][0] = tc
[0] / tc
[3];
143 span
->attrStart
[attr
][1] = tc
[1] / tc
[3];
144 span
->attrStart
[attr
][2] = tc
[2] / tc
[3];
145 span
->attrStart
[attr
][3] = 1.0;
148 ASSIGN_4V(span
->attrStart
[attr
], 0.0F
, 0.0F
, 0.0F
, 1.0F
);
150 ASSIGN_4V(span
->attrStepX
[attr
], 0.0F
, 0.0F
, 0.0F
, 0.0F
);
151 ASSIGN_4V(span
->attrStepY
[attr
], 0.0F
, 0.0F
, 0.0F
, 0.0F
);
158 * Interpolate the active attributes (and'd with attrMask) to
159 * fill in span->array->attribs[].
160 * Perspective correction will be done. The point/line/triangle function
161 * should have computed attrStart/Step values for FRAG_ATTRIB_WPOS[3]!
164 interpolate_active_attribs(struct gl_context
*ctx
, SWspan
*span
,
165 GLbitfield64 attrMask
)
167 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
170 * Don't overwrite existing array values, such as colors that may have
171 * been produced by glDraw/CopyPixels.
173 attrMask
&= ~span
->arrayAttribs
;
176 if (attrMask
& BITFIELD64_BIT(attr
)) {
177 const GLfloat dwdx
= span
->attrStepX
[FRAG_ATTRIB_WPOS
][3];
178 GLfloat w
= span
->attrStart
[FRAG_ATTRIB_WPOS
][3];
179 const GLfloat dv0dx
= span
->attrStepX
[attr
][0];
180 const GLfloat dv1dx
= span
->attrStepX
[attr
][1];
181 const GLfloat dv2dx
= span
->attrStepX
[attr
][2];
182 const GLfloat dv3dx
= span
->attrStepX
[attr
][3];
183 GLfloat v0
= span
->attrStart
[attr
][0] + span
->leftClip
* dv0dx
;
184 GLfloat v1
= span
->attrStart
[attr
][1] + span
->leftClip
* dv1dx
;
185 GLfloat v2
= span
->attrStart
[attr
][2] + span
->leftClip
* dv2dx
;
186 GLfloat v3
= span
->attrStart
[attr
][3] + span
->leftClip
* dv3dx
;
188 for (k
= 0; k
< span
->end
; k
++) {
189 const GLfloat invW
= 1.0f
/ w
;
190 span
->array
->attribs
[attr
][k
][0] = v0
* invW
;
191 span
->array
->attribs
[attr
][k
][1] = v1
* invW
;
192 span
->array
->attribs
[attr
][k
][2] = v2
* invW
;
193 span
->array
->attribs
[attr
][k
][3] = v3
* invW
;
200 ASSERT((span
->arrayAttribs
& BITFIELD64_BIT(attr
)) == 0);
201 span
->arrayAttribs
|= BITFIELD64_BIT(attr
);
208 * Interpolate primary colors to fill in the span->array->rgba8 (or rgb16)
212 interpolate_int_colors(struct gl_context
*ctx
, SWspan
*span
)
215 const GLuint n
= span
->end
;
218 ASSERT(!(span
->arrayMask
& SPAN_RGBA
));
221 switch (span
->array
->ChanType
) {
223 case GL_UNSIGNED_BYTE
:
225 GLubyte (*rgba
)[4] = span
->array
->rgba8
;
226 if (span
->interpMask
& SPAN_FLAT
) {
228 color
[RCOMP
] = FixedToInt(span
->red
);
229 color
[GCOMP
] = FixedToInt(span
->green
);
230 color
[BCOMP
] = FixedToInt(span
->blue
);
231 color
[ACOMP
] = FixedToInt(span
->alpha
);
232 for (i
= 0; i
< n
; i
++) {
233 COPY_4UBV(rgba
[i
], color
);
237 GLfixed r
= span
->red
;
238 GLfixed g
= span
->green
;
239 GLfixed b
= span
->blue
;
240 GLfixed a
= span
->alpha
;
241 GLint dr
= span
->redStep
;
242 GLint dg
= span
->greenStep
;
243 GLint db
= span
->blueStep
;
244 GLint da
= span
->alphaStep
;
245 for (i
= 0; i
< n
; i
++) {
246 rgba
[i
][RCOMP
] = FixedToChan(r
);
247 rgba
[i
][GCOMP
] = FixedToChan(g
);
248 rgba
[i
][BCOMP
] = FixedToChan(b
);
249 rgba
[i
][ACOMP
] = FixedToChan(a
);
258 case GL_UNSIGNED_SHORT
:
260 GLushort (*rgba
)[4] = span
->array
->rgba16
;
261 if (span
->interpMask
& SPAN_FLAT
) {
263 color
[RCOMP
] = FixedToInt(span
->red
);
264 color
[GCOMP
] = FixedToInt(span
->green
);
265 color
[BCOMP
] = FixedToInt(span
->blue
);
266 color
[ACOMP
] = FixedToInt(span
->alpha
);
267 for (i
= 0; i
< n
; i
++) {
268 COPY_4V(rgba
[i
], color
);
272 GLushort (*rgba
)[4] = span
->array
->rgba16
;
274 GLint dr
, dg
, db
, da
;
280 dg
= span
->greenStep
;
282 da
= span
->alphaStep
;
283 for (i
= 0; i
< n
; i
++) {
284 rgba
[i
][RCOMP
] = FixedToChan(r
);
285 rgba
[i
][GCOMP
] = FixedToChan(g
);
286 rgba
[i
][BCOMP
] = FixedToChan(b
);
287 rgba
[i
][ACOMP
] = FixedToChan(a
);
298 interpolate_active_attribs(ctx
, span
, FRAG_BIT_COL0
);
301 _mesa_problem(ctx
, "bad datatype 0x%x in interpolate_int_colors",
302 span
->array
->ChanType
);
304 span
->arrayMask
|= SPAN_RGBA
;
309 * Populate the FRAG_ATTRIB_COL0 array.
312 interpolate_float_colors(SWspan
*span
)
314 GLfloat (*col0
)[4] = span
->array
->attribs
[FRAG_ATTRIB_COL0
];
315 const GLuint n
= span
->end
;
318 assert(!(span
->arrayAttribs
& FRAG_BIT_COL0
));
320 if (span
->arrayMask
& SPAN_RGBA
) {
321 /* convert array of int colors */
322 for (i
= 0; i
< n
; i
++) {
323 col0
[i
][0] = UBYTE_TO_FLOAT(span
->array
->rgba8
[i
][0]);
324 col0
[i
][1] = UBYTE_TO_FLOAT(span
->array
->rgba8
[i
][1]);
325 col0
[i
][2] = UBYTE_TO_FLOAT(span
->array
->rgba8
[i
][2]);
326 col0
[i
][3] = UBYTE_TO_FLOAT(span
->array
->rgba8
[i
][3]);
330 /* interpolate red/green/blue/alpha to get float colors */
331 ASSERT(span
->interpMask
& SPAN_RGBA
);
332 if (span
->interpMask
& SPAN_FLAT
) {
333 GLfloat r
= FixedToFloat(span
->red
);
334 GLfloat g
= FixedToFloat(span
->green
);
335 GLfloat b
= FixedToFloat(span
->blue
);
336 GLfloat a
= FixedToFloat(span
->alpha
);
337 for (i
= 0; i
< n
; i
++) {
338 ASSIGN_4V(col0
[i
], r
, g
, b
, a
);
342 GLfloat r
= FixedToFloat(span
->red
);
343 GLfloat g
= FixedToFloat(span
->green
);
344 GLfloat b
= FixedToFloat(span
->blue
);
345 GLfloat a
= FixedToFloat(span
->alpha
);
346 GLfloat dr
= FixedToFloat(span
->redStep
);
347 GLfloat dg
= FixedToFloat(span
->greenStep
);
348 GLfloat db
= FixedToFloat(span
->blueStep
);
349 GLfloat da
= FixedToFloat(span
->alphaStep
);
350 for (i
= 0; i
< n
; i
++) {
363 span
->arrayAttribs
|= FRAG_BIT_COL0
;
364 span
->array
->ChanType
= GL_FLOAT
;
370 * Fill in the span.zArray array from the span->z, zStep values.
373 _swrast_span_interpolate_z( const struct gl_context
*ctx
, SWspan
*span
)
375 const GLuint n
= span
->end
;
378 ASSERT(!(span
->arrayMask
& SPAN_Z
));
380 if (ctx
->DrawBuffer
->Visual
.depthBits
<= 16) {
381 GLfixed zval
= span
->z
;
382 GLuint
*z
= span
->array
->z
;
383 for (i
= 0; i
< n
; i
++) {
384 z
[i
] = FixedToInt(zval
);
389 /* Deep Z buffer, no fixed->int shift */
390 GLuint zval
= span
->z
;
391 GLuint
*z
= span
->array
->z
;
392 for (i
= 0; i
< n
; i
++) {
397 span
->interpMask
&= ~SPAN_Z
;
398 span
->arrayMask
|= SPAN_Z
;
403 * Compute mipmap LOD from partial derivatives.
404 * This the ideal solution, as given in the OpenGL spec.
407 _swrast_compute_lambda(GLfloat dsdx
, GLfloat dsdy
, GLfloat dtdx
, GLfloat dtdy
,
408 GLfloat dqdx
, GLfloat dqdy
, GLfloat texW
, GLfloat texH
,
409 GLfloat s
, GLfloat t
, GLfloat q
, GLfloat invQ
)
411 GLfloat dudx
= texW
* ((s
+ dsdx
) / (q
+ dqdx
) - s
* invQ
);
412 GLfloat dvdx
= texH
* ((t
+ dtdx
) / (q
+ dqdx
) - t
* invQ
);
413 GLfloat dudy
= texW
* ((s
+ dsdy
) / (q
+ dqdy
) - s
* invQ
);
414 GLfloat dvdy
= texH
* ((t
+ dtdy
) / (q
+ dqdy
) - t
* invQ
);
415 GLfloat x
= SQRTF(dudx
* dudx
+ dvdx
* dvdx
);
416 GLfloat y
= SQRTF(dudy
* dudy
+ dvdy
* dvdy
);
417 GLfloat rho
= MAX2(x
, y
);
418 GLfloat lambda
= LOG2(rho
);
424 * Compute mipmap LOD from partial derivatives.
425 * This is a faster approximation than above function.
429 _swrast_compute_lambda(GLfloat dsdx
, GLfloat dsdy
, GLfloat dtdx
, GLfloat dtdy
,
430 GLfloat dqdx
, GLfloat dqdy
, GLfloat texW
, GLfloat texH
,
431 GLfloat s
, GLfloat t
, GLfloat q
, GLfloat invQ
)
433 GLfloat dsdx2
= (s
+ dsdx
) / (q
+ dqdx
) - s
* invQ
;
434 GLfloat dtdx2
= (t
+ dtdx
) / (q
+ dqdx
) - t
* invQ
;
435 GLfloat dsdy2
= (s
+ dsdy
) / (q
+ dqdy
) - s
* invQ
;
436 GLfloat dtdy2
= (t
+ dtdy
) / (q
+ dqdy
) - t
* invQ
;
437 GLfloat maxU
, maxV
, rho
, lambda
;
438 dsdx2
= FABSF(dsdx2
);
439 dsdy2
= FABSF(dsdy2
);
440 dtdx2
= FABSF(dtdx2
);
441 dtdy2
= FABSF(dtdy2
);
442 maxU
= MAX2(dsdx2
, dsdy2
) * texW
;
443 maxV
= MAX2(dtdx2
, dtdy2
) * texH
;
444 rho
= MAX2(maxU
, maxV
);
452 * Fill in the span.array->attrib[FRAG_ATTRIB_TEXn] arrays from the
453 * using the attrStart/Step values.
455 * This function only used during fixed-function fragment processing.
457 * Note: in the places where we divide by Q (or mult by invQ) we're
458 * really doing two things: perspective correction and texcoord
459 * projection. Remember, for texcoord (s,t,r,q) we need to index
460 * texels with (s/q, t/q, r/q).
463 interpolate_texcoords(struct gl_context
*ctx
, SWspan
*span
)
466 = (ctx
->Texture
._EnabledCoordUnits
> 1) ? ctx
->Const
.MaxTextureUnits
: 1;
469 /* XXX CoordUnits vs. ImageUnits */
470 for (u
= 0; u
< maxUnit
; u
++) {
471 if (ctx
->Texture
._EnabledCoordUnits
& (1 << u
)) {
472 const GLuint attr
= FRAG_ATTRIB_TEX0
+ u
;
473 const struct gl_texture_object
*obj
= ctx
->Texture
.Unit
[u
]._Current
;
475 GLboolean needLambda
;
476 GLfloat (*texcoord
)[4] = span
->array
->attribs
[attr
];
477 GLfloat
*lambda
= span
->array
->lambda
[u
];
478 const GLfloat dsdx
= span
->attrStepX
[attr
][0];
479 const GLfloat dsdy
= span
->attrStepY
[attr
][0];
480 const GLfloat dtdx
= span
->attrStepX
[attr
][1];
481 const GLfloat dtdy
= span
->attrStepY
[attr
][1];
482 const GLfloat drdx
= span
->attrStepX
[attr
][2];
483 const GLfloat dqdx
= span
->attrStepX
[attr
][3];
484 const GLfloat dqdy
= span
->attrStepY
[attr
][3];
485 GLfloat s
= span
->attrStart
[attr
][0] + span
->leftClip
* dsdx
;
486 GLfloat t
= span
->attrStart
[attr
][1] + span
->leftClip
* dtdx
;
487 GLfloat r
= span
->attrStart
[attr
][2] + span
->leftClip
* drdx
;
488 GLfloat q
= span
->attrStart
[attr
][3] + span
->leftClip
* dqdx
;
491 const struct gl_texture_image
*img
= obj
->Image
[0][obj
->BaseLevel
];
492 const struct swrast_texture_image
*swImg
=
493 swrast_texture_image_const(img
);
495 needLambda
= (obj
->Sampler
.MinFilter
!= obj
->Sampler
.MagFilter
);
496 /* LOD is calculated directly in the ansiotropic filter, we can
497 * skip the normal lambda function as the result is ignored.
499 if (obj
->Sampler
.MaxAnisotropy
> 1.0 &&
500 obj
->Sampler
.MinFilter
== GL_LINEAR_MIPMAP_LINEAR
) {
501 needLambda
= GL_FALSE
;
503 texW
= swImg
->WidthScale
;
504 texH
= swImg
->HeightScale
;
507 /* using a fragment program */
510 needLambda
= GL_FALSE
;
515 for (i
= 0; i
< span
->end
; i
++) {
516 const GLfloat invQ
= (q
== 0.0F
) ? 1.0F
: (1.0F
/ q
);
517 texcoord
[i
][0] = s
* invQ
;
518 texcoord
[i
][1] = t
* invQ
;
519 texcoord
[i
][2] = r
* invQ
;
521 lambda
[i
] = _swrast_compute_lambda(dsdx
, dsdy
, dtdx
, dtdy
,
522 dqdx
, dqdy
, texW
, texH
,
529 span
->arrayMask
|= SPAN_LAMBDA
;
534 /* Ortho projection or polygon's parallel to window X axis */
535 const GLfloat invQ
= (q
== 0.0F
) ? 1.0F
: (1.0F
/ q
);
536 for (i
= 0; i
< span
->end
; i
++) {
537 texcoord
[i
][0] = s
* invQ
;
538 texcoord
[i
][1] = t
* invQ
;
539 texcoord
[i
][2] = r
* invQ
;
548 for (i
= 0; i
< span
->end
; i
++) {
549 const GLfloat invQ
= (q
== 0.0F
) ? 1.0F
: (1.0F
/ q
);
550 texcoord
[i
][0] = s
* invQ
;
551 texcoord
[i
][1] = t
* invQ
;
552 texcoord
[i
][2] = r
* invQ
;
568 * Fill in the arrays->attribs[FRAG_ATTRIB_WPOS] array.
571 interpolate_wpos(struct gl_context
*ctx
, SWspan
*span
)
573 GLfloat (*wpos
)[4] = span
->array
->attribs
[FRAG_ATTRIB_WPOS
];
575 const GLfloat zScale
= 1.0F
/ ctx
->DrawBuffer
->_DepthMaxF
;
578 if (span
->arrayMask
& SPAN_XY
) {
579 for (i
= 0; i
< span
->end
; i
++) {
580 wpos
[i
][0] = (GLfloat
) span
->array
->x
[i
];
581 wpos
[i
][1] = (GLfloat
) span
->array
->y
[i
];
585 for (i
= 0; i
< span
->end
; i
++) {
586 wpos
[i
][0] = (GLfloat
) span
->x
+ i
;
587 wpos
[i
][1] = (GLfloat
) span
->y
;
591 dw
= span
->attrStepX
[FRAG_ATTRIB_WPOS
][3];
592 w
= span
->attrStart
[FRAG_ATTRIB_WPOS
][3] + span
->leftClip
* dw
;
593 for (i
= 0; i
< span
->end
; i
++) {
594 wpos
[i
][2] = (GLfloat
) span
->array
->z
[i
] * zScale
;
602 * Apply the current polygon stipple pattern to a span of pixels.
605 stipple_polygon_span(struct gl_context
*ctx
, SWspan
*span
)
607 GLubyte
*mask
= span
->array
->mask
;
609 ASSERT(ctx
->Polygon
.StippleFlag
);
611 if (span
->arrayMask
& SPAN_XY
) {
612 /* arrays of x/y pixel coords */
614 for (i
= 0; i
< span
->end
; i
++) {
615 const GLint col
= span
->array
->x
[i
] % 32;
616 const GLint row
= span
->array
->y
[i
] % 32;
617 const GLuint stipple
= ctx
->PolygonStipple
[row
];
618 if (((1 << col
) & stipple
) == 0) {
624 /* horizontal span of pixels */
625 const GLuint highBit
= 1 << 31;
626 const GLuint stipple
= ctx
->PolygonStipple
[span
->y
% 32];
627 GLuint i
, m
= highBit
>> (GLuint
) (span
->x
% 32);
628 for (i
= 0; i
< span
->end
; i
++) {
629 if ((m
& stipple
) == 0) {
638 span
->writeAll
= GL_FALSE
;
643 * Clip a pixel span to the current buffer/window boundaries:
644 * DrawBuffer->_Xmin, _Xmax, _Ymin, _Ymax. This will accomplish
645 * window clipping and scissoring.
646 * Return: GL_TRUE some pixels still visible
647 * GL_FALSE nothing visible
650 clip_span( struct gl_context
*ctx
, SWspan
*span
)
652 const GLint xmin
= ctx
->DrawBuffer
->_Xmin
;
653 const GLint xmax
= ctx
->DrawBuffer
->_Xmax
;
654 const GLint ymin
= ctx
->DrawBuffer
->_Ymin
;
655 const GLint ymax
= ctx
->DrawBuffer
->_Ymax
;
659 if (span
->arrayMask
& SPAN_XY
) {
660 /* arrays of x/y pixel coords */
661 const GLint
*x
= span
->array
->x
;
662 const GLint
*y
= span
->array
->y
;
663 const GLint n
= span
->end
;
664 GLubyte
*mask
= span
->array
->mask
;
667 if (span
->arrayMask
& SPAN_MASK
) {
668 /* note: using & intead of && to reduce branches */
669 for (i
= 0; i
< n
; i
++) {
670 mask
[i
] &= (x
[i
] >= xmin
) & (x
[i
] < xmax
)
671 & (y
[i
] >= ymin
) & (y
[i
] < ymax
);
676 /* note: using & intead of && to reduce branches */
677 for (i
= 0; i
< n
; i
++) {
678 mask
[i
] = (x
[i
] >= xmin
) & (x
[i
] < xmax
)
679 & (y
[i
] >= ymin
) & (y
[i
] < ymax
);
686 /* horizontal span of pixels */
687 const GLint x
= span
->x
;
688 const GLint y
= span
->y
;
691 /* Trivial rejection tests */
692 if (y
< ymin
|| y
>= ymax
|| x
+ n
<= xmin
|| x
>= xmax
) {
694 return GL_FALSE
; /* all pixels clipped */
700 n
= span
->end
= xmax
- x
;
703 /* Clip to the left */
705 const GLint leftClip
= xmin
- x
;
708 ASSERT(leftClip
> 0);
709 ASSERT(x
+ n
> xmin
);
711 /* Clip 'leftClip' pixels from the left side.
712 * The span->leftClip field will be applied when we interpolate
713 * fragment attributes.
714 * For arrays of values, shift them left.
716 for (i
= 0; i
< FRAG_ATTRIB_MAX
; i
++) {
717 if (span
->interpMask
& (1 << i
)) {
719 for (j
= 0; j
< 4; j
++) {
720 span
->attrStart
[i
][j
] += leftClip
* span
->attrStepX
[i
][j
];
725 span
->red
+= leftClip
* span
->redStep
;
726 span
->green
+= leftClip
* span
->greenStep
;
727 span
->blue
+= leftClip
* span
->blueStep
;
728 span
->alpha
+= leftClip
* span
->alphaStep
;
729 span
->index
+= leftClip
* span
->indexStep
;
730 span
->z
+= leftClip
* span
->zStep
;
731 span
->intTex
[0] += leftClip
* span
->intTexStep
[0];
732 span
->intTex
[1] += leftClip
* span
->intTexStep
[1];
734 #define SHIFT_ARRAY(ARRAY, SHIFT, LEN) \
735 memmove(ARRAY, ARRAY + (SHIFT), (LEN) * sizeof(ARRAY[0]))
737 for (i
= 0; i
< FRAG_ATTRIB_MAX
; i
++) {
738 if (span
->arrayAttribs
& (1 << i
)) {
739 /* shift array elements left by 'leftClip' */
740 SHIFT_ARRAY(span
->array
->attribs
[i
], leftClip
, n
- leftClip
);
744 SHIFT_ARRAY(span
->array
->mask
, leftClip
, n
- leftClip
);
745 SHIFT_ARRAY(span
->array
->rgba8
, leftClip
, n
- leftClip
);
746 SHIFT_ARRAY(span
->array
->rgba16
, leftClip
, n
- leftClip
);
747 SHIFT_ARRAY(span
->array
->x
, leftClip
, n
- leftClip
);
748 SHIFT_ARRAY(span
->array
->y
, leftClip
, n
- leftClip
);
749 SHIFT_ARRAY(span
->array
->z
, leftClip
, n
- leftClip
);
750 SHIFT_ARRAY(span
->array
->index
, leftClip
, n
- leftClip
);
751 for (i
= 0; i
< MAX_TEXTURE_COORD_UNITS
; i
++) {
752 SHIFT_ARRAY(span
->array
->lambda
[i
], leftClip
, n
- leftClip
);
754 SHIFT_ARRAY(span
->array
->coverage
, leftClip
, n
- leftClip
);
758 span
->leftClip
= leftClip
;
760 span
->end
-= leftClip
;
761 span
->writeAll
= GL_FALSE
;
764 ASSERT(span
->x
>= xmin
);
765 ASSERT(span
->x
+ span
->end
<= xmax
);
766 ASSERT(span
->y
>= ymin
);
767 ASSERT(span
->y
< ymax
);
769 return GL_TRUE
; /* some pixels visible */
775 * Add specular colors to primary colors.
776 * Only called during fixed-function operation.
777 * Result is float color array (FRAG_ATTRIB_COL0).
780 add_specular(struct gl_context
*ctx
, SWspan
*span
)
782 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
783 const GLubyte
*mask
= span
->array
->mask
;
784 GLfloat (*col0
)[4] = span
->array
->attribs
[FRAG_ATTRIB_COL0
];
785 GLfloat (*col1
)[4] = span
->array
->attribs
[FRAG_ATTRIB_COL1
];
788 ASSERT(!_swrast_use_fragment_program(ctx
));
789 ASSERT(span
->arrayMask
& SPAN_RGBA
);
790 ASSERT(swrast
->_ActiveAttribMask
& FRAG_BIT_COL1
);
791 (void) swrast
; /* silence warning */
793 if (span
->array
->ChanType
== GL_FLOAT
) {
794 if ((span
->arrayAttribs
& FRAG_BIT_COL0
) == 0) {
795 interpolate_active_attribs(ctx
, span
, FRAG_BIT_COL0
);
799 /* need float colors */
800 if ((span
->arrayAttribs
& FRAG_BIT_COL0
) == 0) {
801 interpolate_float_colors(span
);
805 if ((span
->arrayAttribs
& FRAG_BIT_COL1
) == 0) {
806 /* XXX could avoid this and interpolate COL1 in the loop below */
807 interpolate_active_attribs(ctx
, span
, FRAG_BIT_COL1
);
810 ASSERT(span
->arrayAttribs
& FRAG_BIT_COL0
);
811 ASSERT(span
->arrayAttribs
& FRAG_BIT_COL1
);
813 for (i
= 0; i
< span
->end
; i
++) {
815 col0
[i
][0] += col1
[i
][0];
816 col0
[i
][1] += col1
[i
][1];
817 col0
[i
][2] += col1
[i
][2];
821 span
->array
->ChanType
= GL_FLOAT
;
826 * Apply antialiasing coverage value to alpha values.
829 apply_aa_coverage(SWspan
*span
)
831 const GLfloat
*coverage
= span
->array
->coverage
;
833 if (span
->array
->ChanType
== GL_UNSIGNED_BYTE
) {
834 GLubyte (*rgba
)[4] = span
->array
->rgba8
;
835 for (i
= 0; i
< span
->end
; i
++) {
836 const GLfloat a
= rgba
[i
][ACOMP
] * coverage
[i
];
837 rgba
[i
][ACOMP
] = (GLubyte
) CLAMP(a
, 0.0, 255.0);
838 ASSERT(coverage
[i
] >= 0.0);
839 ASSERT(coverage
[i
] <= 1.0);
842 else if (span
->array
->ChanType
== GL_UNSIGNED_SHORT
) {
843 GLushort (*rgba
)[4] = span
->array
->rgba16
;
844 for (i
= 0; i
< span
->end
; i
++) {
845 const GLfloat a
= rgba
[i
][ACOMP
] * coverage
[i
];
846 rgba
[i
][ACOMP
] = (GLushort
) CLAMP(a
, 0.0, 65535.0);
850 GLfloat (*rgba
)[4] = span
->array
->attribs
[FRAG_ATTRIB_COL0
];
851 for (i
= 0; i
< span
->end
; i
++) {
852 rgba
[i
][ACOMP
] = rgba
[i
][ACOMP
] * coverage
[i
];
860 * Clamp span's float colors to [0,1]
863 clamp_colors(SWspan
*span
)
865 GLfloat (*rgba
)[4] = span
->array
->attribs
[FRAG_ATTRIB_COL0
];
867 ASSERT(span
->array
->ChanType
== GL_FLOAT
);
868 for (i
= 0; i
< span
->end
; i
++) {
869 rgba
[i
][RCOMP
] = CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
870 rgba
[i
][GCOMP
] = CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
871 rgba
[i
][BCOMP
] = CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
872 rgba
[i
][ACOMP
] = CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
878 * Convert the span's color arrays to the given type.
879 * The only way 'output' can be greater than zero is when we have a fragment
880 * program that writes to gl_FragData[1] or higher.
881 * \param output which fragment program color output is being processed
884 convert_color_type(SWspan
*span
, GLenum newType
, GLuint output
)
888 if (output
> 0 || span
->array
->ChanType
== GL_FLOAT
) {
889 src
= span
->array
->attribs
[FRAG_ATTRIB_COL0
+ output
];
890 span
->array
->ChanType
= GL_FLOAT
;
892 else if (span
->array
->ChanType
== GL_UNSIGNED_BYTE
) {
893 src
= span
->array
->rgba8
;
896 ASSERT(span
->array
->ChanType
== GL_UNSIGNED_SHORT
);
897 src
= span
->array
->rgba16
;
900 if (newType
== GL_UNSIGNED_BYTE
) {
901 dst
= span
->array
->rgba8
;
903 else if (newType
== GL_UNSIGNED_SHORT
) {
904 dst
= span
->array
->rgba16
;
907 dst
= span
->array
->attribs
[FRAG_ATTRIB_COL0
];
910 _mesa_convert_colors(span
->array
->ChanType
, src
,
912 span
->end
, span
->array
->mask
);
914 span
->array
->ChanType
= newType
;
915 span
->array
->rgba
= dst
;
921 * Apply fragment shader, fragment program or normal texturing to span.
924 shade_texture_span(struct gl_context
*ctx
, SWspan
*span
)
926 if (ctx
->Texture
._EnabledCoordUnits
) {
927 /* conventional texturing */
930 if ((span
->arrayAttribs
& FRAG_BIT_COL0
) == 0) {
931 interpolate_int_colors(ctx
, span
);
934 if (!(span
->arrayMask
& SPAN_RGBA
))
935 interpolate_int_colors(ctx
, span
);
937 if ((span
->arrayAttribs
& FRAG_BITS_TEX_ANY
) == 0x0)
938 interpolate_texcoords(ctx
, span
);
940 _swrast_texture_span(ctx
, span
);
945 /** Put colors at x/y locations into a renderbuffer */
947 put_values(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
949 GLuint count
, const GLint x
[], const GLint y
[],
950 const void *values
, const GLubyte
*mask
)
952 gl_pack_ubyte_rgba_func pack_ubyte
;
953 gl_pack_float_rgba_func pack_float
;
956 if (datatype
== GL_UNSIGNED_BYTE
)
957 pack_ubyte
= _mesa_get_pack_ubyte_rgba_function(rb
->Format
);
959 pack_float
= _mesa_get_pack_float_rgba_function(rb
->Format
);
961 for (i
= 0; i
< count
; i
++) {
963 GLubyte
*dst
= _swrast_pixel_address(rb
, x
[i
], y
[i
]);
965 if (datatype
== GL_UNSIGNED_BYTE
) {
966 pack_ubyte((const GLubyte
*) values
+ 4 * i
, dst
);
969 assert(datatype
== GL_FLOAT
);
970 pack_float((const GLfloat
*) values
+ 4 * i
, dst
);
977 /** Put row of colors into renderbuffer */
979 _swrast_put_row(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
981 GLuint count
, GLint x
, GLint y
,
982 const void *values
, const GLubyte
*mask
)
984 GLubyte
*dst
= _swrast_pixel_address(rb
, x
, y
);
987 if (datatype
== GL_UNSIGNED_BYTE
) {
988 _mesa_pack_ubyte_rgba_row(rb
->Format
, count
,
989 (const GLubyte (*)[4]) values
, dst
);
992 assert(datatype
== GL_FLOAT
);
993 _mesa_pack_float_rgba_row(rb
->Format
, count
,
994 (const GLfloat (*)[4]) values
, dst
);
998 const GLuint bpp
= _mesa_get_format_bytes(rb
->Format
);
999 GLuint i
, runLen
, runStart
;
1000 /* We can't pass a 'mask' array to the _mesa_pack_rgba_row() functions
1001 * so look for runs where mask=1...
1003 runLen
= runStart
= 0;
1004 for (i
= 0; i
< count
; i
++) {
1011 if (!mask
[i
] || i
== count
- 1) {
1012 /* might be the end of a run of pixels */
1014 if (datatype
== GL_UNSIGNED_BYTE
) {
1015 _mesa_pack_ubyte_rgba_row(rb
->Format
, runLen
,
1016 (const GLubyte (*)[4]) values
+ runStart
,
1017 dst
+ runStart
* bpp
);
1020 assert(datatype
== GL_FLOAT
);
1021 _mesa_pack_float_rgba_row(rb
->Format
, runLen
,
1022 (const GLfloat (*)[4]) values
+ runStart
,
1023 dst
+ runStart
* bpp
);
1035 * Apply all the per-fragment operations to a span.
1036 * This now includes texturing (_swrast_write_texture_span() is history).
1037 * This function may modify any of the array values in the span.
1038 * span->interpMask and span->arrayMask may be changed but will be restored
1039 * to their original values before returning.
1042 _swrast_write_rgba_span( struct gl_context
*ctx
, SWspan
*span
)
1044 const SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1045 const GLuint colorMask
= *((GLuint
*)ctx
->Color
.ColorMask
);
1046 const GLbitfield origInterpMask
= span
->interpMask
;
1047 const GLbitfield origArrayMask
= span
->arrayMask
;
1048 const GLbitfield64 origArrayAttribs
= span
->arrayAttribs
;
1049 const GLenum origChanType
= span
->array
->ChanType
;
1050 void * const origRgba
= span
->array
->rgba
;
1051 const GLboolean texture
= ctx
->Texture
._EnabledCoordUnits
;
1052 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
1055 printf("%s() interp 0x%x array 0x%x\n", __FUNCTION__,
1056 span->interpMask, span->arrayMask);
1059 ASSERT(span
->primitive
== GL_POINT
||
1060 span
->primitive
== GL_LINE
||
1061 span
->primitive
== GL_POLYGON
||
1062 span
->primitive
== GL_BITMAP
);
1064 /* Fragment write masks */
1065 if (span
->arrayMask
& SPAN_MASK
) {
1066 /* mask was initialized by caller, probably glBitmap */
1067 span
->writeAll
= GL_FALSE
;
1070 memset(span
->array
->mask
, 1, span
->end
);
1071 span
->writeAll
= GL_TRUE
;
1074 /* Clip to window/scissor box */
1075 if (!clip_span(ctx
, span
)) {
1079 ASSERT(span
->end
<= MAX_WIDTH
);
1081 /* Depth bounds test */
1082 if (ctx
->Depth
.BoundsTest
&& fb
->Visual
.depthBits
> 0) {
1083 if (!_swrast_depth_bounds_test(ctx
, span
)) {
1089 /* Make sure all fragments are within window bounds */
1090 if (span
->arrayMask
& SPAN_XY
) {
1091 /* array of pixel locations */
1093 for (i
= 0; i
< span
->end
; i
++) {
1094 if (span
->array
->mask
[i
]) {
1095 assert(span
->array
->x
[i
] >= fb
->_Xmin
);
1096 assert(span
->array
->x
[i
] < fb
->_Xmax
);
1097 assert(span
->array
->y
[i
] >= fb
->_Ymin
);
1098 assert(span
->array
->y
[i
] < fb
->_Ymax
);
1104 /* Polygon Stippling */
1105 if (ctx
->Polygon
.StippleFlag
&& span
->primitive
== GL_POLYGON
) {
1106 stipple_polygon_span(ctx
, span
);
1109 /* This is the normal place to compute the fragment color/Z
1110 * from texturing or shading.
1112 if (texture
&& !swrast
->_DeferredTexture
) {
1113 shade_texture_span(ctx
, span
);
1116 /* Do the alpha test */
1117 if (ctx
->Color
.AlphaEnabled
) {
1118 if (!_swrast_alpha_test(ctx
, span
)) {
1119 /* all fragments failed test */
1124 /* Stencil and Z testing */
1125 if (ctx
->Stencil
._Enabled
|| ctx
->Depth
.Test
) {
1126 if (!(span
->arrayMask
& SPAN_Z
))
1127 _swrast_span_interpolate_z(ctx
, span
);
1129 if (ctx
->Stencil
._Enabled
) {
1130 /* Combined Z/stencil tests */
1131 if (!_swrast_stencil_and_ztest_span(ctx
, span
)) {
1132 /* all fragments failed test */
1136 else if (fb
->Visual
.depthBits
> 0) {
1137 /* Just regular depth testing */
1138 ASSERT(ctx
->Depth
.Test
);
1139 ASSERT(span
->arrayMask
& SPAN_Z
);
1140 if (!_swrast_depth_test_span(ctx
, span
)) {
1141 /* all fragments failed test */
1147 /* We had to wait until now to check for glColorMask(0,0,0,0) because of
1148 * the occlusion test.
1150 if (colorMask
== 0) {
1151 /* no colors to write */
1155 /* If we were able to defer fragment color computation to now, there's
1156 * a good chance that many fragments will have already been killed by
1157 * Z/stencil testing.
1159 if (texture
&& swrast
->_DeferredTexture
) {
1160 shade_texture_span(ctx
, span
);
1164 if ((span
->arrayAttribs
& FRAG_BIT_COL0
) == 0) {
1165 interpolate_active_attribs(ctx
, span
, FRAG_BIT_COL0
);
1168 if ((span
->arrayMask
& SPAN_RGBA
) == 0) {
1169 interpolate_int_colors(ctx
, span
);
1173 ASSERT(span
->arrayMask
& SPAN_RGBA
);
1175 if (span
->primitive
== GL_BITMAP
|| !swrast
->SpecularVertexAdd
) {
1176 /* Add primary and specular (diffuse + specular) colors */
1177 if (ctx
->Fog
.ColorSumEnabled
||
1178 (ctx
->Light
.Enabled
&&
1179 ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
)) {
1180 add_specular(ctx
, span
);
1185 if (swrast
->_FogEnabled
) {
1186 _swrast_fog_rgba_span(ctx
, span
);
1189 /* Antialias coverage application */
1190 if (span
->arrayMask
& SPAN_COVERAGE
) {
1191 apply_aa_coverage(span
);
1194 /* Clamp color/alpha values over the range [0.0, 1.0] before storage */
1195 if (ctx
->Color
.ClampFragmentColor
== GL_TRUE
&&
1196 span
->array
->ChanType
== GL_FLOAT
) {
1201 * Write to renderbuffers.
1202 * Depending on glDrawBuffer() state and the which color outputs are
1203 * written by the fragment shader, we may either replicate one color to
1204 * all renderbuffers or write a different color to each renderbuffer.
1205 * multiFragOutputs=TRUE for the later case.
1208 struct gl_renderbuffer
*rb
= fb
->_ColorDrawBuffer
;
1210 /* color[fragOutput] will be written to buffer */
1213 struct swrast_renderbuffer
*srb
= swrast_renderbuffer(rb
);
1214 GLenum colorType
= srb
->ColorType
;
1216 assert(colorType
== GL_UNSIGNED_BYTE
||
1217 colorType
== GL_FLOAT
);
1219 /* set span->array->rgba to colors for renderbuffer's datatype */
1220 if (span
->array
->ChanType
!= colorType
) {
1221 convert_color_type(span
, colorType
, 0);
1224 if (span
->array
->ChanType
== GL_UNSIGNED_BYTE
) {
1225 span
->array
->rgba
= span
->array
->rgba8
;
1228 span
->array
->rgba
= (void *)span
->array
->attribs
[FRAG_ATTRIB_COL0
];
1233 ASSERT(rb
->_BaseFormat
== GL_RGBA
||
1234 rb
->_BaseFormat
== GL_RGB
||
1235 rb
->_BaseFormat
== GL_RED
||
1236 rb
->_BaseFormat
== GL_RG
||
1237 rb
->_BaseFormat
== GL_ALPHA
);
1239 if (ctx
->Color
.ColorLogicOpEnabled
) {
1240 _swrast_logicop_rgba_span(ctx
, rb
, span
);
1242 else if (ctx
->Color
.BlendEnabled
) {
1243 _swrast_blend_span(ctx
, rb
, span
);
1246 if (colorMask
!= 0xffffffff) {
1247 _swrast_mask_rgba_span(ctx
, rb
, span
);
1250 if (span
->arrayMask
& SPAN_XY
) {
1251 /* array of pixel coords */
1253 span
->array
->ChanType
, span
->end
,
1254 span
->array
->x
, span
->array
->y
,
1255 span
->array
->rgba
, span
->array
->mask
);
1258 /* horizontal run of pixels */
1259 _swrast_put_row(ctx
, rb
,
1260 span
->array
->ChanType
,
1261 span
->end
, span
->x
, span
->y
,
1263 span
->writeAll
? NULL
: span
->array
->mask
);
1270 /* restore these values before returning */
1271 span
->interpMask
= origInterpMask
;
1272 span
->arrayMask
= origArrayMask
;
1273 span
->arrayAttribs
= origArrayAttribs
;
1274 span
->array
->ChanType
= origChanType
;
1275 span
->array
->rgba
= origRgba
;
1280 * Read float RGBA pixels from a renderbuffer. Clipping will be done to
1281 * prevent reading ouside the buffer's boundaries.
1282 * \param rgba the returned colors
1285 _swrast_read_rgba_span( struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1286 GLuint n
, GLint x
, GLint y
,
1289 struct swrast_renderbuffer
*srb
= swrast_renderbuffer(rb
);
1290 GLenum dstType
= GL_FLOAT
;
1291 const GLint bufWidth
= (GLint
) rb
->Width
;
1292 const GLint bufHeight
= (GLint
) rb
->Height
;
1294 if (y
< 0 || y
>= bufHeight
|| x
+ (GLint
) n
< 0 || x
>= bufWidth
) {
1295 /* completely above, below, or right */
1296 /* XXX maybe leave rgba values undefined? */
1297 memset(rgba
, 0, 4 * n
* sizeof(GLchan
));
1304 /* left edge clipping */
1306 length
= (GLint
) n
- skip
;
1308 /* completely left of window */
1311 if (length
> bufWidth
) {
1315 else if ((GLint
) (x
+ n
) > bufWidth
) {
1316 /* right edge clipping */
1318 length
= bufWidth
- x
;
1320 /* completely to right of window */
1331 ASSERT(rb
->_BaseFormat
== GL_RGBA
||
1332 rb
->_BaseFormat
== GL_RGB
||
1333 rb
->_BaseFormat
== GL_RG
||
1334 rb
->_BaseFormat
== GL_RED
||
1335 rb
->_BaseFormat
== GL_LUMINANCE
||
1336 rb
->_BaseFormat
== GL_INTENSITY
||
1337 rb
->_BaseFormat
== GL_LUMINANCE_ALPHA
||
1338 rb
->_BaseFormat
== GL_ALPHA
);
1342 src
= _swrast_pixel_address(rb
, x
+ skip
, y
);
1344 if (dstType
== GL_UNSIGNED_BYTE
) {
1345 _mesa_unpack_ubyte_rgba_row(rb
->Format
, length
, src
,
1346 (GLubyte (*)[4]) rgba
+ skip
);
1348 else if (dstType
== GL_FLOAT
) {
1349 _mesa_unpack_rgba_row(rb
->Format
, length
, src
,
1350 (GLfloat (*)[4]) rgba
+ skip
);
1353 _mesa_problem(ctx
, "unexpected type in _swrast_read_rgba_span()");
1360 * Get colors at x/y positions with clipping.
1361 * \param type type of values to return
1364 get_values(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1365 GLuint count
, const GLint x
[], const GLint y
[],
1366 void *values
, GLenum type
)
1370 for (i
= 0; i
< count
; i
++) {
1371 if (x
[i
] >= 0 && y
[i
] >= 0 &&
1372 x
[i
] < (GLint
) rb
->Width
&& y
[i
] < (GLint
) rb
->Height
) {
1374 const GLubyte
*src
= _swrast_pixel_address(rb
, x
[i
], y
[i
]);
1376 if (type
== GL_UNSIGNED_BYTE
) {
1377 _mesa_unpack_ubyte_rgba_row(rb
->Format
, 1, src
,
1378 (GLubyte (*)[4]) values
+ i
);
1380 else if (type
== GL_FLOAT
) {
1381 _mesa_unpack_rgba_row(rb
->Format
, 1, src
,
1382 (GLfloat (*)[4]) values
+ i
);
1385 _mesa_problem(ctx
, "unexpected type in get_values()");
1393 * Get row of colors with clipping.
1394 * \param type type of values to return
1397 get_row(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1398 GLuint count
, GLint x
, GLint y
,
1399 GLvoid
*values
, GLenum type
)
1404 if (y
< 0 || y
>= (GLint
) rb
->Height
)
1405 return; /* above or below */
1407 if (x
+ (GLint
) count
<= 0 || x
>= (GLint
) rb
->Width
)
1408 return; /* entirely left or right */
1410 if (x
+ count
> rb
->Width
) {
1412 GLint clip
= x
+ count
- rb
->Width
;
1423 src
= _swrast_pixel_address(rb
, x
, y
);
1425 if (type
== GL_UNSIGNED_BYTE
) {
1426 _mesa_unpack_ubyte_rgba_row(rb
->Format
, count
, src
,
1427 (GLubyte (*)[4]) values
+ skip
);
1429 else if (type
== GL_FLOAT
) {
1430 _mesa_unpack_rgba_row(rb
->Format
, count
, src
,
1431 (GLfloat (*)[4]) values
+ skip
);
1434 _mesa_problem(ctx
, "unexpected type in get_row()");
1440 * Get RGBA pixels from the given renderbuffer.
1441 * Used by blending, logicop and masking functions.
1442 * \return pointer to the colors we read.
1445 _swrast_get_dest_rgba(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
1450 /* Point rbPixels to a temporary space */
1451 rbPixels
= span
->array
->attribs
[FRAG_ATTRIB_MAX
- 1];
1453 /* Get destination values from renderbuffer */
1454 if (span
->arrayMask
& SPAN_XY
) {
1455 get_values(ctx
, rb
, span
->end
, span
->array
->x
, span
->array
->y
,
1456 rbPixels
, span
->array
->ChanType
);
1459 get_row(ctx
, rb
, span
->end
, span
->x
, span
->y
,
1460 rbPixels
, span
->array
->ChanType
);