| 1007 | } |
| 1008 | |
| 1009 | void TextureBase::InitData::FromTextureData(const TextureData& textureData, bool generateMips) |
| 1010 | { |
| 1011 | Format = textureData.Format; |
| 1012 | Width = textureData.Width; |
| 1013 | Height = textureData.Height; |
| 1014 | ArraySize = textureData.GetArraySize(); |
| 1015 | if (generateMips) |
| 1016 | Mips.Resize(MipLevelsCount(textureData.Width, textureData.Height)); |
| 1017 | else |
| 1018 | Mips.Resize(textureData.GetMipLevels()); |
| 1019 | |
| 1020 | for (int32 mipIndex = 0; mipIndex < textureData.GetMipLevels(); mipIndex++) |
| 1021 | { |
| 1022 | auto& mip = Mips[mipIndex]; |
| 1023 | auto& data = *textureData.GetData(0, mipIndex); |
| 1024 | mip.Data.Allocate(data.Data.Length() * ArraySize); |
| 1025 | mip.RowPitch = data.RowPitch; |
| 1026 | mip.SlicePitch = data.Data.Length(); |
| 1027 | |
| 1028 | byte* dst = mip.Data.Get(); |
| 1029 | for (int32 arrayIndex = 0; arrayIndex < ArraySize; arrayIndex++) |
| 1030 | { |
| 1031 | auto& d = *textureData.GetData(arrayIndex, mipIndex); |
| 1032 | ASSERT(data.RowPitch == d.RowPitch); |
| 1033 | ASSERT(data.Data.Length() == d.Data.Length()); |
| 1034 | Platform::MemoryCopy(dst, d.Data.Get(), d.Data.Length()); |
| 1035 | dst += data.Data.Length(); |
| 1036 | ASSERT((int32)(dst - mip.Data.Get()) <= mip.Data.Length()); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | if (generateMips) |
| 1041 | { |
| 1042 | for (int32 mipIndex = textureData.GetMipLevels(); mipIndex < Mips.Count(); mipIndex++) |
| 1043 | { |
| 1044 | GenerateMip(mipIndex, true); |
| 1045 | } |
| 1046 | } |
| 1047 | } |
no test coverage detected