# Access Cube Map's Mip Maps

This topic is 4159 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey everyone. I am trying to create a new cube map from a mip map of another cube map. Basically i am trying to access a smaller mip level of a cube map and store it as another cube map. The reason is that i have data stored in a cube map that i can not just linearly interpolate on the GPU but instead need to do some other operations. Does anyone know how to copy a mip level from a cube? Currently, i have tried creating a new cube map and copying each mip map surface of the cube to it but i do not get correct results. If you can figure out what is wrong with this then I do not need another solution but ideally there has to be a simpler method to do this.
    V_RETURN( D3DXCreateCubeTextureFromFileEx( pd3dDevice, strPath, 512, 10, 0, D3DFMT_A16B16G16R16F,
D3DPOOL_MANAGED, D3DX_FILTER_LINEAR, D3DX_FILTER_LINEAR, 0, NULL, NULL, &m_pEnvironmentMap ) );

DWORD levelCount = m_pEnvironmentMap->GetLevelCount() - 1;

LPDIRECT3DSURFACE9 faceSurface;
LPDIRECT3DSURFACE9 mipFaceSurface;
int size = 1;

for (DWORD i = 0; i <= levelCount; i++)
{
D3DXCreateCubeTexture ( pd3dDevice, size, 1, 0, D3DFMT_A16B16G16R16F,
D3DPOOL_MANAGED, &m_pEnvironmentMipMaps);

size *= 2;
}// for


##### Share on other sites
Quote:
 Original post by ilflyer12Hey everyone. I am trying to create a new cube map from a mip map of another cube map. Basically i am trying to access a smaller mip level of a cube map and store it as another cube map. The reason is that i have data stored in a cube map that i can not just linearly interpolate on the GPU but instead need to do some other operations. Does anyone know how to copy a mip level from a cube?Currently, i have tried creating a new cube map and copying each mip map surface of the cube to it but i do not get correct results. If you can figure out what is wrong with this then I do not need another solution but ideally there has to be a simpler method to do this.*** SNIP ***

I don't see where you're actually copying the texture data. All you're doing is creating a new cubemap for each level of the original cube, but you never initialize the data.

Also, you seem to assume that level 0 is the smallest, of size 1. That is incorrect. In general, level 0 should be the biggest one, but you shouldn't actually care about that. What you should be doing is calling GetLevelDesc for each level, to get a description of it's size, and creating a new texture using that size. Keep in mind that a texture doesn't have to have a 1x1 MIP map. A texture that's 16x16 can only have two MIP map surfaces, meaning a 16x16 surface and an 8x8 surface, and nothing else.

Other than that, maybe your error is in how you copy the data over between the two?

Hope this helps.

##### Share on other sites
Sorry I was editing my code while i was pasting it and i forgot to include my call to UpdateSurface so here it is. Here is the code again but this time its all there. All i get is a blue surface and not the actual environment map.

	DWORD levelCount = m_pEnvironmentMap->GetLevelCount() - 1;	LPDIRECT3DSURFACE9 faceSurface;	LPDIRECT3DSURFACE9 mipFaceSurface;	int size = 1;	for (DWORD i = 0; i <= levelCount; i++)	{		D3DXCreateCubeTexture ( pd3dDevice, size, 1, 0, D3DFMT_A16B16G16R16F, 			D3DPOOL_MANAGED, &m_pEnvironmentMipMaps);		for (DWORD j = 0; j < 6; j++)		{			m_pEnvironmentMipMaps->GetCubeMapSurface((D3DCUBEMAP_FACES)j, 0, &faceSurface);			m_pEnvironmentMap->GetCubeMapSurface((D3DCUBEMAP_FACES)j, levelCount - i, &mipFaceSurface);			pd3dDevice->UpdateSurface(mipFaceSurface, NULL, faceSurface, NULL);		}// for				V( D3DXSaveTextureToFile( L"mipMap.dds", D3DXIFF_DDS, m_pEnvironmentMipMaps, NULL ) ); 		size *= 2;	}// for

Once again I appreciate the help.

##### Share on other sites
Alright after messing with it for a while here is the solution i came up with. Just figured i would post it just in case anyone else had been wondering how to do it.

	DWORD levelCount = m_pEnvironmentMap->GetLevelCount() - 1;	int size = 1;	for (DWORD i = 0; i <= levelCount; i++)	{		D3DXCreateCubeTexture ( pd3dDevice, size, 1, 0, D3DFMT_A16B16G16R16F, 			D3DPOOL_MANAGED, &m_pEnvironmentMipMaps);		for (DWORD j = 0; j < 6; j++)		{			LPDIRECT3DSURFACE9 faceSurface;			LPDIRECT3DSURFACE9 mipFaceSurface;			m_pEnvironmentMipMaps->GetCubeMapSurface((D3DCUBEMAP_FACES)j, 0, &faceSurface);						m_pEnvironmentMap->GetCubeMapSurface((D3DCUBEMAP_FACES)j, levelCount - i, &mipFaceSurface);									V ( D3DXLoadSurfaceFromSurface (faceSurface, NULL, NULL, mipFaceSurface, NULL, NULL, D3DX_DEFAULT, 0 ) );			// Make sure it is writing properly			// V ( D3DXSaveSurfaceToFile (L"surface.dds", D3DXIFF_DDS, faceSurface, NULL, NULL) );			SAFE_RELEASE(faceSurface);			SAFE_RELEASE(mipFaceSurface);		}// for			V( D3DXSaveTextureToFile( L"mipMap.dds", D3DXIFF_DDS, m_pEnvironmentMipMaps, NULL ) ); 		size *= 2;	}// for

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11
• ### Forum Statistics

• Total Topics
633768
• Total Posts
3013747
×