Texture.generated.cs 8.0 KB

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