【发布时间】:2022-11-04 01:46:07
【问题描述】:
OpenGL 版本 450 引入了一个新函数,可用于为纹理 2D 分配内存:
glTextureStorage2D(textureObj,levels,internal_format,width,height);
//here, parameter 'levels' refers to the levels of mipmaps
//we need to set it 1 if we only want to use the original texture we loaded because then there is only one mipmap level
而且,还有一个函数可以帮助我们方便地为纹理生成 mipmap:
glGenerateTextureMipmap(textureObj);
所以,我有一个问题:当我使用glTextureStorage2D时我需要指定存储的大小,我是否需要为以后使用glGenerateTextureMipmap保留额外的空间,因为mipmap需要额外的内存? 我知道我可以使用 glTexImage2D 来避免这个问题,我可以先将纹理绑定到目标 GL_TEXTURE_2D,然后使用 glTexImage2D 将图像的数据复制到纹理的内存中,它只要求我给出目标 mipmap 级别而不是 mipmap 的数量级别,最后使用 glGenerateMipmap(GL_TEXTURE_2D)。
我对 glGenerateMipmap 有点困惑。它会为生成的 mipmap 级别分配额外的空间吗?
【问题讨论】: