MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / SetPixels

Method SetPixels

Source/Engine/Graphics/Textures/TextureBase.cpp:471–558  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

469}
470
471bool TextureBase::SetPixels(const Span<Color32>& pixels, int32 mipIndex, int32 arrayIndex, bool generateMips)
472{
473 PROFILE_CPU_NAMED("Texture.SetPixels");
474 if (!IsVirtual())
475 {
476 LOG(Error, "Texture must be virtual.");
477 return true;
478 }
479 ScopeLock lock(Locker);
480 if (_customData == nullptr || Width() == 0)
481 {
482 LOG(Error, "Texture must be initialized.");
483 return true;
484 }
485 const PixelFormat format = Format();
486 const int32 width = Math::Max(1, Width() >> mipIndex);
487 const int32 height = Math::Max(1, Height() >> mipIndex);
488 auto& mipData = _customData->Mips[mipIndex];
489 const int32 rowPitch = mipData.RowPitch;
490 const int32 sliceSize = mipData.SlicePitch;
491 if (pixels.Length() != width * height)
492 {
493 Log::ArgumentOutOfRangeException();
494 return true;
495 }
496
497 // Convert pixels to the texture format
498 ASSERT(mipData.Data.IsAllocated());
499 byte* dst = mipData.Data.Get() + sliceSize * arrayIndex;
500 bool error = true;
501 switch (format)
502 {
503 case PixelFormat::R8G8B8A8_SInt:
504 case PixelFormat::R8G8B8A8_Typeless:
505 case PixelFormat::R8G8B8A8_SNorm:
506 case PixelFormat::R8G8B8A8_UInt:
507 case PixelFormat::R8G8B8A8_UNorm:
508 case PixelFormat::R8G8B8A8_UNorm_sRGB:
509 case PixelFormat::R8G8_B8G8_UNorm:
510 case PixelFormat::B8G8R8A8_Typeless:
511 case PixelFormat::B8G8R8A8_UNorm:
512 case PixelFormat::B8G8R8A8_UNorm_sRGB:
513 case PixelFormat::B8G8R8X8_Typeless:
514 case PixelFormat::B8G8R8X8_UNorm:
515 case PixelFormat::B8G8R8X8_UNorm_sRGB:
516 if (rowPitch == width * sizeof(Color32))
517 {
518 Platform::MemoryCopy(dst, pixels.Get(), sliceSize);
519 error = false;
520 }
521 break;
522 }
523 if (error)
524 {
525 // Try to use texture sampler utility
526 auto sampler = PixelFormatSampler::Get(format);
527 if (sampler)
528 {

Callers

nothing calls this directly

Calls 15

IsVirtualFunction · 0.85
IsAllocatedMethod · 0.80
GenerateMipMethod · 0.80
SetResidentMipLevelsMethod · 0.80
GetTextureMethod · 0.80
WidthFunction · 0.70
FormatFunction · 0.70
HeightFunction · 0.70
ToStringFunction · 0.70
MaxFunction · 0.50

Tested by

no test coverage detected