This is a helper object primarily used by the Model loader implementations to provide sharing of material instances of Effects and textures. This can be used standalone as well, and allows access to any existing ‘materials’ definitions already created.
It uses a simple case-sensitive string-based (wide-character) map for finding effect and texture instances that have already been created by the factory, which avoid duplication of texture and effect resources in complex models and scenes.
Note: The EffectFactory is declared in the Effects.h header.
For exception safety, it is recommended you make use of the C++ RAII pattern and use a std::uniqueptr or std::sharedptr
Note: On the Windows phone 8 platform, WIC is not supported or used. Only DDS textures are supported on this platform.
It uses a simple case-sensitive string-based (wide-character) map for finding effect and texture instances that have already been created by the factory, which avoid duplication of texture and effect resources in complex models and scenes.
Note: The EffectFactory is declared in the Effects.h header.
Initialization
The EffectFactory constructor requires a Direct3D 11 device.
std::unique_ptr<EffectFactory> fxFactory( new EffectFactory( device ) )
Creating effects
Fill out the EffectInfo structure, then call CreateEffect to obtain an Effects instance. If the EffectIfo.name string is provided then any already created effect from the factory that has the same name will be returned as a shared instance rather than a new instance created. If there is a name match, then all the other parameters in the EffectInfo are ignored. Otherwise a new effect is created from the provided EffectInfo parameters, and CreateTexture is called automatically if the EffectInfo.texture string is provided. Remember that the use of a texture or perVertexColor will result in a varying the input layout requirements for the resulting Effect.EffectFactory::EffectInfo info; info.name = L”default”; info.alpha = 1.f; info.ambientColor = XMFLOAT3( 0.2f, 0.2f, 0.2f); info.diffuseColor = XMFLOAT3( 0.8f, 0.8f, 0.8f ); auto effect = fxFactory->CreateEffect( info, deviceContext );
Creating textures
CreateTexture assumes the name given is the filename of the texture to load. If the name string provided matches an already returned texture from the factory, then the existing shader resource view is returned rather than a new texture instance being created. If the name contains the extension “.dds”, then DDSTextureLoader is used to create the texture and return the shader resource view, otherwise it will attempt to use WICTextureLoader. The device context is not used by the DDSTextureLoader, only by the WICTextureLoader or can be null to skip auto-gen of mipmaps.
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv;
fxFactory->CreateTexture( L”stone.dds”, nullptr, &srv );