[Mesa-dev] [PATCH 3/6] mga: Merge texformat fallbacks into core.

Eric Anholt eric at anholt.net
Fri Sep 24 17:08:49 PDT 2010


This drops the screen-depth-dependent texture formatting and
force-16-bits option.  The (default) screen depth dependency of format
choice for unsized internal formats would have resulted in additional
banding on 16-bit screens since 32-bit textures would get truncated
down to 16 bits before dithering occurred.
---
 src/mesa/drivers/dri/mga/mga_xmesa.c  |   24 ++++--
 src/mesa/drivers/dri/mga/mgacontext.h |    2 -
 src/mesa/drivers/dri/mga/mgatex.c     |  141 ---------------------------------
 src/mesa/main/texformat.c             |   31 ++++++-
 4 files changed, 44 insertions(+), 154 deletions(-)

diff --git a/src/mesa/drivers/dri/mga/mga_xmesa.c b/src/mesa/drivers/dri/mga/mga_xmesa.c
index 3a31dfb..eb7b44b 100644
--- a/src/mesa/drivers/dri/mga/mga_xmesa.c
+++ b/src/mesa/drivers/dri/mga/mga_xmesa.c
@@ -88,7 +88,6 @@ DRI_CONF_BEGIN
         DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0)
     DRI_CONF_SECTION_END
     DRI_CONF_SECTION_QUALITY
-        DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB)
         DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER)
     DRI_CONF_SECTION_END
     DRI_CONF_SECTION_SOFTWARE
@@ -99,7 +98,7 @@ DRI_CONF_BEGIN
         DRI_CONF_NO_RAST(false)
     DRI_CONF_SECTION_END
 DRI_CONF_END;
-static const GLuint __driNConfigOptions = 6;
+static const GLuint __driNConfigOptions = 5;
 
 #ifndef MGA_DEBUG
 int MGA_DEBUG = 0;
@@ -527,6 +526,22 @@ mgaCreateContext( gl_api api,
 				 GL_FALSE,
 				 0 );
 
+   memset(&ctx->texture_format_supported, 0,
+	  sizeof(ctx->texture_format_supported));
+   ctx->texture_format_supported[MESA_FORMAT_ARGB8888] = GL_TRUE;
+   ctx->texture_format_supported[MESA_FORMAT_ARGB4444] = GL_TRUE;
+   ctx->texture_format_supported[MESA_FORMAT_ARGB1555] = GL_TRUE;
+   ctx->texture_format_supported[MESA_FORMAT_RGB565] = GL_TRUE;
+   ctx->texture_format_supported[MESA_FORMAT_CI8] = GL_TRUE;
+   if (MGA_IS_G400(mmesa)) {
+      ctx->texture_format_supported[MESA_FORMAT_I8] = GL_TRUE;
+      ctx->texture_format_supported[MESA_FORMAT_AL88] = GL_TRUE;
+
+      /* ctx->Extensions.MESA_ycbcr_texture */
+      ctx->texture_format_supported[MESA_FORMAT_YCBCR] = GL_TRUE;
+      ctx->texture_format_supported[MESA_FORMAT_YCBCR_REV] = GL_TRUE;
+   }
+
    ctx->Const.MinLineWidth = 1.0;
    ctx->Const.MinLineWidthAA = 1.0;
    ctx->Const.MaxLineWidth = 10.0;
