| 397 | } |
| 398 | |
| 399 | bool TextureBase::GetTextureMipData(TextureMipData& result, int32 mipIndex, int32 arrayIndex, bool copyData) |
| 400 | { |
| 401 | PROFILE_CPU_NAMED("Texture.GetTextureMipData"); |
| 402 | if (!IsVirtual() && WaitForLoaded()) |
| 403 | { |
| 404 | LOG(Error, "Asset load failed."); |
| 405 | return true; |
| 406 | } |
| 407 | if (mipIndex < 0 || mipIndex > GetMipLevels() || arrayIndex < 0 || arrayIndex > GetArraySize()) |
| 408 | { |
| 409 | Log::ArgumentOutOfRangeException(); |
| 410 | return true; |
| 411 | } |
| 412 | |
| 413 | // Get raw texture data |
| 414 | int32 rowPitch, slicePitch; |
| 415 | BytesContainer mipData = GetMipData(mipIndex, rowPitch, slicePitch); |
| 416 | if (mipData.IsInvalid()) |
| 417 | { |
| 418 | LOG(Error, "Failed to get texture mip data."); |
| 419 | return true; |
| 420 | } |
| 421 | if (mipData.Length() != slicePitch * _texture.TotalArraySize()) |
| 422 | { |
| 423 | LOG(Error, "Invalid custom texture data (slice pitch * array size is different than data bytes count)."); |
| 424 | return true; |
| 425 | } |
| 426 | |
| 427 | // Fill result |
| 428 | result.RowPitch = rowPitch; |
| 429 | result.DepthPitch = slicePitch; |
| 430 | result.Lines = Math::Max(1, Height() >> mipIndex); |
| 431 | if (copyData) |
| 432 | result.Data.Copy(mipData.Get() + (arrayIndex * slicePitch), slicePitch); |
| 433 | else |
| 434 | result.Data.Link(mipData.Get() + (arrayIndex * slicePitch), slicePitch); |
| 435 | return false; |
| 436 | } |
| 437 | |
| 438 | bool TextureBase::GetPixels(Array<Color32>& pixels, int32 mipIndex, int32 arrayIndex) |
| 439 | { |