D3D9Texture.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // Copyright (c) 2008-2020 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. #include "../../Precompiled.h"
  23. #include "../../Core/StringUtils.h"
  24. #include "../../Graphics/Graphics.h"
  25. #include "../../Graphics/GraphicsImpl.h"
  26. #include "../../Graphics/Material.h"
  27. #include "../../IO/FileSystem.h"
  28. #include "../../Resource/ResourceCache.h"
  29. #include "../../Resource/XMLFile.h"
  30. #include "../../DebugNew.h"
  31. namespace Urho3D
  32. {
  33. void Texture::SetSRGB(bool enable)
  34. {
  35. if (graphics_)
  36. enable &= graphics_->GetSRGBSupport();
  37. sRGB_ = enable;
  38. }
  39. void Texture::UpdateParameters()
  40. {
  41. // No-op on Direct3D9, handled by Graphics instead by modifying the sampler settings as necessary
  42. }
  43. bool Texture::GetParametersDirty() const
  44. {
  45. return false;
  46. }
  47. bool Texture::IsCompressed() const
  48. {
  49. return format_ == D3DFMT_DXT1 || format_ == D3DFMT_DXT3 || format_ == D3DFMT_DXT5;
  50. }
  51. unsigned Texture::GetRowDataSize(int width) const
  52. {
  53. switch (format_)
  54. {
  55. case D3DFMT_A8:
  56. case D3DFMT_L8:
  57. return (unsigned)width;
  58. case D3DFMT_D16:
  59. case D3DFMT_R5G6B5:
  60. case D3DFMT_A4R4G4B4:
  61. case D3DFMT_A8L8:
  62. case D3DFMT_R16F:
  63. return (unsigned)(width * 2);
  64. case D3DFMT_X8R8G8B8:
  65. // Note: here source and destination data size differ
  66. return (unsigned)(width * 3);
  67. case D3DFMT_A8R8G8B8:
  68. case D3DFMT_G16R16:
  69. case D3DFMT_R32F:
  70. case D3DFMT_G16R16F:
  71. case D3DFMT_D24S8:
  72. case D3DFMT_D32:
  73. return (unsigned)(width * 4);
  74. case D3DFMT_A16B16G16R16:
  75. case D3DFMT_A16B16G16R16F:
  76. return (unsigned)(width * 8);
  77. case D3DFMT_A32B32G32R32F:
  78. return (unsigned)(width * 16);
  79. case D3DFMT_DXT1:
  80. return (unsigned)(((width + 3) >> 2) * 8);
  81. case D3DFMT_DXT3:
  82. case D3DFMT_DXT5:
  83. return (unsigned)(((width + 3) >> 2) * 16);
  84. default:
  85. return 0;
  86. }
  87. }
  88. void Texture::RegenerateLevels()
  89. {
  90. // No-op on Direct3D9
  91. levelsDirty_ = false;
  92. }
  93. }