PDA

View Full Version : Question on Mipmapping



Lee_Jennifer_82
01-31-2016, 01:26 PM
Hello, I've some basic questions on mipmapping. I found that level parameter in glTexImage2D is set to '0' when we'd like to generate mipmap. For example:



glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, format, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);


Is it by default OpenGL taking care of mipmaps and we don't know how many levels will be generated.
Now when we need to explicitly change level from '0' to some other value , i.e. '4' and call glTexImage2D as follows:

glTexImage2D(GL_TEXTURE_2D, 4, GL_RGBA, width, height, 0, format, GL_UNSIGNED_BYTE, data);

When do we also need to call the following parameters:



glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BASE_LEVE L, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4);

Any clarification will be highly appreciated!

Alfonse Reinheart
01-31-2016, 07:26 PM
As clearly stated on the OpenGL Wiki article about allocating storage for textures (https://www.opengl.org/wiki/Texture_Storage#Mutable_storage), glTexImage2D allocates the storage for a single mipmap level. So if you want 5 mipmap levels, you have to allocate 5 mipmap levels, 0 through 4. Each with a call to glTexImage2D.

And you must calculate the size of each mipmap level manually.

Carmine
02-01-2016, 02:05 AM
You may find 'gluBuild2dmipmaps' to be helpful.

Lee_Jennifer_82
02-02-2016, 11:21 AM
But what happened when I don't explicitly define the mipmap levels:





glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, format, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);


Will OpenGL generate a number of mipmap level automatically?

mhagain
02-02-2016, 11:34 AM
But what happened when I don't explicitly define the mipmap levels:

Will OpenGL generate a number of mipmap level automatically?

You can always read the documentation for glGenerateMipmap, bearing in mind that what it doesn't say can be as important as what it does say: https://www.opengl.org/sdk/docs/man/html/glGenerateMipmap.xhtml

In this case, the only completeness requirement is that a cube map or cube map array texture must be cube-complete; regular 2D (etc) textures don't have a completeness requirement documented so you can infer from that that there is no completeness requirement.

Driver bugs are, of course, always the exception to this rule. If it was me I wouldn't trust the driver as far as I could throw it to get this right (fair disclosure: I haven't tested all drivers) so I'd call glTexImage2D with NULL data to specify the other levels first.