summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/mipmap.c
diff options
context:
space:
mode:
authorKenneth Graunke <[email protected]>2016-06-19 00:36:48 -0700
committerKenneth Graunke <[email protected]>2018-02-16 10:48:10 -0800
commit9bcd31ea90addd7a16802de8a28b2f3242dc8298 (patch)
tree881bc896089ffb72bfe5713f5585b6ec42de1e55 /src/mesa/main/mipmap.c
parent03ab40b1f7bbff7f1c6ba128e202bdf31352ea66 (diff)
mesa: Move compute_num_levels from st_gen_mipmap.c to mipmap.c.
I want to use compute_num_levels inside i965. Rather than duplicating it, move it from mesa/st to core Mesa, and make it non-static. Reviewed-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src/mesa/main/mipmap.c')
-rw-r--r--src/mesa/main/mipmap.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/mesa/main/mipmap.c b/src/mesa/main/mipmap.c
index fc36d408f91..1ed82c52ab6 100644
--- a/src/mesa/main/mipmap.c
+++ b/src/mesa/main/mipmap.c
@@ -42,6 +42,30 @@
#include "util/format_r11g11b10f.h"
+/**
+ * Compute the expected number of mipmap levels in the texture given
+ * the width/height/depth of the base image and the GL_TEXTURE_BASE_LEVEL/
+ * GL_TEXTURE_MAX_LEVEL settings. This will tell us how many mipmap
+ * levels should be generated.
+ */
+unsigned
+_mesa_compute_num_levels(struct gl_context *ctx,
+ struct gl_texture_object *texObj,
+ GLenum target)
+{
+ const struct gl_texture_image *baseImage;
+ GLuint numLevels;
+
+ baseImage = _mesa_get_tex_image(ctx, texObj, target, texObj->BaseLevel);
+
+ numLevels = texObj->BaseLevel + baseImage->MaxNumLevels;
+ numLevels = MIN2(numLevels, (GLuint) texObj->MaxLevel + 1);
+ if (texObj->Immutable)
+ numLevels = MIN2(numLevels, texObj->NumLevels);
+ assert(numLevels >= 1);
+
+ return numLevels;
+}
static GLint
bytes_per_pixel(GLenum datatype, GLuint comps)