2f5c901fdf81ce0213df99eafef33eac09bf772f
[mesa.git] / src / mesa / drivers / dri / i965 / intel_state.c
1 /*
2 * Copyright 2003 VMware, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #include "main/glheader.h"
27 #include "main/context.h"
28 #include "main/macros.h"
29 #include "main/enums.h"
30 #include "main/dd.h"
31
32 #include "intel_screen.h"
33 #include "brw_context.h"
34 #include "brw_defines.h"
35
36 int
37 intel_translate_shadow_compare_func(GLenum func)
38 {
39 /* GL specifies the result of shadow comparisons as:
40 * 1 if ref <op> texel,
41 * 0 otherwise.
42 *
43 * The hardware does:
44 * 0 if texel <op> ref,
45 * 1 otherwise.
46 *
47 * So, these look a bit strange because there's both a negation
48 * and swapping of the arguments involved.
49 */
50 switch (func) {
51 case GL_NEVER:
52 return BRW_COMPAREFUNCTION_ALWAYS;
53 case GL_LESS:
54 return BRW_COMPAREFUNCTION_LEQUAL;
55 case GL_LEQUAL:
56 return BRW_COMPAREFUNCTION_LESS;
57 case GL_GREATER:
58 return BRW_COMPAREFUNCTION_GEQUAL;
59 case GL_GEQUAL:
60 return BRW_COMPAREFUNCTION_GREATER;
61 case GL_NOTEQUAL:
62 return BRW_COMPAREFUNCTION_EQUAL;
63 case GL_EQUAL:
64 return BRW_COMPAREFUNCTION_NOTEQUAL;
65 case GL_ALWAYS:
66 return BRW_COMPAREFUNCTION_NEVER;
67 }
68
69 unreachable("Invalid shadow comparison function.");
70 }
71
72 int
73 intel_translate_compare_func(GLenum func)
74 {
75 switch (func) {
76 case GL_NEVER:
77 return BRW_COMPAREFUNCTION_NEVER;
78 case GL_LESS:
79 return BRW_COMPAREFUNCTION_LESS;
80 case GL_LEQUAL:
81 return BRW_COMPAREFUNCTION_LEQUAL;
82 case GL_GREATER:
83 return BRW_COMPAREFUNCTION_GREATER;
84 case GL_GEQUAL:
85 return BRW_COMPAREFUNCTION_GEQUAL;
86 case GL_NOTEQUAL:
87 return BRW_COMPAREFUNCTION_NOTEQUAL;
88 case GL_EQUAL:
89 return BRW_COMPAREFUNCTION_EQUAL;
90 case GL_ALWAYS:
91 return BRW_COMPAREFUNCTION_ALWAYS;
92 }
93
94 unreachable("Invalid comparison function.");
95 }
96
97 int
98 intel_translate_stencil_op(GLenum op)
99 {
100 switch (op) {
101 case GL_KEEP:
102 return BRW_STENCILOP_KEEP;
103 case GL_ZERO:
104 return BRW_STENCILOP_ZERO;
105 case GL_REPLACE:
106 return BRW_STENCILOP_REPLACE;
107 case GL_INCR:
108 return BRW_STENCILOP_INCRSAT;
109 case GL_DECR:
110 return BRW_STENCILOP_DECRSAT;
111 case GL_INCR_WRAP:
112 return BRW_STENCILOP_INCR;
113 case GL_DECR_WRAP:
114 return BRW_STENCILOP_DECR;
115 case GL_INVERT:
116 return BRW_STENCILOP_INVERT;
117 default:
118 return BRW_STENCILOP_ZERO;
119 }
120 }
121
122 int
123 intel_translate_logic_op(GLenum opcode)
124 {
125 switch (opcode) {
126 case GL_CLEAR:
127 return BRW_LOGICOPFUNCTION_CLEAR;
128 case GL_AND:
129 return BRW_LOGICOPFUNCTION_AND;
130 case GL_AND_REVERSE:
131 return BRW_LOGICOPFUNCTION_AND_REVERSE;
132 case GL_COPY:
133 return BRW_LOGICOPFUNCTION_COPY;
134 case GL_COPY_INVERTED:
135 return BRW_LOGICOPFUNCTION_COPY_INVERTED;
136 case GL_AND_INVERTED:
137 return BRW_LOGICOPFUNCTION_AND_INVERTED;
138 case GL_NOOP:
139 return BRW_LOGICOPFUNCTION_NOOP;
140 case GL_XOR:
141 return BRW_LOGICOPFUNCTION_XOR;
142 case GL_OR:
143 return BRW_LOGICOPFUNCTION_OR;
144 case GL_OR_INVERTED:
145 return BRW_LOGICOPFUNCTION_OR_INVERTED;
146 case GL_NOR:
147 return BRW_LOGICOPFUNCTION_NOR;
148 case GL_EQUIV:
149 return BRW_LOGICOPFUNCTION_EQUIV;
150 case GL_INVERT:
151 return BRW_LOGICOPFUNCTION_INVERT;
152 case GL_OR_REVERSE:
153 return BRW_LOGICOPFUNCTION_OR_REVERSE;
154 case GL_NAND:
155 return BRW_LOGICOPFUNCTION_NAND;
156 case GL_SET:
157 return BRW_LOGICOPFUNCTION_SET;
158 default:
159 return BRW_LOGICOPFUNCTION_SET;
160 }
161 }