virtual void InitRHI() { TextureCubeRHI = RHICreateTextureCube(Size, Format, NumMips, 0, NULL); TextureRHI = TextureCubeRHI; if (SourceData) { check(SourceData->Num() > 0); const int32 BlockBytes = GPixelFormats[Format].BlockBytes; int32 MipBaseIndex = 0; for (int32 MipIndex = 0; MipIndex < NumMips; MipIndex++) { const int32 MipSize = 1 << (NumMips - MipIndex - 1); const int32 CubeFaceBytes = MipSize * MipSize * BlockBytes; for (int32 CubeFace = 0; CubeFace < CubeFace_MAX; CubeFace++) { uint32 DestStride = 0; uint8* DestBuffer = (uint8*)RHILockTextureCubeFace(TextureCubeRHI, CubeFace, 0, MipIndex, RLM_WriteOnly, DestStride, false); // Handle DestStride by copying each row for (int32 Y = 0; Y < MipSize; Y++) { uint8* DestPtr = ((uint8*)DestBuffer + Y * DestStride); const int32 SourceIndex = MipBaseIndex + CubeFace * CubeFaceBytes + Y * MipSize * BlockBytes; const uint8* SourcePtr = &(*SourceData)[SourceIndex]; FMemory::Memcpy(DestPtr, SourcePtr, MipSize * BlockBytes); } RHIUnlockTextureCubeFace(TextureCubeRHI, CubeFace, 0, MipIndex, false); } MipBaseIndex += CubeFaceBytes * CubeFace_MAX; } if (!GIsEditor) { // Toss the source data now that we've created the cubemap // Note: can't do this if we ever use this texture resource in the editor and want to save the data later DEC_MEMORY_STAT_BY(STAT_ReflectionCaptureMemory,SourceData->GetAllocatedSize()); SourceData->Empty(); } } // Create the sampler state RHI resource. FSamplerStateInitializerRHI SamplerStateInitializer ( SF_Trilinear, AM_Clamp, AM_Clamp, AM_Clamp ); SamplerStateRHI = RHICreateSamplerState(SamplerStateInitializer); INC_MEMORY_STAT_BY(STAT_ReflectionCaptureTextureMemory,CalcTextureSize(Size,Size,Format,NumMips) * 6); }
/** * Called when the resource is initialized. This is only called by the rendering thread. */ virtual void InitRHI() override { INC_DWORD_STAT_BY( STAT_TextureMemory, TextureSize ); INC_DWORD_STAT_FNAME_BY( LODGroupStatName, TextureSize ); // Create the RHI texture. uint32 TexCreateFlags = (Owner->SRGB ? TexCreate_SRGB : 0) | TexCreate_OfflineProcessed; FRHIResourceCreateInfo CreateInfo; TextureCubeRHI = RHICreateTextureCube( Owner->GetSizeX(), Owner->GetPixelFormat(), Owner->GetNumMips(), TexCreateFlags, CreateInfo ); TextureRHI = TextureCubeRHI; RHIBindDebugLabelName(TextureRHI, *Owner->GetName()); RHIUpdateTextureReference(Owner->TextureReference.TextureReferenceRHI,TextureRHI); // Read the mip-levels into the RHI texture. int32 NumMips = Owner->GetNumMips(); for( int32 FaceIndex=0; FaceIndex<6; FaceIndex++ ) { for(int32 MipIndex=0; MipIndex < NumMips; MipIndex++) { if( MipData[FaceIndex][MipIndex] != NULL ) { uint32 DestStride; void* TheMipData = RHILockTextureCubeFace( TextureCubeRHI, FaceIndex, 0, MipIndex, RLM_WriteOnly, DestStride, false ); GetData( FaceIndex, MipIndex, TheMipData, DestStride ); RHIUnlockTextureCubeFace( TextureCubeRHI, FaceIndex, 0, MipIndex, false ); } } } // Create the sampler state RHI resource. FSamplerStateInitializerRHI SamplerStateInitializer ( GSystemSettings.TextureLODSettings.GetSamplerFilter( Owner ), AM_Clamp, AM_Clamp, AM_Clamp ); SamplerStateRHI = RHICreateSamplerState(SamplerStateInitializer); // Set the greyscale format flag appropriately. EPixelFormat PixelFormat = Owner->GetPixelFormat(); bGreyScaleFormat = (PixelFormat == PF_G8) || (PixelFormat == PF_BC4); }