This project has moved and is read-only. For the latest updates, please go here.

Does model loaded with Model::CreateFromSDKMESH or Model::CreateFromCMO have mipmaps generated?

Oct 17, 2014 at 10:26 AM
Hello. I started to load models with Model::CreateFromCMO/Model::CreateFromSDKMESH and I can see that there is no ID3D11DeviceContext parameter. Without this parameter textures loaded with these methods will not have mipmaps generated, because as far as I know DirectXTK (opposite to DirectXTex) doesn't have software mipmap generation. Why is it made that way? Wouldn't be better if these methods had optional device context parameter for mipmaps? Without mipmaps loading models is useless, unless I'm missing something. Thanks in advance for any response.
Oct 17, 2014 at 6:37 PM
Edited Oct 17, 2014 at 6:39 PM
The assumption is that if you want your textures on your models to have mipmaps, then you should be using DDS files which have pregenerated mipmaps as is standard practice. The Visual Studio CMO content pipeline will generate mips when converting textures from PNG/JPG/etc. to DDS, and the Samples Content Exporter for SDKMESH files also includes mips for generated DDS files as well.

The DirectXTK texture loaders take an optional context to handle 'auto-gen mipmaps' scenarios. This also makes loading not thread-safe, so I use 'nullptr' for effects loading by default for Model to keep it thread-safe. Keep in mind that 'auto-gen' mipmap quality is highly variable, and subject to the whims of the hardware/driver and a number of format restrictions.

If you had a case where you really had to have auto-gen mipmaps on your models (i.e. maybe you are texturing with generic images supplied by the user), you could create an alterative IEffectFactory interface that does this:
class AutoMipEffectFactory : public EffectFactory
    explicit AutoMipEffectFactory(_In_ ID3D11Device* device, _In_ ID3D11DeviceContext* context) :

    virtual void __cdecl CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override
        // If deviceContext is nullptr, then default to the one we constructed with
        EffectFactory::CreateTexture( name, (deviceContext) ? deviceContext : mDeviceContext.Get(), textureView );

    ComPtr<ID3D11DeviceContext> mDeviceContext;

    // Prevent copying.
    AutoMipEffectFactory AutoMipEffectFactory const&);
    AutoMipEffectFactory operator= AutoMipEffectFactory const&);


AutoMipEffectFactory fx( device, immediateContext );

auto tiny = Model::CreateFromSDKMESH( device, L"tiny.sdkmesh", fx );
Marked as answer by walbourn on 10/17/2014 at 10:38 AM