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