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); } }