Game Development Reference
In-Depth Information
{
shared_ptr<D3DTextureResourceExtraData11> extra =
shared_ptr<D3DTextureResourceExtraData11>(
GCC_NEW D3DTextureResourceExtraData11());
// Load the Texture
if ( FAILED ( D3DX11CreateShaderResourceViewFromMemory(
DXUTGetD3D11Device(), rawBuffer, rawSize, NULL, NULL,
&extra->m_pTexture, NULL ) ) )
return false;
// Create the sample state
D3D11_SAMPLER_DESC sampDesc;
ZeroMemory( &sampDesc, sizeof(sampDesc) );
sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
sampDesc.MinLOD = 0;
sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
if( FAILED( DXUTGetD3D11Device()->CreateSamplerState( &sampDesc,
&extra->m_pSamplerLinear ) ) )
return false;
handle->SetExtra(shared_ptr<D3DTextureResourceExtraData11>(extra));
return true;
}
This method makes two calls to Direct3D 11 utility functions. The first,
D3DX11CreateShaderResourceViewFromMemory , fills the shader resource view
interface with the texture data. Next, the sampler state is created by filling a
D3D11_SAMPLER_DESC structure with a description of the kind of sampler needed
and calling ID3D11Device::CreateSamplerState() . The filter parameter,
D3D11_FILTER_MIN_MAG_MIP_LINEAR , requests a sampler that will use linear
interpolation for minimization, magnification, and mip-level sampling; this is a
good choice to avoid subsampling issues. Minimization is what happens when the
texture is rendered so far away as to only take up a single pixel. Magnification is
what happens when the texture is so close that a single texel fills the entire screen.
There are almost two dozen other filter types in Direct3D 11, so it makes for a
great experiment to change this value and see what results. Some of the filters have
the ability to use multiple sampling methods, compare the results, and then choose
one over the other; that is why you would choose to set the ComparisonFunc mem-
ber of the structure. For this simple filter, we
'
ll leave it at the default setting.
Search WWH ::




Custom Search