@@ -535,11 +550,6 @@ mgaCreateContext( gl_api api,
 
    ctx->Const.MaxDrawBuffers = 1;
 
-   mmesa->texture_depth = driQueryOptioni (&mmesa->optionCache,
-					   "texture_depth");
-   if (mmesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_FB)
-      mmesa->texture_depth = ( mesaVis->rgbBits >= 24 ) ?
-	 DRI_CONF_TEXTURE_DEPTH_32 : DRI_CONF_TEXTURE_DEPTH_16;
    mmesa->hw_stencil = mesaVis->stencilBits && mesaVis->depthBits == 24;
 
    switch (mesaVis->depthBits) {
diff --git a/src/mesa/drivers/dri/mga/mgacontext.h b/src/mesa/drivers/dri/mga/mgacontext.h
index 4141565..fc52d27 100644
--- a/src/mesa/drivers/dri/mga/mgacontext.h
+++ b/src/mesa/drivers/dri/mga/mgacontext.h
@@ -199,8 +199,6 @@ struct mga_context_t {
    /* Map GL texture units onto hardware.
     */
    GLuint tmu_source[2];
-   
-   int texture_depth;
 
    /* Manage fallbacks
     */
diff --git a/src/mesa/drivers/dri/mga/mgatex.c b/src/mesa/drivers/dri/mga/mgatex.c
index ca3dd4b..977bf73 100644
--- a/src/mesa/drivers/dri/mga/mgatex.c
+++ b/src/mesa/drivers/dri/mga/mgatex.c
@@ -159,146 +159,6 @@ static void mgaSetTexBorderColor(mgaTextureObjectPtr t, const GLfloat color[4])
    t->setup.texbordercol = PACK_COLOR_8888(c[3], c[0], c[1], c[2] );
 }
 
-
-static gl_format
-mgaChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
-		        GLenum format, GLenum type )
-{
-   mgaContextPtr mmesa = MGA_CONTEXT(ctx);
-   const GLboolean do32bpt =
-       ( mmesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_32 );
-   const GLboolean force16bpt =
-       ( mmesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_FORCE_16 );
-   (void) format;
-
-   switch ( internalFormat ) {
-   case 4:
-   case GL_RGBA:
-   case GL_COMPRESSED_RGBA:
-      switch ( type ) {
-      case GL_UNSIGNED_INT_10_10_10_2:
-      case GL_UNSIGNED_INT_2_10_10_10_REV:
-	 return do32bpt ? MESA_FORMAT_ARGB8888 : MESA_FORMAT_ARGB1555;
-      case GL_UNSIGNED_SHORT_4_4_4_4:
-      case GL_UNSIGNED_SHORT_4_4_4_4_REV:
-	 return MESA_FORMAT_ARGB4444;
-      case GL_UNSIGNED_SHORT_5_5_5_1:
-      case GL_UNSIGNED_SHORT_1_5_5_5_REV:
-	 return MESA_FORMAT_ARGB1555;
-      default:
-         return do32bpt ? MESA_FORMAT_ARGB8888 : MESA_FORMAT_ARGB4444;
-      }
-
-   case 3:
-   case GL_RGB:
-   case GL_COMPRESSED_RGB:
-      switch ( type ) {
-      case GL_UNSIGNED_SHORT_4_4_4_4:
-      case GL_UNSIGNED_SHORT_4_4_4_4_REV:
-	 return MESA_FORMAT_ARGB4444;
-      case GL_UNSIGNED_SHORT_5_5_5_1:
-      case GL_UNSIGNED_SHORT_1_5_5_5_REV:
-	 return MESA_FORMAT_ARGB1555;
-      case GL_UNSIGNED_SHORT_5_6_5:
-      case GL_UNSIGNED_SHORT_5_6_5_REV:
-	 return MESA_FORMAT_RGB565;
-      default:
-         return do32bpt ? MESA_FORMAT_ARGB8888 : MESA_FORMAT_RGB565;
-      }
-
-   case GL_RGBA8:
-   case GL_RGB10_A2:
-   case GL_RGBA12:
-   case GL_RGBA16:
-      return !force16bpt ?
-	  MESA_FORMAT_ARGB8888 : MESA_FORMAT_ARGB4444;
-
-   case GL_RGBA4:
-   case GL_RGBA2:
-      return MESA_FORMAT_ARGB4444;
-
-   case GL_RGB5_A1:
-      return MESA_FORMAT_ARGB1555;
-
-   case GL_RGB8:
-   case GL_RGB10:
-   case GL_RGB12:
-   case GL_RGB16:
-      return !force16bpt ? MESA_FORMAT_ARGB8888 : MESA_FORMAT_RGB565;
-
-   case GL_RGB5:
-   case GL_RGB4:
-   case GL_R3_G3_B2:
-      return MESA_FORMAT_RGB565;
-
-   case GL_ALPHA:
-   case GL_ALPHA4:
-   case GL_ALPHA8:
-   case GL_ALPHA12:
-   case GL_ALPHA16:
-   case GL_COMPRESSED_ALPHA:
-      /* FIXME: This will report incorrect component sizes... */
-      return MGA_IS_G400(mmesa) ? MESA_FORMAT_AL88 : MESA_FORMAT_ARGB4444;
-
-   case 1:
-   case GL_LUMINANCE:
-   case GL_LUMINANCE4:
-   case GL_LUMINANCE8:
-   case GL_LUMINANCE12:
-   case GL_LUMINANCE16:
-   case GL_COMPRESSED_LUMINANCE:
-      /* FIXME: This will report incorrect component sizes... */
-      return MGA_IS_G400(mmesa) ? MESA_FORMAT_AL88 : MESA_FORMAT_RGB565;
-
-   case 2:
-   case GL_LUMINANCE_ALPHA:
-   case GL_LUMINANCE4_ALPHA4:
-   case GL_LUMINANCE6_ALPHA2:
-   case GL_LUMINANCE8_ALPHA8:
-   case GL_LUMINANCE12_ALPHA4:
-   case GL_LUMINANCE12_ALPHA12:
-   case GL_LUMINANCE16_ALPHA16:
-   case GL_COMPRESSED_LUMINANCE_ALPHA:
-      /* FIXME: This will report incorrect component sizes... */
-      return MGA_IS_G400(mmesa) ? MESA_FORMAT_AL88 : MESA_FORMAT_ARGB4444;
-
-   case GL_INTENSITY:
-   case GL_INTENSITY4:
-   case GL_INTENSITY8:
-   case GL_INTENSITY12:
-   case GL_INTENSITY16:
-   case GL_COMPRESSED_INTENSITY:
-      /* FIXME: This will report incorrect component sizes... */
-      return MGA_IS_G400(mmesa) ? MESA_FORMAT_I8 : MESA_FORMAT_ARGB4444;
-
-   case GL_YCBCR_MESA:
-      if (MGA_IS_G400(mmesa) &&
-          (type == GL_UNSIGNED_SHORT_8_8_APPLE ||
-           type == GL_UNSIGNED_BYTE))
-         return MESA_FORMAT_YCBCR;
-      else
-         return MESA_FORMAT_YCBCR_REV;
-
-   case GL_COLOR_INDEX:
-   case GL_COLOR_INDEX1_EXT:
-   case GL_COLOR_INDEX2_EXT:
-   case GL_COLOR_INDEX4_EXT:
-   case GL_COLOR_INDEX8_EXT:
-   case GL_COLOR_INDEX12_EXT:
-   case GL_COLOR_INDEX16_EXT:
-      return MESA_FORMAT_CI8;
-
-   default:
-      _mesa_problem( ctx, "unexpected texture format in %s", __FUNCTION__ );
-      return MESA_FORMAT_NONE;
-   }
-
-   return MESA_FORMAT_NONE; /* never get here */
-}
-
-
-
-
 /**
  * Allocate space for and load the mesa images into the texture memory block.
  * This will happen before drawing with a new texture, or drawing with a
@@ -528,7 +388,6 @@ mgaNewTextureObject( GLcontext *ctx, GLuint name, GLenum target )
 void
 mgaInitTextureFuncs( struct dd_function_table *functions )
 {
-   functions->ChooseTextureFormat	= mgaChooseTextureFormat;
    functions->TexImage2D		= mgaTexImage2D;
    functions->TexSubImage2D		= mgaTexSubImage2D;
    functions->BindTexture		= mgaBindTexture;
diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c
index 30f0a32..c8ada5b 100644
--- a/src/mesa/main/texformat.c
+++ b/src/mesa/main/texformat.c
@@ -70,6 +70,8 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
       case GL_RGBA:
 	 if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
 	    RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444);
+	 } else if (type == GL_UNSIGNED_SHORT_4_4_4_4) {
+	    RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444);
 	 } else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
 	    RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB1555);
 	 }
@@ -133,30 +135,45 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
 
       /* Alpha formats */
       case GL_ALPHA:
-      case GL_ALPHA4:
       case GL_ALPHA12:
       case GL_ALPHA16:
       case GL_ALPHA8:
          RETURN_IF_SUPPORTED(MESA_FORMAT_A8);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
+	 break;
+      case GL_ALPHA4:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_A8);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
 	 break;
 
       /* Luminance formats */
       case 1:
       case GL_LUMINANCE:
