• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007-2010 The Nouveau Project.
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a 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
15  * portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  */
26 
27 #ifndef __NOUVEAU_GLDEFS_H__
28 #define __NOUVEAU_GLDEFS_H__
29 
30 static inline unsigned
nvgl_blend_func(unsigned func)31 nvgl_blend_func(unsigned func)
32 {
33 	switch (func) {
34 	case GL_ZERO:
35 		return 0x0000;
36 	case GL_ONE:
37 		return 0x0001;
38 	case GL_SRC_COLOR:
39 		return 0x0300;
40 	case GL_ONE_MINUS_SRC_COLOR:
41 		return 0x0301;
42 	case GL_SRC_ALPHA:
43 		return 0x0302;
44 	case GL_ONE_MINUS_SRC_ALPHA:
45 		return 0x0303;
46 	case GL_DST_ALPHA:
47 		return 0x0304;
48 	case GL_ONE_MINUS_DST_ALPHA:
49 		return 0x0305;
50 	case GL_DST_COLOR:
51 		return 0x0306;
52 	case GL_ONE_MINUS_DST_COLOR:
53 		return 0x0307;
54 	case GL_SRC_ALPHA_SATURATE:
55 		return 0x0308;
56 	case GL_CONSTANT_COLOR:
57 		return 0x8001;
58 	case GL_ONE_MINUS_CONSTANT_COLOR:
59 		return 0x8002;
60 	case GL_CONSTANT_ALPHA:
61 		return 0x8003;
62 	case GL_ONE_MINUS_CONSTANT_ALPHA:
63 		return 0x8004;
64 	default:
65 		assert(0);
66 	}
67 }
68 
69 static inline unsigned
nvgl_blend_eqn(unsigned eqn)70 nvgl_blend_eqn(unsigned eqn)
71 {
72 	switch (eqn) {
73 	case GL_FUNC_ADD:
74 		return 0x8006;
75 	case GL_MIN:
76 		return 0x8007;
77 	case GL_MAX:
78 		return 0x8008;
79 	case GL_FUNC_SUBTRACT:
80 		return 0x800a;
81 	case GL_FUNC_REVERSE_SUBTRACT:
82 		return 0x800b;
83 	default:
84 		assert(0);
85 	}
86 }
87 
88 static inline unsigned
nvgl_logicop_func(unsigned func)89 nvgl_logicop_func(unsigned func)
90 {
91 	switch (func) {
92 	case GL_CLEAR:
93 		return 0x1500;
94 	case GL_NOR:
95 		return 0x1508;
96 	case GL_AND_INVERTED:
97 		return 0x1504;
98 	case GL_COPY_INVERTED:
99 		return 0x150c;
100 	case GL_AND_REVERSE:
101 		return 0x1502;
102 	case GL_INVERT:
103 		return 0x150a;
104 	case GL_XOR:
105 		return 0x1506;
106 	case GL_NAND:
107 		return 0x150e;
108 	case GL_AND:
109 		return 0x1501;
110 	case GL_EQUIV:
111 		return 0x1509;
112 	case GL_NOOP:
113 		return 0x1505;
114 	case GL_OR_INVERTED:
115 		return 0x150d;
116 	case GL_COPY:
117 		return 0x1503;
118 	case GL_OR_REVERSE:
119 		return 0x150b;
120 	case GL_OR:
121 		return 0x1507;
122 	case GL_SET:
123 		return 0x150f;
124 	default:
125 		assert(0);
126 	}
127 }
128 
129 static inline unsigned
nvgl_comparison_op(unsigned op)130 nvgl_comparison_op(unsigned op)
131 {
132 	switch (op) {
133 	case GL_NEVER:
134 		return 0x0200;
135 	case GL_LESS:
136 		return 0x0201;
137 	case GL_EQUAL:
138 		return 0x0202;
139 	case GL_LEQUAL:
140 		return 0x0203;
141 	case GL_GREATER:
142 		return 0x0204;
143 	case GL_NOTEQUAL:
144 		return 0x0205;
145 	case GL_GEQUAL:
146 		return 0x0206;
147 	case GL_ALWAYS:
148 		return 0x0207;
149 	default:
150 		assert(0);
151 	}
152 }
153 
154 static inline unsigned
nvgl_polygon_mode(unsigned mode)155 nvgl_polygon_mode(unsigned mode)
156 {
157 	switch (mode) {
158 	case GL_POINT:
159 		return 0x1b00;
160 	case GL_LINE:
161 		return 0x1b01;
162 	case GL_FILL:
163 		return 0x1b02;
164 	default:
165 		assert(0);
166 	}
167 }
168 
169 static inline unsigned
nvgl_stencil_op(unsigned op)170 nvgl_stencil_op(unsigned op)
171 {
172 	switch (op) {
173 	case GL_ZERO:
174 		return 0x0000;
175 	case GL_INVERT:
176 		return 0x150a;
177 	case GL_KEEP:
178 		return 0x1e00;
179 	case GL_REPLACE:
180 		return 0x1e01;
181 	case GL_INCR:
182 		return 0x1e02;
183 	case GL_DECR:
184 		return 0x1e03;
185 	case GL_INCR_WRAP_EXT:
186 		return 0x8507;
187 	case GL_DECR_WRAP_EXT:
188 		return 0x8508;
189 	default:
190 		assert(0);
191 	}
192 }
193 
194 static inline unsigned
nvgl_primitive(unsigned prim)195 nvgl_primitive(unsigned prim)
196 {
197 	switch (prim) {
198 	case GL_POINTS:
199 		return 0x0001;
200 	case GL_LINES:
201 		return 0x0002;
202 	case GL_LINE_LOOP:
203 		return 0x0003;
204 	case GL_LINE_STRIP:
205 		return 0x0004;
206 	case GL_TRIANGLES:
207 		return 0x0005;
208 	case GL_TRIANGLE_STRIP:
209 		return 0x0006;
210 	case GL_TRIANGLE_FAN:
211 		return 0x0007;
212 	case GL_QUADS:
213 		return 0x0008;
214 	case GL_QUAD_STRIP:
215 		return 0x0009;
216 	case GL_POLYGON:
217 		return 0x000a;
218 	default:
219 		assert(0);
220 	}
221 }
222 
223 static inline unsigned
nvgl_wrap_mode(unsigned wrap)224 nvgl_wrap_mode(unsigned wrap)
225 {
226 	switch (wrap) {
227 	case GL_REPEAT:
228 		return 0x1;
229 	case GL_MIRRORED_REPEAT:
230 		return 0x2;
231 	case GL_CLAMP:
232 	case GL_CLAMP_TO_EDGE:
233 		return 0x3;
234 	case GL_CLAMP_TO_BORDER:
235 		return 0x4;
236 	default:
237 		assert(0);
238 	}
239 }
240 
241 static inline unsigned
nvgl_wrap_mode_nv20(unsigned wrap)242 nvgl_wrap_mode_nv20(unsigned wrap)
243 {
244 	switch (wrap) {
245 	case GL_REPEAT:
246 		return 0x1;
247 	case GL_MIRRORED_REPEAT:
248 		return 0x2;
249 	case GL_CLAMP:
250 		return 0x5;
251 	case GL_CLAMP_TO_EDGE:
252 		return 0x3;
253 	case GL_CLAMP_TO_BORDER:
254 		return 0x4;
255 	default:
256 		unreachable("Bad GL texture wrap mode");
257 	}
258 }
259 
260 static inline unsigned
nvgl_filter_mode(unsigned filter)261 nvgl_filter_mode(unsigned filter)
262 {
263 	switch (filter) {
264 	case GL_NEAREST:
265 		return 0x1;
266 	case GL_LINEAR:
267 		return 0x2;
268 	case GL_NEAREST_MIPMAP_NEAREST:
269 		return 0x3;
270 	case GL_LINEAR_MIPMAP_NEAREST:
271 		return 0x4;
272 	case GL_NEAREST_MIPMAP_LINEAR:
273 		return 0x5;
274 	case GL_LINEAR_MIPMAP_LINEAR:
275 		return 0x6;
276 	default:
277 		assert(0);
278 	}
279 }
280 
281 static inline unsigned
nvgl_texgen_mode(unsigned mode)282 nvgl_texgen_mode(unsigned mode)
283 {
284 	switch (mode) {
285 	case GL_EYE_LINEAR:
286 		return 0x2400;
287 	case GL_OBJECT_LINEAR:
288 		return 0x2401;
289 	case GL_SPHERE_MAP:
290 		return 0x2402;
291 	case GL_NORMAL_MAP:
292 		return 0x8511;
293 	case GL_REFLECTION_MAP:
294 		return 0x8512;
295 	default:
296 		assert(0);
297 	}
298 }
299 
300 #endif
301