Exemple #1
0
        public static Task <Texture2D> RawToTexture2DAsync(GraphicsDevice graphicsDevice, BinaryReader r)
        {
            var rawData = ReadRaw(r);

            return(GLCallLocker.InvokeAsync(() => {
                var tex = new Texture2D(graphicsDevice, rawData.Item1, rawData.Item2);
                tex.SetData(rawData.Item3);
                return tex;
            }));
        }
Exemple #2
0
        public static Task <Texture2D> PngToTexture2DAsync(GraphicsDevice graphicsDevice, Stream stream)
        {
#if XNA
            if (!(stream is MemoryStream))
            {
                var ms = new MemoryStream((int)stream.Length);
                stream.CopyTo(ms);
                ms.Position = 0;
                stream      = ms;
            }
            return(GLCallLocker.InvokeAsync(() => Texture2D.FromStream(graphicsDevice, stream)));
#else
            Texture2D.TextureDataFromStreamEXT(stream, out int width, out int height, out byte[] rawdata, -1, -1, false);
            return(GLCallLocker.InvokeAsync(() => {
                var tex = new Texture2D(graphicsDevice, width, height);
                tex.SetData(rawdata);
                return tex;
            }));
#endif
        }