void RenderingDevice::SetMaterial(const Material &material) { SetRasterizerState(material.GetRasterizerState()); SetBlendState(material.GetBlendState()); SetDepthStencilState(material.GetDepthStencilState()); for (size_t i = 0; i < material.GetSamplers().size(); ++i) { auto& sampler = material.GetSamplers()[i]; if (sampler.GetTexture()) { D3DLOG(mDevice->SetTexture(i, sampler.GetTexture()->GetDeviceTexture())); } else { D3DLOG(mDevice->SetTexture(i, nullptr)); } SetSamplerState(i, sampler.GetState()); } // Free up the texture bindings of the samplers currently being used for (size_t i = material.GetSamplers().size(); i < mUsedSamplers; ++i) { D3DLOG(mDevice->SetTexture(i, nullptr)); } mUsedSamplers = material.GetSamplers().size(); material.GetVertexShader()->Bind(); material.GetPixelShader()->Bind(); }