Add GPUTexture::DownloadData to C#

#2973 #1446
This commit is contained in:
Wojtek Figat
2025-04-07 23:32:37 +02:00
parent 6fc5e1f423
commit 15da2d59e5
7 changed files with 109 additions and 42 deletions

View File

@@ -44,8 +44,9 @@ public:
/// <summary>
/// Texture data container (used to keep data downloaded from the GPU).
/// </summary>
class FLAXENGINE_API TextureData
API_CLASS() class FLAXENGINE_API TextureData : public ScriptingObject
{
DECLARE_SCRIPTING_TYPE_WITH_CONSTRUCTOR_IMPL(TextureData, ScriptingObject);
public:
/// <summary>
/// Single entry of the texture array. Contains collection of mip maps.
@@ -60,39 +61,24 @@ public:
public:
/// <summary>
/// Init
/// Top level texture surface width (in pixels).
/// </summary>
TextureData()
{
}
API_FIELD(ReadOnly) int32 Width = 0;
/// <summary>
/// Destructor
/// Top level texture surface height (in pixels).
/// </summary>
~TextureData()
{
}
public:
/// <summary>
/// Top level texture width (in pixels).
/// </summary>
int32 Width = 0;
API_FIELD(ReadOnly) int32 Height = 0;
/// <summary>
/// Top level texture height (in pixels).
/// Top level texture surface depth (in pixels).
/// </summary>
int32 Height = 0;
/// <summary>
/// Top level texture depth (in pixels).
/// </summary>
int32 Depth = 0;
API_FIELD(ReadOnly) int32 Depth = 0;
/// <summary>
/// The texture data format.
/// </summary>
PixelFormat Format = PixelFormat::Unknown;
API_FIELD(ReadOnly) PixelFormat Format = PixelFormat::Unknown;
/// <summary>
/// The items collection (depth slices or array slices).
@@ -123,26 +109,38 @@ public:
}
/// <summary>
/// Gets amount of textures in the array
/// Gets amount of texture slices in the array.
/// </summary>
int32 GetArraySize() const
{
return Items.Count();
}
API_PROPERTY() int32 GetArraySize() const;
/// <summary>
/// Gets amount of mip maps in the textures
/// Gets amount of mip maps in the texture.
/// </summary>
int32 GetMipLevels() const
{
return Items.HasItems() ? Items[0].Mips.Count() : 0;
}
API_PROPERTY() int32 GetMipLevels() const;
/// <summary>
/// Clear data
/// Clear allocated memory.
/// </summary>
void Clear()
{
Items.Resize(0, false);
}
API_FUNCTION() void Clear();
public:
/// <summary>
/// Gets the texture pixels as Color32 array.
/// </summary>
/// <remarks>Supported only for 'basic' texture formats (uncompressed, single plane).</remarks>
/// <param name="pixels">The result texture pixels array.</param>
/// <param name="mipIndex">The mip index (zero-based).</param>
/// <param name="arrayIndex">The array or depth slice index (zero-based).</param>
/// <returns>True if failed, otherwise false.</returns>
API_FUNCTION() bool GetPixels(API_PARAM(Out) Array<Color32>& pixels, int32 mipIndex = 0, int32 arrayIndex = 0);
/// <summary>
/// Gets the texture pixels as Color array.
/// </summary>
/// <remarks>Supported only for 'basic' texture formats (uncompressed, single plane).</remarks>
/// <param name="pixels">The result texture pixels array.</param>
/// <param name="mipIndex">The mip index (zero-based).</param>
/// <param name="arrayIndex">The array or depth slice index (zero-based).</param>
/// <returns>True if failed, otherwise false.</returns>
API_FUNCTION() bool GetPixels(API_PARAM(Out) Array<Color>& pixels, int32 mipIndex = 0, int32 arrayIndex = 0);
};