using System; using JetBrains.Annotations; using Robust.Shared.Utility; using YamlDotNet.RepresentationModel; namespace Robust.Shared.Graphics; /// /// Sample flags for textures. /// These are separate from , /// because it is possible to create "proxies" to existing textures /// with different sampling parameters than the base texture. /// [PublicAPI] public struct 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 /// /// If true, use bi-linear texture filtering if the texture cannot be rendered 1:1 /// public bool Filter { get; set; } /// /// Controls how to wrap the texture if texture coordinates outside 0-1 are accessed. /// 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 }; }