Fix various API issues

This commit is contained in:
2026-04-24 11:20:45 +02:00
parent 1988fae929
commit 49943e13de
6 changed files with 41 additions and 8 deletions
@@ -101,6 +101,30 @@ bool TextureMipData::GetPixels(Array<Color32>& pixels, int32 width, int32 height
src += srcRowSize;
}
}
if (PixelFormatExtensions::IsBGRAOrder(format))
{
// BGRA -> RGBA
for (int32 y = 0; y < height; y++)
{
for (int32 x = 0; x < width; x++)
{
auto& color = *((Color32*)(dst + y * RowPitch + x * sizeof(Color32)));
color = Color32(color.B, color.G, color.R, color.A);
}
}
}
if (PixelFormatExtensions::IsSRGB(format))
{
// sRGB -> Linear
for (int32 y = 0; y < height; y++)
{
for (int32 x = 0; x < width; x++)
{
auto& color = *((Color32*)(dst + y * RowPitch + x * sizeof(Color32)));
color = Color32(Color::SrgbToLinear(Color(color)));
}
}
}
break;
default:
{
@@ -118,7 +142,10 @@ bool TextureMipData::GetPixels(Array<Color32>& pixels, int32 width, int32 height
}
return false;
}
LOG(Error, "Unsupported texture data format {0}.", ScriptingEnum::ToString(format));
if (PixelFormatExtensions::IsCompressed(format))
LOG(Error, "Unsupported texture data format {0}. Compressed texture data cannot be accessed directly without decompressing first.", ScriptingEnum::ToString(format));
else
LOG(Error, "Unsupported texture data format {0}.", ScriptingEnum::ToString(format));
return true;
}
}
@@ -221,7 +248,7 @@ void TextureData::Clear()
Items.Resize(0, false);
}
bool TextureData::GetPixels(Array<Color32>& pixels, int32 mipIndex, int32 arrayIndex)
bool TextureData::GetPixels(Array<Color32>& pixels, int32 mipIndex, int32 arrayIndex) const
{
if (Items.IsValidIndex(arrayIndex) && Items.Get()[arrayIndex].Mips.IsValidIndex(mipIndex))
{
@@ -232,7 +259,7 @@ bool TextureData::GetPixels(Array<Color32>& pixels, int32 mipIndex, int32 arrayI
return true;
}
bool TextureData::GetPixels(Array<Color>& pixels, int32 mipIndex, int32 arrayIndex)
bool TextureData::GetPixels(Array<Color>& pixels, int32 mipIndex, int32 arrayIndex) const
{
if (Items.IsValidIndex(arrayIndex) && Items.Get()[arrayIndex].Mips.IsValidIndex(mipIndex))
{
@@ -162,6 +162,7 @@ public:
/// <summary>
/// Gets the mip data.
/// </summary>
/// <remarks>Use with caution as this operation loads texture data from the file.</remarks>
/// <param name="mipIndex">The mip index (zero-based).</param>
/// <param name="rowPitch">The data row pitch (in bytes).</param>
/// <param name="slicePitch">The data slice pitch (in bytes).</param>
@@ -171,6 +172,7 @@ public:
/// <summary>
/// Loads the texture data from the asset.
/// </summary>
/// <remarks>Use with caution as this operation loads texture data from the file.</remarks>
/// <param name="result">The result data.</param>
/// <param name="copyData">True if copy asset data to the result buffer, otherwise texture data will be linked to the internal storage (then the data is valid while asset is loaded and there is no texture data copy operations - faster).</param>
/// <returns>True if cannot load data, otherwise false.</returns>
@@ -179,6 +181,7 @@ public:
/// <summary>
/// Loads the texture data from the asset (single mip).
/// </summary>
/// <remarks>Use with caution as this operation loads texture data from the file.</remarks>
/// <param name="result">The result data.</param>
/// <param name="mipIndex">The mip index (zero-based).</param>
/// <param name="arrayIndex">The array or depth slice index (zero-based).</param>
@@ -189,6 +192,7 @@ public:
/// <summary>
/// Gets the texture pixels as Color32 array.
/// </summary>
/// <remarks>Use with caution as this operation loads texture data from the file.</remarks>
/// <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>
@@ -199,6 +203,7 @@ public:
/// <summary>
/// Gets the texture pixels as Color array.
/// </summary>
/// <remarks>Use with caution as this operation loads texture data from the file.</remarks>
/// <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>
@@ -252,6 +257,7 @@ private:
#if !COMPILE_WITHOUT_CSHARP
// Internal bindings
API_FUNCTION(NoProxy) bool InitCSharp(void* ptr);
API_FUNCTION(NoProxy) TextureData* GetTextureData();
#endif
public:
@@ -132,7 +132,7 @@ public:
/// <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);
API_FUNCTION() bool GetPixels(API_PARAM(Out) Array<Color32>& pixels, int32 mipIndex = 0, int32 arrayIndex = 0) const;
/// <summary>
/// Gets the texture pixels as Color array.
@@ -142,5 +142,5 @@ public:
/// <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);
API_FUNCTION() bool GetPixels(API_PARAM(Out) Array<Color>& pixels, int32 mipIndex = 0, int32 arrayIndex = 0) const;
};
+1 -1
View File
@@ -597,7 +597,7 @@ public:
/// Sets the window icon.
/// </summary>
/// <param name="icon">The icon.</param>
virtual void SetIcon(TextureData& icon)
virtual void SetIcon(const TextureData& icon)
{
}
+1 -1
View File
@@ -1033,7 +1033,7 @@ void SDLWindow::UpdateCursor()
SDL_SetCursor(cursor);
}
void SDLWindow::SetIcon(TextureData& icon)
void SDLWindow::SetIcon(const TextureData& icon)
{
Array<Color32> colorData;
icon.GetPixels(colorData);
+1 -1
View File
@@ -107,7 +107,7 @@ public:
void EndClippingCursor() override;
void SetMousePosition(const Float2& position) const override;
void SetCursor(CursorType type) override;
void SetIcon(TextureData& icon) override;
void SetIcon(const TextureData& icon) override;
void SetCursorImage(void* image) override;
static void* LoadCursorImage(const StringView& path);
static void* LoadCursorImage(const TextureData& image, const Int2& hotSpot = Int2::Zero);