16b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/************************************************************************** 26b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * 36b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 46b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * All Rights Reserved. 56b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * 66b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 76b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * copy of this software and associated documentation files (the 86b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * "Software"), to deal in the Software without restriction, including 96b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * without limitation the rights to use, copy, modify, merge, publish, 106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * distribute, sub license, and/or sell copies of the Software, and to 116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * permit persons to whom the Software is furnished to do so, subject to 126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * the following conditions: 136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * 146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * The above copyright notice and this permission notice (including the 156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * next paragraph) shall be included in all copies or substantial portions 166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * of the Software. 176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * 186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * 266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell **************************************************************************/ 276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 28ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/glheader.h" 29ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/macros.h" 30ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/mtypes.h" 31ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/simple_list.h" 32ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/enums.h" 33ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/mm.h" 346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_screen.h" 366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_tex.h" 376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "i830_context.h" 396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "i830_reg.h" 406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* ================================================================ 436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Texture combine functions 446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLuint 466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellpass_through(GLuint * state, GLuint blendUnit) 476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[0] = (_3DSTATE_MAP_BLEND_OP_CMD(blendUnit) | 496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXPIPE_COLOR | 506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ENABLE_TEXOUTPUT_WRT_SEL | 516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXOP_OUTPUT_CURRENT | 526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DISABLE_TEX_CNTRL_STAGE | 536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXOP_SCALE_1X | TEXOP_MODIFY_PARMS | TEXBLENDOP_ARG1); 546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[1] = (_3DSTATE_MAP_BLEND_OP_CMD(blendUnit) | 556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXPIPE_ALPHA | 566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ENABLE_TEXOUTPUT_WRT_SEL | 576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXOP_OUTPUT_CURRENT | 586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXOP_SCALE_1X | TEXOP_MODIFY_PARMS | TEXBLENDOP_ARG1); 596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[2] = (_3DSTATE_MAP_BLEND_ARG_CMD(blendUnit) | 606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXPIPE_COLOR | 616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXBLEND_ARG1 | 626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXBLENDARG_MODIFY_PARMS | TEXBLENDARG_CURRENT); 636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[3] = (_3DSTATE_MAP_BLEND_ARG_CMD(blendUnit) | 646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXPIPE_ALPHA | 656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXBLEND_ARG1 | 666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXBLENDARG_MODIFY_PARMS | TEXBLENDARG_CURRENT); 676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return 4; 696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLuint 726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellemit_factor(GLuint blendUnit, GLuint * state, GLuint count, 736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell const GLfloat * factor) 746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLubyte r, g, b, a; 766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint col; 776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (0) 796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell fprintf(stderr, "emit constant %d: %.2f %.2f %.2f %.2f\n", 806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell blendUnit, factor[0], factor[1], factor[2], factor[3]); 816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell UNCLAMPED_FLOAT_TO_UBYTE(r, factor[0]); 836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell UNCLAMPED_FLOAT_TO_UBYTE(g, factor[1]); 846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell UNCLAMPED_FLOAT_TO_UBYTE(b, factor[2]); 856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell UNCLAMPED_FLOAT_TO_UBYTE(a, factor[3]); 866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell col = ((a << 24) | (r << 16) | (g << 8) | b); 886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[count++] = _3DSTATE_COLOR_FACTOR_N_CMD(blendUnit); 906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[count++] = col; 916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return count; 936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic INLINE GLuint 976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith WhitwellGetTexelOp(GLint unit) 986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (unit) { 1006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case 0: 1016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return TEXBLENDARG_TEXEL0; 1026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case 1: 1036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return TEXBLENDARG_TEXEL1; 1046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case 2: 1056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return TEXBLENDARG_TEXEL2; 1066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case 3: 1076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return TEXBLENDARG_TEXEL3; 1086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 1096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return TEXBLENDARG_TEXEL0; 1106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 1116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 1126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/** 1156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Calculate the hardware instuctions to setup the current texture enviromnemt 1166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * settings. Since \c gl_texture_unit::_CurrentCombine is used, both 1176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * "classic" texture enviroments and GL_ARB_texture_env_combine type texture 1186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * environments are treated identically. 1196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * 1206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * \todo 1212e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke * This function should return \c bool. When \c false is returned, 1226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * it means that an environment is selected that the hardware cannot do. This 1236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * is the way the Radeon and R200 drivers work. 1246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * 1256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * \todo 1266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Looking at i830_3d_regs.h, it seems the i830 can do part of 1276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * GL_ATI_texture_env_combine3. It can handle using \c GL_ONE and 1286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * \c GL_ZERO as combine inputs (which the code already supports). It can 1296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * also handle the \c GL_MODULATE_ADD_ATI mode. Is it worth investigating 1306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * partial support for the extension? 1316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 1326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith WhitwellGLuint 1336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830SetTexEnvCombine(struct i830_context * i830, 1346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell const struct gl_tex_env_combine_state * combine, 1356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLint blendUnit, 1366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint texel_op, GLuint * state, const GLfloat * factor) 1376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 1386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell const GLuint numColorArgs = combine->_NumArgsRGB; 1396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell const GLuint numAlphaArgs = combine->_NumArgsA; 1406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint blendop; 1426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint ablendop; 1436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint args_RGB[3]; 1446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint args_A[3]; 1456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint rgb_shift; 1466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint alpha_shift; 1472e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke bool need_factor = 0; 1486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell int i; 1496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell unsigned used; 1506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell static const GLuint tex_blend_rgb[3] = { 1516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXPIPE_COLOR | TEXBLEND_ARG1 | TEXBLENDARG_MODIFY_PARMS, 1526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXPIPE_COLOR | TEXBLEND_ARG2 | TEXBLENDARG_MODIFY_PARMS, 1536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXPIPE_COLOR | TEXBLEND_ARG0 | TEXBLENDARG_MODIFY_PARMS, 1546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell }; 1556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell static const GLuint tex_blend_a[3] = { 1566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXPIPE_ALPHA | TEXBLEND_ARG1 | TEXBLENDARG_MODIFY_PARMS, 1576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXPIPE_ALPHA | TEXBLEND_ARG2 | TEXBLENDARG_MODIFY_PARMS, 1586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXPIPE_ALPHA | TEXBLEND_ARG0 | TEXBLENDARG_MODIFY_PARMS, 1596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell }; 1606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (INTEL_DEBUG & DEBUG_TEXTURE) 1626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell fprintf(stderr, "%s\n", __FUNCTION__); 1636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* The EXT version of the DOT3 extension does not support the 1666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * scale factor, but the ARB version (and the version in OpenGL 1676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * 1.3) does. 1686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 1696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (combine->ModeRGB) { 1706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_DOT3_RGB_EXT: 1716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell alpha_shift = combine->ScaleShiftA; 1726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell rgb_shift = 0; 1736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_DOT3_RGBA_EXT: 1766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell alpha_shift = 0; 1776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell rgb_shift = 0; 1786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 1816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell rgb_shift = combine->ScaleShiftRGB; 1826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell alpha_shift = combine->ScaleShiftA; 1836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 1856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (combine->ModeRGB) { 1886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_REPLACE: 1896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell blendop = TEXBLENDOP_ARG1; 1906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_MODULATE: 1926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell blendop = TEXBLENDOP_MODULATE; 1936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_ADD: 1956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell blendop = TEXBLENDOP_ADD; 1966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 1976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_ADD_SIGNED: 1986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell blendop = TEXBLENDOP_ADDSIGNED; 1996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_INTERPOLATE: 2016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell blendop = TEXBLENDOP_BLEND; 2026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_SUBTRACT: 2046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell blendop = TEXBLENDOP_SUBTRACT; 2056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_DOT3_RGB_EXT: 2076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_DOT3_RGB: 2086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell blendop = TEXBLENDOP_DOT3; 2096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_DOT3_RGBA_EXT: 2116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_DOT3_RGBA: 2126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell blendop = TEXBLENDOP_DOT3; 2136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 2156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return pass_through(state, blendUnit); 2166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 2176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell blendop |= (rgb_shift << TEXOP_SCALE_SHIFT); 2196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Handle RGB args */ 2226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell for (i = 0; i < 3; i++) { 2236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (combine->SourceRGB[i]) { 2246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_TEXTURE: 2256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_RGB[i] = texel_op; 2266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_TEXTURE0: 2286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_TEXTURE1: 2296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_TEXTURE2: 2306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_TEXTURE3: 2316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_RGB[i] = GetTexelOp(combine->SourceRGB[i] - GL_TEXTURE0); 2326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_CONSTANT: 2346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_RGB[i] = TEXBLENDARG_FACTOR_N; 2356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell need_factor = 1; 2366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_PRIMARY_COLOR: 2386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_RGB[i] = TEXBLENDARG_DIFFUSE; 2396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_PREVIOUS: 2416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_RGB[i] = TEXBLENDARG_CURRENT; 2426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 2446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return pass_through(state, blendUnit); 2456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 2466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (combine->OperandRGB[i]) { 2486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_SRC_COLOR: 2496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_RGB[i] |= 0; 2506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_ONE_MINUS_SRC_COLOR: 2526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_RGB[i] |= TEXBLENDARG_INV_ARG; 2536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_SRC_ALPHA: 2556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_RGB[i] |= TEXBLENDARG_REPLICATE_ALPHA; 2566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_ONE_MINUS_SRC_ALPHA: 2586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_RGB[i] |= (TEXBLENDARG_REPLICATE_ALPHA | TEXBLENDARG_INV_ARG); 2596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 2616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return pass_through(state, blendUnit); 2626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 2636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 2646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Need to knobble the alpha calculations of TEXBLENDOP_DOT4 to 2676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * match the spec. Can't use DOT3 as it won't propogate values 2686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * into alpha as required: 2696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * 2706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Note - the global factor is set up with alpha == .5, so 2716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * the alpha part of the DOT4 calculation should be zero. 2726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 2736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (combine->ModeRGB == GL_DOT3_RGBA_EXT || 2746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell combine->ModeRGB == GL_DOT3_RGBA) { 2756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ablendop = TEXBLENDOP_DOT4; 2766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_A[0] = TEXBLENDARG_FACTOR; /* the global factor */ 2776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_A[1] = TEXBLENDARG_FACTOR; 2786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_A[2] = TEXBLENDARG_FACTOR; 2796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 2806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell else { 2816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (combine->ModeA) { 2826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_REPLACE: 2836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ablendop = TEXBLENDOP_ARG1; 2846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_MODULATE: 2866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ablendop = TEXBLENDOP_MODULATE; 2876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_ADD: 2896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ablendop = TEXBLENDOP_ADD; 2906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_ADD_SIGNED: 2926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ablendop = TEXBLENDOP_ADDSIGNED; 2936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_INTERPOLATE: 2956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ablendop = TEXBLENDOP_BLEND; 2966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_SUBTRACT: 2986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ablendop = TEXBLENDOP_SUBTRACT; 2996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 3006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 3016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return pass_through(state, blendUnit); 3026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 3036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ablendop |= (alpha_shift << TEXOP_SCALE_SHIFT); 3066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Handle A args */ 3086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell for (i = 0; i < 3; i++) { 3096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (combine->SourceA[i]) { 3106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_TEXTURE: 3116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_A[i] = texel_op; 3126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 3136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_TEXTURE0: 3146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_TEXTURE1: 3156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_TEXTURE2: 3166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_TEXTURE3: 3176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_A[i] = GetTexelOp(combine->SourceA[i] - GL_TEXTURE0); 3186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 3196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_CONSTANT: 3206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_A[i] = TEXBLENDARG_FACTOR_N; 3216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell need_factor = 1; 3226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 3236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_PRIMARY_COLOR: 3246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_A[i] = TEXBLENDARG_DIFFUSE; 3256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 3266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_PREVIOUS: 3276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_A[i] = TEXBLENDARG_CURRENT; 3286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 3296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 3306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return pass_through(state, blendUnit); 3316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 3326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (combine->OperandA[i]) { 3346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_SRC_ALPHA: 3356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_A[i] |= 0; 3366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 3376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_ONE_MINUS_SRC_ALPHA: 3386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell args_A[i] |= TEXBLENDARG_INV_ARG; 3396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 3406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 3416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return pass_through(state, blendUnit); 3426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 3436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 3446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 3456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Native Arg1 == Arg0 in GL_EXT_texture_env_combine spec */ 3496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Native Arg2 == Arg1 in GL_EXT_texture_env_combine spec */ 3506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Native Arg0 == Arg2 in GL_EXT_texture_env_combine spec */ 3516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* When we render we need to figure out which is the last really enabled 3536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * tex unit, and put last stage on it 3546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 3556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Build color & alpha pipelines */ 3586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell used = 0; 3606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[used++] = (_3DSTATE_MAP_BLEND_OP_CMD(blendUnit) | 3616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXPIPE_COLOR | 3626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ENABLE_TEXOUTPUT_WRT_SEL | 3636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXOP_OUTPUT_CURRENT | 3646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell DISABLE_TEX_CNTRL_STAGE | TEXOP_MODIFY_PARMS | blendop); 3656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[used++] = (_3DSTATE_MAP_BLEND_OP_CMD(blendUnit) | 3666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXPIPE_ALPHA | 3676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ENABLE_TEXOUTPUT_WRT_SEL | 3686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXOP_OUTPUT_CURRENT | TEXOP_MODIFY_PARMS | ablendop); 3696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell for (i = 0; i < numColorArgs; i++) { 3716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[used++] = (_3DSTATE_MAP_BLEND_ARG_CMD(blendUnit) | 3726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell tex_blend_rgb[i] | args_RGB[i]); 3736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 3746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell for (i = 0; i < numAlphaArgs; i++) { 3766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[used++] = (_3DSTATE_MAP_BLEND_ARG_CMD(blendUnit) | 3776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell tex_blend_a[i] | args_A[i]); 3786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 3796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (need_factor) 3826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return emit_factor(blendUnit, state, used, factor); 3836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell else 3846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return used; 3856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 3866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void 3896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellemit_texblend(struct i830_context *i830, GLuint unit, GLuint blendUnit, 3902e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke bool last_stage) 3916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 3926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct gl_texture_unit *texUnit = &i830->intel.ctx.Texture.Unit[unit]; 3936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint tmp[I830_TEXBLEND_SIZE], tmp_sz; 3946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (0) 3976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell fprintf(stderr, "%s unit %d\n", __FUNCTION__, unit); 3986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Update i830->state.TexBlend 4006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 4016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell tmp_sz = i830SetTexEnvCombine(i830, texUnit->_CurrentCombine, blendUnit, 4026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GetTexelOp(unit), tmp, texUnit->EnvColor); 4036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (last_stage) 4056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell tmp[0] |= TEXOP_LAST_STAGE; 4066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (tmp_sz != i830->state.TexBlendWordsUsed[blendUnit] || 4086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell memcmp(tmp, i830->state.TexBlend[blendUnit], 4096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell tmp_sz * sizeof(GLuint))) { 4106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell I830_STATECHANGE(i830, I830_UPLOAD_TEXBLEND(blendUnit)); 4126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell memcpy(i830->state.TexBlend[blendUnit], tmp, tmp_sz * sizeof(GLuint)); 4136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830->state.TexBlendWordsUsed[blendUnit] = tmp_sz; 4146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 4156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4162e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke I830_ACTIVESTATE(i830, I830_UPLOAD_TEXBLEND(blendUnit), true); 4176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 4186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void 4206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellemit_passthrough(struct i830_context *i830) 4216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 4226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint tmp[I830_TEXBLEND_SIZE], tmp_sz; 4236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint unit = 0; 4246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell tmp_sz = pass_through(tmp, unit); 4266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell tmp[0] |= TEXOP_LAST_STAGE; 4276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (tmp_sz != i830->state.TexBlendWordsUsed[unit] || 4296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell memcmp(tmp, i830->state.TexBlend[unit], tmp_sz * sizeof(GLuint))) { 4306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell I830_STATECHANGE(i830, I830_UPLOAD_TEXBLEND(unit)); 4326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell memcpy(i830->state.TexBlend[unit], tmp, tmp_sz * sizeof(GLuint)); 4336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830->state.TexBlendWordsUsed[unit] = tmp_sz; 4346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 4356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4362e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke I830_ACTIVESTATE(i830, I830_UPLOAD_TEXBLEND(unit), true); 4376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 4386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid 4406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830EmitTextureBlend(struct i830_context *i830) 4416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 442f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = &i830->intel.ctx; 4436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint unit, last_stage = 0, blendunit = 0; 4446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4452e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke I830_ACTIVESTATE(i830, I830_UPLOAD_TEXBLEND_ALL, false); 4466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (ctx->Texture._EnabledUnits) { 4486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) 4496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (ctx->Texture.Unit[unit]._ReallyEnabled) 4506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell last_stage = unit; 4516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 4526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) 4536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (ctx->Texture.Unit[unit]._ReallyEnabled) 4546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell emit_texblend(i830, unit, blendunit++, last_stage == unit); 4556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 4566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell else { 4576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell emit_passthrough(i830); 4586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 4596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 460