summaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/mtypes.h3
-rw-r--r--src/mesa/main/teximage.c41
-rw-r--r--src/mesa/main/teximage.h3
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,