SLMCProcessor.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #region License
  2. // Copyright 2019 Kastellanos Nikolaos
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #endregion
  16. using Microsoft.Xna.Framework;
  17. using Microsoft.Xna.Framework.Content.Pipeline;
  18. using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
  19. using Microsoft.Xna.Framework.Content.Pipeline.Processors;
  20. using Microsoft.Xna.Framework.Graphics;
  21. using Microsoft.Xna.Framework.Graphics.PackedVector;
  22. using System.ComponentModel;
  23. namespace nkast.Aether.Content.Pipeline
  24. {
  25. [ContentProcessor(DisplayName = "SLMCProcessor - Aether")]
  26. public class SLMCProcessor : ContentProcessor<TextureContent, TextureContent>
  27. {
  28. SLMCOutputFormat _textureFormat = SLMCOutputFormat.BGRA4444;
  29. bool _generateMipmaps = true;
  30. [DefaultValue(SLMCOutputFormat.BGRA4444)]
  31. public virtual SLMCOutputFormat TextureFormat
  32. {
  33. get { return _textureFormat; }
  34. set { _textureFormat = value; }
  35. }
  36. [DefaultValue(true)]
  37. public virtual bool GenerateMipmaps
  38. {
  39. get { return _generateMipmaps; }
  40. set { _generateMipmaps = value; }
  41. }
  42. public SLMCProcessor()
  43. {
  44. }
  45. public override TextureContent Process(TextureContent input, ContentProcessorContext context)
  46. {
  47. TextureContent output = input;
  48. SurfaceFormat format;
  49. output.Faces[0][0].TryGetFormat(out format);
  50. if (format != SurfaceFormat.Color)
  51. throw new InvalidContentException("Input SurfaceFormat must be color.");
  52. if (TextureFormat == SLMCOutputFormat.BGRA4444)
  53. {
  54. output.ConvertBitmapType(typeof(PixelBitmapContent<Bgra4444>));
  55. }
  56. if (GenerateMipmaps)
  57. output.GenerateMipmaps(false);
  58. // TODO: implement TextureContent.Validate in MonoGame
  59. //output.Validate(context.TargetProfile);
  60. return output;
  61. }
  62. }
  63. }