OpenGL version 450引入了一个新函数,可用于为texture2D分配内存:
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级别分配额外的空间吗?
发布于 2022-10-22 05:34:53
你所说的“保留额外记忆”是什么意思?您告诉OpenGL当您使用glTextureStorage2D
时需要多少个mipmap。当涉及到不变存储时,你不能食言。如果你说一个纹理有宽度W,高度H,和mipmap计数L,那么这个纹理就是这样的。永远不变。
因此,glGenerateTextureMipmaps
只会为您放置到纹理中的mipmap的数量(减去基本级别)生成数据。
https://stackoverflow.com/questions/74161145
复制相似问题