From 8f613774cb19f7f9f658fa264a275f0dbbcd1f8e Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Tue, 19 Sep 2023 21:23:54 +0300 Subject: [PATCH] Expose `GPUTexture::DownloadData` to Scripting API --- Source/Editor/Utilities/EditorUtilities.h | 2 +- Source/Engine/Graphics/Textures/GPUTexture.h | 6 +- Source/Engine/Graphics/Textures/TextureBase.h | 4 +- Source/Engine/Graphics/Textures/TextureData.h | 73 +++++++++++++------ Source/Engine/Level/Scene/Lightmap.h | 2 +- Source/Engine/Platform/Base/WindowBase.h | 2 +- 6 files changed, 60 insertions(+), 29 deletions(-) diff --git a/Source/Editor/Utilities/EditorUtilities.h b/Source/Editor/Utilities/EditorUtilities.h index 2357f995a..99e59f289 100644 --- a/Source/Editor/Utilities/EditorUtilities.h +++ b/Source/Editor/Utilities/EditorUtilities.h @@ -7,7 +7,7 @@ enum class PixelFormat : unsigned; enum class DirectorySearchOption; -class TextureData; +struct TextureData; /// /// Helper functions for the editor. diff --git a/Source/Engine/Graphics/Textures/GPUTexture.h b/Source/Engine/Graphics/Textures/GPUTexture.h index f39ed0b0f..db294034c 100644 --- a/Source/Engine/Graphics/Textures/GPUTexture.h +++ b/Source/Engine/Graphics/Textures/GPUTexture.h @@ -7,8 +7,8 @@ class GPUContext; class GPUTask; -class TextureMipData; -class TextureData; +struct TextureMipData; +struct TextureData; template class DataContainer; typedef DataContainer BytesContainer; @@ -533,7 +533,7 @@ public: /// /// The result data. /// True if cannot download data, otherwise false. - bool DownloadData(TextureData& result); + API_FUNCTION() bool DownloadData(API_PARAM(Out) TextureData& result); /// /// Creates GPU async task that will gather texture data from the GPU. diff --git a/Source/Engine/Graphics/Textures/TextureBase.h b/Source/Engine/Graphics/Textures/TextureBase.h index d97421bfd..eda2086ac 100644 --- a/Source/Engine/Graphics/Textures/TextureBase.h +++ b/Source/Engine/Graphics/Textures/TextureBase.h @@ -5,8 +5,8 @@ #include "Engine/Content/BinaryAsset.h" #include "StreamingTexture.h" -class TextureData; -class TextureMipData; +struct TextureData; +struct TextureMipData; /// /// Base class for , , and other assets that can contain texture data. diff --git a/Source/Engine/Graphics/Textures/TextureData.h b/Source/Engine/Graphics/Textures/TextureData.h index 4c5da250a..d77fb761f 100644 --- a/Source/Engine/Graphics/Textures/TextureData.h +++ b/Source/Engine/Graphics/Textures/TextureData.h @@ -10,13 +10,21 @@ /// /// Single texture mip map entry data. /// -class FLAXENGINE_API TextureMipData +API_STRUCT() struct FLAXENGINE_API TextureMipData { + DECLARE_SCRIPTING_TYPE_MINIMAL(TextureMipData); public: - uint32 RowPitch; - uint32 DepthPitch; - uint32 Lines; - BytesContainer Data; + // The row pitch. + API_FIELD() uint32 RowPitch; + + // The depth pitch. + API_FIELD() uint32 DepthPitch; + + // The number of lines. + API_FIELD() uint32 Lines; + + // The data. + API_FIELD(ReadOnly) BytesContainer Data; TextureMipData(); TextureMipData(const TextureMipData& other); @@ -40,22 +48,39 @@ public: } }; +template<> +struct TIsPODType +{ + enum { Value = true }; +}; + +/// +/// Single entry of the texture array. Contains collection of mip maps. +/// +API_STRUCT(NoDefault) struct FLAXENGINE_API TextureDataArrayEntry +{ + DECLARE_SCRIPTING_TYPE_MINIMAL(TextureDataArrayEntry); + + /// + /// The mip maps collection. + /// + API_FIELD(ReadOnly) Array> Mips; +}; + +template<> +struct TIsPODType +{ + enum { Value = false }; +}; + /// /// Texture data container (used to keep data downloaded from the GPU). /// -class FLAXENGINE_API TextureData +API_STRUCT() struct FLAXENGINE_API TextureData { + DECLARE_SCRIPTING_TYPE_MINIMAL(TextureData); public: - /// - /// Single entry of the texture array. Contains collection of mip maps. - /// - struct FLAXENGINE_API ArrayEntry - { - /// - /// The mip maps collection. - /// - Array> Mips; - }; + public: /// @@ -76,27 +101,27 @@ public: /// /// Top level texture width (in pixels). /// - int32 Width = 0; + API_FIELD() int32 Width = 0; /// /// Top level texture height (in pixels). /// - int32 Height = 0; + API_FIELD() int32 Height = 0; /// /// Top level texture depth (in pixels). /// - int32 Depth = 0; + API_FIELD() int32 Depth = 0; /// /// The texture data format. /// - PixelFormat Format = PixelFormat::Unknown; + API_FIELD() PixelFormat Format = PixelFormat::Unknown; /// /// The items collection (depth slices or array slices). /// - Array> Items; + API_FIELD() Array> Items; public: /// @@ -145,3 +170,9 @@ public: Items.Resize(0, false); } }; + +template<> +struct TIsPODType +{ + enum { Value = false }; +}; diff --git a/Source/Engine/Level/Scene/Lightmap.h b/Source/Engine/Level/Scene/Lightmap.h index 1fa4a02ea..a5a09ed81 100644 --- a/Source/Engine/Level/Scene/Lightmap.h +++ b/Source/Engine/Level/Scene/Lightmap.h @@ -97,6 +97,6 @@ public: private: #if USE_EDITOR - bool OnInitLightmap(class TextureData& image); + bool OnInitLightmap(struct TextureData& image); #endif }; diff --git a/Source/Engine/Platform/Base/WindowBase.h b/Source/Engine/Platform/Base/WindowBase.h index 7196f046b..dfcb56550 100644 --- a/Source/Engine/Platform/Base/WindowBase.h +++ b/Source/Engine/Platform/Base/WindowBase.h @@ -14,7 +14,7 @@ class Engine; class RenderTask; class SceneRenderTask; class GPUSwapChain; -class TextureData; +struct TextureData; class IGuiData; ///