SamplerStateContent.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using TEXFILTER = Microsoft.Xna.Framework.Graphics.TextureFilter;
  5. using TEXADDRESS = Microsoft.Xna.Framework.Graphics.TextureAddressMode;
  6. using TEXSAMPLER = Microsoft.Xna.Framework.Graphics.SamplerState;
  7. namespace MonoScene.Graphics.Content
  8. {
  9. /// <summary>
  10. /// Structure used to create <see cref="SamplerState"/> objects.
  11. /// </summary>
  12. public struct SamplerStateContent
  13. {
  14. public static SamplerStateContent CreateDefault()
  15. {
  16. return new SamplerStateContent
  17. {
  18. AddressU = TEXADDRESS.Wrap,
  19. AddressV = TEXADDRESS.Wrap,
  20. AddressW = TEXADDRESS.Wrap,
  21. Filter = TEXFILTER.Linear
  22. };
  23. }
  24. public TEXFILTER Filter { get; set; }
  25. public TEXADDRESS AddressU { get; set; }
  26. public TEXADDRESS AddressV { get; set; }
  27. public TEXADDRESS AddressW { get; set; }
  28. public TEXSAMPLER CreateState()
  29. {
  30. return new TEXSAMPLER()
  31. {
  32. Filter = this.Filter,
  33. AddressU = this.AddressU,
  34. AddressV = this.AddressV,
  35. AddressW = this.AddressW
  36. };
  37. }
  38. public TEXSAMPLER TryGetPredefinedSampler()
  39. {
  40. if (AddressU != AddressV) return null;
  41. if (Filter == TEXFILTER.Point)
  42. {
  43. if (AddressU == TEXADDRESS.Clamp) return TEXSAMPLER.PointClamp;
  44. if (AddressU == TEXADDRESS.Wrap) return TEXSAMPLER.PointWrap;
  45. }
  46. if (Filter == TEXFILTER.Linear)
  47. {
  48. if (AddressU == TEXADDRESS.Clamp) return TEXSAMPLER.LinearClamp;
  49. if (AddressU == TEXADDRESS.Wrap) return TEXSAMPLER.LinearWrap;
  50. }
  51. if (Filter == TEXFILTER.Anisotropic)
  52. {
  53. if (AddressU == TEXADDRESS.Clamp) return TEXSAMPLER.AnisotropicClamp;
  54. if (AddressU == TEXADDRESS.Wrap) return TEXSAMPLER.AnisotropicWrap;
  55. }
  56. return null;
  57. }
  58. }
  59. }