Texture.generated.cs 8.5 KB

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