| 502 | } |
| 503 | |
| 504 | bool Texture::LoadFromImage(const Image& image, bool generateMipmaps) |
| 505 | { |
| 506 | #if NAZARA_RENDERER_SAFE |
| 507 | if (!image.IsValid()) |
| 508 | { |
| 509 | NazaraError("Image must be valid"); |
| 510 | return false; |
| 511 | } |
| 512 | #endif |
| 513 | |
| 514 | // Vive le Copy-On-Write |
| 515 | Image newImage(image); |
| 516 | |
| 517 | PixelFormatType format = newImage.GetFormat(); |
| 518 | if (!IsFormatSupported(format)) |
| 519 | { |
| 520 | ///TODO: Sélectionner le format le plus adapté selon les composantes présentes dans le premier format |
| 521 | PixelFormatType newFormat = (PixelFormat::HasAlpha(format)) ? PixelFormatType_BGRA8 : PixelFormatType_BGR8; |
| 522 | NazaraWarning("Format " + PixelFormat::GetName(format) + " not supported, trying to convert it to " + PixelFormat::GetName(newFormat) + "..."); |
| 523 | |
| 524 | if (PixelFormat::IsConversionSupported(format, newFormat)) |
| 525 | { |
| 526 | if (newImage.Convert(newFormat)) |
| 527 | { |
| 528 | NazaraWarning("Conversion succeed"); |
| 529 | format = newFormat; |
| 530 | } |
| 531 | else |
| 532 | { |
| 533 | NazaraError("Conversion failed"); |
| 534 | return false; |
| 535 | } |
| 536 | } |
| 537 | else |
| 538 | { |
| 539 | NazaraError("Conversion not supported"); |
| 540 | return false; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | ImageType type = newImage.GetType(); |
| 545 | UInt8 levelCount = newImage.GetLevelCount(); |
| 546 | if (!Create(type, format, newImage.GetWidth(), newImage.GetHeight(), newImage.GetDepth(), (generateMipmaps) ? 0xFF : levelCount)) |
| 547 | { |
| 548 | NazaraError("Failed to create texture"); |
| 549 | return false; |
| 550 | } |
| 551 | |
| 552 | CallOnExit destroyOnExit([this]() |
| 553 | { |
| 554 | Destroy(); |
| 555 | }); |
| 556 | |
| 557 | if (type == ImageType_Cubemap) |
| 558 | { |
| 559 | for (UInt8 level = 0; level < levelCount; ++level) |
| 560 | { |
| 561 | for (unsigned int i = 0; i <= CubemapFace_Max; ++i) |
nothing calls this directly
no test coverage detected