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/context.h"
27 #include "main/macros.h"
28 #include "main/enums.h"
29 #include "main/dd.h"
30 
31 #include "intel_screen.h"
32 #include "brw_context.h"
33 #include "brw_defines.h"
34 
35 int
36 intel_translate_shadow_compare_func(GLenum func)
37 {
38    /* GL specifies the result of shadow comparisons as:
39     *     1     if   ref <op> texel,
40     *     0     otherwise.
41     *
42     * The hardware does:
43     *     0     if texel <op> ref,
44     *     1     otherwise.
45     *
46     * So, these look a bit strange because there's both a negation
47     * and swapping of the arguments involved.
48     */
49    switch (func) {
50    case GL_NEVER:
51       return BRW_COMPAREFUNCTION_ALWAYS;
52    case GL_LESS:
53       return BRW_COMPAREFUNCTION_LEQUAL;
54    case GL_LEQUAL:
55       return BRW_COMPAREFUNCTION_LESS;
56    case GL_GREATER:
57       return BRW_COMPAREFUNCTION_GEQUAL;
58    case GL_GEQUAL:
59       return BRW_COMPAREFUNCTION_GREATER;
60    case GL_NOTEQUAL:
61       return BRW_COMPAREFUNCTION_EQUAL;
62    case GL_EQUAL:
63       return BRW_COMPAREFUNCTION_NOTEQUAL;
64    case GL_ALWAYS:
65       return BRW_COMPAREFUNCTION_NEVER;
66    }
67 
68    unreachable("Invalid shadow comparison function.");
69 }
70 
71 int
72 intel_translate_compare_func(GLenum func)
73 {
74    switch (func) {
75    case GL_NEVER:
76       return BRW_COMPAREFUNCTION_NEVER;
77    case GL_LESS:
78       return BRW_COMPAREFUNCTION_LESS;
79    case GL_LEQUAL:
80       return BRW_COMPAREFUNCTION_LEQUAL;
81    case GL_GREATER:
82       return BRW_COMPAREFUNCTION_GREATER;
83    case GL_GEQUAL:
84       return BRW_COMPAREFUNCTION_GEQUAL;
85    case GL_NOTEQUAL:
86       return BRW_COMPAREFUNCTION_NOTEQUAL;
87    case GL_EQUAL:
88       return BRW_COMPAREFUNCTION_EQUAL;
89    case GL_ALWAYS:
90       return BRW_COMPAREFUNCTION_ALWAYS;
91    }
92 
93    unreachable("Invalid comparison function.");
94 }
95 
96 int
97 intel_translate_stencil_op(GLenum op)
98 {
99    switch (op) {
100    case GL_KEEP:
101       return BRW_STENCILOP_KEEP;
102    case GL_ZERO:
103       return BRW_STENCILOP_ZERO;
104    case GL_REPLACE:
105       return BRW_STENCILOP_REPLACE;
106    case GL_INCR:
107       return BRW_STENCILOP_INCRSAT;
108    case GL_DECR:
109       return BRW_STENCILOP_DECRSAT;
110    case GL_INCR_WRAP:
111       return BRW_STENCILOP_INCR;
112    case GL_DECR_WRAP:
113       return BRW_STENCILOP_DECR;
114    case GL_INVERT:
115       return BRW_STENCILOP_INVERT;
116    default:
117       return BRW_STENCILOP_ZERO;
118    }
119 }
120 
121 int
122 intel_translate_logic_op(GLenum opcode)
123 {
124    switch (opcode) {
125    case GL_CLEAR:
126       return BRW_LOGICOPFUNCTION_CLEAR;
127    case GL_AND:
128       return BRW_LOGICOPFUNCTION_AND;
129    case GL_AND_REVERSE:
130       return BRW_LOGICOPFUNCTION_AND_REVERSE;
131    case GL_COPY:
132       return BRW_LOGICOPFUNCTION_COPY;
133    case GL_COPY_INVERTED:
134       return BRW_LOGICOPFUNCTION_COPY_INVERTED;
135    case GL_AND_INVERTED:
136       return BRW_LOGICOPFUNCTION_AND_INVERTED;
137    case GL_NOOP:
138       return BRW_LOGICOPFUNCTION_NOOP;
139    case GL_XOR:
140       return BRW_LOGICOPFUNCTION_XOR;
141    case GL_OR:
142       return BRW_LOGICOPFUNCTION_OR;
143    case GL_OR_INVERTED:
144       return BRW_LOGICOPFUNCTION_OR_INVERTED;
145    case GL_NOR:
146       return BRW_LOGICOPFUNCTION_NOR;
147    case GL_EQUIV:
148       return BRW_LOGICOPFUNCTION_EQUIV;
149    case GL_INVERT:
150       return BRW_LOGICOPFUNCTION_INVERT;
151    case GL_OR_REVERSE:
152       return BRW_LOGICOPFUNCTION_OR_REVERSE;
153    case GL_NAND:
154       return BRW_LOGICOPFUNCTION_NAND;
155    case GL_SET:
156       return BRW_LOGICOPFUNCTION_SET;
157    default:
158       return BRW_LOGICOPFUNCTION_SET;
159    }
160 }
161