Two functions are fully orthogonal.
Choose between glTexImage2D and glTexStorage2D . Both of these provide storage for texture images ; they just do it differently.
glTexImage2D is an old way of allocating memory. It creates mutable storage (there are other functions that also create mutable storage) . If you want mipmaps, you must allocate each mipmap level with a separate function call, manually calculating the size of the mipmap image (see below for an exception).
glTexStorage2D allocates an immutable image data storage . It selects all the mip cards that you want all at once.
Immutable storage, as the name implies, cannot be changed. See, you can call glTexImage2D at the same mipmap level, with a different size. And if you do, OpenGL will destroy the original mipmap level and allocate storage for the new one. You can even change the formats.
Immutable storage will not let you change anything. You can load new data using functions such as glTexSubImage2D . But these functions do not change the repository; they change the contents.
glTexImage2D and glTexStorage2D are similar to malloc . glTexSubImage2D is similar to memcpy ; It only works for existing memory.
glGenerateMipmap is a function that will take the base texture layer and generate data for all the mip cards from this base layer (given the mipmap range) . He does it once. Think of it as a rendering function; he does his work and then does it.
For mutable storage textures, glGenerateMipmap also allocates storage for any mipmaps in the mipmap range that were not previously allocated. This is why you can call glTexImage2D once, then call glGenerateMipmap to make it do all the other mipmaps without having to do it manually.
source share