private void ClearTargets(RenderTargetBinding[] targets, SharpDX.Direct3D11.CommonShaderStage shaderStage) { // NOTE: We make the assumption here that the caller has // locked the d3dContext for us to use. // We assume 4 targets to avoid a loop within a loop below. var target0 = targets[0].RenderTarget; var target1 = targets[1].RenderTarget; var target2 = targets[2].RenderTarget; var target3 = targets[3].RenderTarget; // Make one pass across all the texture slots. for (var i = 0; i < _textures.Length; i++) { if (_textures[i] == null) continue; if (_textures[i] != target0 && _textures[i] != target1 && _textures[i] != target2 && _textures[i] != target3) continue; // Immediately clear the texture from the device. _dirty &= ~(1 << i); _textures[i] = null; shaderStage.SetShaderResource(i, null); } }