From e3a6f57ad6c0e7bda5d45eb146194ed39f45abdd Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 28 Sep 2009 09:28:50 -0600 Subject: st/mesa: fix/simplify st_texture_object::lastLevel calculation Don't compute the st_texture_object::lastLevel field based on the texture filters. Use the _MaxLevel value that core Mesa computes for us. When called from the GenerateMipmap path, we'll use the lastLevel field as-is. --- src/mesa/state_tracker/st_cb_texture.c | 62 +++++----------------------------- 1 file changed, 9 insertions(+), 53 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_texture.c') diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index cfa33d48e1..085da3eab4 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -1708,53 +1708,6 @@ st_CopyTexSubImage3D(GLcontext * ctx, GLenum target, GLint level, } -/** - * Compute which mipmap levels that really need to be sent to the hardware. - * This depends on the base image size, GL_TEXTURE_MIN_LOD, - * GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL, and GL_TEXTURE_MAX_LEVEL. - */ -static void -calculate_first_last_level(struct st_texture_object *stObj) -{ - struct gl_texture_object *tObj = &stObj->base; - - /* These must be signed values. MinLod and MaxLod can be negative numbers, - * and having firstLevel and lastLevel as signed prevents the need for - * extra sign checks. - */ - GLint firstLevel; - GLint lastLevel; - - /* Yes, this looks overly complicated, but it's all needed. - */ - switch (tObj->Target) { - case GL_TEXTURE_1D: - case GL_TEXTURE_2D: - case GL_TEXTURE_3D: - case GL_TEXTURE_CUBE_MAP: - if (tObj->MinFilter == GL_NEAREST || tObj->MinFilter == GL_LINEAR) { - /* GL_NEAREST and GL_LINEAR only care about GL_TEXTURE_BASE_LEVEL. - */ - firstLevel = lastLevel = tObj->BaseLevel; - } - else { - firstLevel = 0; - lastLevel = MIN2(tObj->MaxLevel, - (int) tObj->Image[0][tObj->BaseLevel]->WidthLog2); - } - break; - case GL_TEXTURE_RECTANGLE_NV: - case GL_TEXTURE_4D_SGIS: - firstLevel = lastLevel = 0; - break; - default: - return; - } - - stObj->lastLevel = lastLevel; -} - - static void copy_image_data_to_texture(struct st_context *st, struct st_texture_object *stObj, @@ -1818,13 +1771,16 @@ st_finalize_texture(GLcontext *ctx, *needFlush = GL_FALSE; - /* We know/require this is true by now: - */ - assert(stObj->base._Complete); + if (stObj->base._Complete) { + /* The texture is complete and we know exactly how many mipmap levels + * are present/needed. This is conditional because we may be called + * from the st_generate_mipmap() function when the texture object is + * incomplete. In that case, we'll have set stObj->lastLevel before + * we get here. + */ + stObj->lastLevel = stObj->base._MaxLevel - stObj->base.BaseLevel; + } - /* What levels must the texture include at a minimum? - */ - calculate_first_last_level(stObj); firstImage = st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]); /* If both firstImage and stObj point to a texture which can contain -- cgit v1.2.3 From 05bad193f56d48384097e37e47fae3fdda85f144 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 28 Sep 2009 10:03:58 -0600 Subject: st/mesa: check gl_texture_object::GenerateMipmap field when allocating texmem In guess_and_alloc_texture() use the gl_texture_object::GenerateMipmap field as another hint as to whether to allocate space for a whole mipmap. --- src/mesa/state_tracker/st_cb_texture.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_texture.c') diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index c0fba8641b..771a0e2bbd 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -328,10 +328,13 @@ guess_and_alloc_texture(struct st_context *st, stObj->base.MinFilter == GL_LINEAR || stImage->base._BaseFormat == GL_DEPTH_COMPONENT || stImage->base._BaseFormat == GL_DEPTH_STENCIL_EXT) && + !stObj->base.GenerateMipmap && stImage->level == firstLevel) { + /* only alloc space for a single mipmap level */ lastLevel = firstLevel; } else { + /* alloc space for a full mipmap */ GLuint l2width = util_logbase2(width); GLuint l2height = util_logbase2(height); GLuint l2depth = util_logbase2(depth); -- cgit v1.2.3 From ae2daacbac7242938cffe0e2409071e030e00863 Mon Sep 17 00:00:00 2001 From: Cooper Yuan Date: Thu, 1 Oct 2009 17:54:27 +0800 Subject: st/mesa: fix non-mipmap lastLevel calculation. reviewed by Brian Paul. --- src/mesa/state_tracker/st_cb_texture.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/mesa/state_tracker/st_cb_texture.c') diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 771a0e2bbd..9a634bb930 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -1766,7 +1766,11 @@ st_finalize_texture(GLcontext *ctx, * incomplete. In that case, we'll have set stObj->lastLevel before * we get here. */ - stObj->lastLevel = stObj->base._MaxLevel - stObj->base.BaseLevel; + if (stObj->base.MinFilter == GL_LINEAR || + stObj->base.MinFilter == GL_NEAREST) + stObj->lastLevel = stObj->base.BaseLevel; + else + stObj->lastLevel = stObj->base._MaxLevel - stObj->base.BaseLevel; } firstImage = st_texture_image(stObj->base.Image[0][stObj->base.BaseLevel]); -- cgit v1.2.3