public void Initialize(DeviceContextHolder holder) {
const Format format = Format.R16G16B16A16_Float;
using (var cubeTex = new Texture2D(holder.Device, new Texture2DDescription {
Width = _cubeMapSize,
Height = _cubeMapSize,
MipLevels = 2,
ArraySize = 6,
SampleDescription = new SampleDescription(1, 0),
Format = format,
Usage = ResourceUsage.Default,
BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.GenerateMipMaps | ResourceOptionFlags.TextureCube
})) {
_targetView = Enumerable.Range(0, 6).Select(x => new RenderTargetView(holder.Device, cubeTex,
new RenderTargetViewDescription {
Format = format,
Dimension =
RenderTargetViewDimension
.Texture2DArray,
ArraySize = 1,
FirstArraySlice = x,
MipSlice = 0
})).ToArray();
_view = new ShaderResourceView(holder.Device, cubeTex, new ShaderResourceViewDescription {
Format = format,
Dimension = ShaderResourceViewDimension.TextureCube,
MostDetailedMip = 0,
MipLevels = -1
});
}
const Format depthFormat = Format.D32_Float;
using (var depthTex = new Texture2D(holder.Device, new Texture2DDescription {
Width = _cubeMapSize,
Height = _cubeMapSize,
MipLevels = 1,
ArraySize = 1,
SampleDescription = new SampleDescription(1, 0),
Format = depthFormat,
Usage = ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
})) {
_depthTargetView = new DepthStencilView(holder.Device, depthTex, new DepthStencilViewDescription {
Format = depthFormat,
Flags = DepthStencilViewFlags.None,
Dimension = DepthStencilViewDimension.Texture2D,
MipSlice = 0,
});
}
}