D3D9Texture.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "Color.h"
  25. #include "GPUObject.h"
  26. #include "Image.h"
  27. #include "GraphicsDefs.h"
  28. #include "Resource.h"
  29. static const int MAX_TEXTURE_QUALITY_LEVELS = 3;
  30. class XMLElement;
  31. class XMLFile;
  32. /// Base class for texture resources.
  33. class 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 border color for border addressing mode.
  47. void SetBorderColor(const Color& color);
  48. /// %Set backup texture to use when rendering to this texture.
  49. void SetBackupTexture(Texture* texture);
  50. /// Clear default pool data lost flag.
  51. void ClearDataLost();
  52. /// Return texture format.
  53. unsigned GetFormat() const { return format_; }
  54. /// Return number of mip levels.
  55. unsigned GetLevels() const { return levels_; }
  56. /// Return width.
  57. int GetWidth() const { return width_; }
  58. /// Return height.
  59. int GetHeight() const { return height_; }
  60. /// Return whether default pool data is lost.
  61. bool IsDataLost() const { return dataLost_; }
  62. /// Return filtering mode.
  63. TextureFilterMode GetFilterMode() const { return filterMode_; }
  64. /// Return addressing mode by texture coordinate.
  65. TextureAddressMode GetAddressMode(TextureCoordinate coord) const { return addressMode_[coord]; }
  66. /// Return border color.
  67. const Color& GetBorderColor() const { return borderColor_; }
  68. /// Return backup texture.
  69. Texture* GetBackupTexture() const { return backupTexture_; }
  70. /// Return mip level width, or 0 if level does not exist.
  71. int GetLevelWidth(unsigned level) const;
  72. /// Return mip level width, or 0 if level does not exist.
  73. int GetLevelHeight(unsigned level) const;
  74. /// Return texture usage type.
  75. TextureUsage GetUsage() const;
  76. /// Return data size in bytes for a rectangular region.
  77. unsigned GetDataSize(int width, int height) const;
  78. /// Return data size in bytes for a pixel or block row.
  79. unsigned GetRowDataSize(int width) const;
  80. /// Return API-specific DXT compressed texture format.
  81. static unsigned GetDXTFormat(CompressedFormat format);
  82. /// Load parameters.
  83. void LoadParameters();
  84. /// Load parameters from an XML file.
  85. void LoadParameters(XMLFile* xml);
  86. /// Load parameters from an XML element.
  87. void LoadParameters(const XMLElement& elem);
  88. protected:
  89. /// Check whether texture memory budget has been exceeded. Free unused materials in that case to release the texture references.
  90. void CheckTextureBudget(ShortStringHash type);
  91. /// Texture format.
  92. unsigned format_;
  93. /// Memory pool.
  94. unsigned pool_;
  95. /// Texture usage type.
  96. unsigned usage_;
  97. /// Current mip levels.
  98. unsigned levels_;
  99. /// Requested mip levels.
  100. unsigned requestedLevels_;
  101. /// Texture width.
  102. int width_;
  103. /// Texture height.
  104. int height_;
  105. /// Default pool data lost flag.
  106. bool dataLost_;
  107. /// Filtering mode.
  108. TextureFilterMode filterMode_;
  109. /// Addressing mode.
  110. TextureAddressMode addressMode_[MAX_COORDS];
  111. /// Mipmaps to skip when loading.
  112. unsigned mipsToSkip_[MAX_TEXTURE_QUALITY_LEVELS];
  113. /// Border color.
  114. Color borderColor_;
  115. /// Backup texture.
  116. SharedPtr<Texture> backupTexture_;
  117. };