Example #1
0
        /// <summary>
        /// Loads a texture from a stream.
        /// </summary>
        /// <param name="device">The <see cref="GraphicsDevice" />.</param>
        /// <param name="image">The image.</param>
        /// <param name="textureFlags">True to load the texture with unordered access enabled. Default is false.</param>
        /// <param name="usage">Usage of the resource. Default is <see cref="GraphicsResourceUsage.Immutable" /></param>
        /// <returns>A texture</returns>
        /// <exception cref="System.InvalidOperationException">Dimension not supported</exception>
        public static Texture New(GraphicsDevice device, Image image, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }
            switch (image.Description.Dimension)
            {
            case TextureDimension.Texture1D:
                return(Texture1D.New(device, image, textureFlags, usage));

            case TextureDimension.Texture2D:
                return(Texture2D.New(device, image, textureFlags, usage));

            case TextureDimension.Texture3D:
                return(Texture3D.New(device, image, textureFlags, usage));

            case TextureDimension.TextureCube:
                return(TextureCube.New(device, image, textureFlags, usage));
            }

            throw new InvalidOperationException("Dimension not supported");
        }
Example #2
0
        private void InitializeFromImpl(DataBox[] dataBoxes = null)
        {
            if (ParentTexture != null)
            {
                NativeDeviceChild = ParentTexture.NativeDeviceChild;
            }

            if (NativeDeviceChild == null)
            {
                switch (Dimension)
                {
                case TextureDimension.Texture1D:
                    NativeDeviceChild = new Texture1D(GraphicsDevice.NativeDevice, ConvertToNativeDescription1D(), ConvertDataBoxes(dataBoxes));
                    break;

                case TextureDimension.Texture2D:
                case TextureDimension.TextureCube:
                    NativeDeviceChild = new Texture2D(GraphicsDevice.NativeDevice, ConvertToNativeDescription2D(), ConvertDataBoxes(dataBoxes));
                    break;

                case TextureDimension.Texture3D:
                    NativeDeviceChild = new Texture3D(GraphicsDevice.NativeDevice, ConvertToNativeDescription3D(), ConvertDataBoxes(dataBoxes));
                    break;
                }
            }

            NativeShaderResourceView  = GetShaderResourceView(ViewType, ArraySlice, MipLevel);
            NativeUnorderedAccessView = GetUnorderedAccessView(ViewType, ArraySlice, MipLevel);
            NativeRenderTargetView    = GetRenderTargetView(ViewType, ArraySlice, MipLevel);
            NativeDepthStencilView    = GetDepthStencilView(out HasStencil);
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Texture1DBase" /> class.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="description1D">The description.</param>
 protected internal Texture1D(GraphicsDevice device, Texture1D texture, ViewType viewType, int arraySlice, int mipMapSlice, PixelFormat viewFormat = PixelFormat.None) : base(device, texture, viewType, arraySlice, mipMapSlice, viewFormat)
 {
     // Copy the device child, but don't use NativeDeviceChild, as it is registering it for disposing.
     _nativeDeviceChild        = texture._nativeDeviceChild;
     Resource                  = texture.Resource;
     NativeDescription         = texture.NativeDescription;
     dxgiSurface               = texture.dxgiSurface;
     NativeShaderResourceView  = GetShaderResourceView(ViewType, ArraySlice, MipLevel);
     NativeUnorderedAccessView = GetUnorderedAccessView(ArraySlice, MipLevel);
 }
Example #4
0
 protected internal Texture1D(GraphicsDevice device, Texture1D texture) : base(device, texture, ViewType.Full, 0, 0)
 {
     Target = TextureTarget1D;
 }
Example #5
0
 protected internal Texture1D(GraphicsDevice device, Texture1D texture) : base(device, texture, ViewType.Full, 0, 0)
 {
     Target = TextureTarget1D;
 }