private void SaveMultipleLevel(ExportModel info, TextureArray2D texture) { Debug.Assert(info.TexFormat.Format.HasGliFormat); var numLayer = info.Layer == -1 ? models.Images.NumLayers : 1; var numLevels = info.Mipmap == -1 ? models.Images.NumMipmaps : 1; var supportCropping = numLevels == 1; var width = info.GetCropWidth(); var height = info.GetCropHeight(); if (!info.UseCropping && numLevels == 1) { // set full width and height width = models.Images.GetWidth(info.Mipmap); height = models.Images.GetHeight(info.Mipmap); } Debug.Assert(width > 0); Debug.Assert(height > 0); if (!supportCropping) { width = models.Images.Width; height = models.Images.Height; } // allocate ImageLoader.CreateStorage(info.TexFormat.Format.GliFormat, width, height, numLayer, numLevels); // store data for (var layerIdx = 0; layerIdx < numLayer; ++layerIdx) { for (var levelIdx = 0; levelIdx < numLevels; ++levelIdx) { ImageLoader.GetLevelSize(levelIdx, out var bufSize); var data = texture.GetData( numLayer == 1 ? info.Layer : layerIdx, numLevels == 1 ? info.Mipmap : levelIdx, info.TexFormat.Format, info.UseCropping && supportCropping, info.CropStartX, info.CropStartY, ref width, ref height, models.GlData.ExportShader, (int)bufSize); ImageLoader.StoreLevel(layerIdx, levelIdx, data, (UInt64)data.Length); } } // save texture if (info.FileType == ExportModel.FileFormat.Ktx) { ImageLoader.SaveKtx(info.Filename); } else if (info.FileType == ExportModel.FileFormat.Ktx2) { ImageLoader.SaveKtx2(info.Filename); } else if (info.FileType == ExportModel.FileFormat.Dds) { ImageLoader.SaveDDS(info.Filename); } }
private void SaveSingleLevel(ExportModel info, TextureArray2D texture) { var width = info.GetCropWidth(); var height = info.GetCropHeight(); Debug.Assert(width > 0); Debug.Assert(height > 0); var data = texture.GetData(info.Layer, info.Mipmap, info.TexFormat.Format, info.UseCropping, info.CropStartX, info.CropStartY, ref width, ref height, models.GlData.ExportShader); if (data == null) { throw new Exception("error retrieving image from gpu"); } var numComponents = 0; numComponents = TextureArray2D.GetPixelFormatCount(info.TexFormat.Format.Format); switch (info.FileType) { case ExportModel.FileFormat.Png: ImageLoader.SavePng(info.Filename, width, height, numComponents, data); break; case ExportModel.FileFormat.Bmp: ImageLoader.SaveBmp(info.Filename, width, height, numComponents, data); break; case ExportModel.FileFormat.Hdr: ImageLoader.SaveHdr(info.Filename, width, height, numComponents, data); break; case ExportModel.FileFormat.Pfm: ImageLoader.SavePfm(info.Filename, width, height, numComponents, data); break; case ExportModel.FileFormat.Jpg: ImageLoader.SaveJpg(info.Filename, width, height, numComponents, data, info.Quality); break; } }