Texture.generated.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using System.Runtime.InteropServices;
  4. namespace BansheeEngine
  5. {
  6. /** @addtogroup Rendering
  7. * @{
  8. */
  9. /// <summary>
  10. /// Abstract class representing a texture. Specific render systems have their own Texture implementations. Internally
  11. /// represented as one or more surfaces with pixels in a certain number of dimensions, backed by a hardware buffer.
  12. /// </summary>
  13. [ShowInInspector]
  14. public partial class Texture : Resource
  15. {
  16. private Texture(bool __dummy0) { }
  17. protected Texture() { }
  18. private Texture(PixelFormat format, uint width, uint height, uint depth, TextureType texType, TextureUsage usage, uint numSamples, bool hasMipmaps, bool gammaCorrection)
  19. {
  20. Internal_create(this, format, width, height, depth, texType, usage, numSamples, hasMipmaps, gammaCorrection);
  21. }
  22. /// <summary>Returns a reference wrapper for this resource.</summary>
  23. public RRef<Texture> Ref
  24. {
  25. get { return Internal_GetRef(mCachedPtr); }
  26. }
  27. /// <summary>Returns the pixel format for the texture surface.</summary>
  28. [ShowInInspector]
  29. public PixelFormat PixelFormat
  30. {
  31. get { return Internal_getPixelFormat(mCachedPtr); }
  32. }
  33. /// <summary>Returns a value that signals the engine in what way is the texture expected to be used.</summary>
  34. [ShowInInspector]
  35. public TextureUsage Usage
  36. {
  37. get { return Internal_getUsage(mCachedPtr); }
  38. }
  39. /// <summary>Gets the type of texture.</summary>
  40. [ShowInInspector]
  41. public TextureType Type
  42. {
  43. get { return Internal_getType(mCachedPtr); }
  44. }
  45. /// <summary>Returns the width of the texture.</summary>
  46. [ShowInInspector]
  47. public uint Width
  48. {
  49. get { return Internal_getWidth(mCachedPtr); }
  50. }
  51. /// <summary>Returns the height of the texture.</summary>
  52. [ShowInInspector]
  53. public uint Height
  54. {
  55. get { return Internal_getHeight(mCachedPtr); }
  56. }
  57. /// <summary>Returns the depth of the texture (only applicable for 3D textures).</summary>
  58. [ShowInInspector]
  59. public uint Depth
  60. {
  61. get { return Internal_getDepth(mCachedPtr); }
  62. }
  63. /// <summary>
  64. /// Determines does the texture contain gamma corrected data. If true then the GPU will automatically convert the pixels
  65. /// to linear space before reading from the texture, and convert them to gamma space when writing to the texture.
  66. /// </summary>
  67. [ShowInInspector]
  68. public bool GammaSpace
  69. {
  70. get { return Internal_getGammaCorrection(mCachedPtr); }
  71. }
  72. /// <summary>Gets the number of samples used for multisampling (0 or 1 if multisampling is not used).</summary>
  73. [ShowInInspector]
  74. public uint SampleCount
  75. {
  76. get { return Internal_getSampleCount(mCachedPtr); }
  77. }
  78. /// <summary>
  79. /// Gets the number of mipmaps to be used for this texture. This number excludes the top level map (which is always
  80. /// assumed to be present).
  81. /// </summary>
  82. [ShowInInspector]
  83. public uint MipMapCount
  84. {
  85. get { return Internal_getMipmapCount(mCachedPtr); }
  86. }
  87. /// <summary>Returns a reference wrapper for this resource.</summary>
  88. public static implicit operator RRef<Texture>(Texture x)
  89. { return Internal_GetRef(x.mCachedPtr); }
  90. /// <summary>
  91. /// Returns pixels for the specified mip level & face. Pixels will be read from system memory, which means the texture
  92. /// has to be created with TextureUsage.CPUCached. If the texture was updated from the GPU the pixels retrieved from this
  93. /// method will not reflect that, and you should use GetGPUPixels instead.
  94. /// </summary>
  95. /// <param name="mipLevel">Mip level to retrieve pixels for. Top level (0) is the highest quality.</param>
  96. /// <param name="face">
  97. /// Face to read the pixels from. Cubemap textures have six faces whose face indices are as specified in the CubeFace
  98. /// enum. Array textures can have an arbitrary number of faces (if it's a cubemap array it has to be a multiple of 6).
  99. /// </param>
  100. /// <returns>A set of pixels for the specified mip level.</returns>
  101. public PixelData GetPixels(uint face = 0, uint mipLevel = 0)
  102. {
  103. return Internal_getPixels(mCachedPtr, face, mipLevel);
  104. }
  105. /// <summary>
  106. /// Reads texture pixels directly from the GPU. This is similar to GetPixels but the texture doesn't need to be created
  107. /// with TextureUsage.CPUCached, and the data will contain any updates performed by the GPU. This method can be
  108. /// potentially slow as it introduces a CPU-GPU synchronization point. Additionally this method is asynchronous which
  109. /// means the data is not available immediately.
  110. /// </summary>
  111. /// <param name="mipLevel">Mip level to retrieve pixels for. Top level (0) is the highest quality.</param>
  112. /// <param name="face">
  113. /// Face to read the pixels from. Cubemap textures have six faces whose face indices are as specified in the CubeFace
  114. /// enum. Array textures can have an arbitrary number of faces (if it's a cubemap array it has to be a multiple of 6).
  115. /// </param>
  116. /// <returns>AsyncOp object that will contain a PixelData object when the operation completes.</returns>
  117. public AsyncOp GetGPUPixels(uint face = 0, uint mipLevel = 0)
  118. {
  119. return Internal_getGPUPixels(mCachedPtr, face, mipLevel);
  120. }
  121. /// <summary>Sets pixels for the specified mip level and face.</summary>
  122. /// <param name="data">
  123. /// Pixels to assign to the specified mip level. Pixel data must match the mip level size and texture pixel format.
  124. /// </param>
  125. /// <param name="mipLevel">Mip level to set pixels for. Top level (0) is the highest quality.</param>
  126. /// <param name="face">
  127. /// Face to write the pixels to. Cubemap textures have six faces whose face indices are as specified in the CubeFace
  128. /// enum. Array textures can have an arbitrary number of faces (if it's a cubemap array it has to be a multiple of 6).
  129. /// </param>
  130. public void SetPixels(PixelData data, uint face = 0, uint mipLevel = 0)
  131. {
  132. Internal_setPixels(mCachedPtr, data, face, mipLevel);
  133. }
  134. /// <summary>Sets pixels for the specified mip level and face.</summary>
  135. /// <param name="colors">
  136. /// Pixels to assign to the specified mip level. Size of the array must match the mip level dimensions. Data is expected
  137. /// to be laid out row by row. Pixels will be automatically converted to the valid pixel format.
  138. /// </param>
  139. /// <param name="mipLevel">Mip level to set pixels for. Top level (0) is the highest quality.</param>
  140. /// <param name="face">
  141. /// Face to write the pixels to. Cubemap textures have six faces whose face indices are as specified in the CubeFace
  142. /// enum. Array textures can have an arbitrary number of faces (if it's a cubemap array it has to be a multiple of 6).
  143. /// </param>
  144. public void SetPixels(Color[] colors, uint face = 0, uint mipLevel = 0)
  145. {
  146. Internal_setPixelsArray(mCachedPtr, colors, face, mipLevel);
  147. }
  148. [MethodImpl(MethodImplOptions.InternalCall)]
  149. private static extern RRef<Texture> Internal_GetRef(IntPtr thisPtr);
  150. [MethodImpl(MethodImplOptions.InternalCall)]
  151. private static extern void Internal_create(Texture managedInstance, PixelFormat format, uint width, uint height, uint depth, TextureType texType, TextureUsage usage, uint numSamples, bool hasMipmaps, bool gammaCorrection);
  152. [MethodImpl(MethodImplOptions.InternalCall)]
  153. private static extern PixelFormat Internal_getPixelFormat(IntPtr thisPtr);
  154. [MethodImpl(MethodImplOptions.InternalCall)]
  155. private static extern TextureUsage Internal_getUsage(IntPtr thisPtr);
  156. [MethodImpl(MethodImplOptions.InternalCall)]
  157. private static extern TextureType Internal_getType(IntPtr thisPtr);
  158. [MethodImpl(MethodImplOptions.InternalCall)]
  159. private static extern uint Internal_getWidth(IntPtr thisPtr);
  160. [MethodImpl(MethodImplOptions.InternalCall)]
  161. private static extern uint Internal_getHeight(IntPtr thisPtr);
  162. [MethodImpl(MethodImplOptions.InternalCall)]
  163. private static extern uint Internal_getDepth(IntPtr thisPtr);
  164. [MethodImpl(MethodImplOptions.InternalCall)]
  165. private static extern bool Internal_getGammaCorrection(IntPtr thisPtr);
  166. [MethodImpl(MethodImplOptions.InternalCall)]
  167. private static extern uint Internal_getSampleCount(IntPtr thisPtr);
  168. [MethodImpl(MethodImplOptions.InternalCall)]
  169. private static extern uint Internal_getMipmapCount(IntPtr thisPtr);
  170. [MethodImpl(MethodImplOptions.InternalCall)]
  171. private static extern PixelData Internal_getPixels(IntPtr thisPtr, uint face, uint mipLevel);
  172. [MethodImpl(MethodImplOptions.InternalCall)]
  173. private static extern AsyncOp Internal_getGPUPixels(IntPtr thisPtr, uint face, uint mipLevel);
  174. [MethodImpl(MethodImplOptions.InternalCall)]
  175. private static extern void Internal_setPixels(IntPtr thisPtr, PixelData data, uint face, uint mipLevel);
  176. [MethodImpl(MethodImplOptions.InternalCall)]
  177. private static extern void Internal_setPixelsArray(IntPtr thisPtr, Color[] colors, uint face, uint mipLevel);
  178. }
  179. /** @} */
  180. }