i915_texstate.c revision ae69a046505d8c94cd3a59a9376310a904c35b3c
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) |
188e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer       ((firstImage->Width - 1) << MS3_WIDTH_SHIFT) | format |
1896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       MS3_USE_FENCE_REGS);
1906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   state[I915_TEXREG_MS4] =
192e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer     ((((pitch / 4) - 1) << MS4_PITCH_SHIFT) | MS4_CUBE_FACE_ENA_MASK |
193e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer       ((((intelObj->lastLevel - intelObj->firstLevel) * 4)) <<
194e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer	MS4_MAX_LOD_SHIFT) | ((firstImage->Depth - 1) <<
195e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer			      MS4_VOLUME_DEPTH_SHIFT));
1966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   {
1996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      GLuint minFilt, mipFilt, magFilt;
2006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      switch (tObj->MinFilter) {
2026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_NEAREST:
2036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_NEAREST;
2046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NONE;
2056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_LINEAR:
2076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_LINEAR;
2086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NONE;
2096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_NEAREST_MIPMAP_NEAREST:
2116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_NEAREST;
2126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NEAREST;
2136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_LINEAR_MIPMAP_NEAREST:
2156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_LINEAR;
2166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NEAREST;
2176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_NEAREST_MIPMAP_LINEAR:
2196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_NEAREST;
2206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_LINEAR;
2216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_LINEAR_MIPMAP_LINEAR:
2236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_LINEAR;
2246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_LINEAR;
2256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      default:
2276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         return GL_FALSE;
2286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (tObj->MaxAnisotropy > 1.0) {
2316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_ANISOTROPIC;
2326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         magFilt = FILTER_ANISOTROPIC;
233ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger         if (tObj->MaxAnisotropy > 2.0)
234ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger            aniso = SS2_MAX_ANISO_4;
235ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger         else
236ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger            aniso = SS2_MAX_ANISO_2;
2376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      else {
2396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         switch (tObj->MagFilter) {
2406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         case GL_NEAREST:
2416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            magFilt = FILTER_NEAREST;
2426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            break;
2436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         case GL_LINEAR:
2446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            magFilt = FILTER_LINEAR;
2456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            break;
2466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         default:
2476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            return GL_FALSE;
2486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         }
2496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
251d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao      lodbias = (int) ((tUnit->LodBias + tObj->LodBias) * 16.0);
252d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao      if (lodbias < -256)
253d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao          lodbias = -256;
254d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao      if (lodbias > 255)
255d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao          lodbias = 255;
256d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao      state[I915_TEXREG_SS2] = ((lodbias << SS2_LOD_BIAS_SHIFT) &
257d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao                                SS2_LOD_BIAS_MASK);
2586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* YUV conversion:
2606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
2616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (firstImage->TexFormat->MesaFormat == MESA_FORMAT_YCBCR ||
2626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          firstImage->TexFormat->MesaFormat == MESA_FORMAT_YCBCR_REV)
2636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         state[I915_TEXREG_SS2] |= SS2_COLORSPACE_CONVERSION;
2646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* Shadow:
2666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
2676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (tObj->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB &&
2686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          tObj->Target != GL_TEXTURE_3D) {
26975e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao         if (tObj->Target == GL_TEXTURE_1D)
27075e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao            return GL_FALSE;
2716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         state[I915_TEXREG_SS2] |=
2736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            (SS2_SHADOW_ENABLE |
274b422e5ad3716d32f2434ca38819f4a877c7eeeebXiang, Haihao             intel_translate_shadow_compare_func(tObj->CompareFunc));
2756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
27675e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao         minFilt = FILTER_4X4_FLAT;
27775e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao         magFilt = FILTER_4X4_FLAT;
2786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS2] |= ((minFilt << SS2_MIN_FILTER_SHIFT) |
2816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 (mipFilt << SS2_MIP_FILTER_SHIFT) |
282ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger                                 (magFilt << SS2_MAG_FILTER_SHIFT) |
283ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger                                 aniso);
2846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
2856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   {
2876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      GLenum ws = tObj->WrapS;
2886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      GLenum wt = tObj->WrapT;
2896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      GLenum wr = tObj->WrapR;
2906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* 3D textures don't seem to respect the border color.
2936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * Fallback if there's ever a danger that they might refer to
2946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * it.
2956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       *
2966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * Effectively this means fallback on 3D clamp or
2976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * clamp_to_border.
2986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
2996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (tObj->Target == GL_TEXTURE_3D &&
3006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          (tObj->MinFilter != GL_NEAREST ||
3016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           tObj->MagFilter != GL_NEAREST) &&
3026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          (ws == GL_CLAMP ||
3036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           wt == GL_CLAMP ||
3046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           wr == GL_CLAMP ||
3056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           ws == GL_CLAMP_TO_BORDER ||
3066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           wt == GL_CLAMP_TO_BORDER || wr == GL_CLAMP_TO_BORDER))
3076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         return GL_FALSE;
3086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
309c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao      /* Only support TEXCOORDMODE_CLAMP_EDGE and TEXCOORDMODE_CUBE (not
310c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao       * used) when using cube map texture coordinates
311c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao       */
312c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao      if (tObj->Target == GL_TEXTURE_CUBE_MAP_ARB &&
313c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao          (((ws != GL_CLAMP) && (ws != GL_CLAMP_TO_EDGE)) ||
314cb453244caa15342bf229ee5ae16a78d038b8bdcXiang, Haihao           ((wt != GL_CLAMP) && (wt != GL_CLAMP_TO_EDGE))))
315c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao          return GL_FALSE;
3166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS3] = ss3;     /* SS3_NORMALIZED_COORDS */
3186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS3] |=
3206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         ((translate_wrap_mode(ws) << SS3_TCX_ADDR_MODE_SHIFT) |
3216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          (translate_wrap_mode(wt) << SS3_TCY_ADDR_MODE_SHIFT) |
3226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          (translate_wrap_mode(wr) << SS3_TCZ_ADDR_MODE_SHIFT));
3236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS3] |= (unit << SS3_TEXTUREMAP_INDEX_SHIFT);
3256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
3266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
32779c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul   /* convert border color from float to ubyte */
32879c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul   CLAMPED_FLOAT_TO_UBYTE(border[0], tObj->BorderColor[0]);
32979c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul   CLAMPED_FLOAT_TO_UBYTE(border[1], tObj->BorderColor[1]);
33079c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul   CLAMPED_FLOAT_TO_UBYTE(border[2], tObj->BorderColor[2]);
33179c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul   CLAMPED_FLOAT_TO_UBYTE(border[3], tObj->BorderColor[3]);
3326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3339aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt   if (firstImage->_BaseFormat == GL_DEPTH_COMPONENT) {
3349aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt      /* GL specs that border color for depth textures is taken from the
3359aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt       * R channel, while the hardware uses A.  Spam R into all the channels
3369aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt       * for safety.
3379aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt       */
33879c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul      state[I915_TEXREG_SS4] = INTEL_PACKCOLOR8888(border[0],
33979c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul						   border[0],
34079c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul						   border[0],
34179c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul						   border[0]);
3429aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt   } else {
34379c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul      state[I915_TEXREG_SS4] = INTEL_PACKCOLOR8888(border[0],
34479c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul						   border[1],
34579c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul						   border[2],
34679c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul						   border[3]);
3479aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt   }
3486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I915_ACTIVESTATE(i915, I915_UPLOAD_TEX(unit), GL_TRUE);
3516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* memcmp was already disabled, but definitely won't work as the
3526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * region might now change and that wouldn't be detected:
3536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
3546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I915_STATECHANGE(i915, I915_UPLOAD_TEX(unit));
3556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#if 0
3586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_SS2] = 0x%x\n", state[I915_TEXREG_SS2]);
3596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_SS3] = 0x%x\n", state[I915_TEXREG_SS3]);
3606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_SS4] = 0x%x\n", state[I915_TEXREG_SS4]);
3616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_MS2] = 0x%x\n", state[I915_TEXREG_MS2]);
3626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_MS3] = 0x%x\n", state[I915_TEXREG_MS3]);
3636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_MS4] = 0x%x\n", state[I915_TEXREG_MS4]);
3646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#endif
3656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   return GL_TRUE;
3676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
3686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid
3736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli915UpdateTextureState(struct intel_context *intel)
3746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
3756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLboolean ok = GL_TRUE;
3766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint i;
3776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   for (i = 0; i < I915_TEX_UNITS && ok; i++) {
3796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      switch (intel->ctx.Texture.Unit[i]._ReallyEnabled) {
3806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_1D_BIT:
3816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_2D_BIT:
3826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_CUBE_BIT:
3836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_3D_BIT:
3846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         ok = i915_update_tex_unit(intel, i, SS3_NORMALIZED_COORDS);
3856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
3866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_RECT_BIT:
3876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         ok = i915_update_tex_unit(intel, i, 0);
3886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
3896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case 0:{
3906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            struct i915_context *i915 = i915_context(&intel->ctx);
3916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            if (i915->state.active & I915_UPLOAD_TEX(i))
3926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               I915_ACTIVESTATE(i915, I915_UPLOAD_TEX(i), GL_FALSE);
3936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	    if (i915->state.tex_buffer[i] != NULL) {
395cfc21190af1038f204d38ab4764a9c731b0323a5Eric Anholt	       dri_bo_unreference(i915->state.tex_buffer[i]);
3966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	       i915->state.tex_buffer[i] = NULL;
3976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	    }
3986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            break;
4006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         }
4016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      default:
4026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         ok = GL_FALSE;
4036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
4046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
4056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
4066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   FALLBACK(intel, I915_FALLBACK_TEXTURE, !ok);
4086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
409