BsTextureEx.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEnginePrerequisites.h"
  5. #include "Wrappers/BsScriptResource.h"
  6. #include "Image/BsPixelData.h"
  7. #include "Image/BsTexture.h"
  8. namespace bs
  9. {
  10. class AsyncOpEx;
  11. /** @addtogroup ScriptInteropEngine
  12. * @{
  13. */
  14. /** @cond SCRIPT_EXTENSIONS */
  15. /** Extension class for Texture, for adding additional functionality for the script version of PixelData. */
  16. class BS_SCRIPT_EXPORT(e:Texture) TextureEx
  17. {
  18. public:
  19. BS_SCRIPT_EXPORT(ec:Texture,v:private)
  20. static HTexture create(PixelFormat format, UINT32 width, UINT32 height, UINT32 depth, TextureType texType,
  21. TextureUsage usage, UINT32 numSamples, bool hasMipmaps, bool gammaCorrection);
  22. /** @copydoc TextureProperties::getFormat */
  23. BS_SCRIPT_EXPORT(e:Texture,n:PixelFormat,pr:getter)
  24. static PixelFormat getPixelFormat(const HTexture& thisPtr);
  25. /** @copydoc TextureProperties::getUsage */
  26. BS_SCRIPT_EXPORT(e:Texture,n:Usage,pr:getter)
  27. static TextureUsage getUsage(const HTexture& thisPtr);
  28. /** @copydoc TextureProperties::getTextureType */
  29. BS_SCRIPT_EXPORT(e:Texture,n:Type,pr:getter)
  30. static TextureType getType(const HTexture& thisPtr);
  31. /** @copydoc TextureProperties::getWidth */
  32. BS_SCRIPT_EXPORT(e:Texture,n:Width,pr:getter)
  33. static UINT32 getWidth(const HTexture& thisPtr);
  34. /** @copydoc TextureProperties::getHeight */
  35. BS_SCRIPT_EXPORT(e:Texture,n:Height,pr:getter)
  36. static UINT32 getHeight(const HTexture& thisPtr);
  37. /** @copydoc TextureProperties::getDepth */
  38. BS_SCRIPT_EXPORT(e:Texture,n:Depth,pr:getter)
  39. static UINT32 getDepth(const HTexture& thisPtr);
  40. /** @copydoc TextureProperties::isHardwareGammaEnabled */
  41. BS_SCRIPT_EXPORT(e:Texture,n:GammaSpace,pr:getter)
  42. static bool getGammaCorrection(const HTexture& thisPtr);
  43. /** @copydoc TextureProperties::getNumSamples */
  44. BS_SCRIPT_EXPORT(e:Texture,n:SampleCount,pr:getter)
  45. static UINT32 getSampleCount(const HTexture& thisPtr);
  46. /** @copydoc TextureProperties::getNumMipmaps */
  47. BS_SCRIPT_EXPORT(e:Texture,n:MipMapCount,pr:getter)
  48. static UINT32 getMipmapCount(const HTexture& thisPtr);
  49. /**
  50. * Returns pixels for the specified mip level & face. Pixels will be read from system memory, which means the
  51. * texture has to be created with TextureUsage.CPUCached. If the texture was updated from the GPU the
  52. * pixels retrieved from this method will not reflect that, and you should use GetGPUPixels instead.
  53. *
  54. * @param mipLevel Mip level to retrieve pixels for. Top level (0) is the highest quality.
  55. * @param face Face to read the pixels from. Cubemap textures have six faces whose face indices are as
  56. * specified in the CubeFace enum. Array textures can have an arbitrary number of faces (if it's a
  57. * cubemap array it has to be a multiple of 6).
  58. * @return A set of pixels for the specified mip level.
  59. */
  60. BS_SCRIPT_EXPORT(e:Texture,n:GetPixels)
  61. static SPtr<PixelData> getPixels(const HTexture& thisPtr, UINT32 face = 0, UINT32 mipLevel = 0);
  62. /**
  63. * Reads texture pixels directly from the GPU. This is similar to GetPixels" but the texture doesn't
  64. * need to be created with TextureUsage.CPUCached, and the data will contain any updates performed by
  65. * the GPU. This method can be potentially slow as it introduces a CPU-GPU synchronization point. Additionally
  66. * this method is asynchronous which means the data is not available immediately.
  67. *
  68. * @param mipLevel Mip level to retrieve pixels for. Top level (0) is the highest quality.
  69. * @param face Face to read the pixels from. Cubemap textures have six faces whose face indices are as
  70. * specified in the CubeFace enum. Array textures can have an arbitrary number of faces (if it's a
  71. * cubemap array it has to be a multiple of 6).
  72. * @return AsyncOp object that will contain a PixelData object when the operation completes.
  73. */
  74. BS_SCRIPT_EXPORT(e:Texture,n:GetGPUPixels)
  75. static SPtr<AsyncOpEx> getGPUPixels(const HTexture& thisPtr, UINT32 face = 0, UINT32 mipLevel = 0);
  76. /**
  77. * Sets pixels for the specified mip level and face.
  78. *
  79. * @param data Pixels to assign to the specified mip level. Pixel data must match the mip level size and
  80. * texture pixel format.
  81. * @param mipLevel Mip level to set pixels for. Top level (0) is the highest quality.
  82. * @param face Face to write the pixels to. Cubemap textures have six faces whose face indices are as
  83. * specified in the CubeFace enum. Array textures can have an arbitrary number of faces (if it's a
  84. * cubemap array it has to be a multiple of 6).
  85. */
  86. BS_SCRIPT_EXPORT(e:Texture,n:SetPixels)
  87. static void setPixels(const HTexture& thisPtr, const SPtr<PixelData>& data, UINT32 face = 0, UINT32 mipLevel = 0);
  88. /**
  89. * Sets pixels for the specified mip level and face.
  90. *
  91. * @param colors Pixels to assign to the specified mip level. Size of the array must match the mip level
  92. * dimensions. Data is expected to be laid out row by row. Pixels will be automatically
  93. * converted to the valid pixel format.
  94. * @param mipLevel Mip level to set pixels for. Top level (0) is the highest quality.
  95. * @param face Face to write the pixels to. Cubemap textures have six faces whose face indices are as
  96. * specified in the CubeFace enum. Array textures can have an arbitrary number of faces (if it's a
  97. * cubemap array it has to be a multiple of 6).
  98. */
  99. BS_SCRIPT_EXPORT(e:Texture,n:SetPixels)
  100. static void setPixelsArray(const HTexture& thisPtr, const Vector<Color>& colors, UINT32 face = 0, UINT32 mipLevel = 0);
  101. };
  102. /** @endcond */
  103. /** @} */
  104. }