3d texture mipmapping?

Started by
5 comments, last by Tree Penguin 18 years, 7 months ago
How to use mipmapping with 3d textures? Is it done by using glTexImage3d and the min filter set to GL_*_MIPMAP_* or do i have to do something else? Thanks.
Advertisement
Here is my code, it works well:

//create 11 textures for different scales
if((j=createTexture(1024,1024))!=CTERRAIN_SUCCESS)
return j;
m_pTextureArray[0]=m_pMyTexture;
m_pMyTexture=NULL;

if((j=createTexture(512,512))!=CTERRAIN_SUCCESS)
return j;
m_pTextureArray[1]=m_pMyTexture;
m_pMyTexture=NULL;

if((j=createTexture(256,256))!=CTERRAIN_SUCCESS)
return j;
m_pTextureArray[2]=m_pMyTexture;
m_pMyTexture=NULL;

if((j=createTexture(128,128))!=CTERRAIN_SUCCESS)
return j;
m_pTextureArray[3]=m_pMyTexture;
m_pMyTexture=NULL;

if((j=createTexture(64,64))!=CTERRAIN_SUCCESS)
return j;
m_pTextureArray[4]=m_pMyTexture;
m_pMyTexture=NULL;

if((j=createTexture(32,32))!=CTERRAIN_SUCCESS)
return j;
m_pTextureArray[5]=m_pMyTexture;
m_pMyTexture=NULL;

if((j=createTexture(16,16))!=CTERRAIN_SUCCESS)
return j;
m_pTextureArray[6]=m_pMyTexture;
m_pMyTexture=NULL;

if((j=createTexture(8,8))!=CTERRAIN_SUCCESS)
return j;
m_pTextureArray[7]=m_pMyTexture;
m_pMyTexture=NULL;

if((j=createTexture(4,4))!=CTERRAIN_SUCCESS)
return j;
m_pTextureArray[8]=m_pMyTexture;
m_pMyTexture=NULL;

if((j=createTexture(2,2))!=CTERRAIN_SUCCESS)
return j;
m_pTextureArray[9]=m_pMyTexture;
m_pMyTexture=NULL;

if((j=createTexture(1,1))!=CTERRAIN_SUCCESS)
return j;
m_pTextureArray[10]=m_pMyTexture;
m_pMyTexture=NULL;
glGenTextures(1,&m_iTextureID);
glBindTexture(GL_TEXTURE_2D,m_iTextureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, m_pTextureArray[0]->getWidth(),m_pTextureArray[0]->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE,m_pTextureArray[0]->getBitmap());
glTexImage2D(GL_TEXTURE_2D, 1, 3, m_pTextureArray[1]->getWidth(),m_pTextureArray[1]->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE,m_pTextureArray[1]->getBitmap());
glTexImage2D(GL_TEXTURE_2D, 2, 3, m_pTextureArray[2]->getWidth(),m_pTextureArray[2]->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE,m_pTextureArray[2]->getBitmap());
glTexImage2D(GL_TEXTURE_2D, 3, 3, m_pTextureArray[3]->getWidth(),m_pTextureArray[3]->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE,m_pTextureArray[3]->getBitmap());
glTexImage2D(GL_TEXTURE_2D, 4, 3, m_pTextureArray[4]->getWidth(),m_pTextureArray[4]->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE,m_pTextureArray[4]->getBitmap());
glTexImage2D(GL_TEXTURE_2D, 5, 3, m_pTextureArray[5]->getWidth(),m_pTextureArray[5]->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE,m_pTextureArray[5]->getBitmap());
glTexImage2D(GL_TEXTURE_2D, 6, 3, m_pTextureArray[6]->getWidth(),m_pTextureArray[6]->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE,m_pTextureArray[6]->getBitmap());
glTexImage2D(GL_TEXTURE_2D, 7, 3, m_pTextureArray[7]->getWidth(),m_pTextureArray[7]->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE,m_pTextureArray[7]->getBitmap());
glTexImage2D(GL_TEXTURE_2D, 8, 3, m_pTextureArray[8]->getWidth(),m_pTextureArray[8]->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE,m_pTextureArray[8]->getBitmap());
glTexImage2D(GL_TEXTURE_2D, 9, 3, m_pTextureArray[9]->getWidth(),m_pTextureArray[9]->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE,m_pTextureArray[9]->getBitmap());
glTexImage2D(GL_TEXTURE_2D, 10, 3, m_pTextureArray[10]->getWidth(),m_pTextureArray[10]->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE,m_pTextureArray[10]->getBitmap());
But I dont recommend u use this approach to achieve multi texture, use extension. This is too resource consuming
Quote:Here is my code, it works well:

:)
Quote:Original post by Tree Penguin
How to use mipmapping with 3d textures? Is it done by using glTexImage3d and the min filter set to GL_*_MIPMAP_* or do i have to do something else?

Thanks.


You treat 3D Texture mipmaping just the same as you treat 2D mipmaping.
Ah yeah, just change the level parameter and send a smaller texture, i guess that could work with 3d textures too.

Thanks.

By the way, is it possible to change the mipmap level dimensions to whatever you want, not neccesserily x/2 and y/2 but maybe something like x/2 and y=y?

-edit-

@phantom:

Yeah, i just discovered i always used gluBuildMipmaps, that's why i didn't think of using glTexImage3d with a mipmap filter as the right way, pretty stupid.

Thanks :).
Quote:Original post by pengzhe1979
But I dont recommend u use this approach to achieve multi texture, use extension. This is too resource consuming


Well, the point is blending between the different z-layers of a texture without extra passes (multitexture units are probably full already) and cpu calculations, as the textures would be in video memory anyway it wouldn't matter much or anything i'd say, but extra pass(es) certainly would.

This topic is closed to new replies.

Advertisement