Game Development Reference
In-Depth Information
The texture address setting determines what happens when the texture coordinates
are close to the border of the texture or are outside of the [0.0, 1.0] range. The choice
made above is for the texture to wrap, so that if a texture coordinate were set to (4.0,
3.0), the texture would repeat four times in the horizontal dimension and three times
in the vertical. You can also choose other settings to mirror the texture, clamp it, set
a specific border color, or even mirror the texture once. These are all defined in the
D3D11_TEXTURE_ADDRESS enum and found in the Direct 3D 11 documentation.
The MinLOD and MaxLOD members define which mip-maps, if they are defined, are
available to the sampler. Typically, you would leave these at the default settings and
have them all available.
Once the loader is defined, you can then access and set the texture with this code:
Resource resource(m_textureResource);
shared_ptr<ResHandle> texture = g_pApp->m_ResCache->GetHandle(&resource);
if (texture)
{
shared_ptr<D3DTextureResourceExtraData11> extra =
static_pointer_cast<D3DTextureResourceExtraData11>(texture->GetExtra());
DXUTGetD3D11DeviceContext()->PSSetShaderResources( 0, 1,
extra->GetTexture());
DXUTGetD3D11DeviceContext()->PSSetSamplers( 0, 1, extra->GetSampler() );
}
Note that the first two parameters to the pixel shader methods define the start slot
(defined above to be zero), and the number of shader resources to set (defined above
as one). This is very specific to how the shader is written; if the shader expected five
textures instead of one, you would load the other four textures and make extra calls
to PSSetShaderResources() . I know, I haven
t said a word yet about what a
shader looks like from the inside, but for now just take my word for it that in addi-
tion to sending texture resources, you
'
'
ll send all the other data we
'
ve been talking
about, including triangle mesh data, which is coming up next.
Triangle Meshes
We
s time to take that knowledge
and create some triangle meshes. You might define a mesh as a long list of vertices,
with each group of three vertices (or verts, as programmers say) defining one triangle.
If you look at the teapot mesh in Figure 14.15 again, you
'
ve been talking so far about individual vertices. It
'
'
ll quickly discover that
you
ll be duplicating a lot of data.
Instead of sending only vertex data to the shader, you can send an index along with
it. This index is an array of numbers that define the verts of each triangle, allowing
'
 
 
Search WWH ::




Custom Search