-      case GL_LUMINANCE4:
       case GL_LUMINANCE12:
       case GL_LUMINANCE16:
       case GL_LUMINANCE8:
          RETURN_IF_SUPPORTED(MESA_FORMAT_L8);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
+	 break;
+      case GL_LUMINANCE4:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_L8);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
 	 break;
 
       /* Luminance/Alpha formats */
       case 2:
       case GL_LUMINANCE_ALPHA:
+      case GL_LUMINANCE8_ALPHA8:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
+	 break;
       case GL_LUMINANCE4_ALPHA4:
       case GL_LUMINANCE6_ALPHA2:
-      case GL_LUMINANCE8_ALPHA8:
          RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
 	 break;
 
       case GL_LUMINANCE12_ALPHA4:
@@ -164,14 +181,20 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
       case GL_LUMINANCE16_ALPHA16:
          RETURN_IF_SUPPORTED(MESA_FORMAT_AL1616);
          RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
 	 break;
 
       case GL_INTENSITY:
-      case GL_INTENSITY4:
       case GL_INTENSITY12:
       case GL_INTENSITY16:
       case GL_INTENSITY8:
          RETURN_IF_SUPPORTED(MESA_FORMAT_I8);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
+	 break;
+      case GL_INTENSITY4:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_I8);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
 	 break;
 
       case GL_COLOR_INDEX:
-- 
1.7.1



More information about the mesa-dev mailing list