Graphics Reference
In-Depth Information
14. Create an override for
DynamicCubeMap.CreateDeviceDependentResources
with the following code to reset the resources and to retrieve the device reference:
RemoveAndDispose(ref EnvMap);
RemoveAndDispose(ref EnvMapSRV);
RemoveAndDispose(ref EnvMapRTV);
RemoveAndDispose(ref EnvMapDSV);
RemoveAndDispose(ref PerEnvMapBuffer);
var device = this.DeviceManager.Direct3DDevice;
15. Within the same function, we will first initialize our
texture
array resource. The two
important properties that define a resource compatible with the
TextureCube
HLSL
shader resource are highlighted in the following code snippet:
// Create the cube map TextureCube (array of 6 textures)
var textureDesc = new Texture2DDescription()
{
Format = Format.R8G8B8A8_UNorm,
Height = this.Size,
Width = this.Size,
ArraySize = 6
, // 6-sides of the cube
BindFlags = BindFlags.ShaderResource |
BindFlags.RenderTarget,
OptionFlags =
ResourceOptionFlags.GenerateMipMaps |
ResourceOptionFlags.TextureCube
,
SampleDescription = new SampleDescription(1, 0),
MipLevels = 0,
Usage = ResourceUsage.Default,
CpuAccessFlags = CpuAccessFlags.None,
};
EnvMap
= ToDispose(new Texture2D(device, textureDesc));
16. Next, we will define the Shader Resource View (SRV) for the previous resource.
// Create the SRV for the texture cube
var descSRV = new ShaderResourceViewDescription();
descSRV.Format = textureDesc.Format;
descSRV.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.
TextureCube;
descSRV.TextureCube.MostDetailedMip = 0;
descSRV.TextureCube.MipLevels = -1;
EnvMapSRV
= ToDispose(new ShaderResourceView(device, EnvMap,
descSRV));