| 602 | #if USE_EDITOR |
| 603 | |
| 604 | bool TextureTool::WriteTextureData(BytesContainer& result, const TextureData& textureData, int32 mipIndex) |
| 605 | { |
| 606 | if (textureData.Format == PixelFormat::Basis) |
| 607 | { |
| 608 | // Store as-is, each slice is stored in a separate block with the same size |
| 609 | int32 maxDataSize = 0; |
| 610 | for (int32 arrayIndex = 0; arrayIndex < textureData.Items.Count(); arrayIndex++) |
| 611 | { |
| 612 | auto& mipData = textureData.Items[arrayIndex].Mips[mipIndex]; |
| 613 | maxDataSize = Math::Max(maxDataSize, mipData.Data.Length()); |
| 614 | } |
| 615 | result.Allocate(maxDataSize * textureData.GetArraySize()); |
| 616 | for (int32 arrayIndex = 0; arrayIndex < textureData.Items.Count(); arrayIndex++) |
| 617 | { |
| 618 | auto& mipData = textureData.Items[arrayIndex].Mips[mipIndex]; |
| 619 | byte* dst = result.Get() + maxDataSize * arrayIndex; |
| 620 | Platform::MemoryCopy(dst, mipData.Data.Get(), mipData.Data.Length()); |
| 621 | Platform::MemoryClear(dst + mipData.Data.Length(), maxDataSize - mipData.Data.Length()); |
| 622 | } |
| 623 | return false; |
| 624 | } |
| 625 | |
| 626 | // Calculate the texture data storage layout |
| 627 | uint32 rowPitch, slicePitch; |
| 628 | const int32 mipWidth = Math::Max(1, textureData.Width >> mipIndex); |
| 629 | const int32 mipHeight = Math::Max(1, textureData.Height >> mipIndex); |
| 630 | RenderTools::ComputePitch(textureData.Format, mipWidth, mipHeight, rowPitch, slicePitch); |
| 631 | result.Allocate(slicePitch * textureData.GetArraySize()); |
| 632 | |
| 633 | // Copy array slices into mip data (sequential) |
| 634 | for (int32 arrayIndex = 0; arrayIndex < textureData.Items.Count(); arrayIndex++) |
| 635 | { |
| 636 | auto& mipData = textureData.Items[arrayIndex].Mips[mipIndex]; |
| 637 | const byte* src = mipData.Data.Get(); |
| 638 | byte* dst = result.Get() + (slicePitch * arrayIndex); |
| 639 | |
| 640 | // Faster path if source and destination data layout matches |
| 641 | if (rowPitch == mipData.RowPitch && slicePitch == mipData.DepthPitch) |
| 642 | { |
| 643 | Platform::MemoryCopy(dst, src, slicePitch); |
| 644 | } |
| 645 | else |
| 646 | { |
| 647 | const uint32 copyRowSize = Math::Min(mipData.RowPitch, rowPitch); |
| 648 | for (uint32 line = 0; line < mipData.Lines; line++) |
| 649 | { |
| 650 | Platform::MemoryCopy(dst, src, copyRowSize); |
| 651 | src += mipData.RowPitch; |
| 652 | dst += rowPitch; |
| 653 | } |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | return false; |
| 658 | } |
| 659 | |
| 660 | #endif |
| 661 |
nothing calls this directly
no test coverage detected