Fix various API issues
This commit is contained in:
@@ -101,6 +101,30 @@ bool TextureMipData::GetPixels(Array<Color32>& pixels, int32 width, int32 height
|
|||||||
src += srcRowSize;
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
@@ -118,7 +142,10 @@ bool TextureMipData::GetPixels(Array<Color32>& pixels, int32 width, int32 height
|
|||||||
}
|
}
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,7 +248,7 @@ void TextureData::Clear()
|
|||||||
Items.Resize(0, false);
|
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))
|
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;
|
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))
|
if (Items.IsValidIndex(arrayIndex) && Items.Get()[arrayIndex].Mips.IsValidIndex(mipIndex))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ public:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the mip data.
|
/// Gets the mip data.
|
||||||
/// </summary>
|
/// </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="mipIndex">The mip index (zero-based).</param>
|
||||||
/// <param name="rowPitch">The data row pitch (in bytes).</param>
|
/// <param name="rowPitch">The data row pitch (in bytes).</param>
|
||||||
/// <param name="slicePitch">The data slice pitch (in bytes).</param>
|
/// <param name="slicePitch">The data slice pitch (in bytes).</param>
|
||||||
@@ -171,6 +172,7 @@ public:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the texture data from the asset.
|
/// Loads the texture data from the asset.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>Use with caution as this operation loads texture data from the file.</remarks>
|
||||||
/// <param name="result">The result data.</param>
|
/// <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>
|
/// <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>
|
/// <returns>True if cannot load data, otherwise false.</returns>
|
||||||
@@ -179,6 +181,7 @@ public:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the texture data from the asset (single mip).
|
/// Loads the texture data from the asset (single mip).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>Use with caution as this operation loads texture data from the file.</remarks>
|
||||||
/// <param name="result">The result data.</param>
|
/// <param name="result">The result data.</param>
|
||||||
/// <param name="mipIndex">The mip index (zero-based).</param>
|
/// <param name="mipIndex">The mip index (zero-based).</param>
|
||||||
/// <param name="arrayIndex">The array or depth slice index (zero-based).</param>
|
/// <param name="arrayIndex">The array or depth slice index (zero-based).</param>
|
||||||
@@ -189,6 +192,7 @@ public:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the texture pixels as Color32 array.
|
/// Gets the texture pixels as Color32 array.
|
||||||
/// </summary>
|
/// </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>
|
/// <remarks>Supported only for 'basic' texture formats (uncompressed, single plane).</remarks>
|
||||||
/// <param name="pixels">The result texture pixels array.</param>
|
/// <param name="pixels">The result texture pixels array.</param>
|
||||||
/// <param name="mipIndex">The mip index (zero-based).</param>
|
/// <param name="mipIndex">The mip index (zero-based).</param>
|
||||||
@@ -199,6 +203,7 @@ public:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the texture pixels as Color array.
|
/// Gets the texture pixels as Color array.
|
||||||
/// </summary>
|
/// </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>
|
/// <remarks>Supported only for 'basic' texture formats (uncompressed, single plane).</remarks>
|
||||||
/// <param name="pixels">The result texture pixels array.</param>
|
/// <param name="pixels">The result texture pixels array.</param>
|
||||||
/// <param name="mipIndex">The mip index (zero-based).</param>
|
/// <param name="mipIndex">The mip index (zero-based).</param>
|
||||||
@@ -252,6 +257,7 @@ private:
|
|||||||
#if !COMPILE_WITHOUT_CSHARP
|
#if !COMPILE_WITHOUT_CSHARP
|
||||||
// Internal bindings
|
// Internal bindings
|
||||||
API_FUNCTION(NoProxy) bool InitCSharp(void* ptr);
|
API_FUNCTION(NoProxy) bool InitCSharp(void* ptr);
|
||||||
|
API_FUNCTION(NoProxy) TextureData* GetTextureData();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ public:
|
|||||||
/// <param name="mipIndex">The mip index (zero-based).</param>
|
/// <param name="mipIndex">The mip index (zero-based).</param>
|
||||||
/// <param name="arrayIndex">The array or depth slice index (zero-based).</param>
|
/// <param name="arrayIndex">The array or depth slice index (zero-based).</param>
|
||||||
/// <returns>True if failed, otherwise false.</returns>
|
/// <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>
|
/// <summary>
|
||||||
/// Gets the texture pixels as Color array.
|
/// Gets the texture pixels as Color array.
|
||||||
@@ -142,5 +142,5 @@ public:
|
|||||||
/// <param name="mipIndex">The mip index (zero-based).</param>
|
/// <param name="mipIndex">The mip index (zero-based).</param>
|
||||||
/// <param name="arrayIndex">The array or depth slice index (zero-based).</param>
|
/// <param name="arrayIndex">The array or depth slice index (zero-based).</param>
|
||||||
/// <returns>True if failed, otherwise false.</returns>
|
/// <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;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -597,7 +597,7 @@ public:
|
|||||||
/// Sets the window icon.
|
/// Sets the window icon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="icon">The icon.</param>
|
/// <param name="icon">The icon.</param>
|
||||||
virtual void SetIcon(TextureData& icon)
|
virtual void SetIcon(const TextureData& icon)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1033,7 +1033,7 @@ void SDLWindow::UpdateCursor()
|
|||||||
SDL_SetCursor(cursor);
|
SDL_SetCursor(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLWindow::SetIcon(TextureData& icon)
|
void SDLWindow::SetIcon(const TextureData& icon)
|
||||||
{
|
{
|
||||||
Array<Color32> colorData;
|
Array<Color32> colorData;
|
||||||
icon.GetPixels(colorData);
|
icon.GetPixels(colorData);
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ public:
|
|||||||
void EndClippingCursor() override;
|
void EndClippingCursor() override;
|
||||||
void SetMousePosition(const Float2& position) const override;
|
void SetMousePosition(const Float2& position) const override;
|
||||||
void SetCursor(CursorType type) override;
|
void SetCursor(CursorType type) override;
|
||||||
void SetIcon(TextureData& icon) override;
|
void SetIcon(const TextureData& icon) override;
|
||||||
void SetCursorImage(void* image) override;
|
void SetCursorImage(void* image) override;
|
||||||
static void* LoadCursorImage(const StringView& path);
|
static void* LoadCursorImage(const StringView& path);
|
||||||
static void* LoadCursorImage(const TextureData& image, const Int2& hotSpot = Int2::Zero);
|
static void* LoadCursorImage(const TextureData& image, const Int2& hotSpot = Int2::Zero);
|
||||||
|
|||||||
Reference in New Issue
Block a user