Texture.cs 5.0 KB

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