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/dd.h"
34 
35 #include "intel_screen.h"
36 #include "intel_context.h"
37 
38 int
39 intel_translate_shadow_compare_func(GLenum func)
40 {
41    switch (func) {
42    case GL_NEVER:
43        return COMPAREFUNC_ALWAYS;
44    case GL_LESS:
45        return COMPAREFUNC_LEQUAL;
46    case GL_LEQUAL:
47        return COMPAREFUNC_LESS;
48    case GL_GREATER:
49        return COMPAREFUNC_GEQUAL;
50    case GL_GEQUAL:
51       return COMPAREFUNC_GREATER;
52    case GL_NOTEQUAL:
53       return COMPAREFUNC_EQUAL;
54    case GL_EQUAL:
55       return COMPAREFUNC_NOTEQUAL;
56    case GL_ALWAYS:
57        return COMPAREFUNC_NEVER;
58    }
59 
60    fprintf(stderr, "Unknown value in %s: %x\n", __func__, func);
61    return COMPAREFUNC_NEVER;
62 }
63 
64 int
65 intel_translate_compare_func(GLenum func)
66 {
67    switch (func) {
68    case GL_NEVER:
69       return COMPAREFUNC_NEVER;
70    case GL_LESS:
71       return COMPAREFUNC_LESS;
72    case GL_LEQUAL:
73       return COMPAREFUNC_LEQUAL;
74    case GL_GREATER:
75       return COMPAREFUNC_GREATER;
76    case GL_GEQUAL:
77       return COMPAREFUNC_GEQUAL;
78    case GL_NOTEQUAL:
79       return COMPAREFUNC_NOTEQUAL;
80    case GL_EQUAL:
81       return COMPAREFUNC_EQUAL;
82    case GL_ALWAYS:
83       return COMPAREFUNC_ALWAYS;
84    }
85 
86    fprintf(stderr, "Unknown value in %s: %x\n", __func__, func);
87    return COMPAREFUNC_ALWAYS;
88 }
89 
90 int
91 intel_translate_stencil_op(GLenum op)
92 {
93    switch (op) {
94    case GL_KEEP:
95       return STENCILOP_KEEP;
96    case GL_ZERO:
97       return STENCILOP_ZERO;
98    case GL_REPLACE:
99       return STENCILOP_REPLACE;
100    case GL_INCR:
101       return STENCILOP_INCRSAT;
102    case GL_DECR:
103       return STENCILOP_DECRSAT;
104    case GL_INCR_WRAP:
105       return STENCILOP_INCR;
106    case GL_DECR_WRAP:
107       return STENCILOP_DECR;
108    case GL_INVERT:
109       return STENCILOP_INVERT;
110    default:
111       return STENCILOP_ZERO;
112    }
113 }
114 
115 int
116 intel_translate_blend_factor(GLenum factor)
117 {
118    switch (factor) {
119    case GL_ZERO:
120       return BLENDFACT_ZERO;
121    case GL_SRC_ALPHA:
122       return BLENDFACT_SRC_ALPHA;
123    case GL_ONE:
124       return BLENDFACT_ONE;
125    case GL_SRC_COLOR:
126       return BLENDFACT_SRC_COLR;
127    case GL_ONE_MINUS_SRC_COLOR:
128       return BLENDFACT_INV_SRC_COLR;
129    case GL_DST_COLOR:
130       return BLENDFACT_DST_COLR;
131    case GL_ONE_MINUS_DST_COLOR:
132       return BLENDFACT_INV_DST_COLR;
133    case GL_ONE_MINUS_SRC_ALPHA:
134       return BLENDFACT_INV_SRC_ALPHA;
135    case GL_DST_ALPHA:
136       return BLENDFACT_DST_ALPHA;
137    case GL_ONE_MINUS_DST_ALPHA:
138       return BLENDFACT_INV_DST_ALPHA;
139    case GL_SRC_ALPHA_SATURATE:
140       return BLENDFACT_SRC_ALPHA_SATURATE;
141    case GL_CONSTANT_COLOR:
142       return BLENDFACT_CONST_COLOR;
143    case GL_ONE_MINUS_CONSTANT_COLOR:
144       return BLENDFACT_INV_CONST_COLOR;
145    case GL_CONSTANT_ALPHA:
146       return BLENDFACT_CONST_ALPHA;
147    case GL_ONE_MINUS_CONSTANT_ALPHA:
148       return BLENDFACT_INV_CONST_ALPHA;
149    }
150 
151    fprintf(stderr, "Unknown value in %s: %x\n", __func__, factor);
152    return BLENDFACT_ZERO;
153 }
154 
155 int
156 intel_translate_logic_op(GLenum opcode)
157 {
158    switch (opcode) {
159    case GL_CLEAR:
160       return LOGICOP_CLEAR;
161    case GL_AND:
162       return LOGICOP_AND;
163    case GL_AND_REVERSE:
164       return LOGICOP_AND_RVRSE;
165    case GL_COPY:
166       return LOGICOP_COPY;
167    case GL_COPY_INVERTED:
168       return LOGICOP_COPY_INV;
169    case GL_AND_INVERTED:
170       return LOGICOP_AND_INV;
171    case GL_NOOP:
172       return LOGICOP_NOOP;
173    case GL_XOR:
174       return LOGICOP_XOR;
175    case GL_OR:
176       return LOGICOP_OR;
177    case GL_OR_INVERTED:
178       return LOGICOP_OR_INV;
179    case GL_NOR:
180       return LOGICOP_NOR;
181    case GL_EQUIV:
182       return LOGICOP_EQUIV;
183    case GL_INVERT:
184       return LOGICOP_INV;
185    case GL_OR_REVERSE:
186       return LOGICOP_OR_RVRSE;
187    case GL_NAND:
188       return LOGICOP_NAND;
189    case GL_SET:
190       return LOGICOP_SET;
191    default:
192       return LOGICOP_SET;
193    }
194 }
195