| 472 | } |
| 473 | |
| 474 | CreateAssetResult ImportTexture::ImportIES(class CreateAssetContext& context) |
| 475 | { |
| 476 | // Base |
| 477 | IMPORT_SETUP(IESProfile, 4); |
| 478 | |
| 479 | // Load file |
| 480 | Array<byte> fileData; |
| 481 | if (File::ReadAllBytes(context.InputPath, fileData)) |
| 482 | { |
| 483 | return CreateAssetResult::InvalidPath; |
| 484 | } |
| 485 | fileData.Add('\0'); |
| 486 | |
| 487 | // Load IES profile data |
| 488 | ::ImportIES loader; |
| 489 | if (loader.Load(fileData.Get())) |
| 490 | { |
| 491 | return CreateAssetResult::Error; |
| 492 | } |
| 493 | |
| 494 | // Extract texture data |
| 495 | Array<byte> rawData; |
| 496 | const float multiplier = loader.ExtractInR16(rawData); |
| 497 | |
| 498 | // Fill texture header |
| 499 | TextureHeader textureHeader; |
| 500 | textureHeader.Width = loader.GetWidth(); |
| 501 | textureHeader.Height = loader.GetHeight(); |
| 502 | textureHeader.MipLevels = 1; |
| 503 | textureHeader.Type = TextureFormatType::Unknown; |
| 504 | textureHeader.Format = PixelFormat::R16_Float; |
| 505 | auto data = (IESProfile::CustomDataLayout*)textureHeader.CustomData; |
| 506 | static_assert(sizeof(IESProfile::CustomDataLayout) <= sizeof(textureHeader.CustomData), "Invalid Custom Data size in Texture Header."); |
| 507 | data->Brightness = loader.GetBrightness(); |
| 508 | data->TextureMultiplier = multiplier; |
| 509 | ASSERT(textureHeader.MipLevels <= GPU_MAX_TEXTURE_MIP_LEVELS); |
| 510 | context.Data.CustomData.Copy(&textureHeader); |
| 511 | |
| 512 | // Set mip |
| 513 | if (context.AllocateChunk(0)) |
| 514 | return CreateAssetResult::CannotAllocateChunk; |
| 515 | context.Data.Header.Chunks[0]->Data.Copy(rawData); |
| 516 | |
| 517 | return CreateAssetResult::Ok; |
| 518 | } |
| 519 | |
| 520 | #endif |
nothing calls this directly
no test coverage detected