OgreTextureManager.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  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. */
  24. #include "OgreTextureManager.h"
  25. #include "OgreException.h"
  26. #include "OgrePixelFormat.h"
  27. namespace Ogre {
  28. //-----------------------------------------------------------------------
  29. template<> TextureManager* Singleton<TextureManager>::ms_Singleton = 0;
  30. TextureManager* TextureManager::getSingletonPtr(void)
  31. {
  32. return ms_Singleton;
  33. }
  34. TextureManager& TextureManager::getSingleton(void)
  35. {
  36. assert( ms_Singleton ); return ( *ms_Singleton );
  37. }
  38. //-----------------------------------------------------------------------
  39. TextureManager::TextureManager(void)
  40. : mPreferredIntegerBitDepth(0)
  41. , mPreferredFloatBitDepth(0)
  42. , mDefaultNumMipmaps(MIP_UNLIMITED)
  43. {
  44. // Subclasses should register (when this is fully constructed)
  45. }
  46. //-----------------------------------------------------------------------
  47. TextureManager::~TextureManager()
  48. {
  49. // subclasses should unregister with resource group manager
  50. }
  51. //-----------------------------------------------------------------------
  52. TexturePtr TextureManager::create(TextureType texType, uint width, uint height, uint depth, int numMipmaps,
  53. PixelFormat format, int usage, bool hwGamma,
  54. uint fsaa, const String& fsaaHint)
  55. {
  56. TexturePtr ret = TexturePtr(createImpl());
  57. ret->setTextureType(texType);
  58. ret->setWidth(width);
  59. ret->setHeight(height);
  60. ret->setDepth(depth);
  61. ret->setNumMipmaps((numMipmaps == MIP_DEFAULT)? mDefaultNumMipmaps :
  62. static_cast<size_t>(numMipmaps));
  63. ret->setFormat(format);
  64. ret->setUsage(usage);
  65. ret->setHardwareGammaEnabled(hwGamma);
  66. ret->setFSAA(fsaa, fsaaHint);
  67. ret->createInternalResources();
  68. return ret;
  69. }
  70. //-----------------------------------------------------------------------
  71. void TextureManager::setPreferredIntegerBitDepth(ushort bits)
  72. {
  73. mPreferredIntegerBitDepth = bits;
  74. }
  75. //-----------------------------------------------------------------------
  76. ushort TextureManager::getPreferredIntegerBitDepth(void) const
  77. {
  78. return mPreferredIntegerBitDepth;
  79. }
  80. //-----------------------------------------------------------------------
  81. void TextureManager::setPreferredFloatBitDepth(ushort bits)
  82. {
  83. mPreferredFloatBitDepth = bits;
  84. }
  85. //-----------------------------------------------------------------------
  86. ushort TextureManager::getPreferredFloatBitDepth(void) const
  87. {
  88. return mPreferredFloatBitDepth;
  89. }
  90. //-----------------------------------------------------------------------
  91. void TextureManager::setPreferredBitDepths(ushort integerBits, ushort floatBits)
  92. {
  93. mPreferredIntegerBitDepth = integerBits;
  94. mPreferredFloatBitDepth = floatBits;
  95. }
  96. //-----------------------------------------------------------------------
  97. void TextureManager::setDefaultNumMipmaps( size_t num )
  98. {
  99. mDefaultNumMipmaps = num;
  100. }
  101. //-----------------------------------------------------------------------
  102. bool TextureManager::isFormatSupported(TextureType ttype, PixelFormat format, int usage)
  103. {
  104. return getNativeFormat(ttype, format, usage) == format;
  105. }
  106. //-----------------------------------------------------------------------
  107. bool TextureManager::isEquivalentFormatSupported(TextureType ttype, PixelFormat format, int usage)
  108. {
  109. PixelFormat supportedFormat = getNativeFormat(ttype, format, usage);
  110. // Assume that same or greater number of bits means quality not degraded
  111. return PixelUtil::getNumElemBits(supportedFormat) >= PixelUtil::getNumElemBits(format);
  112. }
  113. }