D3D9Texture.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. OBJECT(Texture)
  36. BASEOBJECT(Resource)
  37. public:
  38. /// Construct.
  39. Texture(Context* context);
  40. /// Destruct.
  41. virtual ~Texture();
  42. /// Set number of requested mip levels. Needs to be called before setting size.
  43. void SetNumLevels(unsigned levels);
  44. /// Set filtering mode.
  45. void SetFilterMode(TextureFilterMode filter);
  46. /// Set addressing mode by texture coordinate.
  47. void SetAddressMode(TextureCoordinate coord, TextureAddressMode address);
  48. /// Set shadow compare mode. No-op on D3D9.
  49. void SetShadowCompare(bool enable) { }
  50. /// Set border color for border addressing mode.
  51. void SetBorderColor(const Color& color);
  52. /// Set sRGB sampling and writing mode.
  53. void SetSRGB(bool enable);
  54. /// Set backup texture to use when rendering to this texture.
  55. void SetBackupTexture(Texture* texture);
  56. /// Set mip levels to skip on a quality setting when loading. Ensures higher quality levels do not skip more.
  57. void SetMipsToSkip(int quality, int mips);
  58. /// Return texture format.
  59. unsigned GetFormat() const { return format_; }
  60. /// Return whether the texture format is compressed.
  61. bool IsCompressed() const;
  62. /// Return number of mip levels.
  63. unsigned GetLevels() const { return levels_; }
  64. /// Return width.
  65. int GetWidth() const { return width_; }
  66. /// Return height.
  67. int GetHeight() const { return height_; }
  68. /// Return height.
  69. int GetDepth() const { return depth_; }
  70. /// Return filtering mode.
  71. TextureFilterMode GetFilterMode() const { return filterMode_; }
  72. /// Return addressing mode by texture coordinate.
  73. TextureAddressMode GetAddressMode(TextureCoordinate coord) const { return addressMode_[coord]; }
  74. /// Return whether shadow compare is enabled. Always false on D3D9.
  75. bool GetShadowCompare() const { return false; }
  76. /// Return border color.
  77. const Color& GetBorderColor() const { return borderColor_; }
  78. /// Return whether is using sRGB sampling and writing.
  79. bool GetSRGB() const { return sRGB_; }
  80. /// Return backup texture.
  81. Texture* GetBackupTexture() const { return backupTexture_; }
  82. /// Return mip levels to skip on a quality setting when loading.
  83. int GetMipsToSkip(int quality) const;
  84. /// Return mip level width, or 0 if level does not exist.
  85. int GetLevelWidth(unsigned level) const;
  86. /// Return mip level width, or 0 if level does not exist.
  87. int GetLevelHeight(unsigned level) const;
  88. /// Return mip level depth, or 0 if level does not exist.
  89. int GetLevelDepth(unsigned level) const;
  90. /// Return texture usage type.
  91. TextureUsage GetUsage() const;
  92. /// Return data size in bytes for a rectangular region.
  93. unsigned GetDataSize(int width, int height) const;
  94. /// Return data size in bytes for a volume region.
  95. unsigned GetDataSize(int width, int height, int depth) const;
  96. /// Return data size in bytes for a pixel or block row.
  97. unsigned GetRowDataSize(int width) const;
  98. /// Return number of image components required to receive pixel data from GetData(), or 0 for compressed images.
  99. unsigned GetComponents() const;
  100. /// Set additional parameters from an XML file.
  101. void SetParameters(XMLFile* xml);
  102. /// Set additional parameters from an XML element.
  103. void SetParameters(const XMLElement& element);
  104. protected:
  105. /// Check whether texture memory budget has been exceeded. Free unused materials in that case to release the texture references.
  106. void CheckTextureBudget(StringHash type);
  107. /// Texture format.
  108. unsigned format_;
  109. /// Memory pool.
  110. unsigned pool_;
  111. /// Texture usage type.
  112. unsigned usage_;
  113. /// Current mip levels.
  114. unsigned levels_;
  115. /// Requested mip levels.
  116. unsigned requestedLevels_;
  117. /// Texture width.
  118. int width_;
  119. /// Texture height.
  120. int height_;
  121. /// Texture depth.
  122. int depth_;
  123. /// Filtering mode.
  124. TextureFilterMode filterMode_;
  125. /// Addressing mode.
  126. TextureAddressMode addressMode_[MAX_COORDS];
  127. /// Mip levels to skip when loading per texture quality setting.
  128. unsigned mipsToSkip_[MAX_TEXTURE_QUALITY_LEVELS];
  129. /// Border color.
  130. Color borderColor_;
  131. /// sRGB sampling and writing mode flag.
  132. bool sRGB_;
  133. /// Backup texture.
  134. SharedPtr<Texture> backupTexture_;
  135. };
  136. }