Skip to content
This repository has been archived by the owner on May 3, 2019. It is now read-only.

Remove unnecessary copy operations #28

Merged
merged 1 commit into from
Apr 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 5 additions & 22 deletions Source/Blu/Private/BluEye.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,37 +112,20 @@ void UBluEye::TextureUpdate(const void *buffer)
return;
}

const size_t size = Width * Height * sizeof(uint32);

// @TODO This is a bit heavy to keep reallocating/deallocating, but not a big deal. Maybe we can ping pong between buffers instead.
TArray<uint32> ViewBuffer;
ViewBuffer.Init(Width * Height);
FMemory::Memcpy(ViewBuffer.GetData(), buffer, size);

TextureDataPtr dataPtr = MakeShareable(new TextureData);

dataPtr->SetRawData(Width, Height, sizeof(uint32), ViewBuffer);

// Clean up from the per-render
ViewBuffer.Empty();
buffer = 0;

ENQUEUE_UNIQUE_RENDER_COMMAND_THREEPARAMETER(
TextureData,
TextureDataPtr, ImageData, dataPtr,
FTexture2DRHIRef, TargetTexture, ref,
const size_t, DataSize, size,
void, // Return value?
const void*, ImageData, buffer, // const void* ImageData = buffer;
FTexture2DRHIRef, TargetTexture, ref, // FTexture2DRHIRef TargetTexture = ref;
const size_t, DataSize, Width * Height * sizeof(uint32), // const size_t DataSize = Width * Height * sizeof(uint32);
{
uint32 stride = 0;
void* MipData = GDynamicRHI->RHILockTexture2D(TargetTexture, 0, RLM_WriteOnly, stride, false);

if (MipData)
{
FMemory::Memcpy(MipData, ImageData->GetRawBytesPtr(), ImageData->GetDataSize());
FMemory::Memcpy(MipData, ImageData, DataSize);
GDynamicRHI->RHIUnlockTexture2D(TargetTexture, 0, false);
}

ImageData.Reset();
});

}
Expand Down
73 changes: 0 additions & 73 deletions Source/Blu/Public/BluEye.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,79 +4,6 @@
class BrowserClient;
class RenderHandler;

/*
* Struct for Texture data
* Based on code from VaQuoleUI by Vladimir Alyamkin
*/
struct TextureData
{
TextureData(uint32 InWidth = 0, uint32 InHeight = 0, uint32 InStride = 0, const TArray<uint32>& InBytes = TArray<uint32>())
: Bytes(InBytes)
, Width(InWidth)
, Height(InHeight)
, StrideBytes(InStride)
{

}

TextureData(const TextureData &Other)
: Bytes(Other.Bytes)
, Width(Other.Width)
, Height(Other.Height)
, StrideBytes(Other.StrideBytes)
{

}

TextureData& operator=(const TextureData& Other)
{
if (this != &Other)
{
SetRawData(Other.Width, Other.Height, Other.StrideBytes, Other.Bytes);
}
return *this;
}

void SetRawData(uint32 InWidth, uint32 InHeight, uint32 InStride, const TArray<uint32>& InBytes)
{
Width = InWidth;
Height = InHeight;
StrideBytes = InStride;
Bytes = InBytes;
}

void Empty()
{
Bytes.Empty();
}

uint32 GetWidth() const { return Width; }
uint32 GetHeight() const { return Height; }
uint32 GetStride() const { return StrideBytes; }
uint32 GetDataSize() const { return Width * Height * StrideBytes; }
const TArray<uint32>& GetRawBytes() const { return Bytes; }

/** Accesses the raw bytes of already sized texture data */
uint32* GetRawBytesPtr() { return Bytes.GetData(); }

private:
/** Raw uncompressed texture data */
TArray<uint32> Bytes;

/** Width of the texture */
uint32 Width;

/** Height of the texture */
uint32 Height;

/** The number of bytes of each pixel */
uint32 StrideBytes;

};

typedef TSharedPtr<TextureData, ESPMode::ThreadSafe> TextureDataPtr;
typedef TSharedRef<TextureData, ESPMode::ThreadSafe> TextureDataRef;

DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FScriptEvent, const FString&, EventName, const FString&, EventMessage);

UCLASS(ClassGroup = Blu, Blueprintable)
Expand Down