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