AutoGenerateMipMap

Started by
4 comments, last by sune 18 years ago
Hello, I need to render to a texture and have that texture automatically generate the miplevels using AutoGenerateMipMap. I can create the texture just fine using the code below (I´ve checked both with Manager.CheckDeviceFormat and DXCaps to see that this feature is supported, which it is). tex = new Texture(device, vp.Width, vp.Height, 0, Usage.RenderTarget | Usage.AutoGenerateMipMap, Format.A32B32G32R32F, Pool.Default); photexmipmap.AutoGenerateFilterType = TextureFilter.Linear; If i follow up the creation with a call to tex .GenerateMipSubLevels(); i would expect the levels to be created, but the LevelCount of the texture is the same. The same is the case after i´ve rendered to the texture using a RenderToSurface object. Does anyone know what is going on ? (Are the mip levels only available in the shader) ?
Advertisement
Yes, the mipmaps are only created in the videoram and you have no access to them from the CPU. But from the shader size the behave like a texture with mipmaps down to the 1*1 texel level.

According to the DX SDK the autogenerated mipmaps are invisible and non-accessible to the application. The drivers decides when it needs the mipmaps and then generates them.

There is a function IDirect3DBaseTexture9::GenerateMipSubLevels to hint the driver when the mipmap should be generated.

A follow up question, the mip levels are now generated and ready (i have to assmume).

I give them to the shader :
texture.GenerateMipSubLevels();
effect.SetValue("tex", texture);

In the shader I have these bits :
Texture tex;
sampler MipMapSampler = sampler_state{ texture = <tex>; minfilter = linear; magfilter = linear; mipfilter = linear; };
testvalue = 0.5;
float4 lodcoords = float4(0,0,0,testvalue);
lodcoords.xy = tcoords.xy;

outColor = tex2Dlod(MipMapSampler,lodcoords);

The problem is that no matter how i vary the testvalue i get the same result (i assume that it is in the interval [0,1] since its in a float).
Does anyone know how to use tex2Dlod properly ?
Hello again,

I did a little test, using a loaded texture with mip levels (in all the colors of the rainbow :D) generated using DxTex, and it seems that the lod value in tex2Dlod (lodCoords.w) is not restricted to [0,1], but rather
.w = 0.0 , level 0
.w = 1.0 , level 1
.w = 2.0 , level 2
and so forth.

But even with this knowledge it does not seem to produce different results in if i use, .w=1.0 to .w=10.0
Ok, i found my problem and will put it here if it will help others. It seems that I am using Manager.CheckDeviceFormat incorrectly :

Manager.CheckDeviceFormat(0, device.DeviceCaps.DeviceType, device.PresentationParameters.BackBufferFormat, Usage.RenderTarget | Usage.AutoGenerateMipMap, ResourceType.Textures,Format.A32B32G32R32F);

This call returns true, when in fact Format.A32B32G32R32F cannot be using with Usage.AutoGenerateMipMap, which I verified by using DXCapsViewer by going to the Texture Formats under the correct Adapter Format for a HAL device. I dont know why it gives me true, i really have no clue.
However Format.A8R8G8B8 generates the desired mip levels, which is confirmed by CheckDeviceFormat.

Note. beware of the A8B8G8R8 format, this is not the same as A8R8G8B8. :)

This topic is closed to new replies.

Advertisement