Skip to content
  • Author

    A note to this one: both the array containing the texture regions as well as the data pointer are accessed asynchronously. So, do not put them on the stack as you probably get access violations or weird errors.

    By Simon Oehrl on 2020-07-01T18:50:17 (imported from GitLab)

  • Author

    For a synchronized update, this can be used:

    TArray<FColor> ColorData;
    // Init Data
    
    // Create texture if it doesn't exist
    FTexture2DMipMap& Mip = Texture->PlatformData->Mips[0];
    void* TextureData = Mip.BulkData.Lock( LOCK_READ_WRITE );
    FMemory::Memcpy( TextureData, ColorData.GetData(), (X * Y * sizeof(FColor))); // can just loop through values as well 
    Mip.BulkData.Unlock( );
    Texture->UpdateResource();

    By David Gilbert on 2020-07-02T09:24:04 (imported from GitLab)

    Edited by Jan Delember
  • Author

    Yes, that's a nice way to do this. However, but this explicitly introduces synchronization between CPU/GPU introducing quite some overhead.

    By Simon Oehrl on 2020-07-02T09:28:21 (imported from GitLab)

  • Author

    Yeah. The code I ended up with in the end is based on the usage I found in the engine itself - pretty sure it could be improved:

    FUpdateTextureRegion2D* Region = new FUpdateTextureRegion2D(
    		InitialTextureMarker.X, 
    		InitialTextureMarker.Y, 
    		InitialTextureMarker.X,
    		InitialTextureMarker.Y, Line.Num(), 1);	
    
    	// Copy for now - no need to do that generally
    	TArray<FVector4>* TextureData = new TArray<FVector4>(RawLineData);
    
            // Moving the raw arraw data instead of a copy is a lot quicker, if your data structure allows that:
    	TArray<FVector4>* TextureData = new TArray<FVector4>(MoveTemp(RawLineData));
    
    
    	
    	PositionTexture->UpdateTextureRegions(0, 1, Region, TextureWidth * sizeof(FVector4), sizeof(FVector4), (uint8*)TextureData->GetData(),
    		[](auto InTextureData, auto InRegions)
    	{
    		delete InTextureData;
    		delete InRegions;
    	});

    By David Gilbert on 2020-07-02T09:54:17 (imported from GitLab)

0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment