DeferredClearGBufferEffect.cs 4.0 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(GraphicsDevice graphicsDevice, string name)
  30. {
  31. name = GetResourceName(graphicsDevice, name);
  32. using (Stream stream = typeof(DeferredClearGBufferEffect).Assembly.GetManifestResourceStream(name))
  33. {
  34. byte[] bytecode = new byte[stream.Length];
  35. stream.Read(bytecode, 0, (int)stream.Length);
  36. return bytecode;
  37. }
  38. }
  39. private static string GetResourceName(GraphicsDevice graphicsDevice, string name)
  40. {
  41. string platformName = "";
  42. string version = "";
  43. #if XNA
  44. platformName = ".xna.WinReach";
  45. #else
  46. switch (graphicsDevice.Adapter.Backend)
  47. {
  48. case GraphicsBackend.DirectX11:
  49. platformName = ".dx11.fxo";
  50. break;
  51. case GraphicsBackend.OpenGL:
  52. platformName = ".ogl.fxo";
  53. break;
  54. case GraphicsBackend.GLES:
  55. case GraphicsBackend.WebGL:
  56. platformName = ".gles.fxo";
  57. break;
  58. default:
  59. throw new NotSupportedException("Backend");
  60. }
  61. // Detect version
  62. version = ".11";
  63. Version kniVersion = typeof(Effect).Assembly.GetName().Version;
  64. if (kniVersion.Major == 3)
  65. {
  66. if (kniVersion.Minor == 9
  67. || kniVersion.Minor == 10
  68. || kniVersion.Minor == 11
  69. || kniVersion.Minor == 12
  70. || kniVersion.Minor == 13
  71. || kniVersion.Minor == 14)
  72. version = ".10";
  73. }
  74. if (kniVersion.Major == 4)
  75. {
  76. if (kniVersion.Minor == 0
  77. || kniVersion.Minor == 1)
  78. version = ".10";
  79. if (kniVersion.Minor == 2)
  80. version = ".11";
  81. }
  82. #endif
  83. return name + platformName + version;
  84. }
  85. #endregion
  86. #region Public Properties
  87. #endregion
  88. #region Methods
  89. public DeferredClearGBufferEffect(GraphicsDevice graphicsDevice)
  90. : base(graphicsDevice, LoadEffectResource(graphicsDevice, ResourceName))
  91. {
  92. CacheEffectParameters(null);
  93. }
  94. public DeferredClearGBufferEffect(GraphicsDevice graphicsDevice, byte[] Bytecode): base(graphicsDevice, Bytecode)
  95. {
  96. CacheEffectParameters(null);
  97. }
  98. protected DeferredClearGBufferEffect(DeferredClearGBufferEffect cloneSource)
  99. : base(cloneSource)
  100. {
  101. CacheEffectParameters(cloneSource);
  102. }
  103. public override Effect Clone()
  104. {
  105. return new DeferredClearGBufferEffect(this);
  106. }
  107. void CacheEffectParameters(DeferredClearGBufferEffect cloneSource)
  108. {
  109. }
  110. #endregion
  111. }
  112. }