CmTextureData.h 2.8 KB

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