D3D9Texture.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // Copyright (c) 2008-2015 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../../Graphics/GPUObject.h"
  24. #include "../../Graphics/GraphicsDefs.h"
  25. #include "../../Math/Color.h"
  26. #include "../../Resource/Resource.h"
  27. namespace Atomic
  28. {
  29. static const int MAX_TEXTURE_QUALITY_LEVELS = 3;
  30. class XMLElement;
  31. class XMLFile;
  32. /// Base class for texture resources.
  33. class ATOMIC_API Texture : public Resource, public GPUObject
  34. {
  35. public:
  36. /// Construct.
  37. Texture(Context* context);
  38. /// Destruct.
  39. virtual ~Texture();
  40. /// Set number of requested mip levels. Needs to be called before setting size.
  41. void SetNumLevels(unsigned levels);
  42. /// Set filtering mode.
  43. void SetFilterMode(TextureFilterMode filter);
  44. /// Set addressing mode by texture coordinate.
  45. void SetAddressMode(TextureCoordinate coord, TextureAddressMode address);
  46. /// Set shadow compare mode. No-op on D3D9.
  47. void SetShadowCompare(bool enable) { }
  48. /// Set border color for border addressing mode.
  49. void SetBorderColor(const Color& color);
  50. /// Set sRGB sampling and writing mode.
  51. void SetSRGB(bool enable);
  52. /// Set backup texture to use when rendering to this texture.
  53. void SetBackupTexture(Texture* texture);
  54. /// Set mip levels to skip on a quality setting when loading. Ensures higher quality levels do not skip more.
  55. void SetMipsToSkip(int quality, int mips);
  56. /// Return texture format.
  57. unsigned GetFormat() const { return format_; }
  58. /// Return whether the texture format is compressed.
  59. bool IsCompressed() const;
  60. /// Return number of mip levels.
  61. unsigned GetLevels() const { return levels_; }
  62. /// Return width.
  63. int GetWidth() const { return width_; }
  64. /// Return height.
  65. int GetHeight() const { return height_; }
  66. /// Return height.
  67. int GetDepth() const { return depth_; }
  68. /// Return filtering mode.
  69. TextureFilterMode GetFilterMode() const { return filterMode_; }
  70. /// Return addressing mode by texture coordinate.
  71. TextureAddressMode GetAddressMode(TextureCoordinate coord) const { return addressMode_[coord]; }
  72. /// Return whether shadow compare is enabled. Always false on D3D9.
  73. bool GetShadowCompare() const { return false; }
  74. /// Return border color.
  75. const Color& GetBorderColor() const { return borderColor_; }
  76. /// Return whether is using sRGB sampling and writing.
  77. bool GetSRGB() const { return sRGB_; }
  78. /// Return backup texture.
  79. Texture* GetBackupTexture() const { return backupTexture_; }
  80. /// Return mip levels to skip on a quality setting when loading.
  81. int GetMipsToSkip(int quality) const;
  82. /// Return mip level width, or 0 if level does not exist.
  83. int GetLevelWidth(unsigned level) const;
  84. /// Return mip level width, or 0 if level does not exist.
  85. int GetLevelHeight(unsigned level) const;
  86. /// Return mip level depth, or 0 if level does not exist.
  87. int GetLevelDepth(unsigned level) const;
  88. /// Return texture usage type.
  89. TextureUsage GetUsage() const;
  90. /// Return data size in bytes for a rectangular region.
  91. unsigned GetDataSize(int width, int height) const;
  92. /// Return data size in bytes for a volume region.
  93. unsigned GetDataSize(int width, int height, int depth) const;
  94. /// Return data size in bytes for a pixel or block row.
  95. unsigned GetRowDataSize(int width) const;
  96. /// Return number of image components required to receive pixel data from GetData(), or 0 for compressed images.
  97. unsigned GetComponents() const;
  98. /// Set additional parameters from an XML file.
  99. void SetParameters(XMLFile* xml);
  100. /// Set additional parameters from an XML element.
  101. void SetParameters(const XMLElement& element);
  102. protected:
  103. /// Check whether texture memory budget has been exceeded. Free unused materials in that case to release the texture references.
  104. void CheckTextureBudget(StringHash type);
  105. /// Texture format.
  106. unsigned format_;
  107. /// Memory pool.
  108. unsigned pool_;
  109. /// Texture usage type.
  110. unsigned usage_;
  111. /// Current mip levels.
  112. unsigned levels_;
  113. /// Requested mip levels.
  114. unsigned requestedLevels_;
  115. /// Texture width.
  116. int width_;
  117. /// Texture height.
  118. int height_;
  119. /// Texture depth.
  120. int depth_;
  121. /// Filtering mode.
  122. TextureFilterMode filterMode_;
  123. /// Addressing mode.
  124. TextureAddressMode addressMode_[MAX_COORDS];
  125. /// Mip levels to skip when loading per texture quality setting.
  126. unsigned mipsToSkip_[MAX_TEXTURE_QUALITY_LEVELS];
  127. /// Border color.
  128. Color borderColor_;
  129. /// sRGB sampling and writing mode flag.
  130. bool sRGB_;
  131. /// Backup texture.
  132. SharedPtr<Texture> backupTexture_;
  133. };
  134. }