本文整理汇总了C++中UTexture2D::UpdateResource方法的典型用法代码示例。如果您正苦于以下问题:C++ UTexture2D::UpdateResource方法的具体用法?C++ UTexture2D::UpdateResource怎么用?C++ UTexture2D::UpdateResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UTexture2D
的用法示例。
在下文中一共展示了UTexture2D::UpdateResource方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
//Grayscale average texture
UTexture2D* PrivateLeapImage::Texture32FromLeapImage(int32 SrcWidth, int32 SrcHeight, uint8* imageBuffer)
{
// Lock the texture so it can be modified
if (imagePointer == NULL)
return NULL;
uint8* MipData = static_cast<uint8*>(imagePointer->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE));
// Create base mip.
uint8* DestPtr = NULL;
const uint8* SrcPtr = NULL;
for (int32 y = 0; y<SrcHeight; y++)
{
DestPtr = &MipData[(SrcHeight - 1 - y) * SrcWidth * sizeof(FColor)];
SrcPtr = const_cast<uint8*>(&imageBuffer[(SrcHeight - 1 - y) * SrcWidth]);
for (int32 x = 0; x<SrcWidth; x++)
{
//Grayscale, copy to all channels
*DestPtr++ = *SrcPtr;
*DestPtr++ = *SrcPtr;
*DestPtr++ = *SrcPtr;
*DestPtr++ = 0xFF;
SrcPtr++;
}
}
// Unlock the texture
imagePointer->PlatformData->Mips[0].BulkData.Unlock();
imagePointer->UpdateResource();
return imagePointer;
}
示例2: PostLoad
void UFont::PostLoad()
{
Super::PostLoad();
// Cache the character count and the maximum character height for this font
CacheCharacterCountAndMaxCharHeight();
for( int32 TextureIndex = 0 ; TextureIndex < Textures.Num() ; ++TextureIndex )
{
UTexture2D* Texture = Textures[TextureIndex];
if( Texture )
{
Texture->SetFlags(RF_Public);
Texture->LODGroup = TEXTUREGROUP_UI;
// Fix up compression type for distance field fonts.
if (Texture->CompressionSettings == TC_Displacementmap && !Texture->SRGB)
{
Texture->ConditionalPostLoad();
Texture->CompressionSettings = TC_DistanceFieldFont;
Texture->UpdateResource();
}
}
}
}
示例3:
UTexture2D* UTensorFlowBlueprintLibrary::Conv_RenderTargetTextureToTexture2D(UTextureRenderTarget2D* PassedTexture)
{
int TextureLength = PassedTexture->SizeX * PassedTexture->SizeY;
UTexture2D* Pointer = UTexture2D::CreateTransient(PassedTexture->SizeX, PassedTexture->SizeY, PF_R8G8B8A8);
TArray<FColor> SurfData;
FRenderTarget *RenderTarget = PassedTexture->GameThread_GetRenderTargetResource();
RenderTarget->ReadPixels(SurfData);
uint8* MipData = static_cast<uint8*>(Pointer->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE));
//Copy Data
for (int i = 0; i < TextureLength; i++)
{
int MipPointer = i * 4;
const FColor& Color = SurfData[i];
uint8 AdjustedColor = (Color.R + Color.G + Color.B) / 3;
MipData[MipPointer] = AdjustedColor;
MipData[MipPointer + 1] = AdjustedColor;
MipData[MipPointer + 2] = AdjustedColor;
MipData[MipPointer + 3] = 255; //Alpha
}
//Unlock and Return data
Pointer->PlatformData->Mips[0].BulkData.Unlock();
Pointer->UpdateResource();
PassedTexture->Source.UnlockMip(0);
return Pointer;
}
示例4: TEXT
UTexture2D* UTensorFlowBlueprintLibrary::Conv_FloatArrayToTexture2D(const TArray<float>& InFloatArray)
{
//Create square image and lock for writing
int32 Size = FMath::Pow(InFloatArray.Num(), 0.5);
if (Size * Size != InFloatArray.Num())
{
UE_LOG(LogTemp, Warning, TEXT("Invalid float array, needs to be square."));
return nullptr;
}
UTexture2D* Pointer = UTexture2D::CreateTransient(Size, Size, PF_R8G8B8A8);
uint8* MipData = static_cast<uint8*>(Pointer->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE));
//Copy Data
for (int i = 0; i < InFloatArray.Num(); i++)
{
int MipPointer = i * 4;
int InverseValue = (1 - InFloatArray[i]) * 255.f;
MipData[MipPointer] = InverseValue;
MipData[MipPointer + 1] = InverseValue;
MipData[MipPointer + 2] = InverseValue;
MipData[MipPointer + 3] = 255; //Alpha
}
//Unlock and Return data
Pointer->PlatformData->Mips[0].BulkData.Unlock();
Pointer->UpdateResource();
return Pointer;
}
示例5: BuildDistortionTextures
UTexture2D* ULeapMotionImageComponent::BuildDistortionTextures( const Leap::Image& Image )
{
UTexture2D* DistortionTexture = UTexture2D::CreateTransient(Image.distortionWidth() / 2, Image.distortionHeight(), PF_B8G8R8A8);
DistortionTexture->SRGB = 0;
DistortionTexture->UpdateResource();
UpdateDistortionTextures(Image, DistortionTexture);
return DistortionTexture;
}
示例6: GetTexture
UTexture2D* ULRRTextureManager::GetTexture(FString path, bool alpha) {
TArray<uint8> RawFileData;
FFileHelper::LoadFileToArray(RawFileData, *path, 0);
if (RawFileData.Num() != 0)
{
IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName(TEXT("ImageWrapper")));
// Note: PNG format. Other formats are supported
IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::BMP);
if (ImageWrapper.IsValid() && ImageWrapper->SetCompressed(RawFileData.GetData(), RawFileData.Num()))
{
const TArray<uint8>* UncompressedBGRA = nullptr;
TArray<uint8> UncompressedRGBA;
if (ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, UncompressedBGRA))
{
// Create the UTexture for rendering
UncompressedRGBA.AddZeroed(UncompressedBGRA->Num());
for (int i = 0; UncompressedBGRA->Num() > i; i += 4) {
UncompressedRGBA[i] = (*UncompressedBGRA)[i + 2];
UncompressedRGBA[i + 1] = (*UncompressedBGRA)[i + 1];
UncompressedRGBA[i + 2] = (*UncompressedBGRA)[i];
UncompressedRGBA[i + 3] = (*UncompressedBGRA)[i + 3];
if (alpha) {
if ((UncompressedRGBA[i] + UncompressedRGBA[i + 1] + UncompressedRGBA[i + 2]) < 3) {
UncompressedRGBA[i + 3] = 0;
}
}
}
UTexture2D* MyTexture = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_R8G8B8A8);
// Fill in the source data from the file
uint8* TextureData = (uint8*)MyTexture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
FMemory::Memcpy(TextureData, UncompressedRGBA.GetData(), UncompressedRGBA.Num());
MyTexture->PlatformData->Mips[0].BulkData.Unlock();
// Update the rendering resource from data.
MyTexture->UpdateResource();
return MyTexture;
}
}
}
return nullptr;
}
示例7: TEXT
UTexture2D * UAdvancedFriendsLibrary::GetSteamFriendAvatar(APlayerController *PlayerController, const FBPUniqueNetId UniqueNetId, SteamAvatarSize AvatarSize)
{
if (!PlayerController)
{
UE_LOG(AdvancedFriendsLog, Warning, TEXT("IsAFriend Had a bad Player Controller!"));
return nullptr;
}
if (!UniqueNetId.IsValid() || !UniqueNetId.UniqueNetId->IsValid())
{
UE_LOG(AdvancedFriendsLog, Warning, TEXT("IsAFriend Had a bad UniqueNetId!"));
return nullptr;
}
uint32 Width = 0;
uint32 Height = 0;
if (SteamAPI_Init())
{
//Getting the PictureID from the SteamAPI and getting the Size with the ID
//virtual bool RequestUserInformation( CSteamID steamIDUser, bool bRequireNameOnly ) = 0;
uint64 id = *((uint64*)UniqueNetId.UniqueNetId->GetBytes());
int Picture = 0;
switch(AvatarSize)
{
case SteamAvatarSize::SteamAvatar_Small: Picture = SteamFriends()->GetSmallFriendAvatar(id); break;
case SteamAvatarSize::SteamAvatar_Medium: Picture = SteamFriends()->GetMediumFriendAvatar(id); break;
case SteamAvatarSize::SteamAvatar_Large: Picture = SteamFriends()->GetLargeFriendAvatar(id); break;
default: break;
}
if (Picture == -1)
return NULL;
SteamUtils()->GetImageSize(Picture, &Width, &Height);
// STOLEN FROM ANSWERHUB :p
if (Width > 0 && Height > 0)
{
//Creating the buffer "oAvatarRGBA" and then filling it with the RGBA Stream from the Steam Avatar
uint8 *oAvatarRGBA = new uint8[Width * Height * 4];
//Filling the buffer with the RGBA Stream from the Steam Avatar and creating a UTextur2D to parse the RGBA Steam in
SteamUtils()->GetImageRGBA(Picture, (uint8*)oAvatarRGBA, 4 * Height * Width * sizeof(char));
// Removed as I changed the image bit code to be RGB
/*
//Swap R and B channels because for some reason the games whack
for (uint32 i = 0; i < (Width * Height * 4); i += 4)
{
uint8 Temp = oAvatarRGBA[i + 0];
oAvatarRGBA[i + 0] = oAvatarRGBA[i + 2];
oAvatarRGBA[i + 2] = Temp;
}*/
UTexture2D* Avatar = UTexture2D::CreateTransient(Width, Height, PF_R8G8B8A8);
uint8* MipData = (uint8*)Avatar->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
FMemory::Memcpy(MipData, (void*)oAvatarRGBA, Height * Width * 4);
Avatar->PlatformData->Mips[0].BulkData.Unlock();
// Original implementation was missing this!!
// the hell man......
delete[] oAvatarRGBA;
//Setting some Parameters for the Texture and finally returning it
Avatar->PlatformData->NumSlices = 1;
Avatar->NeverStream = true;
//Avatar->CompressionSettings = TC_EditorIcon;
Avatar->UpdateResource();
return Avatar;
}
else
{
UE_LOG(AdvancedFriendsLog, Warning, TEXT("Bad Height / Width with steam avatar!"));
}
return nullptr;
}
UE_LOG(AdvancedFriendsLog, Warning, TEXT("STEAM Couldn't be verified as initialized"));
return nullptr;
}
示例8: FactoryCreateBinary
//.........这里部分代码省略.........
}
else
{
FString TexturePackageName;
FString BasePackageName = FPackageName::GetLongPackagePath(InParent->GetOutermost()->GetName()) / TextureName;
AssetToolsModule.Get().CreateUniqueAssetName(BasePackageName, TEXT(""), TexturePackageName, TextureName);
TexturePackage = CreatePackage(NULL, *TexturePackageName);
}
const uint8* BufferBegin = Data.GetData();
const uint8* BufferEnd = BufferBegin + Data.Num();
UTexture2D* NewTexture = (UTexture2D*)TextureFact->FactoryCreateBinary(
UTexture2D::StaticClass(),
TexturePackage,
FName(*TextureName),
Flags,
NULL,
*FPaths::GetExtension(ImagePaths[i]),
BufferBegin, BufferEnd,
Warn
);
if(NewTexture)
{
if(ImportSettings->bOverwriteMipGenSettings)
{
NewTexture->MipGenSettings = TMGS_NoMipmaps;
}
if(ImportSettings->bOverwriteTextureGroup)
{
NewTexture->LODGroup = ImportSettings->TextureGroup;
}
if(ImportSettings->bOverwriteCompressionSettings)
{
NewTexture->CompressionSettings = TextureCompressionSettings::TC_EditorIcon;
}
if(ImportSettings->bOverwriteTilingMethodFromSspj)
{
switch(ImageWrapModes[i])
{
case SsTexWrapMode::Clamp:
{
NewTexture->AddressX = NewTexture->AddressY = TA_Clamp;
} break;
case SsTexWrapMode::Repeat:
{
NewTexture->AddressX = NewTexture->AddressY = TA_Wrap;
} break;
case SsTexWrapMode::Mirror:
{
NewTexture->AddressX = NewTexture->AddressY = TA_Mirror;
} break;
}
}
if(ImportSettings->bOverwriteNeverStream)
{
NewTexture->NeverStream = true;
}
if(ImportSettings->bOverwriteFilterFromSspj)
{
switch(ImageFilterModes[i])
{
case SsTexFilterMode::Nearest:
{
NewTexture->Filter = TF_Nearest;
} break;
case SsTexFilterMode::Linear:
{
NewTexture->Filter = TF_Bilinear;
} break;
}
}
NewTexture->UpdateResource();
FAssetRegistryModule::AssetCreated(NewTexture);
TexturePackage->SetDirtyFlag(true);
TextureFact->RemoveFromRoot();
ImportedTexture = NewTexture;
}
}
if(ImportedTexture)
{
for(int ii = 0; ii < NewProject->CellmapList.Num(); ++ii)
{
if(NewProject->CellmapList[ii].ImagePath == ImagePaths[i])
{
NewProject->CellmapList[ii].Texture = ImportedTexture;
}
}
}
}
}
// インポート終了
FEditorDelegates::OnAssetPostImport.Broadcast(this, NewProject);
return NewProject;
}