Exemple #1
0
        /// <summary>
        /// Adds the provided texture to the current manager
        /// </summary>
        /// <param name="texture">The tiled texture that needs to be managed</param>
        /// <param name="filePath">The filepath from where to load the texture data</param>
        /// <returns>The shader resource view for the created residency texture</returns>
        public SharpDX.Toolkit.Graphics.Texture2DBase ManageTexture(SharpDX.Toolkit.Graphics.TextureCube texture, string filePath)
        {
            // assume the diffuse texture has the BC1_Unorm format - store a path to it
            if (texture.Description.Format == Format.BC1_UNorm)
            {
                _diffuseFilepath = filePath;
            }

            var resource = new ManagedTiledResource {
                Texture = texture
            };

            var subresourceTilings = texture.Description.MipLevels * texture.Description.ArraySize;

            resource.SubresourceTilings = new SharpDX.Direct3D11.SubResourceTiling[subresourceTilings];

            var device2 = _graphicsDeviceManager.GetDevice2();

            device2.GetResourceTiling(texture,
                                      out resource.TotalTiles,
                                      out resource.PackedMipDescription,
                                      out resource.TileShape,
                                      ref subresourceTilings,
                                      0,
                                      resource.SubresourceTilings);

            if (subresourceTilings != texture.Description.MipLevels * texture.Description.ArraySize)
            {
                throw new ApplicationException("Unexpected value - subresourceTilings has changed");
            }

            resource.Loader = new TileLoader(filePath, resource.SubresourceTilings, false);

            var device = _graphicsDeviceManager.GraphicsDevice;

            var tiling = resource.SubresourceTilings[0];

            var size = Math.Max(tiling.WidthInTiles, tiling.HeightInTiles);

            var description = new SharpDX.Direct3D11.Texture2DDescription
            {
                Width             = size,
                Height            = size,
                MipLevels         = 1,
                ArraySize         = 6,
                BindFlags         = SharpDX.Direct3D11.BindFlags.ShaderResource,
                Format            = Format.R8_UNorm,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = SharpDX.Direct3D11.ResourceUsage.Default,
                OptionFlags       = SharpDX.Direct3D11.ResourceOptionFlags.TextureCube
            };

            resource.ResidencyTexture = ToDispose(SharpDX.Toolkit.Graphics.Texture2D.New(device, description));

            for (var face = 0; face < 6; face++)
            {
                resource.Residency[face] = new byte[tiling.WidthInTiles * tiling.HeightInTiles];
                Set(resource.Residency[face], (byte)0xff);
            }

            _managedTiledResources.Add(resource);

            return(resource.ResidencyTexture);
        }
Exemple #2
0
 /// <summary>
 /// Gets an instance of the DirectX 11.2 device context
 /// </summary>
 /// <param name="manager">The current GraphicsDeviceManager</param>
 /// <returns>DirectX 11.2 DeviceContext instance</returns>
 public static DeviceContext2 GetContext2(this GraphicsDeviceManager manager)
 {
     return(manager.GetDevice2().ImmediateContext2);
 }