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 30static inline unsigned 31nvgl_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 69static inline unsigned 70nvgl_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 88static inline unsigned 89nvgl_comparison_op(unsigned op) 90{ 91 switch (op) { 92 case GL_NEVER: 93 return 0x0200; 94 case GL_LESS: 95 return 0x0201; 96 case GL_EQUAL: 97 return 0x0202; 98 case GL_LEQUAL: 99 return 0x0203; 100 case GL_GREATER: 101 return 0x0204; 102 case GL_NOTEQUAL: 103 return 0x0205; 104 case GL_GEQUAL: 105 return 0x0206; 106 case GL_ALWAYS: 107 return 0x0207; 108 default: 109 assert(0); 110 } 111} 112 113static inline unsigned 114nvgl_polygon_mode(unsigned mode) 115{ 116 switch (mode) { 117 case GL_POINT: 118 return 0x1b00; 119 case GL_LINE: 120 return 0x1b01; 121 case GL_FILL: 122 return 0x1b02; 123 default: 124 assert(0); 125 } 126} 127 128static inline unsigned 129nvgl_stencil_op(unsigned op) 130{ 131 switch (op) { 132 case GL_ZERO: 133 return 0x0000; 134 case GL_INVERT: 135 return 0x150a; 136 case GL_KEEP: 137 return 0x1e00; 138 case GL_REPLACE: 139 return 0x1e01; 140 case GL_INCR: 141 return 0x1e02; 142 case GL_DECR: 143 return 0x1e03; 144 case GL_INCR_WRAP_EXT: 145 return 0x8507; 146 case GL_DECR_WRAP_EXT: 147 return 0x8508; 148 default: 149 assert(0); 150 } 151} 152 153static inline unsigned 154nvgl_primitive(unsigned prim) 155{ 156 switch (prim) { 157 case GL_POINTS: 158 return 0x0001; 159 case GL_LINES: 160 return 0x0002; 161 case GL_LINE_LOOP: 162 return 0x0003; 163 case GL_LINE_STRIP: 164 return 0x0004; 165 case GL_TRIANGLES: 166 return 0x0005; 167 case GL_TRIANGLE_STRIP: 168 return 0x0006; 169 case GL_TRIANGLE_FAN: 170 return 0x0007; 171 case GL_QUADS: 172 return 0x0008; 173 case GL_QUAD_STRIP: 174 return 0x0009; 175 case GL_POLYGON: 176 return 0x000a; 177 default: 178 assert(0); 179 } 180} 181 182static inline unsigned 183nvgl_wrap_mode(unsigned wrap) 184{ 185 switch (wrap) { 186 case GL_REPEAT: 187 return 0x1; 188 case GL_MIRRORED_REPEAT: 189 return 0x2; 190 case GL_CLAMP: 191 case GL_CLAMP_TO_EDGE: 192 return 0x3; 193 case GL_CLAMP_TO_BORDER: 194 return 0x4; 195 default: 196 assert(0); 197 } 198} 199 200static inline unsigned 201nvgl_wrap_mode_nv20(unsigned wrap) 202{ 203 switch (wrap) { 204 case GL_REPEAT: 205 return 0x1; 206 case GL_MIRRORED_REPEAT: 207 return 0x2; 208 case GL_CLAMP: 209 return 0x5; 210 case GL_CLAMP_TO_EDGE: 211 return 0x3; 212 case GL_CLAMP_TO_BORDER: 213 return 0x4; 214 default: 215 unreachable("Bad GL texture wrap mode"); 216 } 217} 218 219static inline unsigned 220nvgl_filter_mode(unsigned filter) 221{ 222 switch (filter) { 223 case GL_NEAREST: 224 return 0x1; 225 case GL_LINEAR: 226 return 0x2; 227 case GL_NEAREST_MIPMAP_NEAREST: 228 return 0x3; 229 case GL_LINEAR_MIPMAP_NEAREST: 230 return 0x4; 231 case GL_NEAREST_MIPMAP_LINEAR: 232 return 0x5; 233 case GL_LINEAR_MIPMAP_LINEAR: 234 return 0x6; 235 default: 236 assert(0); 237 } 238} 239 240static inline unsigned 241nvgl_texgen_mode(unsigned mode) 242{ 243 switch (mode) { 244 case GL_EYE_LINEAR: 245 return 0x2400; 246 case GL_OBJECT_LINEAR: 247 return 0x2401; 248 case GL_SPHERE_MAP: 249 return 0x2402; 250 case GL_NORMAL_MAP: 251 return 0x8511; 252 case GL_REFLECTION_MAP: 253 return 0x8512; 254 default: 255 assert(0); 256 } 257} 258 259#endif 260