Merge commit 'origin/gallium-master-merge'
[mesa.git] / src / gallium / drivers / i965simple / brw_util.c
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial
16 portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32
33 #include "brw_util.h"
34 #include "brw_defines.h"
35
36 #include "pipe/p_defines.h"
37
38 unsigned brw_count_bits( unsigned val )
39 {
40 unsigned i;
41 for (i = 0; val ; val >>= 1)
42 if (val & 1)
43 i++;
44 return i;
45 }
46
47
48 unsigned brw_translate_blend_equation( int mode )
49 {
50 switch (mode) {
51 case PIPE_BLEND_ADD:
52 return BRW_BLENDFUNCTION_ADD;
53 case PIPE_BLEND_MIN:
54 return BRW_BLENDFUNCTION_MIN;
55 case PIPE_BLEND_MAX:
56 return BRW_BLENDFUNCTION_MAX;
57 case PIPE_BLEND_SUBTRACT:
58 return BRW_BLENDFUNCTION_SUBTRACT;
59 case PIPE_BLEND_REVERSE_SUBTRACT:
60 return BRW_BLENDFUNCTION_REVERSE_SUBTRACT;
61 default:
62 assert(0);
63 return BRW_BLENDFUNCTION_ADD;
64 }
65 }
66
67 unsigned brw_translate_blend_factor( int factor )
68 {
69 switch(factor) {
70 case PIPE_BLENDFACTOR_ZERO:
71 return BRW_BLENDFACTOR_ZERO;
72 case PIPE_BLENDFACTOR_SRC_ALPHA:
73 return BRW_BLENDFACTOR_SRC_ALPHA;
74 case PIPE_BLENDFACTOR_ONE:
75 return BRW_BLENDFACTOR_ONE;
76 case PIPE_BLENDFACTOR_SRC_COLOR:
77 return BRW_BLENDFACTOR_SRC_COLOR;
78 case PIPE_BLENDFACTOR_INV_SRC_COLOR:
79 return BRW_BLENDFACTOR_INV_SRC_COLOR;
80 case PIPE_BLENDFACTOR_DST_COLOR:
81 return BRW_BLENDFACTOR_DST_COLOR;
82 case PIPE_BLENDFACTOR_INV_DST_COLOR:
83 return BRW_BLENDFACTOR_INV_DST_COLOR;
84 case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
85 return BRW_BLENDFACTOR_INV_SRC_ALPHA;
86 case PIPE_BLENDFACTOR_DST_ALPHA:
87 return BRW_BLENDFACTOR_DST_ALPHA;
88 case PIPE_BLENDFACTOR_INV_DST_ALPHA:
89 return BRW_BLENDFACTOR_INV_DST_ALPHA;
90 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
91 return BRW_BLENDFACTOR_SRC_ALPHA_SATURATE;
92 case PIPE_BLENDFACTOR_CONST_COLOR:
93 return BRW_BLENDFACTOR_CONST_COLOR;
94 case PIPE_BLENDFACTOR_INV_CONST_COLOR:
95 return BRW_BLENDFACTOR_INV_CONST_COLOR;
96 case PIPE_BLENDFACTOR_CONST_ALPHA:
97 return BRW_BLENDFACTOR_CONST_ALPHA;
98 case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
99 return BRW_BLENDFACTOR_INV_CONST_ALPHA;
100 default:
101 assert(0);
102 return BRW_BLENDFACTOR_ZERO;
103 }
104 }