mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-25 21:00:22 +01:00
st/mesa: move mipmap allocation check logic into a function
Better readability and easier to extend. Reviewed-by: José Fonseca <jfonseca@vmware.com>
This commit is contained in:
parent
0d39b5fc3b
commit
c032ae85ee
1 changed files with 42 additions and 12 deletions
|
|
@ -387,6 +387,43 @@ guess_base_level_size(GLenum target,
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Try to determine whether we should allocate memory for a full texture
|
||||
* mipmap. The problem is when we get a glTexImage(level=0) call, we
|
||||
* can't immediately know if other mipmap levels are coming next. Here
|
||||
* we try to guess whether to allocate memory for a mipmap or just the
|
||||
* 0th level.
|
||||
*
|
||||
* If we guess incorrectly here we'll later reallocate the right amount of
|
||||
* memory either in st_AllocTextureImageBuffer() or st_finalize_texture().
|
||||
*
|
||||
* \param stObj the texture object we're going to allocate memory for.
|
||||
* \param stImage describes the incoming image which we need to store.
|
||||
*/
|
||||
static boolean
|
||||
allocate_full_mipmap(const struct st_texture_object *stObj,
|
||||
const struct st_texture_image *stImage)
|
||||
{
|
||||
if (stImage->base.Level > 0 || stObj->base.GenerateMipmap)
|
||||
return TRUE;
|
||||
|
||||
if (stImage->base._BaseFormat == GL_DEPTH_COMPONENT ||
|
||||
stImage->base._BaseFormat == GL_DEPTH_STENCIL_EXT)
|
||||
/* depth/stencil textures are seldom mipmapped */
|
||||
return FALSE;
|
||||
|
||||
if (stObj->base.BaseLevel == 0 && stObj->base.MaxLevel == 0)
|
||||
return FALSE;
|
||||
|
||||
if (stObj->base.Sampler.MinFilter == GL_NEAREST ||
|
||||
stObj->base.Sampler.MinFilter == GL_LINEAR)
|
||||
/* not a mipmap minification filter */
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Try to allocate a pipe_resource object for the given st_texture_object.
|
||||
*
|
||||
|
|
@ -431,22 +468,15 @@ guess_and_alloc_texture(struct st_context *st,
|
|||
* to re-allocating a texture buffer with space for more (or fewer)
|
||||
* mipmap levels later.
|
||||
*/
|
||||
if ((stObj->base.Sampler.MinFilter == GL_NEAREST ||
|
||||
stObj->base.Sampler.MinFilter == GL_LINEAR ||
|
||||
(stObj->base.BaseLevel == 0 &&
|
||||
stObj->base.MaxLevel == 0) ||
|
||||
stImage->base._BaseFormat == GL_DEPTH_COMPONENT ||
|
||||
stImage->base._BaseFormat == GL_DEPTH_STENCIL_EXT) &&
|
||||
!stObj->base.GenerateMipmap &&
|
||||
stImage->base.Level == 0) {
|
||||
/* only alloc space for a single mipmap level */
|
||||
lastLevel = 0;
|
||||
}
|
||||
else {
|
||||
if (allocate_full_mipmap(stObj, stImage)) {
|
||||
/* alloc space for a full mipmap */
|
||||
lastLevel = _mesa_get_tex_max_num_levels(stObj->base.Target,
|
||||
width, height, depth) - 1;
|
||||
}
|
||||
else {
|
||||
/* only alloc space for a single mipmap level */
|
||||
lastLevel = 0;
|
||||
}
|
||||
|
||||
/* Save the level=0 dimensions */
|
||||
stObj->width0 = width;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue