Texture.cs 5.1 KB

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