mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Texture GetPixel implemented (#2320)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using JetBrains.Annotations;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -31,5 +31,14 @@ namespace Robust.Client.Graphics
|
||||
/// Our sub region within our source, in pixel coordinates.
|
||||
/// </summary>
|
||||
public UIBox2 SubRegion { get; }
|
||||
|
||||
public override Color GetPixel(int x, int y)
|
||||
{
|
||||
DebugTools.Assert(x < SubRegion.Right);
|
||||
DebugTools.Assert(y < SubRegion.Top);
|
||||
int xTranslated = x + (int) SubRegion.Left;
|
||||
int yTranslated = y + (int) SubRegion.Top;
|
||||
return this.SourceTexture[xTranslated, yTranslated];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
@@ -11,6 +12,7 @@ using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using Color = Robust.Shared.Maths.Color;
|
||||
using OGLTextureWrapMode = OpenToolkit.Graphics.OpenGL.TextureWrapMode;
|
||||
using PIF = OpenToolkit.Graphics.OpenGL4.PixelInternalFormat;
|
||||
using PF = OpenToolkit.Graphics.OpenGL4.PixelFormat;
|
||||
@@ -146,7 +148,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
CheckGlError();
|
||||
ApplySampleParameters(loadParams.SampleParameters);
|
||||
|
||||
var (pif, _, _) = PixelEnums<T>(loadParams.Srgb);
|
||||
var (pif, pf, pt) = PixelEnums<T>(loadParams.Srgb);
|
||||
var pixelType = typeof(T);
|
||||
var texPixType = GetTexturePixelType<T>();
|
||||
var isActuallySrgb = false;
|
||||
@@ -633,6 +635,25 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
return $"ClydeTexture: ({TextureId})";
|
||||
}
|
||||
|
||||
public override Color GetPixel(int x, int y)
|
||||
{
|
||||
if (!_clyde._loadedTextures.TryGetValue(TextureId, out var loaded))
|
||||
{
|
||||
throw new DataException("Texture not found");
|
||||
}
|
||||
|
||||
Span<byte> rgba = stackalloc byte[4];
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* p = rgba)
|
||||
{
|
||||
GL.GetTextureImage(loaded.OpenGLObject.Handle, 0, PF.Rgba, PT.UnsignedByte, 4, (IntPtr) p);
|
||||
}
|
||||
}
|
||||
|
||||
return new Color(rgba[0], rgba[1], rgba[2], rgba[3]);
|
||||
}
|
||||
}
|
||||
|
||||
public Texture GetStockTexture(ClydeStockTexture stockTexture)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
@@ -383,6 +383,11 @@ namespace Robust.Client.Graphics.Clyde
|
||||
{
|
||||
// Just do nothing on mutate.
|
||||
}
|
||||
|
||||
public override Color GetPixel(int x, int y)
|
||||
{
|
||||
return Color.Black;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class DummyShaderInstance : ShaderInstance
|
||||
|
||||
@@ -7,6 +7,7 @@ using Robust.Shared.Utility;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
using Color = Robust.Shared.Maths.Color;
|
||||
|
||||
namespace Robust.Client.Graphics
|
||||
{
|
||||
@@ -31,6 +32,8 @@ namespace Robust.Client.Graphics
|
||||
/// </summary>
|
||||
public Vector2i Size { get; /*protected set;*/ }
|
||||
|
||||
public Color this[int x, int y] => this.GetPixel(x, y);
|
||||
|
||||
protected Texture(Vector2i size)
|
||||
{
|
||||
Size = size;
|
||||
@@ -104,6 +107,8 @@ namespace Robust.Client.Graphics
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract Color GetPixel(int x, int y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user