diff --git a/Source/Engine/Graphics/Textures/GPUTexture.cpp b/Source/Engine/Graphics/Textures/GPUTexture.cpp index 127cf2f5b..59b025b70 100644 --- a/Source/Engine/Graphics/Textures/GPUTexture.cpp +++ b/Source/Engine/Graphics/Textures/GPUTexture.cpp @@ -630,6 +630,23 @@ GPUTask* GPUTexture::UploadMipMapAsync(const BytesContainer& data, int32 mipInde return task; } +bool GPUTexture::UploadData(TextureData& data, bool copyData) +{ + if (!IsAllocated()) + return true; + if (data.Width != Width() || data.Height != Height() || data.Depth != Depth() || data.GetArraySize() != ArraySize() || data.Format != Format()) + return true; + for (int32 arrayIndex = 0; arrayIndex < ArraySize(); arrayIndex++) + { + for (int32 mipLevel = 0; mipLevel < MipLevels(); mipLevel++) + { + TextureMipData* mip = data.GetData(arrayIndex, mipLevel); + UploadMipMapAsync(mip->Data, mipLevel, mip->RowPitch, mip->DepthPitch, copyData); + } + } + return false; +} + class TextureDownloadDataTask : public ThreadPoolTask { private: diff --git a/Source/Engine/Graphics/Textures/GPUTexture.h b/Source/Engine/Graphics/Textures/GPUTexture.h index 977723f26..85ac4ae0b 100644 --- a/Source/Engine/Graphics/Textures/GPUTexture.h +++ b/Source/Engine/Graphics/Textures/GPUTexture.h @@ -499,7 +499,7 @@ public: /// /// Uploads mip map data to the GPU. Creates async GPU task. /// - /// Data to upload (it must be valid for the next a few frames due to GPU latency and async works executing) + /// Data to upload, it must match texture dimensions. It must be valid for the next couple of frames due to GPU async task latency or use data copy. /// Mip level index. /// If true, the data will be copied to the async execution task instead of using the input pointer provided. /// Created async task or null if cannot. @@ -508,7 +508,7 @@ public: /// /// Uploads mip map data to the GPU. Creates async GPU task. /// - /// Data to upload (it must be valid for the next a few frames due to GPU latency and async works executing) + /// Data to upload, it must match texture dimensions. It must be valid for the next couple of frames due to GPU async task latency or use data copy. /// Mip level index. /// The data row pitch. /// The data slice pitch. @@ -516,6 +516,14 @@ public: /// Created async task or null if cannot. GPUTask* UploadMipMapAsync(const BytesContainer& data, int32 mipIndex, int32 rowPitch, int32 slicePitch, bool copyData = false); + /// + /// Uploads texture data to the GPU. Actual data copy to the GPU memory is performed via async task. + /// + /// Data to upload, it must match texture dimensions. It must be valid for the next couple of frames due to GPU async task latency or use data copy. + /// If true, the data will be copied to the async execution task instead of using the input pointer provided. + /// True if cannot upload data, otherwise false. + API_FUNCTION() bool UploadData(TextureData& data, bool copyData = false); + /// /// Downloads the texture data to be accessible from CPU. For frequent access, use staging textures, otherwise current thread will be stalled to wait for the GPU frame to copy data into staging buffer. ///