Exemple #1
0
        public ShaderResourceView LoadTexture(ITexture tex)
        {
            TextureInfo ret;

            if (!cache.TryGetValue(tex, out ret))
            {
                var data = tex.GetCoreData();
                //var p =TextureCreationParameters.Default;

                Texture2D tx;

                switch (data.StorageType)
                {
                case TextureCoreData.TextureStorageType.Disk:
                    //ret = Texture2D.FromFile(game.GraphicsDevice, data.DiskFilePath,p);
                    tx = Texture2D.FromFile(game.Device, data.DiskFilePath);
                    break;

                case TextureCoreData.TextureStorageType.Assembly:
                    //ret = Texture2D.FromFile(game.GraphicsDevice,
                    //                         EmbeddedFile.GetStream(data.Assembly, data.AssemblyResourceName, null),p);
                    using (var strm = EmbeddedFile.GetStream(data.Assembly, data.AssemblyResourceName, null))
                        tx = Texture2D.FromStream(game.Device, strm, (int)strm.Length);

                    break;

                default:
                    throw new InvalidOperationException();
                }

                ret = new TextureInfo
                {
                    Texture2D    = tx,
                    ResourceView = new ShaderResourceView(game.Device, tx)
                };

                cache[tex] = ret;
            }
            return(ret.ResourceView);
        }
        public Texture2D LoadTexture(ITexture tex)
        {
            Texture2D ret;

            if (!cache.TryGetValue(tex, out ret))
            {
                var data = tex.GetCoreData();
                var p    = TextureCreationParameters.Default;

                switch (data.StorageType)
                {
                case TextureCoreData.TextureStorageType.Disk:
                    ret = Texture2D.FromFile(game.GraphicsDevice, data.DiskFilePath, p);
                    break;

                case TextureCoreData.TextureStorageType.Assembly:
                    ret = Texture2D.FromFile(game.GraphicsDevice,
                                             EmbeddedFile.GetStream(data.Assembly, data.AssemblyResourceName, null), p);
                    break;
                }
                cache[tex] = ret;
            }
            return(ret);
        }