i915_texstate.c revision 165ae5e2fb57bdb64b4cf01271b4effeb811f675
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/mtypes.h"
29ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/enums.h"
30ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/texformat.h"
316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_mipmap_tree.h"
336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_tex.h"
346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "i915_context.h"
366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "i915_reg.h"
376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLuint
4066175aac7609ad314f25fbdff0d3958af310dc24Eric Anholttranslate_texture_format(GLuint mesa_format, GLuint internal_format,
4166175aac7609ad314f25fbdff0d3958af310dc24Eric Anholt			 GLenum DepthMode)
426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   switch (mesa_format) {
446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_L8:
456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_8BIT | MT_8BIT_L8;
466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_I8:
476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_8BIT | MT_8BIT_I8;
486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_A8:
496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_8BIT | MT_8BIT_A8;
506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_AL88:
516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_16BIT | MT_16BIT_AY88;
526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGB565:
536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_16BIT | MT_16BIT_RGB565;
546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_ARGB1555:
556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_16BIT | MT_16BIT_ARGB1555;
566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_ARGB4444:
576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_16BIT | MT_16BIT_ARGB4444;
586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_ARGB8888:
5966175aac7609ad314f25fbdff0d3958af310dc24Eric Anholt      if (internal_format == GL_RGB)
6066175aac7609ad314f25fbdff0d3958af310dc24Eric Anholt	 return MAPSURF_32BIT | MT_32BIT_XRGB8888;
6166175aac7609ad314f25fbdff0d3958af310dc24Eric Anholt      else
6266175aac7609ad314f25fbdff0d3958af310dc24Eric Anholt	 return MAPSURF_32BIT | MT_32BIT_ARGB8888;
636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_YCBCR_REV:
646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_422 | MT_422_YCRCB_NORMAL);
656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_YCBCR:
666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_422 | MT_422_YCRCB_SWAPY);
676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGB_FXT1:
686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGBA_FXT1:
696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_COMPRESSED | MT_COMPRESS_FXT1);
706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_Z16:
719e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao      if (DepthMode == GL_ALPHA)
729e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao          return (MAPSURF_16BIT | MT_16BIT_A16);
739e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao      else if (DepthMode == GL_INTENSITY)
749e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao          return (MAPSURF_16BIT | MT_16BIT_I16);
759e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao      else
769e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao          return (MAPSURF_16BIT | MT_16BIT_L16);
776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGBA_DXT1:
786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGB_DXT1:
796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT1);
806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGBA_DXT3:
816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT2_3);
826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGBA_DXT5:
836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT4_5);
840adfd1021035e90995a25ec5f20b736e55075d92Xiang, Haihao   case MESA_FORMAT_S8_Z24:
85f94d317d7aea8043b179a0ba64308606375500d7Xiang, Haihao      return (MAPSURF_32BIT | MT_32BIT_xI824);
866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   default:
876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      fprintf(stderr, "%s: bad image format %x\n", __FUNCTION__, mesa_format);
886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      abort();
896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return 0;
906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* The i915 (and related graphics cores) do not support GL_CLAMP.  The
976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Intel drivers for "other operating systems" implement GL_CLAMP as
986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * GL_CLAMP_TO_EDGE, so the same is done here.
996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
1006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLuint
1016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelltranslate_wrap_mode(GLenum wrap)
1026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
1036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   switch (wrap) {
1046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_REPEAT:
1056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_WRAP;
1066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_CLAMP:
1076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_CLAMP_EDGE;   /* not quite correct */
1086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_CLAMP_TO_EDGE:
1096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_CLAMP_EDGE;
1106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_CLAMP_TO_BORDER:
1116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_CLAMP_BORDER;
1126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_MIRRORED_REPEAT:
1136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_MIRROR;
1146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   default:
1156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_WRAP;
1166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
1176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
1186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Recalculate all state from scratch.  Perhaps not the most
1226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * efficient, but this has gotten complex enough that we need
1236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * something which is understandable and reliable.
1246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
1256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLboolean
1266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3)
1276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
1286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLcontext *ctx = &intel->ctx;
1296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i915_context *i915 = i915_context(ctx);
130d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao   struct gl_texture_unit *tUnit = &ctx->Texture.Unit[unit];
131d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao   struct gl_texture_object *tObj = tUnit->_Current;
1326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct intel_texture_object *intelObj = intel_texture_object(tObj);
1336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct gl_texture_image *firstImage;
134e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer   GLuint *state = i915->state.Tex[unit], format, pitch;
135ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger   GLint lodbias, aniso = 0;
13679c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul   GLubyte border[4];
1376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   memset(state, 0, sizeof(state));
1396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /*We need to refcount these. */
1416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (i915->state.tex_buffer[unit] != NULL) {
143cfc21190af1038f204d38ab4764a9c731b0323a5Eric Anholt       dri_bo_unreference(i915->state.tex_buffer[unit]);
1446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       i915->state.tex_buffer[unit] = NULL;
1456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
1466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
147e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer   if (!intelObj->imageOverride && !intel_finalize_mipmap_tree(intel, unit))
1486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return GL_FALSE;
1496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* Get first image here, since intelObj->firstLevel will get set in
1516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * the intel_finalize_mipmap_tree() call above.
1526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
1536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   firstImage = tObj->Image[0][intelObj->firstLevel];
1546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
155e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer   if (intelObj->imageOverride) {
156e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer      i915->state.tex_buffer[unit] = NULL;
157e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer      i915->state.tex_offset[unit] = intelObj->textureOffset;
158e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer
159e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer      switch (intelObj->depthOverride) {
160e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer      case 32:
161e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer	 format = MAPSURF_32BIT | MT_32BIT_ARGB8888;
162e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer	 break;
163e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer      case 24:
164e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer      default:
165e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer	 format = MAPSURF_32BIT | MT_32BIT_XRGB8888;
166e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer	 break;
167e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer      case 16:
168e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer	 format = MAPSURF_16BIT | MT_16BIT_RGB565;
169e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer	 break;
170e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer      }
171e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer
172e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer      pitch = intelObj->pitchOverride;
173e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer   } else {
174fd9d27e0686f5a15803d13d207e58be1972fdf31Eric Anholt      dri_bo_reference(intelObj->mt->region->buffer);
175fd9d27e0686f5a15803d13d207e58be1972fdf31Eric Anholt      i915->state.tex_buffer[unit] = intelObj->mt->region->buffer;
176e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer      i915->state.tex_offset[unit] =  intel_miptree_image_offset(intelObj->mt,
177e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer								 0, intelObj->
178e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer								 firstLevel);
179e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer
1807233eabaf0072b7c50e4f26ec33738b5b89aad20Zou Nan hai      format = translate_texture_format(firstImage->TexFormat->MesaFormat,
18166175aac7609ad314f25fbdff0d3958af310dc24Eric Anholt					firstImage->InternalFormat,
18266175aac7609ad314f25fbdff0d3958af310dc24Eric Anholt					tObj->DepthMode);
183e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer      pitch = intelObj->mt->pitch * intelObj->mt->cpp;
184e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer   }
1856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   state[I915_TEXREG_MS3] =
1876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      (((firstImage->Height - 1) << MS3_HEIGHT_SHIFT) |
188165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt       ((firstImage->Width - 1) << MS3_WIDTH_SHIFT) | format);
189165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt
190165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt   if (intelObj->mt->region->tiling != I915_TILING_NONE) {
191165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt      state[I915_TEXREG_MS3] |= MS3_TILED_SURFACE;
192165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt      if (intelObj->mt->region->tiling == I915_TILING_Y)
193165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt	 state[I915_TEXREG_MS3] |= MS3_TILE_WALK;
194165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt   }
1956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   state[I915_TEXREG_MS4] =
197e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer     ((((pitch / 4) - 1) << MS4_PITCH_SHIFT) | MS4_CUBE_FACE_ENA_MASK |
198e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer       ((((intelObj->lastLevel - intelObj->firstLevel) * 4)) <<
199e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer	MS4_MAX_LOD_SHIFT) | ((firstImage->Depth - 1) <<
200e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer			      MS4_VOLUME_DEPTH_SHIFT));
2016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   {
2046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      GLuint minFilt, mipFilt, magFilt;
2056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      switch (tObj->MinFilter) {
2076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_NEAREST:
2086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_NEAREST;
2096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NONE;
2106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_LINEAR:
2126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_LINEAR;
2136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NONE;
2146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_NEAREST_MIPMAP_NEAREST:
2166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_NEAREST;
2176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NEAREST;
2186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_LINEAR_MIPMAP_NEAREST:
2206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_LINEAR;
2216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NEAREST;
2226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_NEAREST_MIPMAP_LINEAR:
2246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_NEAREST;
2256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_LINEAR;
2266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_LINEAR_MIPMAP_LINEAR:
2286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_LINEAR;
2296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_LINEAR;
2306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      default:
2326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         return GL_FALSE;
2336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (tObj->MaxAnisotropy > 1.0) {
2366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_ANISOTROPIC;
2376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         magFilt = FILTER_ANISOTROPIC;
238ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger         if (tObj->MaxAnisotropy > 2.0)
239ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger            aniso = SS2_MAX_ANISO_4;
240ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger         else
241ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger            aniso = SS2_MAX_ANISO_2;
2426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      else {
2446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         switch (tObj->MagFilter) {
2456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         case GL_NEAREST:
2466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            magFilt = FILTER_NEAREST;
2476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            break;
2486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         case GL_LINEAR:
2496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            magFilt = FILTER_LINEAR;
2506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            break;
2516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         default:
2526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            return GL_FALSE;
2536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         }
2546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
256d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao      lodbias = (int) ((tUnit->LodBias + tObj->LodBias) * 16.0);
257d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao      if (lodbias < -256)
258d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao          lodbias = -256;
259d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao      if (lodbias > 255)
260d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao          lodbias = 255;
261d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao      state[I915_TEXREG_SS2] = ((lodbias << SS2_LOD_BIAS_SHIFT) &
262d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao                                SS2_LOD_BIAS_MASK);
2636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* YUV conversion:
2656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
2666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (firstImage->TexFormat->MesaFormat == MESA_FORMAT_YCBCR ||
2676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          firstImage->TexFormat->MesaFormat == MESA_FORMAT_YCBCR_REV)
2686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         state[I915_TEXREG_SS2] |= SS2_COLORSPACE_CONVERSION;
2696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* Shadow:
2716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
2726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (tObj->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB &&
2736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          tObj->Target != GL_TEXTURE_3D) {
27475e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao         if (tObj->Target == GL_TEXTURE_1D)
27575e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao            return GL_FALSE;
2766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         state[I915_TEXREG_SS2] |=
2786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            (SS2_SHADOW_ENABLE |
279b422e5ad3716d32f2434ca38819f4a877c7eeeebXiang, Haihao             intel_translate_shadow_compare_func(tObj->CompareFunc));
2806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
28175e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao         minFilt = FILTER_4X4_FLAT;
28275e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao         magFilt = FILTER_4X4_FLAT;
2836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS2] |= ((minFilt << SS2_MIN_FILTER_SHIFT) |
2866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 (mipFilt << SS2_MIP_FILTER_SHIFT) |
287ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger                                 (magFilt << SS2_MAG_FILTER_SHIFT) |
288ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger                                 aniso);
2896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
2906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   {
2926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      GLenum ws = tObj->WrapS;
2936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      GLenum wt = tObj->WrapT;
2946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      GLenum wr = tObj->WrapR;
2956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* 3D textures don't seem to respect the border color.
2986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * Fallback if there's ever a danger that they might refer to
2996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * it.
3006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       *
3016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * Effectively this means fallback on 3D clamp or
3026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * clamp_to_border.
3036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
3046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (tObj->Target == GL_TEXTURE_3D &&
3056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          (tObj->MinFilter != GL_NEAREST ||
3066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           tObj->MagFilter != GL_NEAREST) &&
3076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          (ws == GL_CLAMP ||
3086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           wt == GL_CLAMP ||
3096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           wr == GL_CLAMP ||
3106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           ws == GL_CLAMP_TO_BORDER ||
3116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           wt == GL_CLAMP_TO_BORDER || wr == GL_CLAMP_TO_BORDER))
3126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         return GL_FALSE;
3136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
314c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao      /* Only support TEXCOORDMODE_CLAMP_EDGE and TEXCOORDMODE_CUBE (not
315c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao       * used) when using cube map texture coordinates
316c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao       */
317c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao      if (tObj->Target == GL_TEXTURE_CUBE_MAP_ARB &&
318c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao          (((ws != GL_CLAMP) && (ws != GL_CLAMP_TO_EDGE)) ||
319cb453244caa15342bf229ee5ae16a78d038b8bdcXiang, Haihao           ((wt != GL_CLAMP) && (wt != GL_CLAMP_TO_EDGE))))
320c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao          return GL_FALSE;
3216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS3] = ss3;     /* SS3_NORMALIZED_COORDS */
3236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS3] |=
3256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         ((translate_wrap_mode(ws) << SS3_TCX_ADDR_MODE_SHIFT) |
3266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          (translate_wrap_mode(wt) << SS3_TCY_ADDR_MODE_SHIFT) |
3276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          (translate_wrap_mode(wr) << SS3_TCZ_ADDR_MODE_SHIFT));
3286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS3] |= (unit << SS3_TEXTUREMAP_INDEX_SHIFT);
3306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
3316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
33279c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul   /* convert border color from float to ubyte */
33379c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul   CLAMPED_FLOAT_TO_UBYTE(border[0], tObj->BorderColor[0]);
33479c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul   CLAMPED_FLOAT_TO_UBYTE(border[1], tObj->BorderColor[1]);
33579c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul   CLAMPED_FLOAT_TO_UBYTE(border[2], tObj->BorderColor[2]);
33679c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul   CLAMPED_FLOAT_TO_UBYTE(border[3], tObj->BorderColor[3]);
3376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3389aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt   if (firstImage->_BaseFormat == GL_DEPTH_COMPONENT) {
3399aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt      /* GL specs that border color for depth textures is taken from the
3409aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt       * R channel, while the hardware uses A.  Spam R into all the channels
3419aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt       * for safety.
3429aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt       */
34379c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul      state[I915_TEXREG_SS4] = INTEL_PACKCOLOR8888(border[0],
34479c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul						   border[0],
34579c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul						   border[0],
34679c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul						   border[0]);
3479aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt   } else {
34879c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul      state[I915_TEXREG_SS4] = INTEL_PACKCOLOR8888(border[0],
34979c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul						   border[1],
35079c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul						   border[2],
35179c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul						   border[3]);
3529aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt   }
3536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I915_ACTIVESTATE(i915, I915_UPLOAD_TEX(unit), GL_TRUE);
3566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* memcmp was already disabled, but definitely won't work as the
3576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * region might now change and that wouldn't be detected:
3586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
3596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I915_STATECHANGE(i915, I915_UPLOAD_TEX(unit));
3606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#if 0
3636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_SS2] = 0x%x\n", state[I915_TEXREG_SS2]);
3646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_SS3] = 0x%x\n", state[I915_TEXREG_SS3]);
3656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_SS4] = 0x%x\n", state[I915_TEXREG_SS4]);
3666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_MS2] = 0x%x\n", state[I915_TEXREG_MS2]);
3676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_MS3] = 0x%x\n", state[I915_TEXREG_MS3]);
3686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_MS4] = 0x%x\n", state[I915_TEXREG_MS4]);
3696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#endif
3706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   return GL_TRUE;
3726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
3736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid
3786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli915UpdateTextureState(struct intel_context *intel)
3796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
3806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLboolean ok = GL_TRUE;
3816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint i;
3826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   for (i = 0; i < I915_TEX_UNITS && ok; i++) {
3846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      switch (intel->ctx.Texture.Unit[i]._ReallyEnabled) {
3856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_1D_BIT:
3866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_2D_BIT:
3876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_CUBE_BIT:
3886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_3D_BIT:
3896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         ok = i915_update_tex_unit(intel, i, SS3_NORMALIZED_COORDS);
3906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
3916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_RECT_BIT:
3926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         ok = i915_update_tex_unit(intel, i, 0);
3936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
3946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case 0:{
3956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            struct i915_context *i915 = i915_context(&intel->ctx);
3966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            if (i915->state.active & I915_UPLOAD_TEX(i))
3976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               I915_ACTIVESTATE(i915, I915_UPLOAD_TEX(i), GL_FALSE);
3986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	    if (i915->state.tex_buffer[i] != NULL) {
400cfc21190af1038f204d38ab4764a9c731b0323a5Eric Anholt	       dri_bo_unreference(i915->state.tex_buffer[i]);
4016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	       i915->state.tex_buffer[i] = NULL;
4026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	    }
4036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            break;
4056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         }
4066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      default:
4076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         ok = GL_FALSE;
4086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
4096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
4106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
4116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   FALLBACK(intel, I915_FALLBACK_TEXTURE, !ok);
4136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
414