mesa: add texture target field to ChooseTextureFormat() driver hook
authorBrian Paul <brianp@vmware.com>
Fri, 24 Aug 2012 14:31:37 +0000 (08:31 -0600)
committerBrian Paul <brianp@vmware.com>
Fri, 24 Aug 2012 20:08:57 +0000 (14:08 -0600)
This will let us choose the actual hardware format depending on the
type of texture.

v2: fixup radeon, nouveau, intel and swrast drivers too

Reviewed-by: Eric Anholt <eric@anholt.net>
13 files changed:
src/mesa/drivers/dri/intel/intel_fbo.c
src/mesa/drivers/dri/nouveau/nouveau_texture.c
src/mesa/drivers/dri/radeon/radeon_texture.c
src/mesa/drivers/dri/radeon/radeon_texture.h
src/mesa/drivers/dri/swrast/swrast.c
src/mesa/main/dd.h
src/mesa/main/texformat.c
src/mesa/main/texformat.h
src/mesa/main/teximage.c
src/mesa/main/texobj.c
src/mesa/state_tracker/st_format.c
src/mesa/state_tracker/st_format.h
src/mesa/state_tracker/st_manager.c

index 3a610c244b1704723cd983c9c5f590a8dc005e6c..ad78e0a29d8706ba5432cd7711c71cca18aa1f7f 100644 (file)
@@ -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:
index 0e42758040f56390497a988a08a3188e278e1071..37f7577b3d7f7812b12018aada5c96e2092705f0 100644 (file)
@@ -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) {
index 11b825d9dabcb0a5fba9997d4c41358e853ebb04..e405f9746f1e8d699d43693ad6619c0199c02d78 100644 (file)
@@ -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)
index abcce54806df0d03bae786eb24023fd6a92be6a7..88aace840bb310ee404169d43cf89a93e100a2f6 100644 (file)
@@ -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);
index 7773fd9050ac38d5464a034b139276868f396da2..9aed2f6e6c55e085c24c7c6eacb66b3f498a0c0c 100644 (file)
@@ -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
index 226897b1915e922c55d4c3ada85e1972b9ab2018..a91e8083f219f986569f71c783daa78d70705109 100644 (file)
@@ -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 );
 
    /**
index 275e69e31ec2bc3ec11f236f97496a1007612f89..57f535297177908f16417cc530552f029d7b0ea1 100644 (file)
@@ -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;
index 3cf09213ac49725435754599e94c6e4d9b283469..71af9ca223e36f1281e5e30c5f4a5acd26a0af5e 100644 (file)
@@ -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
index 8ec48eb62a68bb7eab94f358cdf280f889ffacc1..59b38dee4aa1385ea5d71a3e2e131c7e359579f1 100644 (file)
@@ -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;
 }
index 2b2dccfbc1fab963a2a535c551c0409b1ddb45a6..638e418dab4de4a4df4ae2c95c8045478cc26a0c 100644 (file)
@@ -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 */
index 962b092507bd19900f124d9a27b47924a51670c0..404b04106376ef72c26ca2fe8fa9307a95917b6d 100644 (file)
@@ -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 ||
index 7cf92eb41e64ff4b29e1144ad2f3c99ac8ba6772..2eef2c0d43866b9c7694fbe687d8dbb0f93d7e36 100644 (file)
@@ -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);
 
 
index c050048aa5d2c6a12938a46045f3e9f174f9177f..df73d0e1bf1479d1ff9d676be2f5738404be2816 100644 (file)
@@ -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,