| 57 | } |
| 58 | |
| 59 | ExportAssetResult AssetExporters::ExportCubeTexture(ExportAssetContext& context) |
| 60 | { |
| 61 | // Prepare |
| 62 | auto asset = (CubeTexture*)context.Asset.Get(); |
| 63 | auto lock = asset->Storage->LockSafe(); |
| 64 | auto path = GET_OUTPUT_PATH(context, "dds"); |
| 65 | |
| 66 | // Load the asset data |
| 67 | if (asset->LoadChunks(ALL_ASSET_CHUNKS)) |
| 68 | return ExportAssetResult::CannotLoadData; |
| 69 | |
| 70 | // Peek image description |
| 71 | const auto format = asset->Format(); |
| 72 | const int32 width = asset->Width(); |
| 73 | const int32 height = asset->Height(); |
| 74 | const int32 mipLevels = asset->StreamingTexture()->TotalMipLevels(); |
| 75 | const int32 arraySize = 6; |
| 76 | |
| 77 | // Setup texture data |
| 78 | TextureData textureData; |
| 79 | textureData.Width = width; |
| 80 | textureData.Height = height; |
| 81 | textureData.Depth = 1; |
| 82 | textureData.Format = format; |
| 83 | textureData.Items.Resize(arraySize); |
| 84 | for (int32 arrayIndex = 0; arrayIndex < 6; arrayIndex++) |
| 85 | { |
| 86 | auto& item = textureData.Items[arrayIndex]; |
| 87 | item.Mips.Resize(mipLevels); |
| 88 | for (int32 mipIndex = 0; mipIndex < mipLevels; mipIndex++) |
| 89 | { |
| 90 | auto& mip = item.Mips[mipIndex]; |
| 91 | |
| 92 | const int32 mipWidth = Math::Max(1, width >> mipIndex); |
| 93 | const int32 mipHeight = Math::Max(1, height >> mipIndex); |
| 94 | uint32 rowPitch, slicePitch; |
| 95 | RenderTools::ComputePitch(format, mipWidth, mipHeight, rowPitch, slicePitch); |
| 96 | |
| 97 | mip.RowPitch = rowPitch; |
| 98 | mip.DepthPitch = slicePitch; |
| 99 | mip.Lines = mipHeight; |
| 100 | |
| 101 | BytesContainer wholeMipData; |
| 102 | asset->GetMipData(mipIndex, wholeMipData); |
| 103 | if (wholeMipData.IsInvalid()) |
| 104 | return ExportAssetResult::Error; |
| 105 | |
| 106 | mip.Data.Link(wholeMipData.Get() + slicePitch * arrayIndex, slicePitch); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | // Export to file |
| 111 | if (TextureTool::ExportTexture(path, textureData)) |
| 112 | { |
| 113 | return ExportAssetResult::Error; |
| 114 | } |
| 115 | |
| 116 | return ExportAssetResult::Ok; |
nothing calls this directly
no test coverage detected