[Mesa-dev] [PATCH] mesa: add texture target field to ChooseTextureFormat() driver hook

Brian Paul brianp at vmware.com
Fri Aug 24 12:06:10 PDT 2012


This will let us choose the actual hardware format depending on the
type of texture.

v2: fixup radeon, nouveau, intel and swrast drivers too
---
 src/mesa/drivers/dri/intel/intel_fbo.c         |    3 ++-
 src/mesa/drivers/dri/nouveau/nouveau_texture.c |    3 ++-
 src/mesa/drivers/dri/radeon/radeon_texture.c   |    1 +
 src/mesa/drivers/dri/radeon/radeon_texture.h   |    1 +
 src/mesa/drivers/dri/swrast/swrast.c           |    3 ++-
 src/mesa/main/dd.h                             |   11 +++++++----
 src/mesa/main/texformat.c                      |    4 ++--
 src/mesa/main/texformat.h                      |    4 ++--
 src/mesa/main/teximage.c                       |    5 +++--
 src/mesa/main/texobj.c                         |    3 ++-
 src/mesa/state_tracker/st_format.c             |    4 ++--
 src/mesa/state_tracker/st_format.h             |    3 ++-
 src/mesa/state_tracker/st_manager.c            |    2 +-
 13 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index 3a610c2..ad78e0a 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -237,7 +237,8 @@ intel_alloc_renderbuffer_storage(struct gl_context * ctx, struct gl_renderbuffer
        * except they're less useful because you can't texture with
        * them.
        */
-      rb->Format = intel->ctx.Driver.ChooseTextureFormat(ctx, internalFormat,
+      rb->Format = intel->ctx.Driver.ChooseTextureFormat(ctx, GL_TEXTURE_2D,
+							 internalFormat,
 							 GL_NONE, GL_NONE);
       break;
    case GL_STENCIL_INDEX:
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_texture.c b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
index 0e42758..37f7577 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_texture.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
@@ -232,7 +232,8 @@ nouveau_unmap_texture_image(struct gl_context *ctx, struct gl_texture_image *ti,
 }
 
 static gl_format
-nouveau_choose_tex_format(struct gl_context *ctx, GLint internalFormat,
+nouveau_choose_tex_format(struct gl_context *ctx, GLenum target,
+                          GLint internalFormat,
 			  GLenum srcFormat, GLenum srcType)
 {
 	switch (internalFormat) {
diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.c b/src/mesa/drivers/dri/radeon/radeon_texture.c
index 11b825d..e405f97 100644
--- a/src/mesa/drivers/dri/radeon/radeon_texture.c
+++ b/src/mesa/drivers/dri/radeon/radeon_texture.c
@@ -311,6 +311,7 @@ static gl_format radeonChoose8888TexFormat(radeonContextPtr rmesa,
 }
 
 gl_format radeonChooseTextureFormat_mesa(struct gl_context * ctx,
+					 GLenum target,
 					 GLint internalFormat,
 					 GLenum format,
 					 GLenum type)
diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.h b/src/mesa/drivers/dri/radeon/radeon_texture.h
index abcce54..88aace8 100644
--- a/src/mesa/drivers/dri/radeon/radeon_texture.h
+++ b/src/mesa/drivers/dri/radeon/radeon_texture.h
@@ -58,6 +58,7 @@ void radeon_swrast_map_texture_images(struct gl_context *ctx, struct gl_texture_
 void radeon_swrast_unmap_texture_images(struct gl_context *ctx, struct gl_texture_object *texObj);
 
 gl_format radeonChooseTextureFormat_mesa(struct gl_context * ctx,
+                                         GLenum target,
                                          GLint internalFormat,
                                          GLenum format,
                                          GLenum type);
diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c
index 7773fd9..9aed2f6e 100644
--- a/src/mesa/drivers/dri/swrast/swrast.c
+++ b/src/mesa/drivers/dri/swrast/swrast.c
@@ -632,13 +632,14 @@ viewport(struct gl_context *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
 }
 
 static gl_format swrastChooseTextureFormat(struct gl_context * ctx,
+                                           GLenum target,
 					   GLint internalFormat,
 					   GLenum format,
 					   GLenum type)
 {
     if (internalFormat == GL_RGB)
 	return MESA_FORMAT_XRGB8888;
-    return _mesa_choose_tex_format(ctx, internalFormat, format, type);
+    return _mesa_choose_tex_format(ctx, target, internalFormat, format, type);
 }
 
 static void
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index 226897b..a91e808 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -189,12 +189,15 @@ struct dd_function_table {
    /*@{*/
 
    /**
-    * Choose actual hardware texture format given the user-provided source
-    * image format and type and the desired internal format.  In some
-    * cases, srcFormat and srcType can be GL_NONE.
+    * Choose actual hardware texture format given the texture target, the
+    * user-provided source image format and type and the desired internal
+    * format.  In some cases, srcFormat and srcType can be GL_NONE.
+    * Note:  target may be GL_TEXTURE_CUBE_MAP, but never
+    * GL_TEXTURE_CUBE_MAP_[POSITIVE/NEGATIVE]_[XYZ].
     * Called by glTexImage(), etc.
     */
-   gl_format (*ChooseTextureFormat)( struct gl_context *ctx, GLint internalFormat,
+   gl_format (*ChooseTextureFormat)( struct gl_context *ctx,
+                                     GLenum target, GLint internalFormat,
                                      GLenum srcFormat, GLenum srcType );
 
    /**
diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c
index 275e69e..57f5352 100644
--- a/src/mesa/main/texformat.c
+++ b/src/mesa/main/texformat.c
@@ -61,8 +61,8 @@
  * will typically override this function with a specialized version.
  */
 gl_format
-_mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
-                         GLenum format, GLenum type )
+_mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
+                        GLint internalFormat, GLenum format, GLenum type)
 {
    (void) format;
    (void) type;
diff --git a/src/mesa/main/texformat.h b/src/mesa/main/texformat.h
index 3cf0921..71af9ca 100644
--- a/src/mesa/main/texformat.h
+++ b/src/mesa/main/texformat.h
@@ -32,8 +32,8 @@
 struct gl_context;
 
 extern gl_format
-_mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
-                         GLenum format, GLenum type );
+_mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
+                        GLint internalFormat, GLenum format, GLenum type);
 
 
 #endif
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 8ec48eb..59b38de 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -2035,7 +2035,7 @@ compressed_texture_error_check(struct gl_context *ctx, GLint dimensions,
    /* check image size against compression block size */
    {
       gl_format texFormat =
-         ctx->Driver.ChooseTextureFormat(ctx, proxy_format,
+         ctx->Driver.ChooseTextureFormat(ctx, target, proxy_format,
 					 choose_format, choose_type);
       GLuint bw, bh;
 
@@ -2797,7 +2797,8 @@ _mesa_choose_texture_format(struct gl_context *ctx,
    }
 
    /* choose format from scratch */
-   f = ctx->Driver.ChooseTextureFormat(ctx, internalFormat, format, type);
+   f = ctx->Driver.ChooseTextureFormat(ctx, texObj->Target, internalFormat,
+                                       format, type);
    ASSERT(f != MESA_FORMAT_NONE);
    return f;
 }
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index 2b2dccf..638e418 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -783,7 +783,8 @@ _mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex)
       texObj->Sampler.MinFilter = GL_NEAREST;
       texObj->Sampler.MagFilter = GL_NEAREST;
 
-      texFormat = ctx->Driver.ChooseTextureFormat(ctx, GL_RGBA, GL_RGBA,
+      texFormat = ctx->Driver.ChooseTextureFormat(ctx, target,
+                                                  GL_RGBA, GL_RGBA,
                                                   GL_UNSIGNED_BYTE);
 
       /* need a loop here just for cube maps */
diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
index 962b092..404b041 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -1631,8 +1631,8 @@ st_ChooseTextureFormat_renderable(struct gl_context *ctx, GLint internalFormat,
  * Called via ctx->Driver.ChooseTextureFormat().
  */
 gl_format
-st_ChooseTextureFormat(struct gl_context *ctx, GLint internalFormat,
-                       GLenum format, GLenum type)
+st_ChooseTextureFormat(struct gl_context *ctx, GLenum target,
+                       GLint internalFormat, GLenum format, GLenum type)
 {
    boolean want_renderable =
       internalFormat == 3 || internalFormat == 4 ||
diff --git a/src/mesa/state_tracker/st_format.h b/src/mesa/state_tracker/st_format.h
index 7cf92eb..2eef2c0 100644
--- a/src/mesa/state_tracker/st_format.h
+++ b/src/mesa/state_tracker/st_format.h
@@ -63,7 +63,8 @@ st_ChooseTextureFormat_renderable(struct gl_context *ctx, GLint internalFormat,
 				  GLenum format, GLenum type, GLboolean renderable);
 
 extern gl_format
-st_ChooseTextureFormat(struct gl_context * ctx, GLint internalFormat,
+st_ChooseTextureFormat(struct gl_context * ctx, GLenum target,
+                       GLint internalFormat,
                        GLenum format, GLenum type);
 
 
diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c
index c050048..df73d0e 100644
--- a/src/mesa/state_tracker/st_manager.c
+++ b/src/mesa/state_tracker/st_manager.c
@@ -533,7 +533,7 @@ st_context_teximage(struct st_context_iface *stctxi,
       else
          internalFormat = GL_RGB;
 
-      texFormat = st_ChooseTextureFormat(ctx, internalFormat,
+      texFormat = st_ChooseTextureFormat(ctx, target, internalFormat,
                                          GL_BGRA, GL_UNSIGNED_BYTE);
 
       _mesa_init_teximage_fields(ctx, texImage,
-- 
1.7.3.4



More information about the mesa-dev mailing list