Merge branch 'llvm-cliptest-viewport'
[mesa.git] / src / mesa / drivers / dri / intel / intel_tex_format.c
index a7c6c45ffe41da25a3a25b8ee324a719de0352df..9d73a2fb3757535e0e98d780fe427ddd9b9615eb 100644 (file)
@@ -1,8 +1,7 @@
 #include "intel_context.h"
 #include "intel_tex.h"
-#include "intel_chipset.h"
 #include "main/enums.h"
-
+#include "main/formats.h"
 
 /**
  * Choose hardware texture format given the user's glTexImage parameters.
  * immediately after sampling...
  */
 gl_format
-intelChooseTextureFormat(GLcontext * ctx, GLint internalFormat,
+intelChooseTextureFormat(struct gl_context * ctx, GLint internalFormat,
                          GLenum format, GLenum type)
 {
    struct intel_context *intel = intel_context(ctx);
-   const GLboolean do32bpt = (intel->ctx.Visual.rgbBits >= 24);
 
 #if 0
    printf("%s intFmt=0x%x format=0x%x type=0x%x\n",
@@ -31,32 +29,28 @@ intelChooseTextureFormat(GLcontext * ctx, GLint internalFormat,
    case 4:
    case GL_RGBA:
    case GL_COMPRESSED_RGBA:
-      if (format == GL_BGRA) {
-         if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) {
-            return MESA_FORMAT_ARGB8888;
-         }
-         else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
-            return MESA_FORMAT_ARGB4444;
-         }
-         else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
-            return MESA_FORMAT_ARGB1555;
-         }
-      }
-      return do32bpt ? MESA_FORMAT_ARGB8888 : MESA_FORMAT_ARGB4444;
+      if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV)
+        return MESA_FORMAT_ARGB4444;
+      else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV)
+        return MESA_FORMAT_ARGB1555;
+      else
+        return MESA_FORMAT_ARGB8888;
 
    case 3:
    case GL_RGB:
    case GL_COMPRESSED_RGB:
-      if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
-         return MESA_FORMAT_RGB565;
-      }
-      return do32bpt ? MESA_FORMAT_XRGB8888 : MESA_FORMAT_RGB565;
+      if (type == GL_UNSIGNED_SHORT_5_6_5)
+        return MESA_FORMAT_RGB565;
+      else if (intel->has_xrgb_textures)
+        return MESA_FORMAT_XRGB8888;
+      else
+        return MESA_FORMAT_ARGB8888;
 
    case GL_RGBA8:
    case GL_RGB10_A2:
    case GL_RGBA12:
    case GL_RGBA16:
-      return do32bpt ? MESA_FORMAT_ARGB8888 : MESA_FORMAT_ARGB4444;
+      return MESA_FORMAT_ARGB8888;
 
    case GL_RGBA4:
    case GL_RGBA2:
@@ -69,7 +63,10 @@ intelChooseTextureFormat(GLcontext * ctx, GLint internalFormat,
    case GL_RGB10:
    case GL_RGB12:
    case GL_RGB16:
-      return MESA_FORMAT_XRGB8888;
+      if (intel->has_xrgb_textures)
+        return MESA_FORMAT_XRGB8888;
+      else
+        return MESA_FORMAT_ARGB8888;
 
    case GL_RGB5:
    case GL_RGB4:
@@ -96,6 +93,10 @@ intelChooseTextureFormat(GLcontext * ctx, GLint internalFormat,
    case GL_LUMINANCE12_ALPHA4:
    case GL_LUMINANCE12_ALPHA12:
    case GL_LUMINANCE16_ALPHA16:
+      /* i915 could implement this mode using MT_32BIT_RG1616.  However, this
+       * would require an extra swizzle instruction in the fragment shader to
+       * convert the { R, G, 1.0, 1.0 } to { R, R, R, G }.
+       */
 #ifndef I915
       return MESA_FORMAT_AL1616;
 #else
@@ -196,6 +197,22 @@ intelChooseTextureFormat(GLcontext * ctx, GLint internalFormat,
    case GL_RGBA_SNORM:
    case GL_RGBA8_SNORM:
       return MESA_FORMAT_SIGNED_RGBA8888_REV;
+
+   /* i915 can do a RG16, but it can't do any of the other RED or RG formats.
+    * In addition, it only implements the broken D3D mode where undefined
+    * components are read as 1.0.  I'm not sure who thought reading
+    * { R, G, 1.0, 1.0 } from a red-green texture would be useful.
+    */
+   case GL_RED:
+   case GL_R8:
+      return MESA_FORMAT_R8;
+   case GL_R16:
+      return MESA_FORMAT_R16;
+   case GL_RG:
+   case GL_RG8:
+      return MESA_FORMAT_RG88;
+   case GL_RG16:
+      return MESA_FORMAT_RG1616;
 #endif
 
    default:
@@ -209,22 +226,11 @@ intelChooseTextureFormat(GLcontext * ctx, GLint internalFormat,
 
 int intel_compressed_num_bytes(GLuint mesaFormat)
 {
-   int bytes = 0;
-   switch(mesaFormat) {
-     
-   case MESA_FORMAT_RGB_FXT1:
-   case MESA_FORMAT_RGBA_FXT1:
-   case MESA_FORMAT_RGB_DXT1:
-   case MESA_FORMAT_RGBA_DXT1:
-     bytes = 2;
-     break;
-     
-   case MESA_FORMAT_RGBA_DXT3:
-   case MESA_FORMAT_RGBA_DXT5:
-     bytes = 4;
-   default:
-     break;
-   }
-   
-   return bytes;
+   GLuint bw, bh;
+   GLuint block_size;
+
+   block_size = _mesa_get_format_bytes(mesaFormat);
+   _mesa_get_format_block_size(mesaFormat, &bw, &bh);
+
+   return block_size / bw;
 }