From: Brian Paul Date: Fri, 24 Aug 2012 14:31:37 +0000 (-0600) Subject: mesa: add texture target field to ChooseTextureFormat() driver hook X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d47a6ada9ca9670c60fc141fabadf40c63031c08;p=mesa.git mesa: add texture target field to ChooseTextureFormat() driver hook 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 --- diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c index 3a610c244b1..ad78e0a29d8 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 0e42758040f..37f7577b3d7 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 11b825d9dab..e405f9746f1 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 abcce54806d..88aace840bb 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 7773fd9050a..9aed2f6e6c5 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 226897b1915..a91e8083f21 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 275e69e31ec..57f53529717 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 3cf09213ac4..71af9ca223e 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 8ec48eb62a6..59b38dee4aa 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 2b2dccfbc1f..638e418dab4 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 962b092507b..404b0410637 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 7cf92eb41e6..2eef2c0d438 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 c050048aa5d..df73d0e1bf1 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,