DeferredClearGBufferEffect.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #region License
  2. // Copyright 2014-2016 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 System;
  17. using System.IO;
  18. using System.Reflection;
  19. using Microsoft.Xna.Framework;
  20. using Microsoft.Xna.Framework.Graphics;
  21. namespace tainicom.Aether.Shaders
  22. {
  23. public class DeferredClearGBufferEffect : Effect
  24. {
  25. #region Effect Parameters
  26. #endregion
  27. #region Fields
  28. #if ((MG && WINDOWS) || W8_1 || W10)
  29. static readonly String resourceName = "tainicom.Aether.Shaders.Resources.DeferredClearGBuffer.dx11.mgfxo";
  30. #else
  31. static readonly String resourceName = "tainicom.Aether.Shaders.Resources.DeferredClearGBuffer.xna.WinReach";
  32. #endif
  33. internal static byte[] LoadEffectResource(string name)
  34. {
  35. using (var stream = LoadEffectResourceStream(name))
  36. {
  37. var bytecode = new byte[stream.Length];
  38. stream.Read(bytecode, 0, (int)stream.Length);
  39. return bytecode;
  40. }
  41. }
  42. internal static Stream LoadEffectResourceStream(string name)
  43. {
  44. // Detect MG version
  45. var version = "";
  46. #if !XNA
  47. version = ".9";
  48. var mgVersion = GetAssembly(typeof(Effect)).GetName().Version;
  49. if (mgVersion.Major == 3)
  50. {
  51. if (mgVersion.Minor == 4)
  52. version = ".6";
  53. if (mgVersion.Minor == 5)
  54. version = ".7";
  55. if (mgVersion.Minor == 6)
  56. version = ".8";
  57. if (mgVersion.Minor == 7)
  58. version = ".8";
  59. if (mgVersion.Minor == 8)
  60. version = ".9";
  61. }
  62. name = name + version;
  63. #endif
  64. Stream stream = GetAssembly(typeof(DeferredClearGBufferEffect)).GetManifestResourceStream(name);
  65. return stream;
  66. }
  67. private static Assembly GetAssembly(Type type)
  68. {
  69. #if W8_1 || W10
  70. return type.GetTypeInfo().Assembly;
  71. #else
  72. return type.Assembly;
  73. #endif
  74. }
  75. #endregion
  76. #region Public Properties
  77. #endregion
  78. #region Methods
  79. public DeferredClearGBufferEffect(GraphicsDevice graphicsDevice)
  80. : base(graphicsDevice,
  81. #if NETFX_CORE || WP8
  82. LoadEffectResourceStream(resourceName), true
  83. #else
  84. LoadEffectResource(resourceName)
  85. #endif
  86. )
  87. {
  88. CacheEffectParameters(null);
  89. }
  90. public DeferredClearGBufferEffect(GraphicsDevice graphicsDevice, byte[] Bytecode): base(graphicsDevice, Bytecode)
  91. {
  92. CacheEffectParameters(null);
  93. }
  94. protected DeferredClearGBufferEffect(DeferredClearGBufferEffect cloneSource)
  95. : base(cloneSource)
  96. {
  97. CacheEffectParameters(cloneSource);
  98. }
  99. public override Effect Clone()
  100. {
  101. return new DeferredClearGBufferEffect(this);
  102. }
  103. void CacheEffectParameters(DeferredClearGBufferEffect cloneSource)
  104. {
  105. }
  106. #endregion
  107. }
  108. }