Ejemplo n.º 1
0
        /// <summary>
        /// Loads a 2D texture from a stream.
        /// </summary>
        /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
        /// <param name="stream">The stream to load the texture from.</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>
        /// <exception cref="ArgumentException">If the texture is not of type 2D</exception>
        /// <returns>A texture</returns>
        public static new Texture2D Load(GraphicsDevice device, Stream stream, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable)
        {
            var texture = Texture.Load(device, stream, textureFlags, usage);

            if (!(texture is Texture2D))
            {
                throw new ArgumentException(string.Format("Texture is not type of [Texture2D] but [{0}]", texture.GetType().Name));
            }
            return((Texture2D)texture);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads a Cube texture from a stream.
        /// </summary>
        /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
        /// <param name="stream">The stream to load the texture from.</param>
        /// <param name="isUnorderedReadWrite">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>
        /// <exception cref="ArgumentException">If the texture is not of type Cube</exception>
        /// <returns>A texture</returns>
        public static TextureCube Load(GraphicsDevice device, Stream stream, bool isUnorderedReadWrite = false, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable)
        {
            var texture = Texture.Load(device, stream, TextureFlags.ShaderResource, usage);

            if (!(texture is TextureCube))
            {
                throw new ArgumentException(string.Format("Texture is not type of [TextureCube] but [{0}]", texture.GetType().Name));
            }
            return((TextureCube)texture);
        }