intel_state.c revision d0c8ed73cc6f2b08906a18a8d60e3bc364e5e48f
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#include "intel_regions.h" 39#include "swrast/swrast.h" 40 41int 42intel_translate_shadow_compare_func(GLenum func) 43{ 44 switch (func) { 45 case GL_NEVER: 46 return COMPAREFUNC_ALWAYS; 47 case GL_LESS: 48 return COMPAREFUNC_LEQUAL; 49 case GL_LEQUAL: 50 return COMPAREFUNC_LESS; 51 case GL_GREATER: 52 return COMPAREFUNC_GEQUAL; 53 case GL_GEQUAL: 54 return COMPAREFUNC_GREATER; 55 case GL_NOTEQUAL: 56 return COMPAREFUNC_EQUAL; 57 case GL_EQUAL: 58 return COMPAREFUNC_NOTEQUAL; 59 case GL_ALWAYS: 60 return COMPAREFUNC_NEVER; 61 } 62 63 fprintf(stderr, "Unknown value in %s: %x\n", __FUNCTION__, func); 64 return COMPAREFUNC_NEVER; 65} 66 67int 68intel_translate_compare_func(GLenum func) 69{ 70 switch (func) { 71 case GL_NEVER: 72 return COMPAREFUNC_NEVER; 73 case GL_LESS: 74 return COMPAREFUNC_LESS; 75 case GL_LEQUAL: 76 return COMPAREFUNC_LEQUAL; 77 case GL_GREATER: 78 return COMPAREFUNC_GREATER; 79 case GL_GEQUAL: 80 return COMPAREFUNC_GEQUAL; 81 case GL_NOTEQUAL: 82 return COMPAREFUNC_NOTEQUAL; 83 case GL_EQUAL: 84 return COMPAREFUNC_EQUAL; 85 case GL_ALWAYS: 86 return COMPAREFUNC_ALWAYS; 87 } 88 89 fprintf(stderr, "Unknown value in %s: %x\n", __FUNCTION__, func); 90 return COMPAREFUNC_ALWAYS; 91} 92 93int 94intel_translate_stencil_op(GLenum op) 95{ 96 switch (op) { 97 case GL_KEEP: 98 return STENCILOP_KEEP; 99 case GL_ZERO: 100 return STENCILOP_ZERO; 101 case GL_REPLACE: 102 return STENCILOP_REPLACE; 103 case GL_INCR: 104 return STENCILOP_INCRSAT; 105 case GL_DECR: 106 return STENCILOP_DECRSAT; 107 case GL_INCR_WRAP: 108 return STENCILOP_INCR; 109 case GL_DECR_WRAP: 110 return STENCILOP_DECR; 111 case GL_INVERT: 112 return STENCILOP_INVERT; 113 default: 114 return STENCILOP_ZERO; 115 } 116} 117 118int 119intel_translate_blend_factor(GLenum factor) 120{ 121 switch (factor) { 122 case GL_ZERO: 123 return BLENDFACT_ZERO; 124 case GL_SRC_ALPHA: 125 return BLENDFACT_SRC_ALPHA; 126 case GL_ONE: 127 return BLENDFACT_ONE; 128 case GL_SRC_COLOR: 129 return BLENDFACT_SRC_COLR; 130 case GL_ONE_MINUS_SRC_COLOR: 131 return BLENDFACT_INV_SRC_COLR; 132 case GL_DST_COLOR: 133 return BLENDFACT_DST_COLR; 134 case GL_ONE_MINUS_DST_COLOR: 135 return BLENDFACT_INV_DST_COLR; 136 case GL_ONE_MINUS_SRC_ALPHA: 137 return BLENDFACT_INV_SRC_ALPHA; 138 case GL_DST_ALPHA: 139 return BLENDFACT_DST_ALPHA; 140 case GL_ONE_MINUS_DST_ALPHA: 141 return BLENDFACT_INV_DST_ALPHA; 142 case GL_SRC_ALPHA_SATURATE: 143 return BLENDFACT_SRC_ALPHA_SATURATE; 144 case GL_CONSTANT_COLOR: 145 return BLENDFACT_CONST_COLOR; 146 case GL_ONE_MINUS_CONSTANT_COLOR: 147 return BLENDFACT_INV_CONST_COLOR; 148 case GL_CONSTANT_ALPHA: 149 return BLENDFACT_CONST_ALPHA; 150 case GL_ONE_MINUS_CONSTANT_ALPHA: 151 return BLENDFACT_INV_CONST_ALPHA; 152 } 153 154 fprintf(stderr, "Unknown value in %s: %x\n", __FUNCTION__, factor); 155 return BLENDFACT_ZERO; 156} 157 158int 159intel_translate_logic_op(GLenum opcode) 160{ 161 switch (opcode) { 162 case GL_CLEAR: 163 return LOGICOP_CLEAR; 164 case GL_AND: 165 return LOGICOP_AND; 166 case GL_AND_REVERSE: 167 return LOGICOP_AND_RVRSE; 168 case GL_COPY: 169 return LOGICOP_COPY; 170 case GL_COPY_INVERTED: 171 return LOGICOP_COPY_INV; 172 case GL_AND_INVERTED: 173 return LOGICOP_AND_INV; 174 case GL_NOOP: 175 return LOGICOP_NOOP; 176 case GL_XOR: 177 return LOGICOP_XOR; 178 case GL_OR: 179 return LOGICOP_OR; 180 case GL_OR_INVERTED: 181 return LOGICOP_OR_INV; 182 case GL_NOR: 183 return LOGICOP_NOR; 184 case GL_EQUIV: 185 return LOGICOP_EQUIV; 186 case GL_INVERT: 187 return LOGICOP_INV; 188 case GL_OR_REVERSE: 189 return LOGICOP_OR_RVRSE; 190 case GL_NAND: 191 return LOGICOP_NAND; 192 case GL_SET: 193 return LOGICOP_SET; 194 default: 195 return LOGICOP_SET; 196 } 197} 198 199 200static void 201intelClearColor(GLcontext *ctx, const GLfloat color[4]) 202{ 203 struct intel_context *intel = intel_context(ctx); 204 GLubyte clear[4]; 205 206 CLAMPED_FLOAT_TO_UBYTE(clear[0], color[0]); 207 CLAMPED_FLOAT_TO_UBYTE(clear[1], color[1]); 208 CLAMPED_FLOAT_TO_UBYTE(clear[2], color[2]); 209 CLAMPED_FLOAT_TO_UBYTE(clear[3], color[3]); 210 211 /* compute both 32 and 16-bit clear values */ 212 intel->ClearColor8888 = INTEL_PACKCOLOR8888(clear[0], clear[1], 213 clear[2], clear[3]); 214 intel->ClearColor565 = INTEL_PACKCOLOR565(clear[0], clear[1], clear[2]); 215} 216 217 218/* Fallback to swrast for select and feedback. 219 */ 220static void 221intelRenderMode(GLcontext *ctx, GLenum mode) 222{ 223 struct intel_context *intel = intel_context(ctx); 224 FALLBACK(intel, INTEL_FALLBACK_RENDERMODE, (mode != GL_RENDER)); 225} 226 227 228void 229intelInitStateFuncs(struct dd_function_table *functions) 230{ 231 functions->RenderMode = intelRenderMode; 232 functions->ClearColor = intelClearColor; 233} 234