Game Development Reference
In-Depth Information
m_pcbPSMaterial, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource ) );
ConstantBuffer_Material* pPSMaterial =
( ConstantBuffer_Material* )MappedResource.pData;
Color color = pNode->VGet()->GetMaterial().GetDiffuse();
pPSMaterial->m_vDiffuseObjectColor = Vec4(color.r, color.g,
color.b, color.a);
if (m_textureResource.length() > 0)
pPSMaterial->m_bHasTexture = true;
else
pPSMaterial->m_bHasTexture = false;
DXUTGetD3D11DeviceContext()->Unmap( m_pcbPSMaterial, 0 );
DXUTGetD3D11DeviceContext()->PSSetConstantBuffers(
0, 1, &m_pcbPSMaterial );
// Set up the texture
SetTexture(m_textureResource);
return S_OK;
}
The last methods are utility methods for setting the texture, either from a texture
name that must be loaded from the resource cache, or a texture that is already
loaded:
HRESULT GameCode4_Hlsl_PixelShader::SetTexture(std::string textureName)
{
m_textureResource = textureName;
if (m_textureResource.length() > 0 )
{
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());
SetTexture(extra->GetTexture(), extra->GetSampler());
}
}
return S_OK;
}
HRESULT GameCode4_Hlsl_PixelShader::SetTexture(
ID3D11ShaderResourceView* const *pDiffuseRV,
ID3D11SamplerState * const *ppSamplers)
{
Search WWH ::




Custom Search