Shader.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Runtime.CompilerServices;
  5. namespace BansheeEngine
  6. {
  7. /** @addtogroup Rendering
  8. * @{
  9. */
  10. /// <summary>
  11. /// Type of parameters that can be defined in a shader.
  12. /// </summary>
  13. public enum ShaderParameterType // Note: Must match C++ ShaderParameterType enum
  14. {
  15. Float, Vector2, Vector3, Vector4, Color,
  16. Matrix3, Matrix4, Texture2D,
  17. Texture3D, TextureCube, Sampler
  18. }
  19. /// <summary>
  20. /// Contains information about a shader parameter.
  21. /// </summary>
  22. public struct ShaderParameter
  23. {
  24. /// <summary>
  25. /// Returns the name of the parameter variable.
  26. /// </summary>
  27. public string Name { get { return name; } }
  28. /// <summary>
  29. /// Returns the data type of the parameter.
  30. /// </summary>
  31. public ShaderParameterType Type { get { return type; } }
  32. /// <summary>
  33. /// Determines is parameter managed internally be the renderer, or is it expected to be set by the user.
  34. /// </summary>
  35. public bool Internal { get { return isInternal; } }
  36. private string name;
  37. private ShaderParameterType type;
  38. private bool isInternal;
  39. /// <summary>
  40. /// Creates a new shader parameter.
  41. /// </summary>
  42. /// <param name="name">Name of the parameter variable.</param>
  43. /// <param name="type">Data type of the parameter.</param>
  44. /// <param name="isInternal">Determines is parameter managed internally be the renderer, or is expected to be set
  45. /// by the user.</param>
  46. internal ShaderParameter(string name, ShaderParameterType type, bool isInternal)
  47. {
  48. this.name = name;
  49. this.type = type;
  50. this.isInternal = isInternal;
  51. }
  52. }
  53. /// <summary>
  54. /// Contains definitions of GPU programs used for rendering, as well as a set of global parameters to control those
  55. /// programs.
  56. /// </summary>
  57. public class Shader : Resource
  58. {
  59. /// <summary>
  60. /// Constuctor for internal runtime use only.
  61. /// </summary>
  62. private Shader()
  63. { }
  64. /// <summary>
  65. /// Returns data about all parameters available in the shader.
  66. /// </summary>
  67. public ShaderParameter[] Parameters
  68. {
  69. get
  70. {
  71. string[] names;
  72. ShaderParameterType[] types;
  73. bool[] visibility;
  74. Internal_GetShaderParameters(mCachedPtr, out names, out types, out visibility);
  75. ShaderParameter[] parameters = new ShaderParameter[names.Length];
  76. for (int i = 0; i < names.Length; i++)
  77. {
  78. parameters[i] = new ShaderParameter(names[i], types[i], visibility[i]);
  79. }
  80. return parameters;
  81. }
  82. }
  83. [MethodImpl(MethodImplOptions.InternalCall)]
  84. private static extern void Internal_GetShaderParameters(IntPtr nativeInstance, out string[] names,
  85. out ShaderParameterType[] types, out bool[] visibility);
  86. }
  87. /** @} */
  88. }