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