Skip to content

Commit

Permalink
Update sRGB API for Texture and RenderTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
Marioalexsan authored and eXpl0it3r committed Jun 3, 2024
1 parent b1cfedb commit 1efcfdc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/SFML.Graphics/RenderTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ public interface RenderTarget
////////////////////////////////////////////////////////////
Vector2u Size { get; }


////////////////////////////////////////////////////////////
/// <summary>
/// Tell if the render target will use sRGB encoding when drawing on it
/// </summary>
////////////////////////////////////////////////////////////
bool IsSrgb { get; }

////////////////////////////////////////////////////////////
/// <summary>
/// Default view of the target
Expand Down
23 changes: 18 additions & 5 deletions src/SFML.Graphics/Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,26 +190,39 @@ public Texture(Image image, IntRect area, bool srgb = false) :
/// <exception cref="LoadingFailedException" />
////////////////////////////////////////////////////////////
public Texture(byte[] bytes, bool srgb = false) :
this(bytes, new IntRect(0, 0, 0, 0), srgb)
{
}

////////////////////////////////////////////////////////////
/// <summary>
/// Construct the texture from a file in memory
/// </summary>
/// <param name="bytes">Byte array containing the file contents</param>
/// <param name="area">Area of the image to load</param>
/// <param name="srgb">True to convert the texture source from sRGB, false otherwise</param>
/// <exception cref="LoadingFailedException" />
////////////////////////////////////////////////////////////
public Texture(byte[] bytes, IntRect area, bool srgb = false) :
base(IntPtr.Zero)
{
GCHandle pin = GCHandle.Alloc(bytes, GCHandleType.Pinned);
try
{
IntRect rect = new IntRect(0, 0, 0, 0);

if (srgb)
{
CPointer = sfTexture_createSrgbFromMemory(pin.AddrOfPinnedObject(), Convert.ToUInt64(bytes.Length), ref rect);
CPointer = sfTexture_createSrgbFromMemory(pin.AddrOfPinnedObject(), Convert.ToUInt64(bytes.Length), ref area);
}
else
{
CPointer = sfTexture_createFromMemory(pin.AddrOfPinnedObject(), Convert.ToUInt64(bytes.Length), ref rect);
}
CPointer = sfTexture_createFromMemory(pin.AddrOfPinnedObject(), Convert.ToUInt64(bytes.Length), ref area);
}
}
finally
{
pin.Free();
}

if (CPointer == IntPtr.Zero)
{
throw new LoadingFailedException("texture");
Expand Down

0 comments on commit 1efcfdc

Please sign in to comment.