BsTextureData.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #pragma once
  2. #include "BsFreeImgPrerequisites.h"
  3. #include "BsPixelUtil.h"
  4. namespace BansheeEngine
  5. {
  6. enum TextureDataFlags
  7. {
  8. TDF_COMPRESSED = 0x00000001,
  9. TDF_CUBEMAP = 0x00000002,
  10. TDF_3D_TEXTURE = 0x00000004
  11. };
  12. class BS_FREEIMG_EXPORT TextureData
  13. {
  14. public:
  15. TextureData(UINT32 width, UINT32 height, UINT32 size,
  16. PixelFormat format, UINT32 depth = 1, INT32 flags = 0, UINT32 numMipmaps = 1);
  17. ~TextureData();
  18. /** Returns a pointer to the internal image buffer.
  19. @remarks
  20. Be careful with this method. You will almost certainly
  21. prefer to use getPixels, especially with complex images
  22. which include custom mipmaps.
  23. */
  24. UINT8* getData(void) { return mData; }
  25. /** Returns a const pointer to the internal image buffer.
  26. @remarks
  27. Be careful with this method. You will almost certainly
  28. prefer to use getPixels, especially with complex images
  29. which include custom mipmaps.
  30. */
  31. const UINT8* getData() const { return mData; }
  32. /** Returns the size of the data buffer.
  33. */
  34. UINT32 getSize() const { return mSize; }
  35. /** Returns the number of mipmaps contained in the image.
  36. */
  37. UINT32 getNumMipmaps() const { return mNumMipmaps; }
  38. /** Returns true if the image has the appropriate flag set.
  39. */
  40. bool hasFlag(const TextureDataFlags flag) const { return (mFlags & flag) != 0; }
  41. /** Gets the width of the image in pixels.
  42. */
  43. UINT32 getWidth(void) const { return mWidth; }
  44. /** Gets the height of the image in pixels.
  45. */
  46. UINT32 getHeight(void) const { return mHeight; }
  47. /** Gets the depth of the image.
  48. */
  49. UINT32 getDepth(void) const { return mDepth; }
  50. /** Returns the image format.
  51. */
  52. PixelFormat getFormat() const { return mFormat; }
  53. /** Returns the number of bits per pixel.
  54. */
  55. UINT8 getBPP() const { return mBPP; }
  56. /** Returns true if the image has an alpha component.
  57. */
  58. bool getHasAlpha() const { return PixelUtil::getFlags(mFormat) & PFF_HASALPHA; }
  59. void getPixels(UINT32 mip, PixelData& output);
  60. private:
  61. UINT32 mNumMipmaps;
  62. UINT32 mWidth;
  63. UINT32 mHeight;
  64. UINT32 mSize;
  65. UINT32 mDepth;
  66. INT32 mFlags;
  67. UINT8 mBPP;
  68. PixelFormat mFormat;
  69. UINT8* mData;
  70. };
  71. }