OgreTexture.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 "OgreHardwarePixelBuffer.h"
  25. #include "OgreTexture.h"
  26. #include "OgreException.h"
  27. namespace CamelotEngine {
  28. //--------------------------------------------------------------------------
  29. Texture::Texture()
  30. : // init defaults; can be overridden before load()
  31. mHeight(512),
  32. mWidth(512),
  33. mDepth(1),
  34. mNumRequestedMipmaps(0),
  35. mNumMipmaps(0),
  36. mMipmapsHardwareGenerated(false),
  37. mGamma(1.0f),
  38. mHwGamma(false),
  39. mFSAA(0),
  40. mTextureType(TEX_TYPE_2D),
  41. mFormat(PF_UNKNOWN),
  42. mUsage(TU_DEFAULT),
  43. mSrcFormat(PF_UNKNOWN),
  44. mSrcWidth(0),
  45. mSrcHeight(0),
  46. mSrcDepth(0),
  47. mDesiredFormat(PF_UNKNOWN),
  48. mDesiredIntegerBitDepth(0),
  49. mDesiredFloatBitDepth(0),
  50. mInternalResourcesCreated(false)
  51. {
  52. }
  53. //--------------------------------------------------------------------------
  54. void Texture::setFormat(PixelFormat pf)
  55. {
  56. mFormat = pf;
  57. mDesiredFormat = pf;
  58. mSrcFormat = pf;
  59. }
  60. //--------------------------------------------------------------------------
  61. bool Texture::hasAlpha(void) const
  62. {
  63. return PixelUtil::hasAlpha(mFormat);
  64. }
  65. //--------------------------------------------------------------------------
  66. void Texture::setDesiredIntegerBitDepth(UINT16 bits)
  67. {
  68. mDesiredIntegerBitDepth = bits;
  69. }
  70. //--------------------------------------------------------------------------
  71. UINT16 Texture::getDesiredIntegerBitDepth(void) const
  72. {
  73. return mDesiredIntegerBitDepth;
  74. }
  75. //--------------------------------------------------------------------------
  76. void Texture::setDesiredFloatBitDepth(UINT16 bits)
  77. {
  78. mDesiredFloatBitDepth = bits;
  79. }
  80. //--------------------------------------------------------------------------
  81. UINT16 Texture::getDesiredFloatBitDepth(void) const
  82. {
  83. return mDesiredFloatBitDepth;
  84. }
  85. //--------------------------------------------------------------------------
  86. void Texture::setDesiredBitDepths(UINT16 integerBits, UINT16 floatBits)
  87. {
  88. mDesiredIntegerBitDepth = integerBits;
  89. mDesiredFloatBitDepth = floatBits;
  90. }
  91. //--------------------------------------------------------------------------
  92. size_t Texture::calculateSize(void) const
  93. {
  94. return getNumFaces() * PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat);
  95. }
  96. //--------------------------------------------------------------------------
  97. size_t Texture::getNumFaces(void) const
  98. {
  99. return getTextureType() == TEX_TYPE_CUBE_MAP ? 6 : 1;
  100. }
  101. //-----------------------------------------------------------------------------
  102. void Texture::createInternalResources(void)
  103. {
  104. if (!mInternalResourcesCreated)
  105. {
  106. createInternalResourcesImpl();
  107. mInternalResourcesCreated = true;
  108. }
  109. }
  110. //-----------------------------------------------------------------------------
  111. void Texture::freeInternalResources(void)
  112. {
  113. if (mInternalResourcesCreated)
  114. {
  115. freeInternalResourcesImpl();
  116. mInternalResourcesCreated = false;
  117. }
  118. }
  119. //-----------------------------------------------------------------------------
  120. void Texture::unloadImpl(void)
  121. {
  122. freeInternalResources();
  123. }
  124. //-----------------------------------------------------------------------------
  125. void Texture::copyToTexture( TexturePtr& target )
  126. {
  127. if(target->getNumFaces() != getNumFaces())
  128. {
  129. OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
  130. "Texture types must match",
  131. "Texture::copyToTexture");
  132. }
  133. size_t numMips = std::min(getNumMipmaps(), target->getNumMipmaps());
  134. if((mUsage & TU_AUTOMIPMAP) || (target->getUsage()&TU_AUTOMIPMAP))
  135. numMips = 0;
  136. for(unsigned int face=0; face<getNumFaces(); face++)
  137. {
  138. for(unsigned int mip=0; mip<=numMips; mip++)
  139. {
  140. target->getBuffer(face, mip)->blit(getBuffer(face, mip));
  141. }
  142. }
  143. }
  144. //---------------------------------------------------------------------
  145. String Texture::getSourceFileType() const
  146. {
  147. // TODO PORT - This requires Resource specific stuff I don't have
  148. return StringUtil::BLANK;
  149. }
  150. }