Merge branch 'gallium-i915-current' into gallium-0.1
[mesa.git] / src / gallium / drivers / softpipe / sp_quad_alpha_test.c
1
2 /**
3 * quad alpha test
4 */
5
6 #include "sp_context.h"
7 #include "sp_headers.h"
8 #include "sp_quad.h"
9 #include "pipe/p_defines.h"
10 #include "pipe/p_util.h"
11
12
13 static void
14 alpha_test_quad(struct quad_stage *qs, struct quad_header *quad)
15 {
16 struct softpipe_context *softpipe = qs->softpipe;
17 const float ref = softpipe->depth_stencil->alpha.ref;
18 unsigned passMask = 0x0, j;
19 const uint cbuf = 0; /* only output[0].alpha is tested */
20 const float *aaaa = quad->outputs.color[cbuf][3];
21
22 switch (softpipe->depth_stencil->alpha.func) {
23 case PIPE_FUNC_NEVER:
24 quad->mask = 0x0;
25 break;
26 case PIPE_FUNC_LESS:
27 /*
28 * If mask were an array [4] we could do this SIMD-style:
29 * passMask = (quad->outputs.color[0][3] <= vec4(ref));
30 */
31 for (j = 0; j < QUAD_SIZE; j++) {
32 if (aaaa[j] < ref) {
33 passMask |= (1 << j);
34 }
35 }
36 break;
37 case PIPE_FUNC_EQUAL:
38 for (j = 0; j < QUAD_SIZE; j++) {
39 if (aaaa[j] == ref) {
40 passMask |= (1 << j);
41 }
42 }
43 break;
44 case PIPE_FUNC_LEQUAL:
45 for (j = 0; j < QUAD_SIZE; j++) {
46 if (aaaa[j] <= ref) {
47 passMask |= (1 << j);
48 }
49 }
50 break;
51 case PIPE_FUNC_GREATER:
52 for (j = 0; j < QUAD_SIZE; j++) {
53 if (aaaa[j] > ref) {
54 passMask |= (1 << j);
55 }
56 }
57 break;
58 case PIPE_FUNC_NOTEQUAL:
59 for (j = 0; j < QUAD_SIZE; j++) {
60 if (aaaa[j] != ref) {
61 passMask |= (1 << j);
62 }
63 }
64 break;
65 case PIPE_FUNC_GEQUAL:
66 for (j = 0; j < QUAD_SIZE; j++) {
67 if (aaaa[j] >= ref) {
68 passMask |= (1 << j);
69 }
70 }
71 break;
72 case PIPE_FUNC_ALWAYS:
73 passMask = MASK_ALL;
74 break;
75 default:
76 assert(0);
77 }
78
79 quad->mask &= passMask;
80
81 if (quad->mask)
82 qs->next->run(qs->next, quad);
83 }
84
85
86 static void alpha_test_begin(struct quad_stage *qs)
87 {
88 qs->next->begin(qs->next);
89 }
90
91
92 static void alpha_test_destroy(struct quad_stage *qs)
93 {
94 FREE( qs );
95 }
96
97
98 struct quad_stage *
99 sp_quad_alpha_test_stage( struct softpipe_context *softpipe )
100 {
101 struct quad_stage *stage = CALLOC_STRUCT(quad_stage);
102
103 stage->softpipe = softpipe;
104 stage->begin = alpha_test_begin;
105 stage->run = alpha_test_quad;
106 stage->destroy = alpha_test_destroy;
107
108 return stage;
109 }