diff options
author | Marek Olšák <[email protected]> | 2012-11-11 15:22:32 +0100 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2012-11-12 21:36:56 +0100 |
commit | 8111342e814304730bed34446ea816cbc17a5775 (patch) | |
tree | 90260b9415bd64076d679125fd8adfd75c787ea3 /src/mesa/main | |
parent | 26097c4855b97ee6e362c19df11d51fb7fd42192 (diff) |
mesa: add MaxNumLevels to gl_texture_image, remove MaxLog2
MaxLog2 led to bugs, because it didn't work well with 1D and 3D textures.
NOTE: This is a candidate for the stable branches.
v2: correct the comment at MaxNumlevels
Reviewed-by: Brian Paul <[email protected]>
Reviewed-by: Dave Airlie <[email protected]>
Diffstat (limited to 'src/mesa/main')
-rw-r--r-- | src/mesa/main/mtypes.h | 3 | ||||
-rw-r--r-- | src/mesa/main/teximage.c | 41 | ||||
-rw-r--r-- | src/mesa/main/teximage.h | 3 |
3 files changed, 45 insertions, 2 deletions
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index b99e7104424..da72da9d106 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1203,7 +1203,8 @@ struct gl_texture_image GLuint WidthLog2; /**< = log2(Width2) */ GLuint HeightLog2; /**< = log2(Height2) */ GLuint DepthLog2; /**< = log2(Depth2) */ - GLuint MaxLog2; /**< = MAX(WidthLog2, HeightLog2) */ + GLuint MaxNumLevels; /**< = maximum possible number of mipmap + levels, computed from the dimensions */ struct gl_texture_object *TexObject; /**< Pointer back to parent object */ GLuint Level; /**< Which mipmap level am I? */ diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index 678833ec5ee..0850ef1110c 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -1027,6 +1027,43 @@ _mesa_get_texture_dimensions(GLenum target) } +/** + * Return the maximum number of mipmap levels for the given target + * and the dimensions. + * The dimensions are expected not to include the border. + */ +GLsizei +_mesa_get_tex_max_num_levels(GLenum target, GLsizei width, GLsizei height, + GLsizei depth) +{ + GLsizei size; + + switch (target) { + case GL_TEXTURE_1D: + case GL_TEXTURE_1D_ARRAY: + size = width; + break; + case GL_TEXTURE_CUBE_MAP: + case GL_TEXTURE_CUBE_MAP_ARRAY: + ASSERT(width == height); + size = width; + break; + case GL_TEXTURE_2D: + case GL_TEXTURE_2D_ARRAY: + size = MAX2(width, height); + break; + case GL_TEXTURE_3D: + size = MAX3(width, height, depth); + break; + case GL_TEXTURE_RECTANGLE: + return 1; + default: + assert(0); + return 1; + } + + return _mesa_logbase2(size) + 1; +} #if 000 /* not used anymore */ @@ -1214,7 +1251,9 @@ _mesa_init_teximage_fields(struct gl_context *ctx, target); } - img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); + img->MaxNumLevels = + _mesa_get_tex_max_num_levels(target, + img->Width2, img->Height2, img->Depth2); img->TexFormat = format; } diff --git a/src/mesa/main/teximage.h b/src/mesa/main/teximage.h index ca4b8c86632..e136faa6d13 100644 --- a/src/mesa/main/teximage.h +++ b/src/mesa/main/teximage.h @@ -138,6 +138,9 @@ _mesa_tex_target_to_face(GLenum target); extern GLint _mesa_get_texture_dimensions(GLenum target); +extern GLsizei +_mesa_get_tex_max_num_levels(GLenum target, GLsizei width, GLsizei height, + GLsizei depth); extern GLboolean _mesa_legal_texture_dimensions(struct gl_context *ctx, GLenum target, |