37
36
#include "s_context.h"
39
#define ALPHA_TEST(ALPHA, LOOP_CODE) \
41
switch (ctx->Color.AlphaFunc) { \
43
for (i = 0; i < n; i++) { \
44
mask[i] &= (ALPHA < ref); \
49
for (i = 0; i < n; i++) { \
50
mask[i] &= (ALPHA <= ref); \
55
for (i = 0; i < n; i++) { \
56
mask[i] &= (ALPHA >= ref); \
61
for (i = 0; i < n; i++) { \
62
mask[i] &= (ALPHA > ref); \
67
for (i = 0; i < n; i++) { \
68
mask[i] &= (ALPHA != ref); \
73
for (i = 0; i < n; i++) { \
74
mask[i] &= (ALPHA == ref); \
79
_mesa_problem(ctx, "Invalid alpha test in _swrast_alpha_test" ); \
41
* \fn GLint _swrast_alpha_test( const GLcontext *ctx, struct sw_span *span )
42
* \brief Apply the alpha test to a span of pixels.
44
* - "0" = all pixels in the span failed the alpha test.
45
* - "1" = one or more pixels passed the alpha test.
87
* Perform the alpha test for an array of pixels.
88
* For pixels that fail the test, mask[i] will be set to 0.
89
* \return 0 if all pixels in the span failed the alpha test,
90
* 1 if one or more pixels passed the alpha test.
48
_swrast_alpha_test( const GLcontext *ctx, struct sw_span *span )
93
_swrast_alpha_test(const GLcontext *ctx, SWspan *span)
50
const GLchan (*rgba)[4] = (const GLchan (*)[4]) span->array->rgba;
52
95
const GLuint n = span->end;
53
96
GLubyte *mask = span->array->mask;
56
CLAMPED_FLOAT_TO_CHAN(ref, ctx->Color.AlphaRef);
99
if (ctx->Color.AlphaFunc == GL_ALWAYS) {
103
else if (ctx->Color.AlphaFunc == GL_NEVER) {
104
/* All pixels failed - caller should check for this return value and
107
span->writeAll = GL_FALSE;
58
111
if (span->arrayMask & SPAN_RGBA) {
59
/* Use the array values */
60
switch (ctx->Color.AlphaFunc) {
62
for (i = 0; i < n; i++)
63
mask[i] &= (rgba[i][ACOMP] < ref);
66
for (i = 0; i < n; i++)
67
mask[i] &= (rgba[i][ACOMP] <= ref);
70
for (i = 0; i < n; i++)
71
mask[i] &= (rgba[i][ACOMP] >= ref);
74
for (i = 0; i < n; i++)
75
mask[i] &= (rgba[i][ACOMP] > ref);
78
for (i = 0; i < n; i++)
79
mask[i] &= (rgba[i][ACOMP] != ref);
82
for (i = 0; i < n; i++)
83
mask[i] &= (rgba[i][ACOMP] == ref);
89
/* caller should check for zero! */
90
span->writeAll = GL_FALSE;
93
_mesa_problem( ctx, "Invalid alpha test in _swrast_alpha_test" );
112
/* Use array's alpha values */
113
if (span->array->ChanType == GL_UNSIGNED_BYTE) {
114
GLubyte (*rgba)[4] = span->array->color.sz1.rgba;
116
CLAMPED_FLOAT_TO_UBYTE(ref, ctx->Color.AlphaRef);
117
ALPHA_TEST(rgba[i][ACOMP], ;);
119
else if (span->array->ChanType == GL_UNSIGNED_SHORT) {
120
GLushort (*rgba)[4] = span->array->color.sz2.rgba;
122
CLAMPED_FLOAT_TO_USHORT(ref, ctx->Color.AlphaRef);
123
ALPHA_TEST(rgba[i][ACOMP], ;);
126
GLfloat (*rgba)[4] = span->array->color.sz4.rgba;
127
const GLfloat ref = ctx->Color.AlphaRef;
128
ALPHA_TEST(rgba[i][ACOMP], ;);
98
/* Use the interpolation values */
99
#if CHAN_TYPE == GL_FLOAT
100
const GLfloat alphaStep = span->alphaStep;
101
GLfloat alpha = span->alpha;
102
ASSERT(span->interpMask & SPAN_RGBA);
103
switch (ctx->Color.AlphaFunc) {
105
for (i = 0; i < n; i++) {
106
mask[i] &= (alpha < ref);
111
for (i = 0; i < n; i++) {
112
mask[i] &= (alpha <= ref);
117
for (i = 0; i < n; i++) {
118
mask[i] &= (alpha >= ref);
123
for (i = 0; i < n; i++) {
124
mask[i] &= (alpha > ref);
129
for (i = 0; i < n; i++) {
130
mask[i] &= (alpha != ref);
135
for (i = 0; i < n; i++) {
136
mask[i] &= (alpha == ref);
144
/* caller should check for zero! */
145
span->writeAll = GL_FALSE;
148
_mesa_problem( ctx, "Invalid alpha test in gl_alpha_test" );
152
/* 8 or 16-bit channel interpolation */
153
const GLfixed alphaStep = span->alphaStep;
154
GLfixed alpha = span->alpha;
155
ASSERT(span->interpMask & SPAN_RGBA);
156
switch (ctx->Color.AlphaFunc) {
158
for (i = 0; i < n; i++) {
159
mask[i] &= (FixedToChan(alpha) < ref);
164
for (i = 0; i < n; i++) {
165
mask[i] &= (FixedToChan(alpha) <= ref);
170
for (i = 0; i < n; i++) {
171
mask[i] &= (FixedToChan(alpha) >= ref);
176
for (i = 0; i < n; i++) {
177
mask[i] &= (FixedToChan(alpha) > ref);
182
for (i = 0; i < n; i++) {
183
mask[i] &= (FixedToChan(alpha) != ref);
188
for (i = 0; i < n; i++) {
189
mask[i] &= (FixedToChan(alpha) == ref);
197
/* caller should check for zero! */
198
span->writeAll = GL_FALSE;
201
_mesa_problem( ctx, "Invalid alpha test in gl_alpha_test" );
204
#endif /* CHAN_TYPE */
132
/* Interpolate alpha values */
133
ASSERT(span->interpMask & SPAN_RGBA);
134
if (span->array->ChanType == GL_UNSIGNED_BYTE) {
135
const GLfixed alphaStep = span->alphaStep;
136
GLfixed alpha = span->alpha;
138
CLAMPED_FLOAT_TO_UBYTE(ref, ctx->Color.AlphaRef);
139
ALPHA_TEST(FixedToInt(alpha), alpha += alphaStep);
141
else if (span->array->ChanType == GL_UNSIGNED_SHORT) {
142
const GLfixed alphaStep = span->alphaStep;
143
GLfixed alpha = span->alpha;
145
CLAMPED_FLOAT_TO_USHORT(ref, ctx->Color.AlphaRef);
146
ALPHA_TEST(FixedToInt(alpha), alpha += alphaStep);
149
const GLfloat alphaStep = span->alphaStep;
150
GLfloat alpha = span->alpha;
151
const GLfloat ref = ctx->Color.AlphaRef;
152
ALPHA_TEST(alpha, alpha += alphaStep);
208
/* XXXX This causes conformance failures!!!! */
209
while ((span->start <= span->end) &&
210
(mask[span->start] == 0))
213
while ((span->end >= span->start) &&
214
(mask[span->end] == 0))
218
156
span->writeAll = GL_FALSE;
220
if (span->start >= span->end)
158
/* XXX examine mask[] values? */