/* ----------------------------------------------------------------------------- This source file is part of OGRE (Object-oriented Graphics Rendering Engine) For the latest info, see http://www.ogre3d.org/ Copyright (c) 2000-2011 Torus Knot Software Ltd Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ----------------------------------------------------------------------------- */ #include "OgreTextureManager.h" #include "OgreException.h" #include "OgrePixelFormat.h" namespace Ogre { //----------------------------------------------------------------------- template<> TextureManager* Singleton::ms_Singleton = 0; TextureManager* TextureManager::getSingletonPtr(void) { return ms_Singleton; } TextureManager& TextureManager::getSingleton(void) { assert( ms_Singleton ); return ( *ms_Singleton ); } //----------------------------------------------------------------------- TextureManager::TextureManager(void) : mPreferredIntegerBitDepth(0) , mPreferredFloatBitDepth(0) , mDefaultNumMipmaps(MIP_UNLIMITED) { // Subclasses should register (when this is fully constructed) } //----------------------------------------------------------------------- TextureManager::~TextureManager() { // subclasses should unregister with resource group manager } //----------------------------------------------------------------------- TexturePtr TextureManager::create(TextureType texType, uint width, uint height, uint depth, int numMipmaps, PixelFormat format, int usage, bool hwGamma, uint fsaa, const String& fsaaHint) { TexturePtr ret = TexturePtr(createImpl()); ret->setTextureType(texType); ret->setWidth(width); ret->setHeight(height); ret->setDepth(depth); ret->setNumMipmaps((numMipmaps == MIP_DEFAULT)? mDefaultNumMipmaps : static_cast(numMipmaps)); ret->setFormat(format); ret->setUsage(usage); ret->setHardwareGammaEnabled(hwGamma); ret->setFSAA(fsaa, fsaaHint); ret->createInternalResources(); return ret; } //----------------------------------------------------------------------- void TextureManager::setPreferredIntegerBitDepth(ushort bits) { mPreferredIntegerBitDepth = bits; } //----------------------------------------------------------------------- ushort TextureManager::getPreferredIntegerBitDepth(void) const { return mPreferredIntegerBitDepth; } //----------------------------------------------------------------------- void TextureManager::setPreferredFloatBitDepth(ushort bits) { mPreferredFloatBitDepth = bits; } //----------------------------------------------------------------------- ushort TextureManager::getPreferredFloatBitDepth(void) const { return mPreferredFloatBitDepth; } //----------------------------------------------------------------------- void TextureManager::setPreferredBitDepths(ushort integerBits, ushort floatBits) { mPreferredIntegerBitDepth = integerBits; mPreferredFloatBitDepth = floatBits; } //----------------------------------------------------------------------- void TextureManager::setDefaultNumMipmaps( size_t num ) { mDefaultNumMipmaps = num; } //----------------------------------------------------------------------- bool TextureManager::isFormatSupported(TextureType ttype, PixelFormat format, int usage) { return getNativeFormat(ttype, format, usage) == format; } //----------------------------------------------------------------------- bool TextureManager::isEquivalentFormatSupported(TextureType ttype, PixelFormat format, int usage) { PixelFormat supportedFormat = getNativeFormat(ttype, format, usage); // Assume that same or greater number of bits means quality not degraded return PixelUtil::getNumElemBits(supportedFormat) >= PixelUtil::getNumElemBits(format); } }