DeferredClearGBufferEffect.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 nkast.Aether.Shaders
  22. {
  23. public class DeferredClearGBufferEffect : Effect
  24. {
  25. #region Effect Parameters
  26. #endregion
  27. #region Fields
  28. static readonly String ResourceName = "nkast.Aether.Shaders.Resources.DeferredClearGBuffer";
  29. internal static byte[] LoadEffectResource(string name)
  30. {
  31. name = GetResourceName(name);
  32. using (var stream = GetAssembly(typeof(DeferredClearGBufferEffect)).GetManifestResourceStream(name))
  33. {
  34. var bytecode = new byte[stream.Length];
  35. stream.Read(bytecode, 0, (int)stream.Length);
  36. return bytecode;
  37. }
  38. }
  39. private static string GetResourceName(string name)
  40. {
  41. String platformName = "";
  42. var version = "";
  43. #if XNA
  44. platformName = ".xna.WinReach";
  45. #else
  46. switch (MonoGame.Framework.Utilities.PlatformInfo.GraphicsBackend)
  47. {
  48. case MonoGame.Framework.Utilities.GraphicsBackend.DirectX:
  49. platformName = ".dx11.fxo";
  50. break;
  51. case MonoGame.Framework.Utilities.GraphicsBackend.OpenGL:
  52. platformName = ".ogl.fxo";
  53. break;
  54. default:
  55. throw new NotSupportedException("platform");
  56. }
  57. // Detect version
  58. version = ".10";
  59. var mgVersion = GetAssembly(typeof(Effect)).GetName().Version;
  60. if (mgVersion.Major == 3)
  61. {
  62. if (mgVersion.Minor == 6)
  63. version = ".8";
  64. if (mgVersion.Minor == 7)
  65. version = ".8";
  66. if (mgVersion.Minor == 8)
  67. {
  68. version = ".9";
  69. if (mgVersion.Build == 1 || mgVersion.Build >= 9100)
  70. version = ".10";
  71. }
  72. }
  73. #endif
  74. return name + platformName + version;
  75. }
  76. private static Assembly GetAssembly(Type type)
  77. {
  78. #if W10
  79. return type.GetTypeInfo().Assembly;
  80. #else
  81. return type.Assembly;
  82. #endif
  83. }
  84. #endregion
  85. #region Public Properties
  86. #endregion
  87. #region Methods
  88. public DeferredClearGBufferEffect(GraphicsDevice graphicsDevice)
  89. : base(graphicsDevice, LoadEffectResource(ResourceName))
  90. {
  91. CacheEffectParameters(null);
  92. }
  93. public DeferredClearGBufferEffect(GraphicsDevice graphicsDevice, byte[] Bytecode): base(graphicsDevice, Bytecode)
  94. {
  95. CacheEffectParameters(null);
  96. }
  97. protected DeferredClearGBufferEffect(DeferredClearGBufferEffect cloneSource)
  98. : base(cloneSource)
  99. {
  100. CacheEffectParameters(cloneSource);
  101. }
  102. public override Effect Clone()
  103. {
  104. return new DeferredClearGBufferEffect(this);
  105. }
  106. void CacheEffectParameters(DeferredClearGBufferEffect cloneSource)
  107. {
  108. }
  109. #endregion
  110. }
  111. }