Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; }
Comment thread
eXpl0it3r marked this conversation as resolved.

////////////////////////////////////////////////////////////
/// <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