Skip to content
Snippets Groups Projects
Commit 91ffe586 authored by David Gilbert's avatar David Gilbert :bug:
Browse files

Started cleaning up more duplicated code and unneeded functions

parent dd8cfb52
Branches
No related tags found
No related merge requests found
...@@ -104,6 +104,21 @@ int32 UGPUInstancedLineComponent::AddNewSegmentInstance(const FLinearColor& Colo ...@@ -104,6 +104,21 @@ int32 UGPUInstancedLineComponent::AddNewSegmentInstance(const FLinearColor& Colo
return InstanceId; return InstanceId;
} }
void UGPUInstancedLineComponent::UpdateTexture(const FIntPoint& StartIndex, int32 NumberOfPoints, uint8* SrcData)
{
int32 NumRegions = 0;
FUpdateTextureRegion2D* Regions = CalculateTextureRegions(StartIndex, NumberOfPoints, NumRegions);
const uint32 Pitch = TextureWidth;
PositionTexture->UpdateTextureRegions(0, NumRegions, Regions, Pitch * sizeof(FVector4), sizeof(FVector4), SrcData,
[](auto InTextureData, auto InRegions)
{
// Clean up the copied data
delete InTextureData;
delete InRegions;
});
}
void UGPUInstancedLineComponent::Init() void UGPUInstancedLineComponent::Init()
{ {
if (PositionTexture == nullptr) if (PositionTexture == nullptr)
...@@ -630,20 +645,7 @@ int32 UGPUInstancedLineComponent::AddLine(const TArray<FVector>& Line, FLinearCo ...@@ -630,20 +645,7 @@ int32 UGPUInstancedLineComponent::AddLine(const TArray<FVector>& Line, FLinearCo
// Store the points in a linear array here // Store the points in a linear array here
LinearLineData.Append(*TextureData); LinearLineData.Append(*TextureData);
int32 NumRegions = 0; UpdateTexture(InitialTextureMarker, Line.Num(), (uint8*)TextureData->GetData());
FUpdateTextureRegion2D* Regions = CalculateTextureRegions(InitialTextureMarker, Line.Num(), NumRegions);
const uint32 Pitch = TextureWidth;
PositionTexture->UpdateTextureRegions(0, NumRegions, Regions, Pitch * sizeof(FVector4), sizeof(FVector4), (uint8*)TextureData->GetData(),
[](auto InTextureData, auto InRegions)
{
// Clean up the copied data
delete InTextureData;
delete InRegions;
});
//UE_LOG(LogLineRendering, Display, TEXT("Added Line #%d"), LineId); // Actually we can!
return LineId; return LineId;
} }
...@@ -687,21 +689,7 @@ int32 UGPUInstancedLineComponent::AddLine(TArray<FVector4>& Line, FLinearColor C ...@@ -687,21 +689,7 @@ int32 UGPUInstancedLineComponent::AddLine(TArray<FVector4>& Line, FLinearColor C
// Store the points in a linear array here // Store the points in a linear array here
LinearLineData.Append(*TextureData); LinearLineData.Append(*TextureData);
int32 NumRegions = 0; UpdateTexture(InitialTextureMarker, Line.Num(), (uint8*)TextureData->GetData());
FUpdateTextureRegion2D* Regions = CalculateTextureRegions(InitialTextureMarker, TextureData->Num(), NumRegions);
const uint32 Pitch = TextureWidth;
PositionTexture->UpdateTextureRegions(0, NumRegions, Regions, Pitch * sizeof(FVector4), sizeof(FVector4), (uint8*)TextureData->GetData(),
[](auto InTextureData, auto InRegions)
{
// Clean up the copied data
delete InTextureData;
delete InRegions;
});
//UE_LOG(LogLineRendering, Display, TEXT("Added Line #%d"), LineId); // Actually we can!
return LineId; return LineId;
...@@ -960,19 +948,8 @@ bool UGPUInstancedLineComponent::AddPoints(int32 LineId, const TArray<FVector>& ...@@ -960,19 +948,8 @@ bool UGPUInstancedLineComponent::AddPoints(int32 LineId, const TArray<FVector>&
// Recreate the data on the heap to allow asynchronous texture update. // Recreate the data on the heap to allow asynchronous texture update.
TArray<FVector4>* TextureData = new TArray<FVector4>(Points); TArray<FVector4>* TextureData = new TArray<FVector4>(Points);
int32 NumberOfRegions = 0;
FUpdateTextureRegion2D* Regions = CalculateTextureRegions(InitialTextureMarker, Points.Num(), NumberOfRegions);
// Update the actual texture on the gpu
const uint32 Pitch = TextureWidth;
PositionTexture->UpdateTextureRegions(0, NumberOfRegions, Regions, Pitch * sizeof(FVector4), sizeof(FVector4), (uint8*)TextureData->GetData(),
[](auto InTextureData, auto InRegions)
{
// Clean up the copied data
delete InTextureData;
delete InRegions;
});
UpdateTexture(InitialTextureMarker, Points.Num(), (uint8*)TextureData->GetData());
MarkRenderStateDirty(); MarkRenderStateDirty();
return true; return true;
...@@ -1117,15 +1094,7 @@ bool UGPUInstancedLineComponent::UpdateLine(int32 LineId, TArray<FVector>& Point ...@@ -1117,15 +1094,7 @@ bool UGPUInstancedLineComponent::UpdateLine(int32 LineId, TArray<FVector>& Point
FMemory::Memcpy(LinearLineData.GetData() + TextureIndex, TextureData->GetData(), TextureData->Num() * sizeof(FVector4)); FMemory::Memcpy(LinearLineData.GetData() + TextureIndex, TextureData->GetData(), TextureData->Num() * sizeof(FVector4));
int32 NumberOfRegions = 0; UpdateTexture(StartIndex, TextureData->Num(), (uint8*)TextureData->GetData());
const FUpdateTextureRegion2D* Regions = CalculateTextureRegions(StartIndex, TextureData->Num(), NumberOfRegions);
PositionTexture->UpdateTextureRegions(0, NumberOfRegions, Regions, TextureWidth * sizeof(FVector4), sizeof(FVector4), (uint8*)TextureData->GetData(),
[](auto InTextureData, auto InRegions)
{
delete InTextureData;
delete InRegions;
});
return true; return true;
} }
...@@ -1149,19 +1118,8 @@ bool UGPUInstancedLineComponent::UpdateLinesDataDirectly(int32 LineIdStart, TArr ...@@ -1149,19 +1118,8 @@ bool UGPUInstancedLineComponent::UpdateLinesDataDirectly(int32 LineIdStart, TArr
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("UGPUInstancedLineComponent::UpdateLines - MoveTemp Texture Data")) TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("UGPUInstancedLineComponent::UpdateLines - MoveTemp Texture Data"))
TextureData = new TArray<FVector4>(MoveTemp(Points)); TextureData = new TArray<FVector4>(MoveTemp(Points));
} }
int32 NumberOfRegions = 0;
FUpdateTextureRegion2D* Regions;
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("UGPUInstancedLineComponent::UpdateLines - Calculate Texture Regions"))
Regions = CalculateTextureRegions(FIntPoint(X, Y), TextureData->Num(), NumberOfRegions);
}
PositionTexture->UpdateTextureRegions(0, NumberOfRegions, Regions, TextureWidth * sizeof(FVector4), sizeof(FVector4), (uint8*)TextureData->GetData(),
[](auto InTextureData, auto InRegions)
{
delete InTextureData;
delete InRegions;
});
UpdateTexture(FIntPoint(X, Y), TextureData->Num(), (uint8*)TextureData->GetData());
return true; return true;
} }
...@@ -1184,14 +1142,8 @@ bool UGPUInstancedLineComponent::DrawLinesDirectly(int32 LineIdStart, TArray<FVe ...@@ -1184,14 +1142,8 @@ bool UGPUInstancedLineComponent::DrawLinesDirectly(int32 LineIdStart, TArray<FVe
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("UGPUInstancedLineComponent::DrawLinesDirectly - MoveTemp Texture Data")) TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("UGPUInstancedLineComponent::DrawLinesDirectly - MoveTemp Texture Data"))
TextureData = new TArray<FVector4>(MoveTemp(Points)); TextureData = new TArray<FVector4>(MoveTemp(Points));
} }
int32 NumberOfRegions = 0; UpdateTexture(FIntPoint(X, Y), TextureData->Num(), (uint8*)TextureData->GetData());
FUpdateTextureRegion2D* Regions = CalculateTextureRegions(FIntPoint(X, Y), TextureData->Num(), NumberOfRegions);
PositionTexture->UpdateTextureRegions(0, NumberOfRegions, Regions, TextureWidth * sizeof(FVector4), sizeof(FVector4), (uint8*)TextureData->GetData(),
[](auto InTextureData, auto InRegions)
{
delete InTextureData;
delete InRegions;
});
return true; return true;
} }
...@@ -1211,14 +1163,7 @@ bool UGPUInstancedLineComponent::DrawLinesDirectly(int32 LineIdStart, TArray<FVe ...@@ -1211,14 +1163,7 @@ bool UGPUInstancedLineComponent::DrawLinesDirectly(int32 LineIdStart, TArray<FVe
const int32 X = LineIdStart % TextureWidth; const int32 X = LineIdStart % TextureWidth;
const int32 Y = LineIdStart / TextureWidth; const int32 Y = LineIdStart / TextureWidth;
int32 NumberOfRegions = 0; UpdateTexture(FIntPoint(X, Y), Points->Num(), (uint8*)Points->GetData());
FUpdateTextureRegion2D* Regions = CalculateTextureRegions(FIntPoint(X, Y), Points->Num(), NumberOfRegions);
PositionTexture->UpdateTextureRegions(0, NumberOfRegions, Regions, TextureWidth * sizeof(FVector4), sizeof(FVector4), (uint8*)Points->GetData(),
[](auto InTextureData, auto InRegions)
{
delete InTextureData;
delete InRegions;
});
return true; return true;
} }
...@@ -1230,14 +1175,7 @@ bool UGPUInstancedLineComponent::DrawLinesDirectly(int32 LineIdStart, uint8* Src ...@@ -1230,14 +1175,7 @@ bool UGPUInstancedLineComponent::DrawLinesDirectly(int32 LineIdStart, uint8* Src
const int32 X = LineIdStart % TextureWidth; const int32 X = LineIdStart % TextureWidth;
const int32 Y = LineIdStart / TextureWidth; const int32 Y = LineIdStart / TextureWidth;
int32 NumberOfRegions = 0; UpdateTexture(FIntPoint(X, Y), Num, SrcData);
FUpdateTextureRegion2D* Regions = CalculateTextureRegions(FIntPoint(X, Y), Num, NumberOfRegions);
PositionTexture->UpdateTextureRegions(0, NumberOfRegions, Regions, TextureWidth * sizeof(FVector4), sizeof(FVector4), SrcData,
[](auto InTextureData, auto InRegions)
{
delete InTextureData;
delete InRegions;
});
return true; return true;
} }
...@@ -1320,15 +1258,7 @@ bool UGPUInstancedLineComponent::UpdatePoints(int32 LineId, int32 StartingPointI ...@@ -1320,15 +1258,7 @@ bool UGPUInstancedLineComponent::UpdatePoints(int32 LineId, int32 StartingPointI
FMemory::Memcpy(LinearLineData.GetData() + StartTextureIndex, TextureData->GetData(), TextureData->Num() * sizeof(FVector4)); FMemory::Memcpy(LinearLineData.GetData() + StartTextureIndex, TextureData->GetData(), TextureData->Num() * sizeof(FVector4));
int32 NumberOfRegions = 0; UpdateTexture(StartIndex, TextureData->Num(), (uint8*)TextureData->GetData());
const FUpdateTextureRegion2D* Regions = CalculateTextureRegions(StartIndex, TextureData->Num(), NumberOfRegions);
PositionTexture->UpdateTextureRegions(0, NumberOfRegions, Regions, TextureWidth * sizeof(FVector4), sizeof(FVector4), (uint8*)TextureData->GetData(),
[](auto InTextureData, auto InRegions)
{
delete InTextureData;
delete InRegions;
});
return true; return true;
} }
......
...@@ -148,6 +148,8 @@ public: ...@@ -148,6 +148,8 @@ public:
int32 AddNewSegmentInstance(const FLinearColor& Color, float Width, int32 Index); int32 AddNewSegmentInstance(const FLinearColor& Color, float Width, int32 Index);
void UpdateTexture(const FIntPoint& StartIndex, int32 NumberOfPoints, uint8* SrcData);
/** /**
* Reserves internal memory for a given amount of Lines and Segments per Line. * Reserves internal memory for a given amount of Lines and Segments per Line.
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment