mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-01 01:27:13 +02:00
* Add load parameter support to RSIs. Currently only supports turning sRGB off. RSIs with custom load parameters are not thrown into the meta-atlas. As part of this, TextureLoadParameters and TextureSampleParameters has been made to support equality. * Add UV2 channel to vertices. This is a bad hack to make displacement maps work in Robust. The UV2 channel goes from 0 -> 1 across the draw and can therefore be used by displacement maps to map a separate displacement map layer on top of the regular meta-atlas RSI texture. This creates float inaccuracy issues but they weren't bad enough to completely void the feature. I'm thinking I learn from this experience and completely re-do how UVs work with the renderer rewrite, so that hopefully won't happen anymore. This required dumping the optimized PadVerticesV2 because the changed struct size made it impractical. RIP. I don't like this approach at all but the renderer is slated for a rewrite anyways, and all shaders will need to be rewritten regardless. * Add CopyToShaderParameters for sprite layers. This effectively allows copying the parameters of a sprite layer into another layer's shader parameters. The use case is to copy texture coordinates for displacement maps, as the exact map used changes depending on orientation. It also enables animations to be used though I didn't use that personally.
91 lines
2.7 KiB
C#
91 lines
2.7 KiB
C#
using System;
|
|
using JetBrains.Annotations;
|
|
using Robust.Shared.Utility;
|
|
using YamlDotNet.RepresentationModel;
|
|
|
|
namespace Robust.Shared.Graphics;
|
|
|
|
/// <summary>
|
|
/// Sample flags for textures.
|
|
/// These are separate from <see cref="TextureLoadParameters"/>,
|
|
/// because it is possible to create "proxies" to existing textures
|
|
/// with different sampling parameters than the base texture.
|
|
/// </summary>
|
|
[PublicAPI]
|
|
public struct TextureSampleParameters : IEquatable<TextureSampleParameters>
|
|
{
|
|
// NOTE: If somebody is gonna add support for 3D/1D textures, change this doc comment.
|
|
// See the note on this page for why: https://www.khronos.org/opengl/wiki/Sampler_Object#Filtering
|
|
/// <summary>
|
|
/// If true, use bi-linear texture filtering if the texture cannot be rendered 1:1
|
|
/// </summary>
|
|
public bool Filter { get; set; }
|
|
|
|
/// <summary>
|
|
/// Controls how to wrap the texture if texture coordinates outside 0-1 are accessed.
|
|
/// </summary>
|
|
public TextureWrapMode WrapMode { get; set; }
|
|
|
|
public static TextureSampleParameters FromYaml(YamlMappingNode node)
|
|
{
|
|
var wrap = TextureWrapMode.None;
|
|
var filter = false;
|
|
|
|
if (node.TryGetNode("filter", out var filterNode))
|
|
{
|
|
filter = filterNode.AsBool();
|
|
}
|
|
|
|
if (node.TryGetNode("wrap", out var wrapNode))
|
|
{
|
|
switch (wrapNode.AsString())
|
|
{
|
|
case "none":
|
|
wrap = TextureWrapMode.None;
|
|
break;
|
|
case "repeat":
|
|
wrap = TextureWrapMode.Repeat;
|
|
break;
|
|
case "mirrored_repeat":
|
|
wrap = TextureWrapMode.MirroredRepeat;
|
|
break;
|
|
default:
|
|
throw new ArgumentException("Not a valid wrap mode.");
|
|
}
|
|
}
|
|
|
|
return new TextureSampleParameters {Filter = filter, WrapMode = wrap};
|
|
}
|
|
|
|
public static readonly TextureSampleParameters Default = new()
|
|
{
|
|
Filter = false,
|
|
WrapMode = TextureWrapMode.None
|
|
};
|
|
|
|
public bool Equals(TextureSampleParameters other)
|
|
{
|
|
return Filter == other.Filter && WrapMode == other.WrapMode;
|
|
}
|
|
|
|
public override bool Equals(object? obj)
|
|
{
|
|
return obj is TextureSampleParameters other && Equals(other);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return HashCode.Combine(Filter, (int) WrapMode);
|
|
}
|
|
|
|
public static bool operator ==(TextureSampleParameters left, TextureSampleParameters right)
|
|
{
|
|
return left.Equals(right);
|
|
}
|
|
|
|
public static bool operator !=(TextureSampleParameters left, TextureSampleParameters right)
|
|
{
|
|
return !left.Equals(right);
|
|
}
|
|
}
|