Texture.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. namespace BansheeEngine
  4. {
  5. /// <summary>
  6. /// Base class for all textures. Contains a set of pixels of certain dimensions that can be used for rendering
  7. /// or read/written directly.
  8. /// </summary>
  9. public class Texture : Resource
  10. {
  11. /// <summary>
  12. /// Returns the pixel format for the texture surface.
  13. /// </summary>
  14. public PixelFormat PixelFormat
  15. {
  16. get
  17. {
  18. PixelFormat value;
  19. Internal_GetPixelFormat(mCachedPtr, out value);
  20. return value;
  21. }
  22. }
  23. /// <summary>
  24. /// Returns a value that signals the engine in what way is the texture expected to be used.
  25. /// </summary>
  26. public TextureUsage Usage
  27. {
  28. get
  29. {
  30. TextureUsage value;
  31. Internal_GetUsage(mCachedPtr, out value);
  32. return value;
  33. }
  34. }
  35. /// <summary>
  36. /// Width of the texture in pixels.
  37. /// </summary>
  38. public int Width
  39. {
  40. get
  41. {
  42. int value;
  43. Internal_GetWidth(mCachedPtr, out value);
  44. return value;
  45. }
  46. }
  47. /// <summary>
  48. /// Height of the texture in pixels.
  49. /// </summary>
  50. public int Height
  51. {
  52. get
  53. {
  54. int value;
  55. Internal_GetHeight(mCachedPtr, out value);
  56. return value;
  57. }
  58. }
  59. /// <summary>
  60. /// Determines does the texture contain gamma corrected data. If true then the GPU will automatically convert
  61. /// the pixels to linear space before reading from the texture, and convert them to gamma space when writing
  62. /// to the texture.
  63. /// </summary>
  64. public bool GammaCorrection
  65. {
  66. get
  67. {
  68. bool value;
  69. Internal_GetGammaCorrection(mCachedPtr, out value);
  70. return value;
  71. }
  72. }
  73. /// <summary>
  74. /// Number of samples per pixel. Zero or one mean no multisampling will be used.
  75. /// </summary>
  76. public int SampleCount
  77. {
  78. get
  79. {
  80. int value;
  81. Internal_GetSampleCount(mCachedPtr, out value);
  82. return value;
  83. }
  84. }
  85. /// <summary>
  86. /// Returns how many mipmap levels does the texture contain.
  87. /// </summary>
  88. public int MipmapCount
  89. {
  90. get
  91. {
  92. int value;
  93. Internal_GetMipmapCount(mCachedPtr, out value);
  94. return value;
  95. }
  96. }
  97. [MethodImpl(MethodImplOptions.InternalCall)]
  98. private static extern void Internal_GetPixelFormat(IntPtr thisPtr, out PixelFormat value);
  99. [MethodImpl(MethodImplOptions.InternalCall)]
  100. private static extern void Internal_GetUsage(IntPtr thisPtr, out TextureUsage value);
  101. [MethodImpl(MethodImplOptions.InternalCall)]
  102. private static extern void Internal_GetWidth(IntPtr thisPtr, out int value);
  103. [MethodImpl(MethodImplOptions.InternalCall)]
  104. private static extern void Internal_GetHeight(IntPtr thisPtr, out int value);
  105. [MethodImpl(MethodImplOptions.InternalCall)]
  106. private static extern void Internal_GetGammaCorrection(IntPtr thisPtr, out bool value);
  107. [MethodImpl(MethodImplOptions.InternalCall)]
  108. private static extern void Internal_GetSampleCount(IntPtr thisPtr, out int value);
  109. [MethodImpl(MethodImplOptions.InternalCall)]
  110. private static extern void Internal_GetMipmapCount(IntPtr thisPtr, out int value);
  111. }
  112. /// <summary>
  113. /// Flags that describe how is a texture used.
  114. /// </summary>
  115. public enum TextureUsage // Note: Must match C++ enum TextureUsage
  116. {
  117. /// <summary>
  118. /// A regular texture that is not often or ever updated from the CPU.
  119. /// </summary>
  120. Default = 0x1,
  121. /// <summary>
  122. /// A regular texture that is often updated by the CPU.
  123. /// </summary>
  124. Dynamic = 0x2,
  125. /// <summary>
  126. /// Texture that can be rendered to by the GPU.
  127. /// </summary>
  128. Render = 0x200,
  129. /// <summary>
  130. /// Texture used as a depth/stencil buffer by the GPU.
  131. /// </summary>
  132. DepthStencil = 0x400,
  133. /// <summary>
  134. /// Texture that allows load/store operations from the GPU program.
  135. /// </summary>
  136. LoadStore = 0x800,
  137. /// <summary>
  138. /// Ensures all texture data will also be cached in system memory so it can be read by the CPU.
  139. /// </summary>
  140. CPUCached = 0x1000
  141. }
  142. }